Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Read all EventGroups from simulators rather than stopping at first page #1927

Merged
merged 1 commit into from
Nov 22, 2024

Conversation

SanjayVas
Copy link
Member

@SanjayVas SanjayVas commented Nov 18, 2024

The MC and EDP simulators were only reading the first page of results from ListEventGroups. This means that in environments with more EventGroups, not all test EventGroups would be read. This is exacerbated by #1916, as the default page size is now smaller.

@wfa-reviewable
Copy link

This change is Reviewable

@SanjayVas
Copy link
Member Author

Depends on #1923

@SanjayVas SanjayVas force-pushed the sanjayvas-test-list-event-groups branch from ac2d7cf to f23d4e4 Compare November 18, 2024 23:05
@SanjayVas SanjayVas changed the title fix: Read all EventGroups from MC simulator rather than stopping at first page fix: Read all EventGroups from simulators rather than stopping at first page Nov 18, 2024
@SanjayVas SanjayVas force-pushed the sanjayvas-test-list-event-groups branch from f23d4e4 to c21917a Compare November 18, 2024 23:15
@SanjayVas SanjayVas force-pushed the sanjayvas-list-resources branch 2 times, most recently from 120f1a2 to ddfb970 Compare November 18, 2024 23:22
Copy link
Collaborator

@stevenwarejones stevenwarejones left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 2 of 6 files at r1, 2 of 14 files at r2, all commit messages.
Reviewable status: 4 of 20 files reviewed, 1 unresolved discussion (waiting on @SanjayVas)


src/main/kotlin/org/wfanet/measurement/common/api/grpc/ListResources.kt line 67 at r2 (raw file):

      val resourceList: ResourceList<T> = list(nextPageToken, remaining)
      require(resourceList.size <= remaining) {

should this really be required here and throw an error? this is a problem with the list that is passed in..... meaning an API that returned too many items. I'd prefer it took only that many elements if there are too many.

Copy link
Member Author

@SanjayVas SanjayVas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: 4 of 20 files reviewed, 1 unresolved discussion (waiting on @stevenwarejones)


src/main/kotlin/org/wfanet/measurement/common/api/grpc/ListResources.kt line 67 at r2 (raw file):

I'd prefer it took only that many elements if there are too many.

That wouldn't work, as the returned next page token wouldn't have the right value to get subsequent items.

@SanjayVas SanjayVas force-pushed the sanjayvas-test-list-event-groups branch from c21917a to 41e3364 Compare November 19, 2024 18:09
Copy link
Member Author

@SanjayVas SanjayVas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: 4 of 20 files reviewed, 1 unresolved discussion (waiting on @stevenwarejones)


src/main/kotlin/org/wfanet/measurement/common/api/grpc/ListResources.kt line 67 at r2 (raw file):

Previously, SanjayVas (Sanjay Vasandani) wrote…

I'd prefer it took only that many elements if there are too many.

That wouldn't work, as the returned next page token wouldn't have the right value to get subsequent items.

Also GitHub got a bit confused and included changes from the base PR. I assume this comment was meant for #1923

@SanjayVas SanjayVas force-pushed the sanjayvas-test-list-event-groups branch from 41e3364 to 8c94407 Compare November 21, 2024 18:27
@SanjayVas SanjayVas force-pushed the sanjayvas-list-resources branch from ddfb970 to ebeeba9 Compare November 21, 2024 18:27
@SanjayVas SanjayVas force-pushed the sanjayvas-test-list-event-groups branch from 8c94407 to 61fb437 Compare November 21, 2024 19:07
@SanjayVas SanjayVas force-pushed the sanjayvas-list-resources branch 2 times, most recently from f761ae0 to 668fa73 Compare November 21, 2024 20:29
@SanjayVas SanjayVas force-pushed the sanjayvas-test-list-event-groups branch from 61fb437 to 81f7ed9 Compare November 21, 2024 20:29
@SanjayVas SanjayVas force-pushed the sanjayvas-list-resources branch from 668fa73 to 929c89a Compare November 21, 2024 20:43
@SanjayVas SanjayVas force-pushed the sanjayvas-test-list-event-groups branch from 81f7ed9 to 673ba6f Compare November 21, 2024 20:43
Copy link
Collaborator

@stevenwarejones stevenwarejones left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 20 of 20 files at r3, all commit messages.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @SanjayVas)


src/main/kotlin/org/wfanet/measurement/loadtest/dataprovider/EdpSimulator.kt line 369 at r3 (raw file):

      }
      .flattenConcat()
      .firstOrNull { it.eventGroupReferenceId == eventGroupReferenceId }

I'd prefer you prefilter instead of unncessarily fetching all event groups.... something like

eturn eventGroupsStub
      .listResources(
          limit = 1
) { pageToken ->
        val response =
          try {
            listEventGroups(
              listEventGroupsRequest {
                parent = edpData.name
                filter =
                  ListEventGroupsRequestKt.filter {
                    measurementConsumers += measurementConsumerName
                  }
                this.pageToken = pageToken
              }
            )
          } catch (e: StatusException) {
            throw Exception("Error listing EventGroups", e)
          }
        ResourceList(
response.eventGroupsList.filter { it.eventGroupReferenceId == eventGroupReferenceId }, 
response.nextPageToken
)
      }
      .flattenConcat()
      

Copy link
Member Author

