Skip to content

Conversation

@colega
Copy link
Contributor

@colega colega commented Dec 4, 2025

What this PR does

Switches to a fork of client_golang that contains the PR prometheus/client_golang#1925 which supports /metrics endpoint handler filtering through the use of name[] query param. I added a test to make sure this functionality doesn't disappear in a possible future removal of this replace directive.

Also updates the costattribution package as this version now has changes introduced by @duricanikolic in prometheus/client_golang#1902

Which issue(s) this PR fixes or relates to

Fixes an internal issue

Checklist

  • Tests updated.
  • Documentation added.
  • CHANGELOG.md updated - the order of entries should be [CHANGE], [FEATURE], [ENHANCEMENT], [BUGFIX]. If changelog entry is not needed, please add the changelog-not-needed label to the PR.
  • about-versioning.md updated with experimental features.

Note

Switch to a forked client_golang to add /metrics filtering via name[], update cost-attribution validation and tests, adapt API usage, and bump compress.

  • Server/HTTP metrics:
    • Enable metric filtering on /metrics via name[] query param (promhttp handler change). Added test TestMetricsEndpointSupportsMetricFiltering.
  • Dependencies:
    • Replace github.com/prometheus/client_golang with fork github.com/colega/prometheus-client_golang (pulls in filtering support) and vendor updates.
    • Bump github.com/klauspost/compress to v1.18.2 and vendor changes.
  • Cost attribution:
    • Simplify metric descriptor validation using prometheus.Desc.Err(); adjust error expectations in tests.
  • Integration tests client:
    • Adapt LabelNames to new model.LabelNames return type and convert to []string.
  • Changelog:
    • Document /metrics filtering enhancement.

Written by Cursor Bugbot for commit 94aa553. This will update automatically on new commits. Configure here.

@colega colega requested review from a team and stevesg as code owners December 4, 2025 15:15
@colega colega changed the title Switch client_golang to a fork with support for /metrics endpoint filtering by name[] Switch client_golang to a fork with support for /metrics endpoint filtering by name[] Dec 4, 2025
@colega colega changed the title Switch client_golang to a fork with support for /metrics endpoint filtering by name[] Switch prometheus/client_golang to a fork with support for /metrics endpoint filtering by name[] Dec 4, 2025

{
// One metric
res, err := http.Get(fmt.Sprintf("http://%s/metrics?name[]=go_info", c.Server.HTTPListenAddr()))
Copy link

Choose a reason for hiding this comment

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

Bug: Test doesn't wait for services to be ready

The test calls sm.StartAsync(t.Context()) but immediately makes HTTP requests to /metrics without waiting for services to become healthy or running. Other tests in this file either use m.AwaitHealthy(ctx) after StartAsync, or poll the /ready endpoint before making requests. This creates a race condition where the HTTP server may not be fully started when the first request is made, leading to intermittent test failures.

Fix in Cursor Fix in Web

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The listener is created before we call StartAsync, so there's no need to wait for it to be healthy, it will just serve the request once it's serving them.

Copy link
Contributor

@duricanikolic duricanikolic left a comment

Choose a reason for hiding this comment

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

LGTM
Thank you

CHANGELOG.md Outdated
* [ENHANCEMENT] OTLP: Add metric `cortex_distributor_otlp_requests_by_content_type_total` to track content type (json or proto) of OTLP packets. #13525
* [ENHANCEMENT] OTLP: Add experimental metric `cortex_distributor_otlp_array_lengths` to better understand the layout of OTLP packets in practice. #13525
* [ENHANCEMENT] Ruler: gRPC errors without details are classified as `operator` errors, and rule evaluation failures (such as duplicate labelsets) are classified as `user` errors. #13586
* [ENHANCEMENT] Server: The `/metrics` endpoint now supports metrics filtering by providing one or more `name[]` query parameters. #13745
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
* [ENHANCEMENT] Server: The `/metrics` endpoint now supports metrics filtering by providing one or more `name[]` query parameters. #13745
* [ENHANCEMENT] Server: The `/metrics` endpoint now supports metrics filtering by providing one or more `name[]` query parameters. #13746

assert.Contains(t, string(body), "go_info")
assert.Contains(t, string(body), "deprecated_flags_inuse_total")
assert.NotContains(t, string(body), "go_gc_duration_seconds")
require.Equal(t, 1, strings.Count(string(body), "2"))
Copy link
Collaborator

Choose a reason for hiding this comment

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

What is this assertion on "2"? I can't understand it. Shouldn't assert on something like "HELP"?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It should be definitely HELP, IDK where that 2 came from, probably I fell with my face on the keyboard and misedited it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed, the "2" was supposed to go on the left, where the 1 was. It just happened that the output string had only one "2" so the test passed 🤦

Copy link
Collaborator

Choose a reason for hiding this comment

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

Surprising that the test passed anyway :D (and the desired value is also wrong, because it should be 2). Probably you replaced "HELP" with "2", instead of replacing "1" with "2".

Copy link
Collaborator

@pracucci pracucci Dec 4, 2025

Choose a reason for hiding this comment

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

This makes me think it wasn't written by claude. AI doesn't make such mistakes :D

@colega colega force-pushed the switch-client-golang-to-a-fork-with-support-for-metrics-endpoint-filtering-by-name- branch from 73a948d to 56f3d09 Compare December 4, 2025 15:22
@colega colega merged commit f79807f into main Dec 5, 2025
39 checks passed
@colega colega deleted the switch-client-golang-to-a-fork-with-support-for-metrics-endpoint-filtering-by-name- branch December 5, 2025 09:06
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.

3 participants