Skip to content

balancer: remove grpc.lb.pick_first.* metrics#9215

Open
deepgolani4 wants to merge 6 commits into
grpc:masterfrom
deepgolani4:master
Open

balancer: remove grpc.lb.pick_first.* metrics#9215
deepgolani4 wants to merge 6 commits into
grpc:masterfrom
deepgolani4:master

Conversation

@deepgolani4

@deepgolani4 deepgolani4 commented Jun 30, 2026

Copy link
Copy Markdown

Fixes #8752

The changes remove the three grpc.lb.pick_first.* metric registrations and their recording calls from pickfirst.go (along with the now-unneeded metricsRecorder/target fields), then update all tests and examples to assert on the equivalent grpc.subchannel.* metrics instead.

RELEASE NOTES:

  • Remove grpc.lb.pick_first.* metrics.

@linux-foundation-easycla

linux-foundation-easycla Bot commented Jun 30, 2026

Copy link
Copy Markdown

CLA Signed
The committers listed above are authorized under a signed CLA.

  • ✅ login: deepgolani4 / name: deepgolani4 (643ead2)

@codecov

codecov Bot commented Jun 30, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 83.31%. Comparing base (2a112a8) to head (b5627a3).

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #9215      +/-   ##
==========================================
+ Coverage   83.26%   83.31%   +0.04%     
==========================================
  Files         420      420              
  Lines       34028    34021       -7     
==========================================
+ Hits        28333    28343      +10     
+ Misses       4267     4257      -10     
+ Partials     1428     1421       -7     
Files with missing lines Coverage Δ
balancer/pickfirst/pickfirst.go 90.55% <100.00%> (+0.79%) ⬆️

... and 31 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@deepgolani4

Copy link
Copy Markdown
Author

@mbissa @arjan-bal @Pranjali-2501 @easwars

Sorry for pinging everyone like this, but I'd really appreciate it if someone could take a quick look and review this when you have a chance. Thanks!

Comment on lines -76 to -83
// These are example experimental gRPC metrics, which are disabled
// by default and must be explicitly enabled. For the full,
// up-to-date list of metrics, see:
// https://grpc.io/docs/guides/opentelemetry-metrics/#instruments
Metrics: opentelemetry.DefaultMetrics().Add(
"grpc.lb.pick_first.connection_attempts_succeeded",
"grpc.lb.pick_first.connection_attempts_failed",
),

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.

Why is this different to the change in examples/features/opentelemetry/client/main.go?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

The grpc.subchannel.* metrics are client-side only. The client example still needs to opt into the renamed metrics, but the server does not create subchannels or outbound connection attempts, so the old block there was just a no-op. That’s why I renamed it on the client and removed it on the server.

Comment on lines -2024 to -2025
if got, _ := tmr.Metric("grpc.lb.subchannel.connection_attempts_succeeded"); got != 0 {
t.Errorf("Unexpected data for metric %v, got: %v, want: %v", "grpc.lb.subchannel.connection_attempts_succeeded", got, 0)

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.

Interesting. Was this broken all this while then, @mbissa ?

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.

Yes. looks like it. I think when tmr.Metric is queried with the typo'd name, it does not find any recorded values, returning (0, false). Since the test code only checked got (which defaults to 0 when not found) and asserted got != 0, the condition 0 != 0 evaluated to false, and the test incorrectly passed instead of failing.

if holds[1].Wait(ctx) != true {
t.Fatalf("Timeout waiting for server %d with address %q to be contacted", 1, addrs[1])
}
if got, _ := tmr.Metric("grpc.lb.pick_first.connection_attempts_failed"); got != 1 {

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.

@mbissa : For all of these removed lines, what was the original plan? Would the pick_first tests continue to track the subchannel metrics or did we plan to have other tests that would track with these metrics?

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.

The plan was to move the tests to different place which is more apt for subchannel and not keep them in pickfirst.

Comment thread balancer/pickfirst/metrics_test.go Outdated
Comment on lines +65 to +66
// TestPickFirstMetrics verifies that a pick_first channel emits the correct
// subchannel metrics on connect and disconnect.

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.

Nit: "a pick_first channel" is very confusing. What we probably want is "a gRPC channel configured with the pick_first LB policy".

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

This is no longer applicable after the test move. TestPickFirstMetrics was removed, and the OTel coverage now lives in stats/opentelemetry/e2e_test.go.

Comment thread balancer/pickfirst/metrics_test.go Outdated
// metrics to emit, and makes sure the correct OpenTelemetry metrics atoms emit.
// TestPickFirstMetricsE2E tests subchannel metrics emitted during a pickfirst
// connection lifecycle: failure, success, and disconnection.
func (s) TestPickFirstMetricsE2E(t *testing.T) {

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.

@mbissa : I don't quite understand why this test uses the OTel stats handler while the other tests in this file seem to use a test stats handler? Should we consider unifying these tests to use a consistent approach? Or is there value in doing what is being currently done?

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.

This is the only test that runs E2E and hence using actual Otel plugin. The test stats handler ones are more geared towards checking the label value plumbing rather than the actual metric value. We could in new tests have unified tests - certainly clean it up.

@easwars easwars assigned deepgolani4 and mbissa and unassigned easwars Jul 8, 2026
@easwars easwars added Area: Observability Includes Stats, Tracing, Channelz, Healthz, Binlog, Reflection, Admin, GCP Observability Type: Behavior Change Behavior changes not categorized as bugs labels Jul 8, 2026
@easwars easwars added this to the 1.83 Release milestone Jul 8, 2026
@mbissa

mbissa commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

@deepgolani4 can you please move the tests to a separate place in the otel package where we run e2e tests instead of changing just the existing tests.

@deepgolani4

Copy link
Copy Markdown
Author

@deepgolani4 can you please move the tests to a separate place in the otel package where we run e2e tests instead of changing just the existing tests.

@mbissa Moved the OTel e2e metric coverage into stats/opentelemetry/e2e_test.go, and removed the duplicate pickfirst metric tests from balancer/pickfirst.

@deepgolani4 deepgolani4 requested a review from easwars July 9, 2026 15:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area: Observability Includes Stats, Tracing, Channelz, Healthz, Binlog, Reflection, Admin, GCP Observability Status: Help Wanted Type: Behavior Change Behavior changes not categorized as bugs

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Remove pickfirst metrics

3 participants