Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions coderd/database/dbmetrics/dbmetrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func NewDBMetrics(s database.Store, logger slog.Logger, reg prometheus.Registere
// retries = Executions - 1 (as 1 execute is expected)
"retries",
// Uniquely naming some transactions can help debug reoccurring errors.
"id",
"tx_id",
})
reg.MustRegister(txRetries)

Expand All @@ -54,7 +54,7 @@ func NewDBMetrics(s database.Store, logger slog.Logger, reg prometheus.Registere
}, []string{
"success", // Did the InTx function return an error?
// Uniquely naming some transactions can help debug reoccurring errors.
"id",
"tx_id",
})
reg.MustRegister(txDuration)
return &metricsStore{
Expand Down Expand Up @@ -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.
m.txDuration.With(prometheus.Labels{
"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())

m.txRetries.With(prometheus.Labels{
"success": strconv.FormatBool(err == nil),
"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()

// Log all serializable transactions that are retried.
Expand All @@ -109,7 +109,7 @@ func (m metricsStore) InTx(f func(database.Store) error, options *database.TxOpt
// since the first error was a serialization error.
slog.Error(err), // Might be nil, that is ok!
slog.F("executions", options.ExecutionCount()),
slog.F("id", options.TxIdentifier),
slog.F("tx_id", options.TxIdentifier),
slog.F("duration", dur),
)
}
Expand Down
6 changes: 3 additions & 3 deletions coderd/database/dbmetrics/dbmetrics_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func TestInTxMetrics(t *testing.T) {

successLabels := prometheus.Labels{
"success": "true",
"id": "",
"tx_id": "",
}
const inTxHistMetricName = "coderd_db_tx_duration_seconds"
const inTxCountMetricName = "coderd_db_tx_executions_count"
Expand Down Expand Up @@ -86,15 +86,15 @@ func TestInTxMetrics(t *testing.T) {
// Check that the metrics are registered
inTxHistMetric := promhelp.HistogramValue(t, reg, inTxHistMetricName, prometheus.Labels{
"success": "false",
"id": id,
"tx_id": id,
})
require.NotNil(t, inTxHistMetric)
require.Equal(t, uint64(1), inTxHistMetric.GetSampleCount())

inTxCountMetric := promhelp.CounterValue(t, reg, inTxCountMetricName, prometheus.Labels{
"success": "false",
"retries": "1",
"id": id,
"tx_id": id,
})
require.NotNil(t, inTxCountMetric)
require.Equal(t, 1, inTxCountMetric)
Expand Down
Loading
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