Skip to content

feat(storage): add http.client.request.duration metric for HTTP requests - #14744

Draft
nidhiii-27 wants to merge 1 commit into
feat/storage-rpc-call-durationfrom
feat/storage-http-request-duration
Draft

nidhiii-27 wants to merge 1 commit into
feat/storage-rpc-call-durationfrom
feat/storage-http-request-duration

Conversation

@nidhiii-27

Copy link
Copy Markdown
Contributor

Instruments HTTP/JSON storage requests to record http.client.request.duration OpenTelemetry histogram metrics.

  • Adds StorageHttpMetricsInterceptor to measure per-request duration and attach http.request.method, http.response.status_code, network.path, url.template, server.address, and error.type attributes across normal responses and IOException failures.
  • Wires StorageHttpMetricsInterceptor into HttpStorageOptions and initializes http.client.request.duration in StorageClientMetrics.
  • Adds unit tests in StorageHttpMetricsInterceptorTest and StorageClientMetricsTest.

Stacked on #14743.

@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 the StorageHttpMetricsInterceptor class to record HTTP client metrics, such as request duration, using OpenTelemetry. It integrates this interceptor into StorageOptions and HttpStorageRpc to decorate request initializers, and adds comprehensive unit tests. Feedback on the changes suggests initializing the recorded AtomicBoolean to true instead of false to prevent recording metrics for requests that fail before execution begins.

HttpIOExceptionHandler existingIoHandler = request.getIOExceptionHandler();

AtomicLong startTimeNanos = new AtomicLong(clock.nanoTime());
AtomicBoolean recorded = new AtomicBoolean(false);

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.

medium

Initializing recorded to false means that if the request fails or is aborted before the execution actually starts (i.e., before the interceptor runs), the IOException handler might still attempt to record a metric. This would result in inaccurate or inflated duration metrics starting from the time of initialize(). Initializing recorded to true and setting it to false inside the interceptor ensures that metrics are only recorded for requests that have actually started execution.

Suggested change
AtomicBoolean recorded = new AtomicBoolean(false);
AtomicBoolean recorded = new AtomicBoolean(true);

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.

1 participant