Skip to content

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

Open
karthunni wants to merge 4 commits into
mainfrom
karthunni/po-migrate-integration-tests
Open

PO to GMP Migration Tool: Add Prometheus Operator Golden Tests#2071
karthunni wants to merge 4 commits into
mainfrom
karthunni/po-migrate-integration-tests

Conversation

@karthunni

@karthunni karthunni commented Aug 17, 2026

Copy link
Copy Markdown
Collaborator

Overview

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 (16 Test Functions / 20 Subtests)

All tests evaluate input manifests against exact upstream golden fixtures for modern Prometheus server targets:

PodMonitor Golden Tests

  • TestPodTargetLabelsFromPodMonitor: Pod target label promotion (podTargetLabels: [example, env]).
  • TestSettingScrapeProtocolsInPodMonitor: Scrape protocol configuration (OpenMetricsText1.0.0, OpenMetricsText0.0.1).
  • TestPodMonitorPhaseFilter: Pod phase dropping (filterRunning: false).
  • TestSettingHonorTimestampsInPodMonitor: Timestamp honoring toggle (honorTimestamps: false).
  • TestSettingTrackTimestampsStalenessInPodMonitor: Staleness tracking toggle (trackTimestampsStaleness: false).
  • TestPodMonitorEndpointFollowRedirects: Table-driven test evaluating both followRedirects: true and followRedirects: false on Prometheus v2.28.0+.
  • TestPodMonitorEndpointEnableHttp2: Table-driven test evaluating both enableHttp2: true and enableHttp2: false on Prometheus v2.35.0+.

ServiceMonitor Golden Tests

  • TestSettingScrapeProtocolsInServiceMonitor: ServiceMonitor scrape protocols (OpenMetricsText1.0.0, OpenMetricsText0.0.1).
  • TestTargetLabels: Service target label extraction from backing Kubernetes Service objects.
  • TestSettingHonorLabels: Scrape configuration honor labels toggle (honorLabels: true).
  • TestHonorLabelsOverriding: Scrape configuration honor labels overridden by Prometheus server configuration.
  • TestPodTargetLabels: Pod target labels defined on ServiceMonitor resources.
  • TestSettingHonorTimestampsInServiceMonitor: ServiceMonitor timestamp honoring toggle (honorTimestamps: false).
  • TestSettingTrackTimestampsStalenessInServiceMonitor: ServiceMonitor staleness tracking toggle (trackTimestampsStaleness: false).
  • TestServiceMonitorEndpointFollowRedirects: Table-driven test evaluating both followRedirects: true and followRedirects: false on Prometheus v2.28.0+.
  • TestServiceMonitorEndpointEnableHttp2: Table-driven test evaluating both enableHttp2: true and enableHttp2: false on Prometheus v2.35.0+.

@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
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
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
// 3. Fallback to Service target labels when fromPod is absent.
if !hasFromPodRules {
for _, l := range targetLabels {
out = append(out, newPORelabelRule(relabel.Replace, []string{metaServiceLabelPrefix + l}, l, "(.+)", "${1}"))

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.

Service target labels are migrated by gmp-migrate into metricRelabelings on PodMonitoring. Generating _meta_kubernetes_service_label* rules here from targetLabels bypasses the actual output of gmp-migrate and drops the converted metricRelabelings.

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.

Changed it to check metricRelabelings for static rules which match Service labels on the input service before mapping back to relabelings

Comment thread pkg/migrate/golden_test.go Outdated
out := &config.ScrapeConfig{
// JobName in Prometheus Operator follows the internal server naming convention.
JobName: expectedPO.JobName,
HonorLabels: expectedPO.HonorLabels,

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.

Copying HonorLabels, HonorTimestamps, and ScrapeProtocols directly from expectedPO makes tests like TestSettingHonorLabels and TestSettingScrapeProtocols pass vacuously, even though gmp-migrate drops these unsupported fields.

// TODO: If GMP CRDs expose followRedirects or enableHttp2 in the future and gmp-migrate
// adds translation support for them, assert gmp values directly.
httpClientCfg := gmp.HTTPClientConfig
httpClientCfg.FollowRedirects = expectedPO.HTTPClientConfig.FollowRedirects

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.

Copying FollowRedirects and EnableHTTP2 from expectedPO masks whether gmp-migrate handles or drops these fields, causing tests like TestPodMonitorEndpointFollowRedirects to pass unconditionally against the golden files.

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?

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