frostfs-node/pkg/metrics/pilorama.go
Alexander Chuprov d61f78ec1f [#1121] node: Change mode of shard components
Signed-off-by: Alexander Chuprov <a.chuprov@yadro.com>
2024-06-04 16:30:04 +03:00

53 lines
1.5 KiB
Go

package metrics
import (
"strconv"
"time"
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/shard/mode"
"git.frostfs.info/TrueCloudLab/frostfs-observability/metrics"
"github.com/prometheus/client_golang/prometheus"
)
type PiloramaMetrics interface {
SetMode(shardID string, m mode.ComponentMode)
Close(shardID string)
AddMethodDuration(shardID string, method string, d time.Duration, success bool)
}
func newPiloramaMetrics() *piloramaMetrics {
return &piloramaMetrics{
mode: newShardIDMode(piloramaSubSystem, "mode", "Pilorama mode"),
reqDuration: metrics.NewHistogramVec(prometheus.HistogramOpts{
Namespace: namespace,
Subsystem: piloramaSubSystem,
Name: "request_duration_seconds",
Help: "Accumulated Pilorama request process duration",
}, []string{shardIDLabel, successLabel, methodLabel}),
}
}
type piloramaMetrics struct {
mode *shardIDModeValue
reqDuration *prometheus.HistogramVec
}
func (m *piloramaMetrics) SetMode(shardID string, mode mode.ComponentMode) {
m.mode.SetMode(shardID, mode.String())
}
func (m *piloramaMetrics) AddMethodDuration(shardID string, method string, d time.Duration, success bool) {
m.reqDuration.With(prometheus.Labels{
shardIDLabel: shardID,
successLabel: strconv.FormatBool(success),
methodLabel: method,
}).Observe(d.Seconds())
}
func (m *piloramaMetrics) Close(shardID string) {
m.mode.SetMode(shardID, closedMode)
m.reqDuration.DeletePartialMatch(prometheus.Labels{
shardIDLabel: shardID,
})
}