Skip to content

Commit

Permalink
fix: todo metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
istae committed Jan 28, 2024
1 parent b384f1c commit d293754
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
12 changes: 6 additions & 6 deletions pkg/storer/internal/transaction/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,32 +10,32 @@ import (
)

type metrics struct {
CommitCalls *prometheus.CounterVec
CommitDuration *prometheus.HistogramVec
MethodCalls *prometheus.CounterVec
MethodDuration *prometheus.HistogramVec
}

// newMetrics is a convenient constructor for creating new metrics.
func newMetrics() metrics {
const subsystem = "transaction"

return metrics{
CommitCalls: prometheus.NewCounterVec(
MethodCalls: prometheus.NewCounterVec(
prometheus.CounterOpts{
Namespace: m.Namespace,
Subsystem: subsystem,
Name: "commit_calls",
Help: "Number of commit calls.",
},
[]string{"status"},
[]string{"method", "status"},
),
CommitDuration: prometheus.NewHistogramVec(
MethodDuration: prometheus.NewHistogramVec(
prometheus.HistogramOpts{
Namespace: m.Namespace,
Subsystem: subsystem,
Name: "commit_duration",
Help: "The duration each commit call took.",
},
[]string{"status"},
[]string{"method", "status"},
),
}
}
9 changes: 5 additions & 4 deletions pkg/storer/internal/transaction/transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
)

// TODO(esad): remove contexts from sharky and any other storage call
// TODO(esad): continue metrics

/*
The rules of the transction is as follows:
Expand Down Expand Up @@ -208,11 +209,11 @@ func (t *transaction) Commit() (err error) {
defer func(ti time.Time) {
t.sharkyTrx.writtenLocs = nil // clear written locs so that the done callback does not remove them
if err != nil {
t.metrics.CommitCalls.WithLabelValues("failure").Inc()
t.metrics.CommitDuration.WithLabelValues("failure").Observe(float64(time.Since(ti)))
t.metrics.MethodCalls.WithLabelValues("commit", "failure").Inc()
t.metrics.MethodDuration.WithLabelValues("commit", "failure").Observe(float64(time.Since(ti)))
} else {
t.metrics.CommitCalls.WithLabelValues("success").Inc()
t.metrics.CommitDuration.WithLabelValues("success").Observe(float64(time.Since(ti)))
t.metrics.MethodCalls.WithLabelValues("commit", "success").Inc()
t.metrics.MethodDuration.WithLabelValues("commit", "success").Observe(float64(time.Since(ti)))
}
}(time.Now())

Expand Down

0 comments on commit d293754

Please sign in to comment.