Repository navigation
meta/sql: expose connection pool metrics - #7722
CodeRusher wants to merge 4 commits into
Conversation
Register the existing Prometheus DBStats collector for SQL metadata clients so connection occupancy, waiting and churn are observable. Preserve common metadata metrics and keep non-SQL backends unchanged. Add pool lifecycle, contention, concurrent collection and backend isolation tests, plus English and Chinese metric references. Signed-off-by: CodeRusher <coderushing@gamil.com>
Keep one table-driven test for SQL collector registration, common metadata metrics, nil registerers and non-SQL backend isolation. Leave connection pool behavior and collector field mapping to the upstream dependencies. Signed-off-by: CodeRusher <coderushing@gamil.com>
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #7722 +/- ##
===========================================
- Coverage 57.86% 22.06% -35.81%
===========================================
Files 180 31 -149
Lines 60562 25446 -35116
===========================================
- Hits 35046 5615 -29431
+ Misses 21907 19231 -2676
+ Partials 3609 600 -3009 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Signed-off-by: CodeRusher <coderushing@gamil.com>
| func (m *dbMeta) InitMetrics(reg prometheus.Registerer) { | ||
| m.baseMeta.InitMetrics(reg) | ||
| if reg != nil { | ||
| reg.MustRegister(collectors.NewDBStatsCollector(m.db.DB().DB, "metadata")) |
There was a problem hiding this comment.
Potential label conflicts need to be handled here to prevent panics.
There was a problem hiding this comment.
Fixed in cb1511a. Replaced MustRegister with Register and a warning. A custom db_name label (even db_name=metadata) now causes the SQL collector to be skipped without a panic; common metadata metrics remain registered.
Validated with a standalone local SQLite reproduction covering ordinary labels, conflicting db_name=app / db_name=metadata, and a nil registerer. Normal registration exports all nine SQL metric families; conflicting registration logs a warning and other metrics still gather successfully. The existing TestSQLiteClient, default / nosqlite / SQL-disabled builds, go vet, and golangci-lint also passed.
Use Register and log failures so conflicting custom labels do not panic during SQL pool metric initialization. Keep existing metadata metrics and omit the SQL collector when registration fails. Signed-off-by: CodeRusher <coderushing@gamil.com>
Closes #7721
SQL metadata operations can slow down while waiting for a client-side connection, but existing transaction/operation metrics do not expose pool occupancy or waiting. For example, holding the only connection in a bounded pool makes subsequent acquisitions wait before their SQL executes.
Register the existing Prometheus
collectors.NewDBStatsCollectorindbMeta.InitMetrics, exporting ninejuicefs_go_sql_*metrics withdb_name="metadata". Common metadata metrics and nil-registerer behavior are preserved; Redis/KV registration is unchanged. Collection reads localDB.Stats()without SQL queries, background collection loops, dependency updates, or pool configuration changes. English and Chinese metric references are included.Registration errors, including conflicts with a custom
db_namelabel, are logged as warnings. The SQL collector is omitted when registration fails, allowing initialization to continue with common metadata metrics.Local validation on Go 1.25.10:
db_name=appanddb_name=metadatalog warnings without panicking, while common metrics still gather successfully; a nil registerer remains supportedgo test -mod=readonly -count=1 -run '^TestSQLiteClient$' ./pkg/metago build -mod=readonly ./pkg/meta, also withnosqliteandnosqlite,nomysql,nopggo vet -mod=readonly ./pkg/meta; golangci-lint v2.6.0 reports no new issuesNo new unit test files are included.