Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 9308331

Browse files
authored
chore: change promtheus label to 'tx_id' (coder#15238)
the 'id' label was not coming through. Maybe it's reserved? Or used in the chain somewhere.
1 parent e03ef62 commit 9308331

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

coderd/database/dbmetrics/dbmetrics.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ func NewDBMetrics(s database.Store, logger slog.Logger, reg prometheus.Registere
4141
// retries = Executions - 1 (as 1 execute is expected)
4242
"retries",
4343
// Uniquely naming some transactions can help debug reoccurring errors.
44-
"id",
44+
"tx_id",
4545
})
4646
reg.MustRegister(txRetries)
4747

@@ -54,7 +54,7 @@ func NewDBMetrics(s database.Store, logger slog.Logger, reg prometheus.Registere
5454
}, []string{
5555
"success", // Did the InTx function return an error?
5656
// Uniquely naming some transactions can help debug reoccurring errors.
57-
"id",
57+
"tx_id",
5858
})
5959
reg.MustRegister(txDuration)
6060
return &metricsStore{
@@ -82,13 +82,13 @@ func (m metricsStore) InTx(f func(database.Store) error, options *database.TxOpt
8282
// So IDs should be used sparingly to prevent too much bloat.
8383
m.txDuration.With(prometheus.Labels{
8484
"success": strconv.FormatBool(err == nil),
85-
"id": options.TxIdentifier, // Can be empty string for unlabeled
85+
"tx_id": options.TxIdentifier, // Can be empty string for unlabeled
8686
}).Observe(dur.Seconds())
8787

8888
m.txRetries.With(prometheus.Labels{
8989
"success": strconv.FormatBool(err == nil),
9090
"retries": strconv.FormatInt(int64(options.ExecutionCount()-1), 10),
91-
"id": options.TxIdentifier, // Can be empty string for unlabeled
91+
"tx_id": options.TxIdentifier, // Can be empty string for unlabeled
9292
}).Inc()
9393

9494
// Log all serializable transactions that are retried.
@@ -109,7 +109,7 @@ func (m metricsStore) InTx(f func(database.Store) error, options *database.TxOpt
109109
// since the first error was a serialization error.
110110
slog.Error(err), // Might be nil, that is ok!
111111
slog.F("executions", options.ExecutionCount()),
112-
slog.F("id", options.TxIdentifier),
112+
slog.F("tx_id", options.TxIdentifier),
113113
slog.F("duration", dur),
114114
)
115115
}

coderd/database/dbmetrics/dbmetrics_test.go

+3-3
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-
"id": "",
25+
"tx_id": "",
2626
}
2727
const inTxHistMetricName = "coderd_db_tx_duration_seconds"
2828
const inTxCountMetricName = "coderd_db_tx_executions_count"
@@ -86,15 +86,15 @@ func TestInTxMetrics(t *testing.T) {
8686
// Check that the metrics are registered
8787
inTxHistMetric := promhelp.HistogramValue(t, reg, inTxHistMetricName, prometheus.Labels{
8888
"success": "false",
89-
"id": id,
89+
"tx_id": id,
9090
})
9191
require.NotNil(t, inTxHistMetric)
9292
require.Equal(t, uint64(1), inTxHistMetric.GetSampleCount())
9393

9494
inTxCountMetric := promhelp.CounterValue(t, reg, inTxCountMetricName, prometheus.Labels{
9595
"success": "false",
9696
"retries": "1",
97-
"id": id,
97+
"tx_id": id,
9898
})
9999
require.NotNil(t, inTxCountMetric)
100100
require.Equal(t, 1, inTxCountMetric)

0 commit comments

Comments
 (0)