mirror of
https://github.com/coder/coder.git
synced 2025-07-13 21:36:50 +00:00
chore: change promtheus label to 'tx_id' (#15238)
the 'id' label was not coming through. Maybe it's reserved? Or used in the chain somewhere.
This commit is contained in:
@ -41,7 +41,7 @@ func NewDBMetrics(s database.Store, logger slog.Logger, reg prometheus.Registere
|
|||||||
// retries = Executions - 1 (as 1 execute is expected)
|
// retries = Executions - 1 (as 1 execute is expected)
|
||||||
"retries",
|
"retries",
|
||||||
// Uniquely naming some transactions can help debug reoccurring errors.
|
// Uniquely naming some transactions can help debug reoccurring errors.
|
||||||
"id",
|
"tx_id",
|
||||||
})
|
})
|
||||||
reg.MustRegister(txRetries)
|
reg.MustRegister(txRetries)
|
||||||
|
|
||||||
@ -54,7 +54,7 @@ func NewDBMetrics(s database.Store, logger slog.Logger, reg prometheus.Registere
|
|||||||
}, []string{
|
}, []string{
|
||||||
"success", // Did the InTx function return an error?
|
"success", // Did the InTx function return an error?
|
||||||
// Uniquely naming some transactions can help debug reoccurring errors.
|
// Uniquely naming some transactions can help debug reoccurring errors.
|
||||||
"id",
|
"tx_id",
|
||||||
})
|
})
|
||||||
reg.MustRegister(txDuration)
|
reg.MustRegister(txDuration)
|
||||||
return &metricsStore{
|
return &metricsStore{
|
||||||
@ -82,13 +82,13 @@ func (m metricsStore) InTx(f func(database.Store) error, options *database.TxOpt
|
|||||||
// So IDs should be used sparingly to prevent too much bloat.
|
// So IDs should be used sparingly to prevent too much bloat.
|
||||||
m.txDuration.With(prometheus.Labels{
|
m.txDuration.With(prometheus.Labels{
|
||||||
"success": strconv.FormatBool(err == nil),
|
"success": strconv.FormatBool(err == nil),
|
||||||
"id": options.TxIdentifier, // Can be empty string for unlabeled
|
"tx_id": options.TxIdentifier, // Can be empty string for unlabeled
|
||||||
}).Observe(dur.Seconds())
|
}).Observe(dur.Seconds())
|
||||||
|
|
||||||
m.txRetries.With(prometheus.Labels{
|
m.txRetries.With(prometheus.Labels{
|
||||||
"success": strconv.FormatBool(err == nil),
|
"success": strconv.FormatBool(err == nil),
|
||||||
"retries": strconv.FormatInt(int64(options.ExecutionCount()-1), 10),
|
"retries": strconv.FormatInt(int64(options.ExecutionCount()-1), 10),
|
||||||
"id": options.TxIdentifier, // Can be empty string for unlabeled
|
"tx_id": options.TxIdentifier, // Can be empty string for unlabeled
|
||||||
}).Inc()
|
}).Inc()
|
||||||
|
|
||||||
// Log all serializable transactions that are retried.
|
// Log all serializable transactions that are retried.
|
||||||
@ -109,7 +109,7 @@ func (m metricsStore) InTx(f func(database.Store) error, options *database.TxOpt
|
|||||||
// since the first error was a serialization error.
|
// since the first error was a serialization error.
|
||||||
slog.Error(err), // Might be nil, that is ok!
|
slog.Error(err), // Might be nil, that is ok!
|
||||||
slog.F("executions", options.ExecutionCount()),
|
slog.F("executions", options.ExecutionCount()),
|
||||||
slog.F("id", options.TxIdentifier),
|
slog.F("tx_id", options.TxIdentifier),
|
||||||
slog.F("duration", dur),
|
slog.F("duration", dur),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -22,7 +22,7 @@ func TestInTxMetrics(t *testing.T) {
|
|||||||
|
|
||||||
successLabels := prometheus.Labels{
|
successLabels := prometheus.Labels{
|
||||||
"success": "true",
|
"success": "true",
|
||||||
"id": "",
|
"tx_id": "",
|
||||||
}
|
}
|
||||||
const inTxHistMetricName = "coderd_db_tx_duration_seconds"
|
const inTxHistMetricName = "coderd_db_tx_duration_seconds"
|
||||||
const inTxCountMetricName = "coderd_db_tx_executions_count"
|
const inTxCountMetricName = "coderd_db_tx_executions_count"
|
||||||
@ -86,7 +86,7 @@ func TestInTxMetrics(t *testing.T) {
|
|||||||
// Check that the metrics are registered
|
// Check that the metrics are registered
|
||||||
inTxHistMetric := promhelp.HistogramValue(t, reg, inTxHistMetricName, prometheus.Labels{
|
inTxHistMetric := promhelp.HistogramValue(t, reg, inTxHistMetricName, prometheus.Labels{
|
||||||
"success": "false",
|
"success": "false",
|
||||||
"id": id,
|
"tx_id": id,
|
||||||
})
|
})
|
||||||
require.NotNil(t, inTxHistMetric)
|
require.NotNil(t, inTxHistMetric)
|
||||||
require.Equal(t, uint64(1), inTxHistMetric.GetSampleCount())
|
require.Equal(t, uint64(1), inTxHistMetric.GetSampleCount())
|
||||||
@ -94,7 +94,7 @@ func TestInTxMetrics(t *testing.T) {
|
|||||||
inTxCountMetric := promhelp.CounterValue(t, reg, inTxCountMetricName, prometheus.Labels{
|
inTxCountMetric := promhelp.CounterValue(t, reg, inTxCountMetricName, prometheus.Labels{
|
||||||
"success": "false",
|
"success": "false",
|
||||||
"retries": "1",
|
"retries": "1",
|
||||||
"id": id,
|
"tx_id": id,
|
||||||
})
|
})
|
||||||
require.NotNil(t, inTxCountMetric)
|
require.NotNil(t, inTxCountMetric)
|
||||||
require.Equal(t, 1, inTxCountMetric)
|
require.Equal(t, 1, inTxCountMetric)
|
||||||
|
Reference in New Issue
Block a user