Skip to content

Add metrics tags to SQLDatasourceParams for Hikari Connection Pool Observability#1254

Merged
niveathika merged 12 commits intoballerina-platform:mainfrom
YasanPunch:add-observability-metrics-tags
Apr 1, 2026
Merged

Add metrics tags to SQLDatasourceParams for Hikari Connection Pool Observability#1254
niveathika merged 12 commits intoballerina-platform:mainfrom
YasanPunch:add-observability-metrics-tags

Conversation

@YasanPunch
Copy link
Copy Markdown
Contributor

@YasanPunch YasanPunch commented Mar 28, 2026

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:

  • Dependency and build updates: bumps in multiple stdlib and observe-related versions in gradle.properties and the sql-native entry in ballerina/Ballerina.toml.
  • Removed build artifact metadata file: deletion of ballerina/Dependencies.toml.
  • Miscellaneous repository additions and project maintenance files updated as part of the commit that updates versions and CI workflows.

Outcome: improved monitoring and diagnostics for PostgreSQL connections and dependency upgrades for compatibility and functionality.

This update introduces metrics tags for database host, port, and name in the SQLDatasourceParams configuration, enhancing observability for PostgreSQL connections.
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Mar 28, 2026

Note

Reviews paused

It 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 reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

createClient 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

Cohort / File(s) Summary
Observability metadata enhancement
native/src/main/java/io/ballerina/stdlib/postgresql/nativeimpl/ClientProcessorUtils.java
Reads HOST, computes PORT as a string, conditionally includes DATABASE; builds a Map<String,String> of metrics tags using ObservabilityUtils keys and passes it to SQLDatasourceParams.setMetricsTags(); added ObservabilityUtils, HashMap, and Map imports.
Build property bumps
gradle.properties, build-config/resources/Ballerina.toml
Updated multiple version properties: ballerinaLangVersion2201.13.0, stdlibLogVersion2.17.0, stdlibSqlVersion1.19.0-20260331-111100-8a9f7f8, observeVersion1.7.1, stdlibCryptoVersion2.10.1, stdlibPostgresqlDriverVersion1.6.3; distribution version in Ballerina.toml updated similarly.
Platform dependency update
ballerina/Ballerina.toml
Updated [[platform.java21.dependency]] for io.ballerina.stdlib:sql-native from 1.16.0 (path ./lib/sql-native-1.16.0.jar) to 1.19.0 (path ./lib/sql-native-1.19.0-20260331-111100-8a9f7f8.jar).
Removed resolved dependencies manifest
ballerina/Dependencies.toml
Deleted the entire file containing resolved package metadata and dependency entries. No replacement file added.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Suggested reviewers

  • shafreenAnfar
  • aashikam
  • daneshk

Poem

🐰 I hopped through lines to tuck in HOST and PORT,

I stitched a tag-map neat — a tiny observability sort.
Database name peeks in when it’s not shy,
Metrics hum softly as connections go by,
🥕✨

🚥 Pre-merge checks | ✅ 1 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Description check ⚠️ Warning The PR description is too brief and does not follow the repository template structure, missing required sections like Purpose, Examples, and Checklist items. Expand the description to include Purpose (why this change is needed), Examples (if applicable), and complete the Checklist section with relevant items marked or explained.
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (1 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately and specifically describes the main change: adding metrics tags to SQLDatasourceParams for enhanced observability of the Hikari Connection Pool.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

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_PORT when portValue > 0
  • Conditionally includes TAG_DB_NAME when database is non-null and non-empty

However, there's a minor inefficiency - host extraction 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

📥 Commits

Reviewing files that changed from the base of the PR and between 18b0395 and 79540a2.

📒 Files selected for processing (1)
  • native/src/main/java/io/ballerina/stdlib/postgresql/nativeimpl/ClientProcessorUtils.java

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

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

📥 Commits

Reviewing files that changed from the base of the PR and between 79540a2 and ae17575.

📒 Files selected for processing (3)
  • ballerina/Ballerina.toml
  • ballerina/Dependencies.toml
  • native/src/main/java/io/ballerina/stdlib/postgresql/nativeimpl/ClientProcessorUtils.java
✅ Files skipped from review due to trivial changes (1)
  • ballerina/Dependencies.toml

@YasanPunch YasanPunch force-pushed the add-observability-metrics-tags branch from ae17575 to 240de0b Compare March 30, 2026 08:40
@YasanPunch YasanPunch requested a review from niveathika March 31, 2026 07:58
@codecov
Copy link
Copy Markdown

codecov bot commented Mar 31, 2026

Codecov Report

❌ Patch coverage is 87.50000% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 78.62%. Comparing base (18b0395) to head (7e0dafd).
⚠️ Report is 13 commits behind head on main.

Files with missing lines Patch % Lines
...ib/postgresql/nativeimpl/ClientProcessorUtils.java 87.50% 0 Missing and 1 partial ⚠️

❌ 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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

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

📥 Commits

Reviewing files that changed from the base of the PR and between 1b473ce and ef74952.

📒 Files selected for processing (4)
  • ballerina/Ballerina.toml
  • ballerina/Dependencies.toml
  • build-config/resources/Ballerina.toml
  • gradle.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

@niveathika niveathika merged commit 8998bce into ballerina-platform:main Apr 1, 2026
4 of 5 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.

2 participants