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

refactor: Use separate queries for each bigquery metrics table #1823

Conversation

tristanvuong2021
Copy link
Contributor

@tristanvuong2021 tristanvuong2021 commented Sep 20, 2024

refactor: Use separate queries for each bigquery metrics table

It will be easier to add additional tables this way. StreamRequisitions also had to be refactored to improve the performance to meet the rpc deadline.

@wfa-reviewable
Copy link

This change is Reviewable

@tristanvuong2021 tristanvuong2021 marked this pull request as ready for review September 23, 2024 16:33
Copy link
Member

@kungfucraig kungfucraig 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: 0 of 16 files reviewed, 1 unresolved discussion (waiting on @tristanvuong2021)


src/main/kotlin/org/wfanet/measurement/kingdom/deploy/gcloud/job/OperationalMetricsExport.kt line 279 at r2 (raw file):

  }

  private suspend fun exportRequisitions() {

It seems like there is a lot of copied code from the other function. Can they share some logic? For example, and this is just one example, the code that handles the Measurement Type Case.

Copy link
Contributor Author

@tristanvuong2021 tristanvuong2021 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: 0 of 17 files reviewed, 1 unresolved discussion (waiting on @kungfucraig)


src/main/kotlin/org/wfanet/measurement/kingdom/deploy/gcloud/job/OperationalMetricsExport.kt line 279 at r2 (raw file):

Previously, kungfucraig (Craig Wright) wrote…

It seems like there is a lot of copied code from the other function. Can they share some logic? For example, and this is just one example, the code that handles the Measurement Type Case.

The only part I could make shared is the Measurement Type part

Copy link
Member

@kungfucraig kungfucraig left a comment

Choose a reason for hiding this comment

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

Reviewed 12 of 16 files at r1, 3 of 4 files at r2, 2 of 2 files at r3, all commit messages.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on @tristanvuong2021)

Copy link
Member

@kungfucraig kungfucraig left a comment

Choose a reason for hiding this comment

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

Reviewed 3 of 3 files at r4, all commit messages.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on @stevenwarejones)

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 5 of 16 files at r1, 1 of 4 files at r2, 1 of 2 files at r3, 1 of 3 files at r4, all commit messages.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on @tristanvuong2021)

Copy link
Member

@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.

Reviewed 4 of 16 files at r1, 1 of 7 files at r5, all commit messages.
Reviewable status: 14 of 20 files reviewed, 1 unresolved discussion (waiting on @kungfucraig, @stevenwarejones, and @tristanvuong2021)


src/main/kotlin/org/wfanet/measurement/kingdom/deploy/gcloud/spanner/queries/StreamRequisitions.kt line 24 at r5 (raw file):

import org.wfanet.measurement.kingdom.deploy.gcloud.spanner.readers.RequisitionReader

class StreamRequisitions(request: StreamRequisitionsRequest) :

Move these changes to a separate PR. We'll want them regardless of what happens with metrics export.

Copy link
Member

@kungfucraig kungfucraig left a comment

Choose a reason for hiding this comment

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

Reviewed 7 of 7 files at r5, all commit messages.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @stevenwarejones and @tristanvuong2021)

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 5 of 16 files at r1, 2 of 3 files at r4, 7 of 7 files at r6, all commit messages.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @tristanvuong2021)

Copy link
Contributor Author

@tristanvuong2021 tristanvuong2021 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: 16 of 20 files reviewed, 1 unresolved discussion (waiting on @SanjayVas and @stevenwarejones)


src/main/kotlin/org/wfanet/measurement/kingdom/deploy/gcloud/spanner/queries/StreamRequisitions.kt line 24 at r5 (raw file):

Previously, SanjayVas (Sanjay Vasandani) wrote…

Move these changes to a separate PR. We'll want them regardless of what happens with metrics export.

Done.

Copy link
Member

@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.

Reviewed 1 of 16 files at r1, 2 of 3 files at r4, 1 of 7 files at r6, 4 of 6 files at r7, all commit messages.
Reviewable status: 18 of 20 files reviewed, 2 unresolved discussions (waiting on @stevenwarejones and @tristanvuong2021)


src/main/proto/wfa/measurement/internal/kingdom/measurement.proto line 39 at r7 (raw file):

    // ComputationParticipants.
    COMPUTATION = 1;

These changes to the Kingdom internal API should also be in a separate PR.

Copy link
Contributor Author

@tristanvuong2021 tristanvuong2021 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: 11 of 20 files reviewed, 2 unresolved discussions (waiting on @kungfucraig, @SanjayVas, and @stevenwarejones)


src/main/proto/wfa/measurement/internal/kingdom/measurement.proto line 39 at r7 (raw file):

Previously, SanjayVas (Sanjay Vasandani) wrote…

These changes to the Kingdom internal API should also be in a separate PR.

Done.

Copy link
Member

@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.

