Skip to content

[Server] Expose per-endpoint latency and in-flight requests in /metrics - #2266

Merged
yili-db merged 6 commits into
unitycatalog:mainfrom
ZephyrYWZhou:server-http-latency-metrics
Nov 18, 2026
Merged

yili-db merged 6 commits into
unitycatalog:mainfrom
ZephyrYWZhou:server-http-latency-metrics

Conversation

@ZephyrYWZhou

@ZephyrYWZhou ZephyrYWZhou commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

PR Checklist

Description of changes

/metrics only 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 lets http.server.total.duration and http.server.active.requests through. Every other http.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, _sum and _max.

Example after a createCatalog call:

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{hostname_pattern="*:8080",method="createCatalog",service="io.unitycatalog.server.service.CatalogService"} 0.0

The metric families table in docs/server/observability.md lists both.

Test plan

  • MetricsRegistriesTest: new test checks which http.server.* meters are exposed and that no quantile= series show up.
  • ObservabilityEndpointsIntegrationTest: accepts the new families and checks for a createCatalog latency series and an active-requests series.
  • With the percentile filter turned off, both tests fail.
  • build/sbt javafmtAll passed.
  • build/sbt "server/testOnly io.unitycatalog.server.observability.ObservabilityEndpointsIntegrationTest io.unitycatalog.server.observability.MetricsRegistriesTest io.unitycatalog.server.UnityCatalogServerTest": 13 passed.
  • Every server test class that reads /metrics (10 classes, including PermissionServiceTest, IcebergRestCatalogTest and AuthServiceTest): 79 passed.

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]>
@ZephyrYWZhou
ZephyrYWZhou marked this pull request as ready for review November 17, 2026 18:39
@yili-db

yili-db commented Nov 17, 2026

Copy link
Copy Markdown
Collaborator

/review

@yili-db yili-db left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

[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.java line 278 still says the registry filters this family to request counts.
  • The http_status label can be 0 for a request cancelled before a response was sent. The docs describe it only as the final response status (docs/server/observability.md around line 124).
  • Follow-up, not for this PR: the / route and other non-annotated services get a service label like io.unitycatalog.server.ArmeriaServerBuilder$$Lambda$693/0x..., where the hex changes on every JVM start, so each restart creates new series. This already applies to http_server_requests_total; a stable route name would fix it.

Comment thread docs/server/observability.md Resolved
…-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]>
@ZephyrYWZhou

ZephyrYWZhou commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor Author

Thanks for the thorough review @yili-db ! Fixed the stale comment in ArmeriaServerBuilder and added the http_status=0 case to the docs. I'll open a separate issue for the lambda service name.

@ZephyrYWZhou

ZephyrYWZhou commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor Author

Opened #2282 issue for the lambda service name.

@ZephyrYWZhou
ZephyrYWZhou requested a review from yili-db November 17, 2026 23:57
@yili-db

yili-db commented Nov 18, 2026

Copy link
Copy Markdown
Collaborator

/review

@yili-db
yili-db requested a review from shba24 November 18, 2026 05:06
@yili-db

yili-db commented Nov 18, 2026

Copy link
Copy Markdown
Collaborator

@shba24 please take a look

Comment thread docs/server/observability.md Outdated
| `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` |

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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.

Suggested change
| `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?

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.

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]>
@ZephyrYWZhou
ZephyrYWZhou requested a review from shba24 November 18, 2026 05:28
@ZephyrYWZhou

Copy link
Copy Markdown
Contributor Author

@yili-db @shba24 thanks both for the review! I think everything is addressed now. Could one of you initiate the CI run when you get a chance? Thanks!

@yili-db

yili-db commented Nov 18, 2026

Copy link
Copy Markdown
Collaborator

/review

.startsWith("http_server_requests_total{")
.contains("service=", "method=", "http_status=")
.doesNotContain("result="));
.startsWith("http_server_total_duration_seconds_count{")

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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"?

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.

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]>
@yili-db

yili-db commented Nov 18, 2026

Copy link
Copy Markdown
Collaborator

/review

@yili-db yili-db left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

[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_requests row (inline) and the count 1 assertion (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` |

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

[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",

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

[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?

@yili-db
yili-db merged commit 30b3f2d into unitycatalog:main Nov 18, 2026
21 checks passed
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.

[Server] Expose per-endpoint latency and in-flight requests in /metrics

3 participants