Skip to content

Enable beholder metrics for sqlutil - #2353

Draft
dhaidashenko wants to merge 2 commits into
mainfrom
feature/PLEX-3345-sqlutil-beholder-metrics
Draft

Enable beholder metrics for sqlutil#2353
dhaidashenko wants to merge 2 commits into
mainfrom
feature/PLEX-3345-sqlutil-beholder-metrics

Conversation

@dhaidashenko

Copy link
Copy Markdown
Contributor

No description provided.

Copilot AI lite review requested due to automatic review settings September 2, 2026 16:45
@dhaidashenko
dhaidashenko requested a review from a team as a code owner September 2, 2026 16:45
@github-actions

github-actions Bot commented Sep 2, 2026

Copy link
Copy Markdown
Contributor

👋 dhaidashenko, thanks for creating this pull request!

To help reviewers, please consider creating future PRs as drafts first. This allows you to self-review and make any final changes before notifying the team.

Once you're ready, you can mark it as "Ready for review" to request feedback. Thanks!

@github-actions

github-actions Bot commented Sep 2, 2026

Copy link
Copy Markdown
Contributor

📊 API Diff Results

No changes detected for module github.com/smartcontractkit/chainlink-common

View full report

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

The new Beholder DB wait-time metric records a cumulative total into a histogram with mismatched naming/units vs the existing Prometheus gauge, which will produce misleading telemetry.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

This PR adds OpenTelemetry/Beholder metric emission for existing sqlutil and Postgres DB stats instrumentation, alongside the current Prometheus metrics, to support Beholder-based observability.

Changes:

  • Extend pg.StatsReporter to record DB connection pool stats to Beholder on each reporting interval.
  • Add Beholder metric plumbing for SQL query timeout-percentage histogram, mirroring the existing Prometheus histogram.
  • Refactor shared bucket definitions for SQL query timeout-percentage metrics.
File summaries
File Description
pkg/sqlutil/pg/stats.go Routes each stats tick through a new report(ctx) that also records Beholder DB stats.
pkg/sqlutil/pg/beholder_metrics.go Introduces Beholder instruments and recording for sql.DBStats fields.
pkg/sqlutil/monitor.go Reuses a shared bucket list and records Beholder histogram alongside Prometheus.
pkg/sqlutil/beholder_metrics.go Adds lazy-initialized Beholder histogram for sql_query_timeout_percent.
Review details
  • Files reviewed: 4/4 changed files
  • Comments generated: 2
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread pkg/sqlutil/pg/beholder_metrics.go Outdated
Comment thread pkg/sqlutil/beholder_metrics.go
@dhaidashenko
dhaidashenko marked this pull request as draft September 2, 2026 17:35
@dhaidashenko
dhaidashenko force-pushed the feature/PLEX-3345-sqlutil-beholder-metrics branch from 7e9f6a6 to 86bf7f6 Compare September 2, 2026 17:43
"go.opentelemetry.io/otel/metric"
"go.opentelemetry.io/otel/metric/noop"

"github.com/smartcontractkit/chainlink-common/pkg/beholder"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I don't think this package should import beholder. We already provide a means of setting a custom hook via StatsCustomReporterFn. Why don't we use that?

Comment on lines +46 to +47
sqlQueryTimeMetricOnce sync.Once
globalSQLQueryTimeMetric sqlQueryTimeMetric

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Do we strictly need a global instance? or could we inject something to use or construct from instead? We don't typically need to suppress errors for metric creation.

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.

3 participants