-
Notifications
You must be signed in to change notification settings - Fork 21
test(promqle2etest): add vanilla Prometheus remote write 2.0 to GCM test case #334
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
Draft
bwplotka
wants to merge
4
commits into
release-2.53.5-gmp
Choose a base branch
from
rw
base: release-2.53.5-gmp
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
1d24735
test(promqle2etest): add vanilla Prometheus remote write 2.0 to GCM t…
bwplotka d87bbbe
Update google/internal/promqle2etest/backend_prw_gcm.go
bwplotka 3ee59d5
test(promqle2etest): comment write_relabel_configs in backend_prw_gcm.go
bwplotka 2cd4370
test(promqle2etest): update image to debuglog and enable failed reque…
bwplotka File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,169 @@ | ||
| // Copyright 2026 Google LLC | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
|
|
||
| package promqle2etest | ||
|
|
||
| import ( | ||
| "fmt" | ||
| "os" | ||
| "path/filepath" | ||
| "strconv" | ||
| "testing" | ||
|
|
||
| gcm "cloud.google.com/go/monitoring/apiv3/v2" | ||
| "github.com/efficientgo/e2e" | ||
| e2emon "github.com/efficientgo/e2e/monitoring" | ||
| "github.com/prometheus/client_golang/api" | ||
| v1 "github.com/prometheus/client_golang/api/prometheus/v1" | ||
| "github.com/prometheus/compliance/promqle2e" | ||
| "golang.org/x/oauth2" | ||
| "golang.org/x/oauth2/google" | ||
| ) | ||
|
|
||
| var _ promqle2e.Backend = PrometheusRemoteWriteGCMBackend{} | ||
|
|
||
| // PrometheusRemoteWriteGCMBackend represents a vanilla Prometheus scraping | ||
| // metrics and pushing to GCM API via Prometheus Remote Write 2.0 protocol. | ||
| // This generally follows https://cloud.google.com/stackdriver/docs/managed-prometheus/setup-unmanaged. | ||
| type PrometheusRemoteWriteGCMBackend struct { | ||
| Image string | ||
| Name string | ||
| GCMSA []byte | ||
| } | ||
|
|
||
| func (p PrometheusRemoteWriteGCMBackend) Ref() string { | ||
| return p.Name | ||
| } | ||
|
|
||
| // newPrometheusRemoteWrite creates a new Prometheus runnable configured with remote write 2.0 against GCM. | ||
| func newPrometheusRemoteWrite(env e2e.Environment, name string, image string, scrapeTargetAddress string, projectID string, location string, cluster string, gcmSA []byte) *e2emon.Prometheus { | ||
| ports := map[string]int{"http": 9090} | ||
|
|
||
| f := env.Runnable(name).WithPorts(ports).Future() | ||
| credsFile := filepath.Join(f.Dir(), "gcm-sa.json") | ||
| if err := os.WriteFile(credsFile, gcmSA, 0600); err != nil { | ||
| return &e2emon.Prometheus{Runnable: e2e.NewFailedRunnable(name, fmt.Errorf("write JSON creds failed: %w", err))} | ||
| } | ||
|
|
||
| config := fmt.Sprintf(` | ||
| global: | ||
| scrape_interval: 5s | ||
| scrape_timeout: 5s | ||
| convert_classic_histograms_to_nhcb: true | ||
| external_labels: | ||
| collector: %v | ||
| project_id: %v | ||
| location: %v | ||
| cluster: %v | ||
| scrape_configs: | ||
| - job_name: 'test' | ||
| scrape_interval: 5s | ||
| scrape_timeout: 5s | ||
| static_configs: | ||
| - targets: [%s] | ||
| metric_relabel_configs: | ||
| - regex: instance | ||
| action: labeldrop | ||
| remote_write: | ||
| - name: "google_cloud" | ||
| url: "https://staging-monitoring.sandbox.googleapis.com/v1/prometheus/api/v1/write" | ||
| protobuf_message: "io.prometheus.write.v2.Request" | ||
| send_exemplars: true | ||
| queue_config: | ||
| retry_on_http_429: true | ||
| google_iam: | ||
| credentials_file: "%s" | ||
| write_relabel_configs: | ||
| - source_labels: ['__type__'] | ||
| action: labeldrop | ||
| - source_labels: ['__unit__'] | ||
| action: labeldrop | ||
| `, name, projectID, location, cluster, scrapeTargetAddress, credsFile) | ||
| if err := os.WriteFile(filepath.Join(f.Dir(), "prometheus.yml"), []byte(config), 0600); err != nil { | ||
| return &e2emon.Prometheus{Runnable: e2e.NewFailedRunnable(name, fmt.Errorf("create prometheus config failed: %w", err))} | ||
| } | ||
|
|
||
| args := map[string]string{ | ||
| "--web.listen-address": fmt.Sprintf(":%d", ports["http"]), | ||
| "--config.file": filepath.Join(f.Dir(), "prometheus.yml"), | ||
| "--storage.tsdb.path": f.Dir(), | ||
| "--enable-feature=exemplar-storage": "", | ||
| "--enable-feature=native-histograms": "", | ||
| "--enable-feature=promql-nhcb-as-classic": "", | ||
| "--enable-feature=st-storage": "", | ||
| "--enable-feature=st-synthesis": "", | ||
| "--enable-feature=type-and-unit-labels": "", | ||
| "--storage.tsdb.no-lockfile": "", | ||
| "--storage.tsdb.retention.time": "1d", | ||
| "--storage.tsdb.wal-compression": "", | ||
| "--storage.tsdb.min-block-duration": "2h", | ||
| "--storage.tsdb.max-block-duration": "2h", | ||
| "--web.enable-lifecycle": "", | ||
| "--log.format": "json", | ||
| "--log.level": "info", | ||
| } | ||
|
|
||
| p := e2emon.AsInstrumented(f.Init(e2e.StartOptions{ | ||
| Image: image, | ||
| Command: e2e.NewCommandWithoutEntrypoint("prometheus", e2e.BuildArgs(args)...), | ||
| Readiness: e2e.NewHTTPReadinessProbe("http", "/-/ready", 200, 200), | ||
| User: strconv.Itoa(os.Getuid()), | ||
| }), "http") | ||
|
|
||
| return &e2emon.Prometheus{ | ||
| Runnable: p, | ||
| Instrumented: p, | ||
| } | ||
| } | ||
|
|
||
| func (p PrometheusRemoteWriteGCMBackend) StartAndWaitReady(t testing.TB, env e2e.Environment) promqle2e.RunningBackend { | ||
| t.Helper() | ||
|
|
||
| ctx := t.Context() | ||
|
|
||
| creds, err := google.CredentialsFromJSON(ctx, p.GCMSA, gcm.DefaultAuthScopes()...) | ||
| if err != nil { | ||
| t.Fatalf("create credentials from JSON: %s", err) | ||
| } | ||
|
|
||
| // Fake, does not matter. | ||
| cluster := "pe-github-action" | ||
| location := "europe-west3-a" | ||
|
|
||
| cl, err := api.NewClient(api.Config{ | ||
| Address: fmt.Sprintf("https://staging-monitoring.sandbox.googleapis.com/v1/projects/%s/location/global/prometheus", creds.ProjectID), | ||
| Client: oauth2.NewClient(ctx, creds.TokenSource), | ||
| }) | ||
| if err != nil { | ||
| t.Fatalf("create Prometheus client: %s", err) | ||
| } | ||
|
|
||
| replayer := promqle2e.StartIngestByScrapeReplayer(t, env) | ||
| prom := newPrometheusRemoteWrite(env, p.Name, p.Image, replayer.Endpoint(env), creds.ProjectID, location, cluster, p.GCMSA) | ||
| if err := e2e.StartAndWaitReady(prom); err != nil { | ||
| t.Fatal(err) | ||
| } | ||
|
|
||
| return promqle2e.NewRunningScrapeReplayBasedBackend( | ||
| replayer, | ||
| map[string]string{ | ||
| "cluster": cluster, | ||
| "location": location, | ||
| "project_id": creds.ProjectID, | ||
| "collector": p.Name, | ||
| "job": "test", | ||
| }, | ||
| v1.NewAPI(cl), | ||
| ) | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.