[#373] metrics: Add metabase metrics

Signed-off-by: Dmitrii Stepanov <d.stepanov@yadro.com>
This commit is contained in:
Dmitrii Stepanov 2023-06-09 12:45:31 +03:00
parent af608da952
commit e89fa110c7
6 changed files with 123 additions and 12 deletions

View file

@ -805,14 +805,7 @@ func (c *cfg) getShardOpts(shCfg shardCfg) shardOptsWithID {
blobstoreOpts = append(blobstoreOpts, blobstor.WithMetrics(lsmetrics.NewBlobstoreMetrics(c.metricsCollector.Blobstore()))) blobstoreOpts = append(blobstoreOpts, blobstor.WithMetrics(lsmetrics.NewBlobstoreMetrics(c.metricsCollector.Blobstore())))
} }
var sh shardOptsWithID mbOptions := []meta.Option{
sh.configID = shCfg.id()
sh.shOpts = []shard.Option{
shard.WithLogger(c.log),
shard.WithRefillMetabase(shCfg.refillMetabase),
shard.WithMode(shCfg.mode),
shard.WithBlobStorOptions(blobstoreOpts...),
shard.WithMetaBaseOptions(
meta.WithPath(shCfg.metaCfg.path), meta.WithPath(shCfg.metaCfg.path),
meta.WithPermissions(shCfg.metaCfg.perm), meta.WithPermissions(shCfg.metaCfg.perm),
meta.WithMaxBatchSize(shCfg.metaCfg.maxBatchSize), meta.WithMaxBatchSize(shCfg.metaCfg.maxBatchSize),
@ -820,10 +813,21 @@ func (c *cfg) getShardOpts(shCfg shardCfg) shardOptsWithID {
meta.WithBoltDBOptions(&bbolt.Options{ meta.WithBoltDBOptions(&bbolt.Options{
Timeout: 100 * time.Millisecond, Timeout: 100 * time.Millisecond,
}), }),
meta.WithLogger(c.log), meta.WithLogger(c.log),
meta.WithEpochState(c.cfgNetmap.state), meta.WithEpochState(c.cfgNetmap.state),
), }
if c.metricsCollector != nil {
mbOptions = append(mbOptions, meta.WithMetrics(lsmetrics.NewMetabaseMetrics(shCfg.metaCfg.path, c.metricsCollector.MetabaseMetrics())))
}
var sh shardOptsWithID
sh.configID = shCfg.id()
sh.shOpts = []shard.Option{
shard.WithLogger(c.log),
shard.WithRefillMetabase(shCfg.refillMetabase),
shard.WithMode(shCfg.mode),
shard.WithBlobStorOptions(blobstoreOpts...),
shard.WithMetaBaseOptions(mbOptions...),
shard.WithPiloramaOptions(piloramaOpts...), shard.WithPiloramaOptions(piloramaOpts...),
shard.WithWriteCache(shCfg.writecacheCfg.enabled), shard.WithWriteCache(shCfg.writecacheCfg.enabled),
shard.WithWriteCacheOptions(writeCacheOpts...), shard.WithWriteCacheOptions(writeCacheOpts...),

View file

@ -356,3 +356,10 @@ func WithEpochState(s EpochState) Option {
c.epochState = s c.epochState = s
} }
} }
// WithMetrics returns option to specify metrics collector.
func WithMetrics(m Metrics) Option {
return func(c *cfg) {
c.metrics = m
}
}

View file

@ -0,0 +1,39 @@
package metrics
import (
"time"
meta "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/metabase"
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/shard/mode"
metrics_impl "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/metrics"
)
func NewMetabaseMetrics(path string, m metrics_impl.MetabaseMetrics) meta.Metrics {
return &metabaseMetrics{
shardID: undefined,
path: path,
m: m,
}
}
type metabaseMetrics struct {
shardID string
path string
m metrics_impl.MetabaseMetrics
}
func (m *metabaseMetrics) SetParentID(parentID string) {
m.shardID = parentID
}
func (m *metabaseMetrics) SetMode(mode mode.Mode) {
m.m.SetMode(m.shardID, m.path, mode.String())
}
func (m *metabaseMetrics) Close() {
m.m.Close(m.shardID, m.path)
}
func (m *metabaseMetrics) AddMethodDuration(method string, d time.Duration, success bool) {
m.m.MethodDuration(m.shardID, m.path, method, d, success)
}

