mirror of
https://github.com/coder/coder.git
synced 2025-07-13 21:36:50 +00:00
chore: name unlabeled db transaction metrics (#15251)
This commit is contained in:
@ -74,6 +74,11 @@ func (m metricsStore) InTx(f func(database.Store) error, options *database.TxOpt
|
|||||||
options = database.DefaultTXOptions()
|
options = database.DefaultTXOptions()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if options.TxIdentifier == "" {
|
||||||
|
// empty strings are hard to deal with in grafana
|
||||||
|
options.TxIdentifier = "unlabeled"
|
||||||
|
}
|
||||||
|
|
||||||
start := time.Now()
|
start := time.Now()
|
||||||
err := m.Store.InTx(f, options)
|
err := m.Store.InTx(f, options)
|
||||||
dur := time.Since(start)
|
dur := time.Since(start)
|
||||||
@ -82,13 +87,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),
|
||||||
"tx_id": options.TxIdentifier, // Can be empty string for unlabeled
|
"tx_id": options.TxIdentifier,
|
||||||
}).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),
|
||||||
"tx_id": options.TxIdentifier, // Can be empty string for unlabeled
|
"tx_id": options.TxIdentifier,
|
||||||
}).Inc()
|
}).Inc()
|
||||||
|
|
||||||
// Log all serializable transactions that are retried.
|
// Log all serializable transactions that are retried.
|
||||||
|
@ -22,7 +22,7 @@ func TestInTxMetrics(t *testing.T) {
|
|||||||
|
|
||||||
successLabels := prometheus.Labels{
|
successLabels := prometheus.Labels{
|
||||||
"success": "true",
|
"success": "true",
|
||||||
"tx_id": "",
|
"tx_id": "unlabeled",
|
||||||
}
|
}
|
||||||
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"
|
||||||
|
Reference in New Issue
Block a user