Skip to content

test(metrics): optimize gRPC metrics test fixture and OTel test helpers - #5265

Open
alleaditya wants to merge 2 commits into
masterfrom
refactor-grpc-metrics-test-infra
Open

alleaditya wants to merge 2 commits into
masterfrom
refactor-grpc-metrics-test-infra

Conversation

@alleaditya

@alleaditya alleaditya commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

Description

Optimize internal/fs/grpc_metrics_test.go and clean up metrics/metrics_test_utils.go:

  • Speed up TestGrpcMetrics_* by ~18x (~1.85s -> ~0.10s) & fix BidiWriteObject / resource leaks: Set GOOGLE_CLOUD_DISABLE_DIRECT_PATH=true and serve GCE metadata endpoints via t.Setenv, eliminating all three sacrificial 100ms shortCtx DirectPath workarounds and 1.5s+ sleeps (using require.EventuallyWithT for ReadObject's async stream OnFinish callback); implement BidiWriteObject with dynamicpb.Message.Reset() reuse so TestGrpcMetrics_CreateFile asserts SyncFile success rather than ignoring Unimplemented; cache google.storage.v2.* descriptors via sync.OnceValue; add LIFO t.Cleanup teardown (server.Destroy, mh.Close, provider.Shutdown); and remove dead fakeStorageControlServer, unary WriteObject, and file-cache scaffolding.
  • Streamline metrics/metrics_test_utils.go for existing callers: Widen t to TestingT (supporting *testing.T, testing.TB, and *assert.CollectT in require.EventuallyWithT), add single-pass CollectResourceMetrics + WithResourceMetrics snapshots used by TestGrpcMetrics_*, replace deprecated string-allocating attribute.Set.Emit() with zero-allocation typed attribute.Value comparison, and guard against negative bucket indices in VerifyHistogramFull.

Link to the issue in case of a bug fix.

Fixes b/586721886

Testing details

  1. Manual - Ran make build (go generate, goimports, go mod tidy, gofmt -s, go vet ./..., golangci-lint, go build ./...).
  2. Unit tests - go test -race -shuffle=on -count=5 ./internal/fs -run "^TestGrpcMetrics" and full internal/fs/*_metrics_test.go suite.
  3. Integration tests - Exercised full FUSE server -> gRPC StorageHandle -> in-process google.storage.v2.Storage fake server in internal/fs.
  4. Perf tests (execute-perf-test) - Kokoro build #18628

Any backward incompatible change? If so, please explain.

N/A (widened *testing.T parameter to TestingT and added backward-compatible WithResourceMetrics in test-only helper package metrics).

@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 refactors the gRPC metrics tests and verification utilities. In internal/fs/grpc_metrics_test.go, the fake storage server is updated to use a centralized protobuf descriptor set and dynamic protobuf messages, and a new BidiWriteObject streaming handler is implemented. In metrics/metrics_test_utils.go, the metric verification helper functions are enhanced with new configuration options (such as scope, unit, and resource metrics reuse) and more robust attribute matching. Additionally, a new test file metrics/metrics_test_utils_test.go is introduced to thoroughly test these verification utilities. Feedback suggests validating that the bucket index is non-negative in VerifyHistogramFull to prevent potential runtime panics.

Comment thread metrics/metrics_test_utils.go Resolved
@alleaditya
alleaditya force-pushed the refactor-grpc-metrics-test-infra branch 2 times, most recently from 618d145 to abc536f Compare November 17, 2026 05:03
@codecov

codecov Bot commented Nov 17, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 90.81633% with 9 lines in your changes missing coverage. Please review.
✅ Project coverage is 85.23%. Comparing base (9f8bc62) to head (bcba7c7).

Files with missing lines Patch % Lines
metrics/metrics_test_utils.go 90.81% 9 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #5265      +/-   ##
==========================================
+ Coverage   85.19%   85.23%   +0.03%     
==========================================
  Files         181      181              
  Lines       19957    19974      +17     
==========================================
+ Hits        17003    17024      +21     
+ Misses       2953     2949       -4     
  Partials        1        1              
Flag Coverage Δ
unittests 85.23% <90.81%> (+0.03%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
@alleaditya
alleaditya force-pushed the refactor-grpc-metrics-test-infra branch from abc536f to 3da0c9e Compare November 17, 2026 05:16
@alleaditya
alleaditya added this pull request to stack #5266 November 17, 2026 05:46
@alleaditya

Copy link
Copy Markdown
Contributor Author

/gemini review

@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 refactors the gRPC metrics tests and verification utilities to improve performance, reliability, and maintainability. Key changes include implementing a cached protobuf descriptor set, adding a BidiWriteObject implementation to the fake storage server, introducing a test fixture to streamline setup, and replacing fragile sleep-based synchronization with require.EventuallyWithT. Additionally, the metrics verification helpers were updated to support a broader TestingT interface and allow reusing collected metrics snapshots. The review feedback suggests increasing the polling interval in EventuallyWithT from 1ms to 10ms to avoid busy-waiting and potential flakiness in CI environments.

Comment thread internal/fs/grpc_metrics_test.go Resolved
@alleaditya
alleaditya marked this pull request as ready for review November 17, 2026 08:09
@alleaditya
alleaditya requested a review from a team as a code owner November 17, 2026 08:09
@github-actions github-actions Bot added the remind-reviewers Auto remind reviewers in attention set for review post 24hrs of inactivity on PR. label Nov 17, 2026
@alleaditya alleaditya self-assigned this Nov 17, 2026
@github-actions

Copy link
Copy Markdown

Hi @kislaykishore, your feedback is needed to move this pull request forward. This automated reminder was triggered because there has been no activity for over 24 hours. Please provide your input when you have a moment. Thank you!

@alleaditya alleaditya added execute-perf-test Execute performance test in PR execute-integration-tests Run only integration tests execute-integration-tests-on-zb To run E2E tests on zonal bucket. labels Nov 18, 2026
@github-actions

Copy link
Copy Markdown

Hi @kislaykishore, your feedback is needed to move this pull request forward. This automated reminder was triggered because there has been no activity for over 24 hours. Please provide your input when you have a moment. Thank you!

2 similar comments
@github-actions

Copy link
Copy Markdown

Hi @kislaykishore, your feedback is needed to move this pull request forward. This automated reminder was triggered because there has been no activity for over 24 hours. Please provide your input when you have a moment. Thank you!

@github-actions

Copy link
Copy Markdown

Hi @kislaykishore, your feedback is needed to move this pull request forward. This automated reminder was triggered because there has been no activity for over 24 hours. Please provide your input when you have a moment. Thank you!

Improve the existing gRPC transport metrics test suite and OpenTelemetry metric
verification helpers:

- Speed up TestGrpcMetrics_* by ~18x (~1.85s -> ~0.10s) in
  internal/fs/grpc_metrics_test.go by setting GOOGLE_CLOUD_DISABLE_DIRECT_PATH=true
  and serving GCE metadata endpoints via t.Setenv, replacing sacrificial 100ms
  shortCtx workarounds and 1.5s+ sleeps with require.EventuallyWithT on
  ReadObject's asynchronous stream OnFinish callback.
- Implement BidiWriteObject on reflectFakeServer with dynamicpb.Message.Reset()
  reuse (so TestGrpcMetrics_CreateFile asserts SyncFile success), cache
  google.storage.v2.* descriptors via sync.OnceValue, fix
  FileSystem/MetricHandle/MeterProvider cleanup leaks, and remove dead
  fakeStorageControlServer, unary WriteObject, and file-cache scaffolding.
- Refactor metrics/metrics_test_utils.go to accept a TestingT interface
  (supporting *testing.T and *assert.CollectT), add single-pass
  CollectResourceMetrics / WithResourceMetrics snapshots, replace deprecated
  string-allocating attribute.Set.Emit() with zero-allocation typed
  attribute.Value matching, and validate negative histogram bucket indices.
Avoid 1ms retry polling if contended on resource-constrained CI runners while
keeping the immediate 0ms initial check in TestGrpcMetrics_ReadFile.
@alleaditya
alleaditya force-pushed the refactor-grpc-metrics-test-infra branch from 3b81ce4 to bcba7c7 Compare November 24, 2026 06:22
@alleaditya alleaditya added execute-integration-tests-on-zb To run E2E tests on zonal bucket. execute-perf-test Execute performance test in PR and removed execute-perf-test Execute performance test in PR execute-integration-tests-on-zb To run E2E tests on zonal bucket. execute-integration-tests Run only integration tests labels Nov 24, 2026
@github-actions

Copy link
Copy Markdown

Hi @kislaykishore, your feedback is needed to move this pull request forward. This automated reminder was triggered because there has been no activity for over 24 hours. Please provide your input when you have a moment. Thank you!

@github-actions

Copy link
Copy Markdown

Hi @kislaykishore, your feedback is needed to move this pull request forward. This automated reminder was triggered because there has been no activity for over 24 hours. Please provide your input when you have a moment. Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

execute-integration-tests-on-zb To run E2E tests on zonal bucket. execute-perf-test Execute performance test in PR remind-reviewers Auto remind reviewers in attention set for review post 24hrs of inactivity on PR.

2 participants