Skip to content

PO to GMP Migration Tool: Add Prometheus Operator Golden Tests - #2071

Merged
dashpole merged 8 commits into
mainfrom
karthunni/po-migrate-integration-tests
Aug 21, 2026
Merged

PO to GMP Migration Tool: Add Prometheus Operator Golden Tests#2071
dashpole merged 8 commits into
mainfrom
karthunni/po-migrate-integration-tests

Conversation

@karthunni

@karthunni karthunni commented Aug 17, 2026

Copy link
Copy Markdown
Collaborator

This PR introduces a Golden Test Equivalence Suite (pkg/migrate/golden_test.go) that asserts gmp-migrate outputs against upstream golden fixtures from prometheus-operator/pkg/prometheus/promcfg_test.go.

normalizeGMPScrapeConfig bridges known differences to verify that user-defined scraping, relabeling, metadata, and endpoint configs match upstream 1:1.

Implemented Test Suite (4 Test Functions)

All tests evaluate input manifests against exact upstream golden fixtures

PodMonitor Golden Tests

  • TestPodTargetLabelsFromPodMonitor: Pod target label promotion (podTargetLabels: [example, env]).
  • TestPodMonitorPhaseFilter: Pod phase dropping (filterRunning: false).

ServiceMonitor Golden Tests

  • TestTargetLabels: Service target label extraction from backing Kubernetes Service objects.
  • TestPodTargetLabels: Pod target labels defined on ServiceMonitor resources.

@karthunni karthunni self-assigned this Aug 17, 2026

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a comprehensive golden file testing framework in golden_test.go along with several golden test fixtures to validate the migration of Prometheus Operator configurations to Google Cloud Managed Service for Prometheus (GMP). The feedback primarily focuses on enhancing the robustness of the test harness by adding defensive nil checks to prevent potential nil pointer dereferences when processing relabel configurations and scrape configs. Additionally, it identifies an unused golden file, NamespaceSetCorrectlyForPodMonitor.golden, which should either be integrated into a test case or removed.

Comment thread pkg/migrate/golden_test.go
Comment thread pkg/migrate/golden_test.go
Comment thread pkg/migrate/golden_test.go Outdated
Comment thread pkg/migrate/golden_test.go Outdated
Comment thread pkg/migrate/golden_test.go
Comment thread pkg/migrate/golden_test.go Outdated
Comment thread pkg/migrate/golden_test.go
Comment thread pkg/migrate/testdata/golden/NamespaceSetCorrectlyForPodMonitor.golden Outdated
@karthunni
karthunni requested a review from dashpole August 17, 2026 21:17
@karthunni
karthunni marked this pull request as ready for review August 17, 2026 21:17
Comment thread pkg/migrate/golden_test.go Outdated
Comment thread pkg/migrate/golden_test.go Outdated
Comment thread pkg/migrate/golden_test.go Outdated
Comment thread pkg/migrate/golden_test.go Outdated
Comment thread pkg/migrate/golden_test.go Outdated
Comment thread pkg/migrate/golden_test.go Outdated
@karthunni

karthunni commented Aug 19, 2026

Copy link
Copy Markdown
Collaborator Author

It looks like the main point of contention is about using expectedPO values to normalize the GMP Config and also whether some tests are necessary. I copied those values over so that all the tests copied over from upstream would pass against the golden files (just copied all tests over for completeness).

A bunch of the upstream tests are testing stuff that GMP doesn't support (and in some cases intentionally won't support, like honorLabels / honorTimestamps).

Do we want to keep these tests in golden_test.go? Now that I'm typing it out, having tests that pass vacuously without actually testing using tool output feels pretty useless. Just that if we ever do, we should copy those cases over from upstream.

Should I just remove the unsupported tests from golden_test.go and only keep the ones for features that we currently support (like fromPod target labels, filterRunning, etc.), and we can add tests for things like followRedirects if we ever add support for them in the future?

Comment thread pkg/migrate/golden_test.go Outdated
Comment thread pkg/migrate/golden_test.go Outdated
Comment thread pkg/migrate/golden_test.go Outdated
@dashpole

Copy link
Copy Markdown
Collaborator

I would remove tests for things that we can't support.

@karthunni
karthunni force-pushed the karthunni/po-migrate-integration-tests branch from af4b3ee to 7c36d29 Compare August 21, 2026 13:21

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

Some suggestions for additional coverage. Could also be done as a follow-up if you'd rather.

out = append(out, extractPhaseDropRule(gmpRelabelConfigs)...)

// 2. Port Keep and Metadata replacements.
// TODO: Add support for node, cluster, or namespace metadata label extraction if future upstream test fixtures

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.

We could add a test case for attachMetadata.node here (similar to upstream TestNamespaceSetCorrectlyForPodMonitor) to verify node metadata extraction and cover resolveAttachMetadata.


// extractCustomRelabelRules filters out GMP internal Monarch rules and preserves user-defined relabel configs.
//
// TODO: If future upstream test cases introduce custom pre-scrape relabelings that gmp-migrate converts into

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.

Pre-scrape relabeling conversions (keep to selector, simple copy to fromPod) and metricRelabelConfigs currently have 0% golden test coverage. We should add test cases for those to verify relabel translation end-to-end.

if err := runtime.DefaultUnstructuredConverter.FromUnstructured(output.Object, &gmpPM); err != nil {
t.Fatalf("FromUnstructured PodMonitoring error: %v", err)
}
// TODO: Inject mock Secret pool references into ScrapeConfigs() if future upstream test cases test

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.

Passing a mock secret pool here would let us add golden tests for basicAuth, TLS, and authorization secret mappings.

// 6. PodMonitor Test Suite.

// TestPodTargetLabelsFromPodMonitor mirrors upstream TestPodTargetLabelsFromPodMonitor in promcfg_test.go.
func TestPodTargetLabelsFromPodMonitor(t *testing.T) {

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.

ClusterPodMonitoring (via namespaceSelector.any: true) is supported by testGoldenEquivalence, but there is no test exercising it yet. Adding a cluster-scoped test would cover buildClusterPodMonitoring.

testGoldenEquivalence(t, "TargetLabels.golden", []runtime.Object{sm, svc}, "web")
}

// TestPodTargetLabels mirrors upstream TestPodTargetLabels in promcfg_test.go for ServiceMonitor.

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.

We could add a test case with numeric or remapped targetPort on the Service to cover resolveServicePort mappings.

@dashpole
dashpole merged commit a1d4b26 into main Aug 21, 2026
43 checks passed
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.

2 participants