Add metrics tags to SQLDatasourceParams for Hikari Connection Pool Observability#1254
Conversation
This update introduces metrics tags for database host, port, and name in the SQLDatasourceParams configuration, enhancing observability for PostgreSQL connections.
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
📝 WalkthroughWalkthroughcreateClient in ClientProcessorUtils now collects HOST, PORT, and DATABASE into a metrics tags map and injects it into SQLDatasourceParams via setMetricsTags(). Several build/dependency files were updated: version bumps, one dependency JAR path update, and removal of Dependencies.toml. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 1 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (1 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
native/src/main/java/io/ballerina/stdlib/postgresql/nativeimpl/ClientProcessorUtils.java (1)
70-78: Metrics tag construction logic is sound, but relies on non-existent API.The logic for constructing the metrics tags map is correct:
- Always includes
TAG_DB_HOST- Conditionally includes
TAG_DB_PORTwhenportValue > 0- Conditionally includes
TAG_DB_NAMEwhen database is non-null and non-emptyHowever, there's a minor inefficiency -
hostextraction on line 70 duplicates the call already used in line 42 for URL construction. Consider reusing a local variable.♻️ Suggested refactor to avoid duplicate getValue() call
public static Object createClient(BObject client, BMap<BString, Object> clientConfig, BMap<BString, Object> globalPool) { - String url = Constants.JDBC_URL + clientConfig.getStringValue(Constants.ClientConfiguration.HOST); + String host = clientConfig.getStringValue(Constants.ClientConfiguration.HOST).getValue(); + String url = Constants.JDBC_URL + host; Long portValue = clientConfig.getIntValue(Constants.ClientConfiguration.PORT); ... - String host = clientConfig.getStringValue(Constants.ClientConfiguration.HOST).getValue(); Map<String, String> metricsTags = new HashMap<>(); - metricsTags.put(ObservabilityUtils.TAG_DB_HOST, host); + metricsTags.put(TAG_DB_HOST, host); // Use constant directly once available🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@native/src/main/java/io/ballerina/stdlib/postgresql/nativeimpl/ClientProcessorUtils.java` around lines 70 - 78, The code extracts the host twice from clientConfig causing a redundant getStringValue() call; in ClientProcessorUtils, reuse the host value already obtained for URL construction instead of calling clientConfig.getStringValue(Constants.ClientConfiguration.HOST).getValue() again when building metricsTags (where you put ObservabilityUtils.TAG_DB_HOST), so remove the duplicate extraction and reference the existing host variable when populating metricsTags and conditional TAG_DB_PORT/TAG_DB_NAME entries.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In
`@native/src/main/java/io/ballerina/stdlib/postgresql/nativeimpl/ClientProcessorUtils.java`:
- Line 27: The build fails because the code imports
io.ballerina.stdlib.sql.observability.ObservabilityUtils and calls
SQLDatasourceParams.setMetricsTags(...) but those symbols/methods don't exist in
the sql module v1.16.0; either upgrade the sql dependency to a version that
exposes ObservabilityUtils and its TAG_DB_HOST/TAG_DB_PORT/TAG_DB_NAME constants
and the SQLDatasourceParams.setMetricsTags(Map<String,String>) method, or
remove/guard the usage: delete the ObservabilityUtils import and any calls to
ObservabilityUtils.TAG_* and SQLDatasourceParams.setMetricsTags in
ClientProcessorUtils, or wrap them behind a feature-detection/compatibility shim
that falls back to the existing API for setting metrics (or no-op) when the
newer sql module is not available; locate references by the class name
ObservabilityUtils and the method setMetricsTags on SQLDatasourceParams to
update accordingly.
---
Nitpick comments:
In
`@native/src/main/java/io/ballerina/stdlib/postgresql/nativeimpl/ClientProcessorUtils.java`:
- Around line 70-78: The code extracts the host twice from clientConfig causing
a redundant getStringValue() call; in ClientProcessorUtils, reuse the host value
already obtained for URL construction instead of calling
clientConfig.getStringValue(Constants.ClientConfiguration.HOST).getValue() again
when building metricsTags (where you put ObservabilityUtils.TAG_DB_HOST), so
remove the duplicate extraction and reference the existing host variable when
populating metricsTags and conditional TAG_DB_PORT/TAG_DB_NAME entries.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: e48a8d1f-2d2d-4757-a9a3-05668cce47d1
📒 Files selected for processing (1)
native/src/main/java/io/ballerina/stdlib/postgresql/nativeimpl/ClientProcessorUtils.java
native/src/main/java/io/ballerina/stdlib/postgresql/nativeimpl/ClientProcessorUtils.java
Show resolved
Hide resolved
native/src/main/java/io/ballerina/stdlib/postgresql/nativeimpl/ClientProcessorUtils.java
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@ballerina/Ballerina.toml`:
- Around line 24-31: The TOML currently references an unreleased snapshot JAR
and local repo: change path = "./lib/sql-native-1.18.0-SNAPSHOT.jar" to the
released artifact (remove SNAPSHOT, e.g., "sql-native-1.18.0.jar" or the
canonical release coordinate) and update [[dependency]] repository = "local" to
the official repository name (e.g., the public Ballerina/Central repo) and
ensure the dependency version remains "1.18.0" to match the released artifact;
update both the path string and the repository value in Ballerina.toml so the
build uses the published sql 1.18.0 release instead of the SNAPSHOT.
In
`@native/src/main/java/io/ballerina/stdlib/postgresql/nativeimpl/ClientProcessorUtils.java`:
- Around line 70-76: The metrics tag for DB port in ClientProcessorUtils is
added unconditionally using portValue.intValue(), which can be 0 while the
actual connection uses the default port or omits it; update the logic that
builds metricsTags (the block that currently calls
metricsTags.put(ObservabilityUtils.TAG_DB_PORT,
String.valueOf(portValue.intValue()))) to mirror the connection URL logic: only
add the TAG_DB_PORT when portValue > 0 (or otherwise set it to the effective
port value used for connection, e.g., 5432) so observability reflects the real
connection port; adjust checks around portValue and the code that populates
metricsTags and the connection URL to keep them consistent.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: af8cbd5a-31a2-44d9-990d-e87597ba4b6f
📒 Files selected for processing (3)
ballerina/Ballerina.tomlballerina/Dependencies.tomlnative/src/main/java/io/ballerina/stdlib/postgresql/nativeimpl/ClientProcessorUtils.java
✅ Files skipped from review due to trivial changes (1)
- ballerina/Dependencies.toml
native/src/main/java/io/ballerina/stdlib/postgresql/nativeimpl/ClientProcessorUtils.java
Show resolved
Hide resolved
ae17575 to
240de0b
Compare
Codecov Report❌ Patch coverage is
❌ Your project status has failed because the head coverage (78.62%) is below the target coverage (80.00%). You can increase the head coverage or adjust the target coverage. Additional details and impacted files@@ Coverage Diff @@
## main #1254 +/- ##
============================================
- Coverage 81.82% 78.62% -3.21%
Complexity 864 864
============================================
Files 28 28
Lines 3566 3242 -324
Branches 494 444 -50
============================================
- Hits 2918 2549 -369
- Misses 432 475 +43
- Partials 216 218 +2 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
…tionality and compatibility
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@gradle.properties`:
- Line 28: The pinned timestamped property stdlibSqlVersion in gradle.properties
(currently set to 1.19.0-20260331-111100-8a9f7f8) should be replaced with a
stable release (e.g., 1.19.0) if one exists, or add a brief comment alongside
the stdlibSqlVersion property explaining that this module intentionally tracks a
development/pre-release snapshot and describing the update/rollback strategy and
expected reproducibility implications; update the stdlibSqlVersion key or its
comment accordingly so future readers see the chosen stable version or the
documented rationale.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 17e5fd76-cab9-4907-bd06-4111cf6a3111
📒 Files selected for processing (4)
ballerina/Ballerina.tomlballerina/Dependencies.tomlbuild-config/resources/Ballerina.tomlgradle.properties
💤 Files with no reviewable changes (1)
- ballerina/Dependencies.toml
✅ Files skipped from review due to trivial changes (2)
- build-config/resources/Ballerina.toml
- ballerina/Ballerina.toml
Updated stdlibSqlVersion to remove timestamp.
Introduces metrics tags for database host, port, and name in the SQLDatasourceParams configuration, enhancing observability for PostgreSQL connections.
This pull request enhances observability for PostgreSQL database connections by adding standardized metrics tags (host, port, and database name when present) to the SQLDatasourceParams used by the Hikari connection pool. The change collects host and port from connection parameters, conditionally includes the database name, builds a metrics tags map via observability utilities, and sets it on SQLDatasourceParams to enable connection-pool-level monitoring.
Other notable changes in this PR:
Outcome: improved monitoring and diagnostics for PostgreSQL connections and dependency upgrades for compatibility and functionality.