Skip to content

Commit 7cb20d7

Browse files
authored
chore: name unlabeled db transaction metrics (#15251)
1 parent ecb2246 commit 7cb20d7

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

coderd/database/dbmetrics/dbmetrics.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,11 @@ func (m metricsStore) InTx(f func(database.Store) error, options *database.TxOpt
7474
options = database.DefaultTXOptions()
7575
}
7676

77+
if options.TxIdentifier == "" {
78+
// empty strings are hard to deal with in grafana
79+
options.TxIdentifier = "unlabeled"
80+
}
81+
7782
start := time.Now()
7883
err := m.Store.InTx(f, options)
7984
dur := time.Since(start)
@@ -82,13 +87,13 @@ func (m metricsStore) InTx(f func(database.Store) error, options *database.TxOpt
8287
// So IDs should be used sparingly to prevent too much bloat.
8388
m.txDuration.With(prometheus.Labels{
8489
"success": strconv.FormatBool(err == nil),
85-
"tx_id": options.TxIdentifier, // Can be empty string for unlabeled
90+
"tx_id": options.TxIdentifier,
8691
}).Observe(dur.Seconds())
8792

8893
m.txRetries.With(prometheus.Labels{
8994
"success": strconv.FormatBool(err == nil),
9095
"retries": strconv.FormatInt(int64(options.ExecutionCount()-1), 10),
91-
"tx_id": options.TxIdentifier, // Can be empty string for unlabeled
96+
"tx_id": options.TxIdentifier,
9297
}).Inc()
9398

9499
// Log all serializable transactions that are retried.

coderd/database/dbmetrics/dbmetrics_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ func TestInTxMetrics(t *testing.T) {
2222

2323
successLabels := prometheus.Labels{
2424
"success": "true",
25-
"tx_id": "",
25+
"tx_id": "unlabeled",
2626
}
2727
const inTxHistMetricName = "coderd_db_tx_duration_seconds"
2828
const inTxCountMetricName = "coderd_db_tx_executions_count"

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy