2023-05-26 09:15:50 +00:00
|
|
|
package metrics
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2023-06-13 11:19:33 +00:00
|
|
|
"strconv"
|
2023-05-26 09:15:50 +00:00
|
|
|
"time"
|
|
|
|
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-observability/metrics"
|
|
|
|
"github.com/nspcc-dev/neo-go/pkg/util"
|
|
|
|
"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(hash util.Uint256, 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{
|
2023-06-13 11:19:33 +00:00
|
|
|
mcSuccess: strconv.FormatBool(success),
|
2023-05-26 09:15:50 +00:00
|
|
|
},
|
|
|
|
).Observe(float64(d))
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *morphCacheMetrics) AddGroupKeyDuration(success bool, d time.Duration) {
|
|
|
|
m.groupKeyDuration.With(
|
|
|
|
prometheus.Labels{
|
2023-06-13 11:19:33 +00:00
|
|
|
mcSuccess: strconv.FormatBool(success),
|
2023-05-26 09:15:50 +00:00
|
|
|
},
|
|
|
|
).Observe(float64(d))
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *morphCacheMetrics) AddTxHeightDuration(hash util.Uint256, success bool, d time.Duration) {
|
|
|
|
m.txHeightDuration.With(
|
|
|
|
prometheus.Labels{
|
2023-06-13 11:19:33 +00:00
|
|
|
mcSuccess: strconv.FormatBool(success),
|
2023-05-26 09:15:50 +00:00
|
|
|
},
|
|
|
|
).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})
|
|
|
|
}
|