Skip to content

[Server] Report database connection pool usage in /metrics - #2284

Merged
yili-db merged 1 commit into
unitycatalog:mainfrom
sakshi-bhasin:hikaricp-pool-metrics
Nov 20, 2026
Merged

yili-db merged 1 commit into
unitycatalog:mainfrom
sakshi-bhasin:hikaricp-pool-metrics

Conversation

@sakshi-bhasin

Copy link
Copy Markdown
Contributor

PR Checklist

  • A description of the changes is added to the description of this PR.
  • If there is a related issue, make sure it is linked to this PR.
  • If you've fixed a bug or added code that should be tested, add tests!
  • If you've added or modified a feature, documentation in docs is updated

Description of changes

Closes #2257

When observability is on, /metrics now reports the HikariCP pool with HikariCP's standard metric names, tagged by pool:

  • hikaricp_connections_active
  • hikaricp_connections_idle
  • hikaricp_connections_pending
  • hikaricp_connections
  • hikaricp_connections_max

Changes:

  • MetricsRegistries.bindHikariPool registers the five gauges from the pool's HikariPoolMXBean and getMaximumPoolSize(). It uses gauges and not HikariDataSource.setMetricRegistry, since a pool accepts a registry only once and tests can start more than one server on the same pool.
  • UnityCatalogServer.initializeObservability calls it right after the registry is created.
  • Added a row for the pool metrics to docs/server/observability.md.
  • ObservabilityEndpointsIntegrationTest now checks for hikaricp_connections_active and hikaricp_connections_max in the scrape.

Testing

  • build/sbt "server/testOnly io.unitycatalog.server.observability.ObservabilityEndpointsIntegrationTest io.unitycatalog.server.UnityCatalogServerTest" passes (10 tests).
  • Started a local server with --obs-port 8090. The scrape shows all five series, for example hikaricp_connections_max{pool="unity-catalog"} 20.0 and hikaricp_connections_idle{pool="unity-catalog"} 2.0.

@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 08:43
@yili-db

yili-db commented Nov 18, 2026

Copy link
Copy Markdown
Collaborator

@shba24 please take a look

+ " 0.0",
"http_server_requests_total");
"http_server_requests_total",
"hikaricp_connections_active",

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): Pool metric assertions only check name substrings, not series or values

The new assertions at lines 220-221 look for the substrings hikaricp_connections_active and hikaricp_connections_max in the /metrics body. A substring can also match the # HELP or # TYPE lines, so it says nothing about whether a sample with a value exists. The idle, pending and bare hikaricp_connections gauges are not asserted at all. The gauges look correct at head. This only makes the test stricter about what monitoring would rely on.

For example: If hikaricp_connections_pending were dropped from bindHikariPool, or a gauge reported NaN, this test would still pass. The # TYPE hikaricp_connections_active gauge line alone satisfies the substring check.

List<String> poolSamples =
    response.body().lines().filter(line -> line.startsWith("hikaricp_connections")).toList();
for (String name :
    List.of(
        "hikaricp_connections_active",
        "hikaricp_connections_idle",
        "hikaricp_connections_pending",
        "hikaricp_connections",
        "hikaricp_connections_max")) {
  assertThat(poolSamples)
      .anyMatch(line -> line.startsWith(name + "{pool=") && !line.endsWith(" NaN"));
}
assertThat(poolSamples)
    .anyMatch(line -> line.startsWith("hikaricp_connections_max{") && !line.endsWith(" 0.0"));

How about checking the sample lines for all five series in the existing helper, so the test covers real values and not only names?

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! The test now checks a sample line with a value for all five series, and that hikaricp_connections_max is not zero. Also rebased on main to resolve the conflict with #2266.

| `uc_securable_table_creations_total` | Table securables created after their database transactions commit through UC, Delta, or Iceberg REST, including tables, views, and metric views |
| `uc_storage_credential_cache_requests_total` | Credential requests to the [storage credential cache](configuration.md#storage-credential-cache), tagged by `result`: `hit` for a credential served from the cache, `miss` for a request the cache could not serve, which vends a new credential; a vend that fails also counts as a miss. Both series are exposed from startup and stay at zero while the cache is disabled |
| `uc_storage_cleanup_attempts_total` | Attempts by the storage cleanup worker to delete a dropped managed resource's files, tagged by `result` and `resource_type`. `success` means the attempt deleted the files; `failure` means the attempt failed, either deleting the files or saving the result to the database, and the task will be retried. It counts attempts, not dropped resources: when a lease expires and another attempt runs, one resource can record more than one success. `resource_type` is `table`, `volume`, `registered_model`, `model_version`, or `staging_table`. Every series is exposed from startup |
| `hikaricp_connections_active`, `hikaricp_connections_idle`, `hikaricp_connections_pending`, `hikaricp_connections`, `hikaricp_connections_max` | Usage of the database connection pool, tagged by `pool`: connections in use, idle connections, threads waiting for a connection, total connections, and the pool's maximum size. When `pending` stays above zero, requests are waiting for a free connection |

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): Docs say requests are waiting, but pending counts every waiting thread

The hikaricp_connections_pending gauge reads HikariPoolMXBean.getThreadsAwaitingConnection, which counts any thread waiting on the pool. The same pool also serves the readiness checker (its own db-readiness-checker thread) and the storage cleanup worker, so pending can be above zero when no API request is waiting.

For example: The readiness probe waits for a connection while the pool is full and no API call is in flight. pending is 1, and the doc tells the operator that requests are waiting.

Suggested change
| `hikaricp_connections_active`, `hikaricp_connections_idle`, `hikaricp_connections_pending`, `hikaricp_connections`, `hikaricp_connections_max` | Usage of the database connection pool, tagged by `pool`: connections in use, idle connections, threads waiting for a connection, total connections, and the pool's maximum size. When `pending` stays above zero, requests are waiting for a free connection |
| `hikaricp_connections_active`, `hikaricp_connections_idle`, `hikaricp_connections_pending`, `hikaricp_connections`, `hikaricp_connections_max` | Usage of the database connection pool, tagged by `pool`: connections in use, idle connections, threads waiting for a connection, total connections, and the pool's maximum size. When `pending` stays above zero, threads are waiting for a free connection; these can be API requests or background tasks such as the readiness check and the storage cleanup worker |

How about wording the last sentence in terms of threads, so it matches what the gauge counts?

@yili-db

yili-db commented Nov 20, 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 at 6d5443c. The pool gauges, their names and the pool tag match HikariCP's own Micrometer names, and a live scrape shows all five series with pool="unity-catalog". The open points are wording only, not blocking: the docs row should give the default pool name and say what pending counts, and the Javadoc should state the started-pool precondition.

@yili-db
yili-db merged commit 9b94065 into unitycatalog:main Nov 20, 2026
34 of 35 checks passed
shba24 added a commit to shba24/unitycatalog that referenced this pull request Nov 24, 2026
No conflicts. Brings in ownership transfer (unitycatalog#2149), pool metrics (unitycatalog#2284)
and the check that tests leave the checkout clean (unitycatalog#2334).

Co-authored-by: Isaac <[email protected]>
Signed-off-by: Shubham Bansal <[email protected]>
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] Report database connection pool usage in /metrics

3 participants