forked from TrueCloudLab/frostfs-node
[#680] metrics: Initialize log metrics together with services
Signed-off-by: Anton Nikiforov <an.nikiforov@yadro.com>
This commit is contained in:
parent
bf082348d4
commit
3a997d1207
8 changed files with 58 additions and 38 deletions
|
@ -10,6 +10,7 @@ import (
|
||||||
"git.frostfs.info/TrueCloudLab/frostfs-node/internal/logs"
|
"git.frostfs.info/TrueCloudLab/frostfs-node/internal/logs"
|
||||||
"git.frostfs.info/TrueCloudLab/frostfs-node/misc"
|
"git.frostfs.info/TrueCloudLab/frostfs-node/misc"
|
||||||
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/innerring"
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/innerring"
|
||||||
|
irMetrics "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/metrics"
|
||||||
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/util/logger"
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/util/logger"
|
||||||
"github.com/spf13/viper"
|
"github.com/spf13/viper"
|
||||||
"go.uber.org/zap"
|
"go.uber.org/zap"
|
||||||
|
@ -61,12 +62,13 @@ func main() {
|
||||||
cfg, err = newConfig()
|
cfg, err = newConfig()
|
||||||
exitErr(err)
|
exitErr(err)
|
||||||
|
|
||||||
logPrm.MetricsNamespace = "frostfs_ir"
|
metrics := irMetrics.NewInnerRingMetrics()
|
||||||
|
|
||||||
err = logPrm.SetLevelString(
|
err = logPrm.SetLevelString(
|
||||||
cfg.GetString("logger.level"),
|
cfg.GetString("logger.level"),
|
||||||
)
|
)
|
||||||
exitErr(err)
|
exitErr(err)
|
||||||
|
logPrm.SamplingHook = metrics.LogMetrics().GetSamplingHook()
|
||||||
log, err = logger.NewLogger(logPrm)
|
log, err = logger.NewLogger(logPrm)
|
||||||
exitErr(err)
|
exitErr(err)
|
||||||
|
|
||||||
|
@ -78,7 +80,7 @@ func main() {
|
||||||
metricsCmp = newMetricsComponent()
|
metricsCmp = newMetricsComponent()
|
||||||
metricsCmp.init()
|
metricsCmp.init()
|
||||||
|
|
||||||
innerRing, err = innerring.New(ctx, log, cfg, intErr)
|
innerRing, err = innerring.New(ctx, log, cfg, intErr, metrics)
|
||||||
exitErr(err)
|
exitErr(err)
|
||||||
|
|
||||||
pprofCmp.start()
|
pprofCmp.start()
|
||||||
|
|
|
@ -554,22 +554,21 @@ func initCfg(appCfg *config.Config) *cfg {
|
||||||
|
|
||||||
key := nodeconfig.Key(appCfg)
|
key := nodeconfig.Key(appCfg)
|
||||||
|
|
||||||
|
relayOnly := nodeconfig.Relay(appCfg)
|
||||||
|
|
||||||
|
netState := newNetworkState()
|
||||||
|
netState.metrics = c.metricsCollector
|
||||||
|
|
||||||
|
c.shared = initShared(appCfg, key, netState, relayOnly)
|
||||||
|
|
||||||
logPrm, err := c.loggerPrm()
|
logPrm, err := c.loggerPrm()
|
||||||
fatalOnErr(err)
|
fatalOnErr(err)
|
||||||
|
logPrm.SamplingHook = c.metricsCollector.LogMetrics().GetSamplingHook()
|
||||||
logPrm.MetricsNamespace = "frostfs_node"
|
|
||||||
|
|
||||||
log, err := logger.NewLogger(logPrm)
|
log, err := logger.NewLogger(logPrm)
|
||||||
fatalOnErr(err)
|
fatalOnErr(err)
|
||||||
|
|
||||||
c.internals = initInternals(appCfg, log)
|
c.internals = initInternals(appCfg, log)
|
||||||
|
|
||||||
relayOnly := nodeconfig.Relay(appCfg)
|
|
||||||
|
|
||||||
netState := newNetworkState()
|
|
||||||
|
|
||||||
c.shared = initShared(appCfg, key, netState, relayOnly)
|
|
||||||
|
|
||||||
c.cfgAccounting = cfgAccounting{
|
c.cfgAccounting = cfgAccounting{
|
||||||
scriptHash: contractsconfig.Balance(appCfg),
|
scriptHash: contractsconfig.Balance(appCfg),
|
||||||
}
|
}
|
||||||
|
@ -586,9 +585,6 @@ func initCfg(appCfg *config.Config) *cfg {
|
||||||
|
|
||||||
user.IDFromKey(&c.ownerIDFromKey, key.PrivateKey.PublicKey)
|
user.IDFromKey(&c.ownerIDFromKey, key.PrivateKey.PublicKey)
|
||||||
|
|
||||||
c.metricsCollector = metrics.NewNodeMetrics()
|
|
||||||
netState.metrics = c.metricsCollector
|
|
||||||
|
|
||||||
c.onShutdown(c.clientCache.CloseAll) // clean up connections
|
c.onShutdown(c.clientCache.CloseAll) // clean up connections
|
||||||
c.onShutdown(c.bgClientCache.CloseAll) // clean up connections
|
c.onShutdown(c.bgClientCache.CloseAll) // clean up connections
|
||||||
c.onShutdown(c.putClientCache.CloseAll) // clean up connections
|
c.onShutdown(c.putClientCache.CloseAll) // clean up connections
|
||||||
|
@ -630,14 +626,15 @@ func initShared(appCfg *config.Config, key *keys.PrivateKey, netState *networkSt
|
||||||
}
|
}
|
||||||
|
|
||||||
return shared{
|
return shared{
|
||||||
key: key,
|
key: key,
|
||||||
binPublicKey: key.PublicKey().Bytes(),
|
binPublicKey: key.PublicKey().Bytes(),
|
||||||
localAddr: netAddr,
|
localAddr: netAddr,
|
||||||
respSvc: response.NewService(netState),
|
respSvc: response.NewService(netState),
|
||||||
clientCache: cache.NewSDKClientCache(cacheOpts),
|
clientCache: cache.NewSDKClientCache(cacheOpts),
|
||||||
bgClientCache: cache.NewSDKClientCache(cacheOpts),
|
bgClientCache: cache.NewSDKClientCache(cacheOpts),
|
||||||
putClientCache: cache.NewSDKClientCache(cacheOpts),
|
putClientCache: cache.NewSDKClientCache(cacheOpts),
|
||||||
persistate: persistate,
|
persistate: persistate,
|
||||||
|
metricsCollector: metrics.NewNodeMetrics(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -325,11 +325,12 @@ func (s *Server) registerStarter(f func() error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// New creates instance of inner ring sever structure.
|
// New creates instance of inner ring sever structure.
|
||||||
func New(ctx context.Context, log *logger.Logger, cfg *viper.Viper, errChan chan<- error) (*Server, error) {
|
func New(ctx context.Context, log *logger.Logger, cfg *viper.Viper, errChan chan<- error,
|
||||||
|
metrics *metrics.InnerRingServiceMetrics) (*Server, error) {
|
||||||
var err error
|
var err error
|
||||||
server := &Server{
|
server := &Server{
|
||||||
log: log,
|
log: log,
|
||||||
irMetrics: metrics.NewInnerRingMetrics(),
|
irMetrics: metrics,
|
||||||
}
|
}
|
||||||
|
|
||||||
server.setHealthStatus(control.HealthStatus_HEALTH_STATUS_UNDEFINED)
|
server.setHealthStatus(control.HealthStatus_HEALTH_STATUS_UNDEFINED)
|
||||||
|
|
|
@ -4,6 +4,7 @@ import (
|
||||||
"strconv"
|
"strconv"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/util/logger"
|
||||||
"git.frostfs.info/TrueCloudLab/frostfs-observability/metrics"
|
"git.frostfs.info/TrueCloudLab/frostfs-observability/metrics"
|
||||||
"github.com/prometheus/client_golang/prometheus"
|
"github.com/prometheus/client_golang/prometheus"
|
||||||
)
|
)
|
||||||
|
@ -14,6 +15,7 @@ type InnerRingServiceMetrics struct {
|
||||||
health prometheus.Gauge
|
health prometheus.Gauge
|
||||||
eventDuration *prometheus.HistogramVec
|
eventDuration *prometheus.HistogramVec
|
||||||
morphCacheMetrics *morphCacheMetrics
|
morphCacheMetrics *morphCacheMetrics
|
||||||
|
logMetrics logger.LogMetrics
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewInnerRingMetrics returns new instance of metrics collectors for inner ring.
|
// NewInnerRingMetrics returns new instance of metrics collectors for inner ring.
|
||||||
|
@ -44,6 +46,7 @@ func NewInnerRingMetrics() *InnerRingServiceMetrics {
|
||||||
health: health,
|
health: health,
|
||||||
eventDuration: eventDuration,
|
eventDuration: eventDuration,
|
||||||
morphCacheMetrics: newMorphCacheMetrics(innerRingNamespace),
|
morphCacheMetrics: newMorphCacheMetrics(innerRingNamespace),
|
||||||
|
logMetrics: logger.NewLogMetrics(innerRingNamespace),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -67,3 +70,7 @@ func (m *InnerRingServiceMetrics) AddEvent(d time.Duration, typ string, success
|
||||||
func (m *InnerRingServiceMetrics) MorphCacheMetrics() MorphCacheMetrics {
|
func (m *InnerRingServiceMetrics) MorphCacheMetrics() MorphCacheMetrics {
|
||||||
return m.morphCacheMetrics
|
return m.morphCacheMetrics
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (m *InnerRingServiceMetrics) LogMetrics() logger.LogMetrics {
|
||||||
|
return m.logMetrics
|
||||||
|
}
|
||||||
|
|
|
@ -2,6 +2,7 @@ package metrics
|
||||||
|
|
||||||
import (
|
import (
|
||||||
morphmetrics "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/morph/metrics"
|
morphmetrics "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/morph/metrics"
|
||||||
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/util/logger"
|
||||||
"git.frostfs.info/TrueCloudLab/frostfs-observability/metrics"
|
"git.frostfs.info/TrueCloudLab/frostfs-observability/metrics"
|
||||||
"github.com/prometheus/client_golang/prometheus"
|
"github.com/prometheus/client_golang/prometheus"
|
||||||
)
|
)
|
||||||
|
@ -22,6 +23,7 @@ type NodeMetrics struct {
|
||||||
policer *policerMetrics
|
policer *policerMetrics
|
||||||
morphClient *morphClientMetrics
|
morphClient *morphClientMetrics
|
||||||
morphCache *morphCacheMetrics
|
morphCache *morphCacheMetrics
|
||||||
|
log logger.LogMetrics
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewNodeMetrics() *NodeMetrics {
|
func NewNodeMetrics() *NodeMetrics {
|
||||||
|
@ -46,6 +48,7 @@ func NewNodeMetrics() *NodeMetrics {
|
||||||
policer: newPolicerMetrics(),
|
policer: newPolicerMetrics(),
|
||||||
morphClient: newMorphClientMetrics(),
|
morphClient: newMorphClientMetrics(),
|
||||||
morphCache: newMorphCacheMetrics(namespace),
|
morphCache: newMorphCacheMetrics(namespace),
|
||||||
|
log: logger.NewLogMetrics(namespace),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -109,3 +112,7 @@ func (m *NodeMetrics) MorphClientMetrics() morphmetrics.Register {
|
||||||
func (m *NodeMetrics) MorphCacheMetrics() MorphCacheMetrics {
|
func (m *NodeMetrics) MorphCacheMetrics() MorphCacheMetrics {
|
||||||
return m.morphCache
|
return m.morphCache
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (m *NodeMetrics) LogMetrics() logger.LogMetrics {
|
||||||
|
return m.log
|
||||||
|
}
|
||||||
|
|
|
@ -31,8 +31,8 @@ type Prm struct {
|
||||||
// support runtime rereading
|
// support runtime rereading
|
||||||
level zapcore.Level
|
level zapcore.Level
|
||||||
|
|
||||||
// MetricsNamespace is the namespace string used for log counter metrics
|
// SamplingHook hook for the zap.Logger
|
||||||
MetricsNamespace string
|
SamplingHook func(e zapcore.Entry, sd zapcore.SamplingDecision)
|
||||||
|
|
||||||
// do not support runtime rereading
|
// do not support runtime rereading
|
||||||
}
|
}
|
||||||
|
@ -82,14 +82,12 @@ func NewLogger(prm *Prm) (*Logger, error) {
|
||||||
|
|
||||||
lvl := zap.NewAtomicLevelAt(prm.level)
|
lvl := zap.NewAtomicLevelAt(prm.level)
|
||||||
|
|
||||||
m := NewLogMetrics(prm.MetricsNamespace)
|
|
||||||
|
|
||||||
c := zap.NewProductionConfig()
|
c := zap.NewProductionConfig()
|
||||||
c.Level = lvl
|
c.Level = lvl
|
||||||
c.Encoding = "console"
|
c.Encoding = "console"
|
||||||
c.EncoderConfig.EncodeTime = zapcore.ISO8601TimeEncoder
|
c.EncoderConfig.EncodeTime = zapcore.ISO8601TimeEncoder
|
||||||
c.Sampling.Hook = func(e zapcore.Entry, sd zapcore.SamplingDecision) {
|
if prm.SamplingHook != nil {
|
||||||
m.Inc(e.Level, sd == zapcore.LogDropped)
|
c.Sampling.Hook = prm.SamplingHook
|
||||||
}
|
}
|
||||||
|
|
||||||
lZap, err := c.Build(
|
lZap, err := c.Build(
|
||||||
|
|
|
@ -14,12 +14,17 @@ const (
|
||||||
logDroppedLabel = "dropped"
|
logDroppedLabel = "dropped"
|
||||||
)
|
)
|
||||||
|
|
||||||
type LogMetrics struct {
|
type LogMetrics interface {
|
||||||
|
Inc(level zapcore.Level, dropped bool)
|
||||||
|
GetSamplingHook() func(e zapcore.Entry, sd zapcore.SamplingDecision)
|
||||||
|
}
|
||||||
|
|
||||||
|
type logMetrics struct {
|
||||||
logCount *prometheus.CounterVec
|
logCount *prometheus.CounterVec
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewLogMetrics(namespace string) *LogMetrics {
|
func NewLogMetrics(namespace string) LogMetrics {
|
||||||
return &LogMetrics{
|
return &logMetrics{
|
||||||
logCount: metrics.NewCounterVec(prometheus.CounterOpts{
|
logCount: metrics.NewCounterVec(prometheus.CounterOpts{
|
||||||
Namespace: namespace,
|
Namespace: namespace,
|
||||||
Subsystem: logSubsystem,
|
Subsystem: logSubsystem,
|
||||||
|
@ -29,9 +34,15 @@ func NewLogMetrics(namespace string) *LogMetrics {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *LogMetrics) Inc(level zapcore.Level, dropped bool) {
|
func (m *logMetrics) Inc(level zapcore.Level, dropped bool) {
|
||||||
m.logCount.With(prometheus.Labels{
|
m.logCount.With(prometheus.Labels{
|
||||||
logLevelLabel: level.String(),
|
logLevelLabel: level.String(),
|
||||||
logDroppedLabel: strconv.FormatBool(dropped),
|
logDroppedLabel: strconv.FormatBool(dropped),
|
||||||
}).Inc()
|
}).Inc()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (m *logMetrics) GetSamplingHook() func(zapcore.Entry, zapcore.SamplingDecision) {
|
||||||
|
return func(e zapcore.Entry, sd zapcore.SamplingDecision) {
|
||||||
|
m.Inc(e.Level, sd == zapcore.LogDropped)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -7,7 +7,6 @@ import (
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
local_metrics "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/metrics"
|
local_metrics "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/metrics"
|
||||||
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/util/logger"
|
|
||||||
"git.frostfs.info/TrueCloudLab/frostfs-observability/metrics"
|
"git.frostfs.info/TrueCloudLab/frostfs-observability/metrics"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -28,11 +27,9 @@ func main() {
|
||||||
switch {
|
switch {
|
||||||
case *node != "":
|
case *node != "":
|
||||||
_ = local_metrics.NewNodeMetrics()
|
_ = local_metrics.NewNodeMetrics()
|
||||||
_ = logger.NewLogMetrics("frostfs_node")
|
|
||||||
filename = *node
|
filename = *node
|
||||||
case *ir != "":
|
case *ir != "":
|
||||||
_ = local_metrics.NewInnerRingMetrics()
|
_ = local_metrics.NewInnerRingMetrics()
|
||||||
_ = logger.NewLogMetrics("frostfs_ir")
|
|
||||||
filename = *ir
|
filename = *ir
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
|
Loading…
Reference in a new issue