Skip to content

refactor(monitoring): migrate MonitoringDashboard controller to Google REST client - #13574

Open
ldanielmadariaga wants to merge 2 commits into
GoogleCloudPlatform:masterfrom
ldanielmadariaga:refactor-monitoringdashboard-rest-client
Open

ldanielmadariaga wants to merge 2 commits into
GoogleCloudPlatform:masterfrom
ldanielmadariaga:refactor-monitoringdashboard-rest-client

Conversation

@ldanielmadariaga

@ldanielmadariaga ldanielmadariaga commented Oct 1, 2026 •

Copy link
Copy Markdown
Collaborator

What this PR does / why we need it:

Prerequisite for #12458.

Migrates the MonitoringDashboard direct controller from cloud.google.com/go/monitoring/dashboard/apiv1 (gRPC client) to google.golang.org/api/monitoring/v1 (Google REST client).

Using the Google REST client aligns request/response payloads with MockGCP, natively using string enums instead of integer enum encodings (%24alt=json%3Benum-encoding%3Dint). This achieves 100% golden log alignment across all MonitoringDashboard test fixtures without requiring enum mappings or normalizations in golden_alignment_test.go.

Additionally:

  • Updates protobuf references to mockgcp/generated/mockgcp/monitoring/dashboard/v1 (from feat(mockgcp): add google.monitoring.dashboard.v1 proto definitions #13471).
  • Normalizes dashboardFilters.valueType in tests/e2e/normalize.go.
  • Removes unnecessary minAlignmentPeriod: "0s" defaulter in MockGCP to match real GCP behavior.
  • Re-records golden HTTP logs with the REST client across fixtures.

Which issue(s) this PR fixes:

Prerequisite for #7090 / #12458

Does this PR introduce a user-facing change?

NONE
…e REST client

Migrate MonitoringDashboard direct controller from the Cloud Monitoring
v1 gRPC client to google.golang.org/api/monitoring/v1 (REST client).

Using the Google REST client aligns request/response payloads with MockGCP,
natively using string enums instead of integer enum encodings. This enables
100% golden log alignment across all MonitoringDashboard fixtures without
requiring custom enum mappers or normalizations in golden_alignment_test.go.
@google-oss-prow

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please ask for approval from ldanielmadariaga. For more information see the Kubernetes Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@gemmahou gemmahou left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

/lgtm

Two nit comments...

Comment thread mockgcp/mockmonitoring/dashboard.go Outdated
@@ -235,11 +234,6 @@ func (d *dashboardDefaulter) visitPieChart(obj *pb.PieChart) {
}

func (d *dashboardDefaulter) visitTimeSeriesTable(obj *pb.TimeSeriesTable) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

nit: remove this empty function

func computeEtag(obj proto.Message) string {
b, err := proto.Marshal(obj)
clone := proto.Clone(obj)
if dashboard, ok := clone.(*pb.Dashboard); ok {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

nit: I feel this function is to generate unique Etag for objects, I'm curious why do we need this if logic? The dashboard doesn't seem to be used here.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

IIRC the controller is using etag for reconciliation, we should revise that but it's out of scope for the change. I'll let the agent take a look though and reply as well.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Two details explain why this block is there:

  1. In Go, dashboard is a typed pointer to the clone message (clone := proto.Clone(obj)), so setting dashboard.Name = "" and dashboard.Etag = "" mutates clone in place before proto.Marshal(clone) is called.
  2. We zero out Etag and Name on the clone so the hash is deterministically computed from the dashboard specification alone:
    • On updates, incoming objects already have an existing etag set, which would otherwise pollute the computed hash.
    • MockGCP generates random UUIDs in Name, so clearing Name ensures the Etag does not change across runs or mock recreations.

I have added an explanatory doc comment to computeEtag and removed the empty visitTimeSeriesTable helper function as well!

@google-oss-prow google-oss-prow Bot removed the lgtm label Oct 3, 2026
@google-oss-prow

Copy link
Copy Markdown
Contributor

New changes are detected. LGTM label has been removed.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants