Repository navigation
[Server] Expose per-endpoint latency and in-flight requests in /metrics - #2266
Conversation
Allow http.server.total.duration and http.server.active.requests through the /metrics filter, and drop the client-side percentiles Armeria adds to the latency timer so each endpoint and status adds only _count, _sum and _max. Closes unitycatalog#2256 Signed-off-by: Yuewei Zhou <[email protected]>
Use constants for the three exposed meter names. In the docs, give the PromQL for recent average latency and state the measured _max window. Signed-off-by: Yuewei Zhou <[email protected]>
Signed-off-by: Yuewei Zhou <[email protected]>
|
/review |
yili-db
left a comment
There was a problem hiding this comment.
[AI Assisted] Thanks for this. The allow-list and the percentile filter work as described, and the sample output matches the docs. Inline: the in-flight gauge's start point in the docs, and the weakened http_status check. The remaining items are outside the diff, so they are listed here:
ArmeriaServerBuilder.javaline 278 still says the registry filters this family to request counts.- The
http_statuslabel can be0for a request cancelled before a response was sent. The docs describe it only as the final response status (docs/server/observability.mdaround line 124). - Follow-up, not for this PR: the
/route and other non-annotated services get a service label likeio.unitycatalog.server.ArmeriaServerBuilder$$Lambda$693/0x..., where the hex changes on every JVM start, so each restart creates new series. This already applies tohttp_server_requests_total; a stable route name would fix it.
…-histogram - Docs: the in-flight gauge counts requests whose handler has started; http_status is 0 when no response was sent. - Turn off the percentile histogram explicitly and note the _max window. - Tests: require http_status on every line but the gauge, and check that the percentile filter does not touch other timers. - Fix the stale meterRegistry comment. Signed-off-by: Yuewei Zhou <[email protected]>
|
Thanks for the thorough review @yili-db ! Fixed the stale comment in |
|
Opened #2282 issue for the lambda service name. |
|
/review |
|
@shba24 please take a look |
| | `armeria_server_*`, `armeria_executor_*` | Armeria server and executor internals | | ||
| | `http_server_requests_total` | Completed HTTP requests on the API listener, tagged by `hostname_pattern`, `service`, `method`, and `http_status`; includes authentication and authorization rejections | | ||
| | `http_server_total_duration_seconds_count`, `_sum`, `_max` | Time from receiving a request to sending the full response on the API listener, tagged by `hostname_pattern`, `service`, `method`, and `http_status`. For the recent average latency of an endpoint, use `rate(http_server_total_duration_seconds_sum[5m]) / rate(http_server_total_duration_seconds_count[5m])`; `_max` is the slowest request in roughly the last 6 to 9 minutes. Example: `http_server_total_duration_seconds_count{hostname_pattern="*:8080",http_status="200",method="createCatalog",service="io.unitycatalog.server.service.CatalogService"} 1` | | ||
| | `http_server_active_requests` | Requests on the API listener whose handler has started and not finished, tagged by `hostname_pattern`, `service`, and `method`. Sum the series for the total in-flight requests. Example: `http_server_active_requests{hostname_pattern="*:8080",method="createCatalog",service="io.unitycatalog.server.service.CatalogService"} 0.0` | |
There was a problem hiding this comment.
Nit (not a blocker): In-flight gauge description may not match when Armeria counts a request
The row says http_server_active_requests counts requests "whose handler has started and not finished". The metrics decorator is installed on the API virtual host and wraps outside the auth decorators (ArmeriaServerBuilder.java:278-286). The same table says http_server_requests_total includes authentication and authorization rejections. So the gauge probably counts a request from the moment it is received until its response completes, whether or not the annotated handler ran. This could not be settled: no test held an auth-rejected or slow-response request open while scraping the gauge, so the claim rests on reading the decorator order and the Armeria 1.41.1 bytecode.
For example: A request without valid credentials is rejected by the auth decorator before the annotated handler starts. While its response is being sent, http_server_active_requests for that service and method can be 1, although the doc says only requests with a started handler are counted.
| | `http_server_active_requests` | Requests on the API listener whose handler has started and not finished, tagged by `hostname_pattern`, `service`, and `method`. Sum the series for the total in-flight requests. Example: `http_server_active_requests{hostname_pattern="*:8080",method="createCatalog",service="io.unitycatalog.server.service.CatalogService"} 0.0` | | |
| | `http_server_active_requests` | Requests on the API listener that have been received and whose response has not completed, including requests later rejected by authentication or authorization, tagged by `hostname_pattern`, `service`, and `method`. Sum the series for the total in-flight requests. Example: `http_server_active_requests{hostname_pattern="*:8080",method="createCatalog",service="io.unitycatalog.server.service.CatalogService"} 0.0` | |
How about describing the gauge by the request lifecycle, as in the suggested wording, unless a test shows the handler-based description is accurate?
There was a problem hiding this comment.
Good call, I checked: an unauthenticated listVolumes that only ever got a 401 still shows up in http_server_active_requests, so rejected requests are counted. yili-db's point holds too though: for requests that reach the handler, counting starts only once the handler gets the content. Reworded the row to cover both.
Rejected requests are counted too; requests that reach the handler are counted once the handler gets the content. Signed-off-by: Yuewei Zhou <[email protected]>
|
/review |
| .startsWith("http_server_requests_total{") | ||
| .contains("service=", "method=", "http_status=") | ||
| .doesNotContain("result=")); | ||
| .startsWith("http_server_total_duration_seconds_count{") |
There was a problem hiding this comment.
Nit (not a blocker): Duration test passes on a createCatalog series whose count is 0
The anySatisfy at this line checks only the http_server_total_duration_seconds_count prefix and the method label, so a line ending in ' 0' passes. The base setup has already created a catalog, so the count should be at least 1. As written, the test would not notice a timer that is registered but never recorded into. The same presence-only shape appears elsewhere in this PR: the _sum and _max lines in the allSatisfy at lines 224-236 are checked by name and labels only. In MetricsRegistriesTest, lines 47 and 48 use bare contains() on _sum and _max, although the test records exactly 5 ms. For _max I did not check the pinned Micrometer output. The Prometheus format may expose it as its own gauge family with HELP and TYPE lines, which would satisfy the bare substring on their own. The http_server_active_requests check at line 244 has the same shape, but that gauge reads 0 by design in this scrape, so I would leave it.
For example: If the timer were never recorded into, the scrape would show http_server_total_duration_seconds_count{...method="createCatalog"...} 0 and the test would still pass.
assertThat(httpServerLines)
.anySatisfy(
line -> {
assertThat(line)
.startsWith("http_server_total_duration_seconds_count{")
.contains("method=\"createCatalog\"");
assertThat(Double.parseDouble(line.substring(line.lastIndexOf(' ') + 1)))
.isGreaterThanOrEqualTo(1);
})
.anySatisfy(line -> assertThat(line).startsWith("http_server_active_requests{"));
How about parsing the sample value the way tablesCreated() does, and giving the _sum and _max assertions in MetricsRegistriesTest values too, such as "http_server_total_duration_seconds_sum 0.005"?
There was a problem hiding this comment.
Good catch thanks! Fixed.
Require the createCatalog duration count to be at least 1, and check the exact _sum and _max values in the unit test so a HELP line cannot satisfy them. Signed-off-by: Yuewei Zhou <[email protected]>
|
/review |
yili-db
left a comment
There was a problem hiding this comment.
[AI Assisted] Approving after shba24's review. The changes since d1abc2b are docs and tests only.
Three non-blocking leftovers, all inline or below:
- The
http_server_active_requestsrow (inline) and thecount 1assertion (inline) are the open points. - Outside the diff: the heading "HTTP request counter labels" (around line 115 of
docs/server/observability.md) and the sentence "not included in this counter" (around lines 139-140) still describe only the counter, although the same labels and exclusions now cover the duration and in-flight series.
| | `armeria_server_*`, `armeria_executor_*` | Armeria server and executor internals | | ||
| | `http_server_requests_total` | Completed HTTP requests on the API listener, tagged by `hostname_pattern`, `service`, `method`, and `http_status`; includes authentication and authorization rejections | | ||
| | `http_server_total_duration_seconds_count`, `_sum`, `_max` | Time from receiving a request to sending the full response on the API listener, tagged by `hostname_pattern`, `service`, `method`, and `http_status`. For the recent average latency of an endpoint, use `rate(http_server_total_duration_seconds_sum[5m]) / rate(http_server_total_duration_seconds_count[5m])`; `_max` is the slowest request in roughly the last 6 to 9 minutes. Example: `http_server_total_duration_seconds_count{hostname_pattern="*:8080",http_status="200",method="createCatalog",service="io.unitycatalog.server.service.CatalogService"} 1` | | ||
| | `http_server_active_requests` | Requests on the API listener that have been received and whose response has not completed, including requests later rejected by authentication or authorization, tagged by `hostname_pattern`, `service`, and `method`. A request that reaches its handler is counted only once the handler gets the request content, so one still uploading its body or waiting for a worker thread is not counted yet. Sum the series for the total in-flight requests. Example: `http_server_active_requests{hostname_pattern="*:8080",method="createCatalog",service="io.unitycatalog.server.service.CatalogService"} 0.0` | |
There was a problem hiding this comment.
[AI Assisted] This row says the gauge counts requests that have been received, then says a request still uploading its body or waiting for a worker thread is not counted yet. Those two statements conflict. Could the row be reworded so the two clauses agree?
| assertThat(registry.scrape()) | ||
| .contains( | ||
| "http_server_requests_total 1.0", | ||
| "http_server_total_duration_seconds_count 1", |
There was a problem hiding this comment.
[AI Assisted] This is a substring match, so http_server_total_duration_seconds_count 1 also matches a count of 10 or 12. Could the assertion match the whole line?
PR Checklist
docsis updatedDescription of changes
/metricsonly shows request counts per endpoint, so you can't tell when an endpoint gets slow or how many requests are in flight. Armeria already records both, but the registry filter drops them. This letshttp.server.total.durationandhttp.server.active.requeststhrough. Every otherhttp.server.*meter stays denied.One difference from the issue text: Armeria adds 9 client-side percentiles to its timers by default, so allowing the timer alone gives 12 series per endpoint and status, not 3. A small filter turns those off for
http.server.total.duration, leaving only_count,_sumand_max.Example after a
createCatalogcall:The metric families table in
docs/server/observability.mdlists both.Test plan
MetricsRegistriesTest: new test checks whichhttp.server.*meters are exposed and that noquantile=series show up.ObservabilityEndpointsIntegrationTest: accepts the new families and checks for acreateCataloglatency series and an active-requests series.build/sbt javafmtAllpassed.build/sbt "server/testOnly io.unitycatalog.server.observability.ObservabilityEndpointsIntegrationTest io.unitycatalog.server.observability.MetricsRegistriesTest io.unitycatalog.server.UnityCatalogServerTest": 13 passed./metrics(10 classes, includingPermissionServiceTest,IcebergRestCatalogTestandAuthServiceTest): 79 passed.