Reviewed 2 of 16 files at r1, 2 of 6 files at r7, 6 of 7 files at r8, all commit messages.
Reviewable status: 19 of 20 files reviewed, 5 unresolved discussions (waiting on @stevenwarejones and @tristanvuong2021)


src/main/kotlin/org/wfanet/measurement/kingdom/deploy/gcloud/job/OperationalMetricsExport.kt line 153 at r8 (raw file):

              var latestUpdateTime: Timestamp = Timestamp.getDefaultInstance()

              measurementsClient.streamMeasurements(streamMeasurementsRequest).collect { measurement

All gRPC stub calls must handle StatusException at the call site.


src/main/kotlin/org/wfanet/measurement/kingdom/deploy/gcloud/job/OperationalMetricsExport.kt line 172 at r8 (raw file):

                    .toInstant()
                    .minusSeconds(measurement.createTime.toInstant().epochSecond)
                    .epochSecond

This is getting the seconds since epoch for the Instant that happens X seconds before, rather than getting the Duration between the two Instants in seconds. The math may come out the same, but it's not describing what you actually want.

Suggestion:

                  Duration.between(measurement.createTime.toInstant(), measurement.updateTime.toInstant()).toSeconds()

src/main/kotlin/org/wfanet/measurement/kingdom/deploy/gcloud/job/OperationalMetricsExport.kt line 429 at r8 (raw file):

      apiVersion: String,
    ): MeasurementType {
      val measurementSpec = signedMessage {

Why do you need to build a SignedMessage then unpack it? Just the following should be sufficient

require(Version.fromString(apiVersion) == Version.V2_ALPHA)

val measurementSpec = MeasurementSpec.parseFrom(serializedMeasurementSpec)
return when (measurementSpec.measurementTypeCase) {
  // ...
}

src/main/proto/wfa/measurement/internal/kingdom/measurement.proto line 39 at r7 (raw file):

Previously, tristanvuong2021 (Tristan Vuong) wrote…

Done.

I'm still seeing diffs here in this PR.

@tristanvuong2021 tristanvuong2021 changed the base branch from main to tristanvuong-add-create-time-to-requisition-parent-measurement October 10, 2024 21:48
@tristanvuong2021 tristanvuong2021 force-pushed the tristanvuong-do-separate-queries-for-bigquery-metric-writes branch from 79c9932 to ba33c87 Compare October 10, 2024 21:51
Copy link
Contributor Author

@tristanvuong2021 tristanvuong2021 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: 16 of 20 files reviewed, 5 unresolved discussions (waiting on @kungfucraig, @SanjayVas, and @stevenwarejones)


src/main/kotlin/org/wfanet/measurement/kingdom/deploy/gcloud/job/OperationalMetricsExport.kt line 153 at r8 (raw file):

Previously, SanjayVas (Sanjay Vasandani) wrote…

All gRPC stub calls must handle StatusException at the call site.

Done.


src/main/kotlin/org/wfanet/measurement/kingdom/deploy/gcloud/job/OperationalMetricsExport.kt line 172 at r8 (raw file):

Previously, SanjayVas (Sanjay Vasandani) wrote…

This is getting the seconds since epoch for the Instant that happens X seconds before, rather than getting the Duration between the two Instants in seconds. The math may come out the same, but it's not describing what you actually want.

Done.


src/main/kotlin/org/wfanet/measurement/kingdom/deploy/gcloud/job/OperationalMetricsExport.kt line 429 at r8 (raw file):

Previously, SanjayVas (Sanjay Vasandani) wrote…

Why do you need to build a SignedMessage then unpack it? Just the following should be sufficient

require(Version.fromString(apiVersion) == Version.V2_ALPHA)

val measurementSpec = MeasurementSpec.parseFrom(serializedMeasurementSpec)
return when (measurementSpec.measurementTypeCase) {
  // ...
}

Done.


src/main/proto/wfa/measurement/internal/kingdom/measurement.proto line 39 at r7 (raw file):

Previously, SanjayVas (Sanjay Vasandani) wrote…

I'm still seeing diffs here in this PR.

Done.

Copy link
Member

@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.

Reviewed 7 of 7 files at r9, all commit messages.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on @stevenwarejones)

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 r7, 3 of 7 files at r8, 7 of 7 files at r9, all commit messages.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on @tristanvuong2021)

Base automatically changed from tristanvuong-add-create-time-to-requisition-parent-measurement to main October 11, 2024 19:47
@tristanvuong2021 tristanvuong2021 merged commit 3c4c1e7 into main Oct 11, 2024
4 checks passed
@tristanvuong2021 tristanvuong2021 deleted the tristanvuong-do-separate-queries-for-bigquery-metric-writes branch October 11, 2024 20:06
tristanvuong2021 added a commit that referenced this pull request Oct 22, 2024
refactor: Remove unneeded measurement view


[This](#1696)
added the view, but
[this](#1823)
removed the need for the new view.
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.

5 participants