View file

@ -4,6 +4,7 @@ const (
fstreeSubSystem = "fstree" fstreeSubSystem = "fstree"
blobstoreSubSystem = "blobstore" blobstoreSubSystem = "blobstore"
blobovnizaTreeSubSystem = "blobovniza_tree" blobovnizaTreeSubSystem = "blobovniza_tree"
metabaseSubSystem = "metabase"
successLabel = "success" successLabel = "success"
shardIDLabel = "shardID" shardIDLabel = "shardID"

54
pkg/metrics/metabase.go Normal file
View file

@ -0,0 +1,54 @@
package metrics
import (
"strconv"
"time"
"git.frostfs.info/TrueCloudLab/frostfs-observability/metrics"
"github.com/prometheus/client_golang/prometheus"
)
type MetabaseMetrics interface {
SetMode(shardID, path string, mode string)
Close(shardID, path string)
MethodDuration(shardID, path string, method string, d time.Duration, success bool)
}
func newMetabaseMetrics() *metabaseMetrics {
return &metabaseMetrics{
mode: newShardIDPathMode(metabaseSubSystem, "mode", "Metabase mode"),
reqDuration: metrics.NewHistogramVec(prometheus.HistogramOpts{
Namespace: namespace,
Subsystem: metabaseSubSystem,
Name: "request_duration_seconds",
Help: "Accumulated Metabase request process duration",
}, []string{shardIDLabel, successLabel, pathLabel, methodLabel}),
}
}
type metabaseMetrics struct {
mode *shardIDPathModeValue
reqDuration *prometheus.HistogramVec
}
func (m *metabaseMetrics) SetMode(shardID, path string, mode string) {
m.mode.SetMode(shardID, path, mode)
}
func (m *metabaseMetrics) Close(shardID, path string) {
m.mode.SetMode(shardID, path, closedMode)
m.reqDuration.DeletePartialMatch(prometheus.Labels{
shardIDLabel: shardID,
pathLabel: path,
})
}
func (m *metabaseMetrics) MethodDuration(shardID, path string, method string, d time.Duration, success bool) {
m.reqDuration.With(prometheus.Labels{
shardIDLabel: shardID,
pathLabel: path,
successLabel: strconv.FormatBool(success),
methodLabel: method,
}).Observe(d.Seconds())
}

View file

@ -17,6 +17,7 @@ type NodeMetrics struct {
fstree *fstreeMetrics fstree *fstreeMetrics
blobstore *blobstoreMetrics blobstore *blobstoreMetrics
blobobvnizca *blobovnizca blobobvnizca *blobovnizca
metabase *metabaseMetrics
} }
func NewNodeMetrics() *NodeMetrics { func NewNodeMetrics() *NodeMetrics {
@ -35,6 +36,7 @@ func NewNodeMetrics() *NodeMetrics {
fstree: newFSTreeMetrics(), fstree: newFSTreeMetrics(),
blobstore: newBlobstoreMetrics(), blobstore: newBlobstoreMetrics(),
blobobvnizca: newBlobovnizca(), blobobvnizca: newBlobovnizca(),
metabase: newMetabaseMetrics(),
} }
} }
@ -74,3 +76,7 @@ func (m *NodeMetrics) Blobstore() BlobstoreMetrics {
func (m *NodeMetrics) BlobobvnizcaTreeMetrics() BlobobvnizcaMetrics { func (m *NodeMetrics) BlobobvnizcaTreeMetrics() BlobobvnizcaMetrics {
return m.blobobvnizca return m.blobobvnizca
} }
func (m *NodeMetrics) MetabaseMetrics() MetabaseMetrics {
return m.metabase
}