[#412] node: Replace metrics package

Use observability module.

Signed-off-by: Dmitrii Stepanov <d.stepanov@yadro.com>
This commit is contained in:
Dmitrii Stepanov 2023-05-31 12:25:32 +03:00 committed by Evgenii Stratonikov
parent 74578052f9
commit c09144ecf1
15 changed files with 162 additions and 459 deletions

View file

@ -5,24 +5,25 @@ import (
"strings"
"time"
"git.frostfs.info/TrueCloudLab/frostfs-observability/metrics"
"github.com/prometheus/client_golang/prometheus"
)
type (
engineMetrics struct {
listContainersDuration metric[prometheus.Counter]
estimateContainerSizeDuration metric[prometheus.Counter]
deleteDuration metric[prometheus.Counter]
existsDuration metric[prometheus.Counter]
getDuration metric[prometheus.Counter]
headDuration metric[prometheus.Counter]
inhumeDuration metric[prometheus.Counter]
putDuration metric[prometheus.Counter]
rangeDuration metric[prometheus.Counter]
searchDuration metric[prometheus.Counter]
listObjectsDuration metric[prometheus.Counter]
containerSize metric[*prometheus.GaugeVec]
payloadSize metric[*prometheus.GaugeVec]
listContainersDuration prometheus.Counter
estimateContainerSizeDuration prometheus.Counter
deleteDuration prometheus.Counter
existsDuration prometheus.Counter
getDuration prometheus.Counter
headDuration prometheus.Counter
inhumeDuration prometheus.Counter
putDuration prometheus.Counter
rangeDuration prometheus.Counter
searchDuration prometheus.Counter
listObjectsDuration prometheus.Counter
containerSize *prometheus.GaugeVec
payloadSize *prometheus.GaugeVec
}
)
@ -46,8 +47,8 @@ func newEngineMetrics() engineMetrics {
}
}
func newEngineCounter(name, help string) metric[prometheus.Counter] {
return newCounter(prometheus.CounterOpts{
func newEngineCounter(name, help string) prometheus.Counter {
return metrics.NewCounter(prometheus.CounterOpts{
Namespace: namespace,
Subsystem: engineSubsystem,
Name: name,
@ -55,15 +56,15 @@ func newEngineCounter(name, help string) metric[prometheus.Counter] {
})
}
func newEngineMethodDurationCounter(method string) metric[prometheus.Counter] {
func newEngineMethodDurationCounter(method string) prometheus.Counter {
return newEngineCounter(
fmt.Sprintf("%s_duration", method),
fmt.Sprintf("Accumulated duration of engine %s operations", strings.ReplaceAll(method, "_", " ")),
)
}
func newEngineGaugeVector(name, help string, labels []string) metric[*prometheus.GaugeVec] {
return newGaugeVec(prometheus.GaugeOpts{
func newEngineGaugeVector(name, help string, labels []string) *prometheus.GaugeVec {
return metrics.NewGaugeVec(prometheus.GaugeOpts{
Namespace: namespace,
Subsystem: engineSubsystem,
Name: name,
@ -71,70 +72,54 @@ func newEngineGaugeVector(name, help string, labels []string) metric[*prometheus
}, labels)
}
func (m engineMetrics) register() {
mustRegister(m.listContainersDuration)
mustRegister(m.estimateContainerSizeDuration)
mustRegister(m.deleteDuration)
mustRegister(m.existsDuration)
mustRegister(m.getDuration)
mustRegister(m.headDuration)
mustRegister(m.inhumeDuration)
mustRegister(m.putDuration)
mustRegister(m.rangeDuration)
mustRegister(m.searchDuration)
mustRegister(m.listObjectsDuration)
mustRegister(m.containerSize)
mustRegister(m.payloadSize)
}
func (m engineMetrics) AddListContainersDuration(d time.Duration) {
m.listObjectsDuration.value.Add(float64(d))
m.listObjectsDuration.Add(float64(d))
}
func (m engineMetrics) AddEstimateContainerSizeDuration(d time.Duration) {
m.estimateContainerSizeDuration.value.Add(float64(d))
m.estimateContainerSizeDuration.Add(float64(d))
}
func (m engineMetrics) AddDeleteDuration(d time.Duration) {
m.deleteDuration.value.Add(float64(d))
m.deleteDuration.Add(float64(d))
}
func (m engineMetrics) AddExistsDuration(d time.Duration) {
m.existsDuration.value.Add(float64(d))
m.existsDuration.Add(float64(d))
}
func (m engineMetrics) AddGetDuration(d time.Duration) {
m.getDuration.value.Add(float64(d))
m.getDuration.Add(float64(d))
}
func (m engineMetrics) AddHeadDuration(d time.Duration) {
m.headDuration.value.Add(float64(d))
m.headDuration.Add(float64(d))
}
func (m engineMetrics) AddInhumeDuration(d time.Duration) {
m.inhumeDuration.value.Add(float64(d))
m.inhumeDuration.Add(float64(d))
}
func (m engineMetrics) AddPutDuration(d time.Duration) {
m.putDuration.value.Add(float64(d))
m.putDuration.Add(float64(d))
}
func (m engineMetrics) AddRangeDuration(d time.Duration) {
m.rangeDuration.value.Add(float64(d))
m.rangeDuration.Add(float64(d))
}
func (m engineMetrics) AddSearchDuration(d time.Duration) {
m.searchDuration.value.Add(float64(d))
m.searchDuration.Add(float64(d))
}
func (m engineMetrics) AddListObjectsDuration(d time.Duration) {
m.listObjectsDuration.value.Add(float64(d))
m.listObjectsDuration.Add(float64(d))
}
func (m engineMetrics) AddToContainerSize(cnrID string, size int64) {
m.containerSize.value.With(prometheus.Labels{containerIDLabelKey: cnrID}).Add(float64(size))
m.containerSize.With(prometheus.Labels{containerIDLabelKey: cnrID}).Add(float64(size))
}
func (m engineMetrics) AddToPayloadCounter(shardID string, size int64) {
m.payloadSize.value.With(prometheus.Labels{shardIDLabelKey: shardID}).Add(float64(size))
m.payloadSize.With(prometheus.Labels{shardIDLabelKey: shardID}).Add(float64(size))
}