@SanjayVas SanjayVas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @stevenwarejones)


src/main/kotlin/org/wfanet/measurement/loadtest/dataprovider/EdpSimulator.kt line 369 at r3 (raw file):

Previously, stevenwarejones (Steven Ware Jones) wrote…

I'd prefer you prefilter instead of unncessarily fetching all event groups.... something like

eturn eventGroupsStub
      .listResources(
          limit = 1
) { pageToken ->
        val response =
          try {
            listEventGroups(
              listEventGroupsRequest {
                parent = edpData.name
                filter =
                  ListEventGroupsRequestKt.filter {
                    measurementConsumers += measurementConsumerName
                  }
                this.pageToken = pageToken
              }
            )
          } catch (e: StatusException) {
            throw Exception("Error listing EventGroups", e)
          }
        ResourceList(
response.eventGroupsList.filter { it.eventGroupReferenceId == eventGroupReferenceId }, 
response.nextPageToken
)
      }
      .flattenConcat()

That would be less efficient as it means making a call for one EventGroup at a time rather than batching by the default page size. This will still stop making calls once we get a response that contains the event group.

@SanjayVas SanjayVas force-pushed the sanjayvas-list-resources branch from 929c89a to 6d2017a Compare November 21, 2024 22:35
@SanjayVas SanjayVas force-pushed the sanjayvas-test-list-event-groups branch from 673ba6f to 7f251b2 Compare November 21, 2024 22:35
@SanjayVas SanjayVas force-pushed the sanjayvas-list-resources branch from 6d2017a to e6320aa Compare November 21, 2024 22:45
@SanjayVas SanjayVas force-pushed the sanjayvas-test-list-event-groups branch from 7f251b2 to 4bf8612 Compare November 21, 2024 22:45
@SanjayVas SanjayVas force-pushed the sanjayvas-list-resources branch from e6320aa to 43fef9d Compare November 21, 2024 22:51
@SanjayVas SanjayVas force-pushed the sanjayvas-test-list-event-groups branch from 4bf8612 to e026654 Compare November 21, 2024 22:51
Copy link
Member Author

@SanjayVas SanjayVas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @stevenwarejones)


src/main/kotlin/org/wfanet/measurement/loadtest/dataprovider/EdpSimulator.kt line 369 at r3 (raw file):

Previously, SanjayVas (Sanjay Vasandani) wrote…

That would be less efficient as it means making a call for one EventGroup at a time rather than batching by the default page size. This will still stop making calls once we get a response that contains the event group.

To clarify, what I mean is that the implementation in this PR will already stop making requests once it gets a response that has an EventGroup that has the specified reference ID. This is because Flow.flattenConcat is an intermediate Flow operator analogous to Sequence.flatten.

Your suggestion does not add any benefit and furthermore does not meet the constraint of never returning more items than limit since EventGroup reference IDs are not yet guaranteed to be unique (see #1913). In order to meet that constraint, it would have to pass the remaining value as the pageSize in the request resulting in the non-batching behavior I mentioned.

@SanjayVas SanjayVas force-pushed the sanjayvas-test-list-event-groups branch from e026654 to 7b4e922 Compare November 21, 2024 23:52
@SanjayVas SanjayVas force-pushed the sanjayvas-list-resources branch from 43fef9d to 1391cab Compare November 21, 2024 23:52
Copy link
Collaborator

@stevenwarejones stevenwarejones left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on @SanjayVas)


src/main/kotlin/org/wfanet/measurement/loadtest/dataprovider/EdpSimulator.kt line 369 at r3 (raw file):

Previously, SanjayVas (Sanjay Vasandani) wrote…

To clarify, what I mean is that the implementation in this PR will already stop making requests once it gets a response that has an EventGroup that has the specified reference ID. This is because Flow.flattenConcat is an intermediate Flow operator analogous to Sequence.flatten.

Your suggestion does not add any benefit and furthermore does not meet the constraint of never returning more items than limit since EventGroup reference IDs are not yet guaranteed to be unique (see #1913). In order to meet that constraint, it would have to pass the remaining value as the pageSize in the request resulting in the non-batching behavior I mentioned.

I was not aware that Flow.flattenConcat would end up causing the requests to stop once an event group is found.

However, I think you're misunderstanding what what I suggested... I'm suggesting that the listPredicate itself filter out non-matching resource names. That means that it will always return either 1 or 0 items. If it finds no matches, it returns 0 items. Otherwise, it returns 1. Once once is returned, there is no need to continue. I think this is a little more straightforward. The reader may read your code and make the same assumption I did.

@renjiezh renjiezh merged commit 22c5268 into sanjayvas-list-resources Nov 22, 2024
1 check passed
@renjiezh renjiezh deleted the sanjayvas-test-list-event-groups branch November 22, 2024 17:24
@renjiezh renjiezh restored the sanjayvas-test-list-event-groups branch November 22, 2024 17:29
renjiezh pushed a commit that referenced this pull request Nov 22, 2024
…ion (#1923)

This also fixes an issue where EventGroupsServiceTest was waiting for a
real 30s deadline to pass.
Also fixes the simulator issue of PR
#1927:
The MC and EDP simulators were only reading the first page of results
from ListEventGroups. This means that in environments with more
EventGroups, not all test EventGroups would be read. This is exacerbated
by
#1916,
as the default page size is now smaller.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants