Repository navigation
feat(storage): add http.client.request.duration metric for HTTP requests - #14744
nidhiii-27 wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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.
| AtomicBoolean recorded = new AtomicBoolean(false); | |
| AtomicBoolean recorded = new AtomicBoolean(true); |
Instruments HTTP/JSON storage requests to record
http.client.request.durationOpenTelemetry histogram metrics.StorageHttpMetricsInterceptorto measure per-request duration and attachhttp.request.method,http.response.status_code,network.path,url.template,server.address, anderror.typeattributes across normal responses andIOExceptionfailures.StorageHttpMetricsInterceptorintoHttpStorageOptionsand initializeshttp.client.request.durationinStorageClientMetrics.StorageHttpMetricsInterceptorTestandStorageClientMetricsTest.Stacked on #14743.