[#373] metrics: Add pilorama metrics

Signed-off-by: Dmitrii Stepanov <d.stepanov@yadro.com>
This commit is contained in:
Dmitrii Stepanov 2023-06-09 16:19:47 +03:00
parent e89fa110c7
commit b5d9f4a285
5 changed files with 100 additions and 0 deletions

View file

@ -729,6 +729,9 @@ func (c *cfg) getPiloramaOpts(shCfg shardCfg) []pilorama.Option {
pilorama.WithMaxBatchSize(prRead.maxBatchSize),
pilorama.WithMaxBatchDelay(prRead.maxBatchDelay),
)
if c.metricsCollector != nil {
piloramaOpts = append(piloramaOpts, pilorama.WithMetrics(lsmetrics.NewPiloramaMetrics(c.metricsCollector.PiloramaMetrics())))
}
}
return piloramaOpts
}

View file

@ -0,0 +1,37 @@
package metrics
import (
"time"
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/pilorama"
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/shard/mode"
metrics_impl "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/metrics"
)
func NewPiloramaMetrics(m metrics_impl.PiloramaMetrics) pilorama.Metrics {
return &piloramaMetrics{
shardID: undefined,
m: m,
}
}
type piloramaMetrics struct {
shardID string
m metrics_impl.PiloramaMetrics
}
func (m *piloramaMetrics) SetParentID(id string) {
m.shardID = id
}
func (m *piloramaMetrics) SetMode(mode mode.Mode) {
m.m.SetMode(m.shardID, mode)
}
func (m *piloramaMetrics) Close() {
m.m.Close(m.shardID)
}
func (m *piloramaMetrics) AddMethodDuration(method string, d time.Duration, success bool) {
m.m.AddMethodDuration(m.shardID, method, d, success)
}

View file

@ -5,6 +5,7 @@ const (
blobstoreSubSystem = "blobstore"
blobovnizaTreeSubSystem = "blobovniza_tree"
metabaseSubSystem = "metabase"
piloramaSubSystem = "pilorama"
successLabel = "success"
shardIDLabel = "shardID"

View file

@ -18,6 +18,7 @@ type NodeMetrics struct {
blobstore *blobstoreMetrics
blobobvnizca *blobovnizca
metabase *metabaseMetrics
pilorama *piloramaMetrics
}
func NewNodeMetrics() *NodeMetrics {
@ -37,6 +38,7 @@ func NewNodeMetrics() *NodeMetrics {
blobstore: newBlobstoreMetrics(),
blobobvnizca: newBlobovnizca(),
metabase: newMetabaseMetrics(),
pilorama: newPiloramaMetrics(),
}
}
@ -80,3 +82,7 @@ func (m *NodeMetrics) BlobobvnizcaTreeMetrics() BlobobvnizcaMetrics {
func (m *NodeMetrics) MetabaseMetrics() MetabaseMetrics {
return m.metabase
}
func (m *NodeMetrics) PiloramaMetrics() PiloramaMetrics {
return m.pilorama
}

53
pkg/metrics/pilorama.go Normal file
View file

@ -0,0 +1,53 @@
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.Mode)
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.Mode) {
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,
})
}