frostfs-node/internal/metrics/pilorama.go
Dmitrii Stepanov 8bd6d8dd8c
All checks were successful
DCO action / DCO (pull_request) Successful in 43s
Vulncheck / Vulncheck (pull_request) Successful in 1m0s
Tests and linters / Run gofumpt (pull_request) Successful in 1m19s
Build / Build Components (pull_request) Successful in 1m26s
Pre-commit hooks / Pre-commit (pull_request) Successful in 1m31s
Tests and linters / Staticcheck (pull_request) Successful in 2m12s
Tests and linters / Tests with -race (pull_request) Successful in 2m38s
Tests and linters / Tests (pull_request) Successful in 3m0s
Tests and linters / Lint (pull_request) Successful in 3m14s
Tests and linters / gopls check (pull_request) Successful in 3m38s
[#9999] pilorama: Add IO tag label to metrics
Signed-off-by: Dmitrii Stepanov <d.stepanov@yadro.com>
2025-02-24 11:36:17 +03:00

54 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, ioTag string)
}
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, ioTagLabel}),
}
}
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, ioTag string) {
m.reqDuration.With(prometheus.Labels{
shardIDLabel: shardID,
successLabel: strconv.FormatBool(success),
methodLabel: method,
ioTagLabel: ioTag,
}).Observe(d.Seconds())
}
func (m *piloramaMetrics) Close(shardID string) {
m.mode.SetMode(shardID, closedMode)
m.reqDuration.DeletePartialMatch(prometheus.Labels{
shardIDLabel: shardID,
})
}