frostfs-node/pkg/metrics/morphcache.go
Dmitrii Stepanov 71bbeddb64 [#424] metrics: Drop unused arg
Signed-off-by: Dmitrii Stepanov <d.stepanov@yadro.com>
2023-06-14 14:51:40 +03:00

77 lines
2 KiB
Go

package metrics
import (
"fmt"
"strconv"
"time"
"git.frostfs.info/TrueCloudLab/frostfs-observability/metrics"
"github.com/prometheus/client_golang/prometheus"
)
const (
mcSubsystem = "morphcache"
mcSuccess = "success"
)
type MorphCacheMetrics interface {
AddNNSContractHashDuration(success bool, d time.Duration)
AddGroupKeyDuration(success bool, d time.Duration)
AddTxHeightDuration(success bool, d time.Duration)
}
type morphCacheMetrics struct {
// Duration of processing get nns contract hash request
nnsContractHashDuration *prometheus.HistogramVec
// Duration of processing get group key request
groupKeyDuration *prometheus.HistogramVec
// Duration of processing get tx height request
txHeightDuration *prometheus.HistogramVec
}
var _ MorphCacheMetrics = (*morphCacheMetrics)(nil)
func newMorphCacheMetrics() *morphCacheMetrics {
return &morphCacheMetrics{
nnsContractHashDuration: newMCMethodDurationCounter("nns_contract_hash"),
groupKeyDuration: newMCMethodDurationCounter("group_key"),
txHeightDuration: newMCMethodDurationCounter("tx_height"),
}
}
func (m *morphCacheMetrics) AddNNSContractHashDuration(success bool, d time.Duration) {
m.nnsContractHashDuration.With(
prometheus.Labels{
mcSuccess: strconv.FormatBool(success),
},
).Observe(float64(d))
}
func (m *morphCacheMetrics) AddGroupKeyDuration(success bool, d time.Duration) {
m.groupKeyDuration.With(
prometheus.Labels{
mcSuccess: strconv.FormatBool(success),
},
).Observe(float64(d))
}
func (m *morphCacheMetrics) AddTxHeightDuration(success bool, d time.Duration) {
m.txHeightDuration.With(
prometheus.Labels{
mcSuccess: strconv.FormatBool(success),
},
).Observe(float64(d))
}
func newMCMethodDurationCounter(method string) *prometheus.HistogramVec {
return metrics.NewHistogramVec(prometheus.HistogramOpts{
Namespace: namespace,
Subsystem: mcSubsystem,
Name: fmt.Sprintf("%s_req_duration_seconds", method),
Help: fmt.Sprintf("Accumulated %s request process duration", method),
}, []string{mcSuccess})
}