Anton Nikiforov
3a997d1207
All checks were successful
DCO action / DCO (pull_request) Successful in 3m31s
Vulncheck / Vulncheck (pull_request) Successful in 3m17s
Build / Build Components (1.21) (pull_request) Successful in 3m56s
Tests and linters / Staticcheck (pull_request) Successful in 5m13s
Tests and linters / Lint (pull_request) Successful in 5m50s
Tests and linters / Tests (1.20) (pull_request) Successful in 7m31s
Build / Build Components (1.20) (pull_request) Successful in 7m44s
Tests and linters / Tests (1.21) (pull_request) Successful in 7m32s
Tests and linters / Tests with -race (pull_request) Successful in 7m33s
Signed-off-by: Anton Nikiforov <an.nikiforov@yadro.com>
48 lines
1.2 KiB
Go
48 lines
1.2 KiB
Go
package logger
|
|
|
|
import (
|
|
"strconv"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-observability/metrics"
|
|
"github.com/prometheus/client_golang/prometheus"
|
|
"go.uber.org/zap/zapcore"
|
|
)
|
|
|
|
const (
|
|
logSubsystem = "logger"
|
|
logLevelLabel = "level"
|
|
logDroppedLabel = "dropped"
|
|
)
|
|
|
|
type LogMetrics interface {
|
|
Inc(level zapcore.Level, dropped bool)
|
|
GetSamplingHook() func(e zapcore.Entry, sd zapcore.SamplingDecision)
|
|
}
|
|
|
|
type logMetrics struct {
|
|
logCount *prometheus.CounterVec
|
|
}
|
|
|
|
func NewLogMetrics(namespace string) LogMetrics {
|
|
return &logMetrics{
|
|
logCount: metrics.NewCounterVec(prometheus.CounterOpts{
|
|
Namespace: namespace,
|
|
Subsystem: logSubsystem,
|
|
Name: "entry_count",
|
|
Help: "Total log entries emitted or dropped by severity level",
|
|
}, []string{logLevelLabel, logDroppedLabel}),
|
|
}
|
|
}
|
|
|
|
func (m *logMetrics) Inc(level zapcore.Level, dropped bool) {
|
|
m.logCount.With(prometheus.Labels{
|
|
logLevelLabel: level.String(),
|
|
logDroppedLabel: strconv.FormatBool(dropped),
|
|
}).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)
|
|
}
|
|
}
|