Skip to content

feat(storage): add gcp.storage.client.ttfb metric - #14745

Open
nidhiii-27 wants to merge 8 commits into
feat/storage-http-request-durationfrom
feat/storage-ttfb-metric
Open

nidhiii-27 wants to merge 8 commits into
feat/storage-http-request-durationfrom
feat/storage-ttfb-metric

Conversation

@nidhiii-27

@nidhiii-27 nidhiii-27 commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

Instruments gRPC and HTTP transports to record gcp.storage.client.ttfb (time to first byte) OpenTelemetry histogram metrics.

  • Records time to first response message across all gRPC RPCs in StorageGrpcMetricsInterceptor (anchored at call start for reads, unary RPCs, and open(), and re-anchored at flush/finish_write for writes; maps BidiReadObject to ReadObject and BidiWriteObject, StartResumableWrite, and QueryWriteStatus to WriteObject) with rpc.system.name, gcp.storage.operation, network.path, and server.address attributes.
  • Records time from request execution to response headers across all HTTP response status codes on media download requests in StorageHttpMetricsInterceptor (HTTP unary/upload TTFB is tracked as a follow-up).
  • Adds unit test coverage in StorageGrpcMetricsInterceptorTest and StorageHttpMetricsInterceptorTest.

Stacked on #14744.

@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 adds Time to First Byte (TTFB) metrics tracking for both gRPC and HTTP storage clients, along with corresponding unit tests. The feedback highlights a potential NullPointerException in StorageGrpcMetricsInterceptor due to a missing null check in onClose when rpcClientCallDuration is null, and suggests restricting HTTP TTFB recording to 2xx status codes to prevent misleading metrics on 3xx responses.

@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 Time to First Byte (TTFB) metrics tracking for both gRPC and HTTP Google Cloud Storage clients, along with comprehensive unit tests. The feedback highlights a potential NullPointerException in the gRPC interceptor if call duration metrics are disabled while TTFB is enabled, and suggests a refactoring to safely guard against this. Additionally, an optimization is suggested for the HTTP interceptor to avoid registering response interceptors when no metrics need to be recorded.

…ceptor checks

Use KEY_GCP_STORAGE_OPERATION (ReadObject) for gcp.storage.client.ttfb across gRPC and HTTP interceptors, restrict HTTP TTFB recording to 2xx status codes, hoist recordDuration/recordTtfb checks, and expand unit test coverage.

[Generated-by: AI]
@nidhiii-27
nidhiii-27 marked this pull request as ready for review November 9, 2026 12:59
@nidhiii-27
nidhiii-27 requested review from a team as code owners November 9, 2026 12:59

@cpriti-os cpriti-os 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.

Implementation looks solid against the ttfb label set and measurement points. Left a couple of spec-scope questions and a nit inline.

@nidhiii-27
nidhiii-27 requested a review from cpriti-os November 12, 2026 09:00
// Evaluate isMediaDownloadRequest(request) at response time rather than in
// initialize(HttpRequest), because callers such as MediaHttpDownloader may append
// query parameters (e.g. alt=media) to request.getUrl() after buildGetRequest().
if (recordTtfb && isMediaDownloadRequest(request)) {

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.

gRPC now records ttfb for every RPC, while HTTP only records it for media downloads. Fine to keep this PR downloads-only — just checking HTTP unary/upload ttfb is tracked as a follow-up.

@nidhiii-27 nidhiii-27 Nov 18, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Confirmed — keeping HTTP TTFB scoped to media downloads in this PR and raised #15066 for HTTP unary/upload TTFB (propagating operation names via StorageMetricsContext).

Co-authored by AI Agent

…etric

- Merge updated feat/storage-http-request-duration (572ea33) and build StorageClientMetrics.recordTtfb directly from baseAttributes (rpc.system.name, server.address)
- Re-anchor gRPC ttfbStartNanos only on write flush/finish (BidiWriteObjectRequest flush/finish_write and WriteObjectRequest finish_write) and drop Math.max
- Map StartResumableWrite and QueryWriteStatus to WriteObject in package-private defaultOperationName
- Drop redundant recordDuration/recordTtfb booleans across gRPC and HTTP interceptors
- Record HTTP media-download TTFB inside StorageHttpMetricsInterceptor.recordResponse (excluding 401 token-refresh latency and synthetic batch responses) and update Javadoc
- Consolidate HTTP and gRPC TTFB unit tests into existing cases with exact 7-attribute assertions and add defaultOperationName/isWriteFlush unit tests

[Generated-by: AI]
@nidhiii-27 nidhiii-27 changed the title feat(storage): add gcp.storage.client.ttfb metric for read operations feat(storage): add gcp.storage.client.ttfb metric Nov 18, 2026
@nidhiii-27
nidhiii-27 requested a review from cpriti-os November 18, 2026 10:56

This branch has not been deployed

No deployments
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