[#1619] logger: Set tags for node components

Signed-off-by: Anton Nikiforov <an.nikiforov@yadro.com>
This commit is contained in:
Anton Nikiforov 2025-01-29 15:39:28 +03:00
parent b0bf4643d0
commit cb1792c69b
19 changed files with 63 additions and 20 deletions

View file

@ -14,6 +14,7 @@ import (
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/morph/event"
netmapEvent "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/morph/event/netmap"
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/morph/subscriber"
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/util/logger"
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/util/rand"
"github.com/nspcc-dev/neo-go/pkg/core/block"
"github.com/nspcc-dev/neo-go/pkg/core/state"
@ -172,14 +173,14 @@ func listenMorphNotifications(ctx context.Context, c *cfg) {
}
subs, err = subscriber.New(ctx, &subscriber.Params{
Log: c.log,
Log: c.log.WithTag(logger.TagMorph),
StartFromBlock: fromSideChainBlock,
Client: c.cfgMorph.client,
})
fatalOnErr(err)
lis, err := event.NewListener(event.ListenerParams{
Logger: c.log,
Logger: c.log.WithTag(logger.TagMorph),
Subscriber: subs,
})
fatalOnErr(err)

View file

@ -1,6 +1,7 @@
FROSTFS_LOGGER_LEVEL=debug
FROSTFS_LOGGER_DESTINATION=journald
FROSTFS_LOGGER_TIMESTAMP=true
FROSTFS_LOGGER_ALLOWED_TAGS="main:debug"
FROSTFS_PPROF_ENABLED=true
FROSTFS_PPROF_ADDRESS=localhost:6060

View file

@ -2,7 +2,8 @@
"logger": {
"level": "debug",
"destination": "journald",
"timestamp": true
"timestamp": true,
"allowed_tags": ["main:debug"]
},
"pprof": {
"enabled": true,

View file

@ -2,6 +2,8 @@ logger:
level: debug # logger level: one of "debug", "info" (default), "warn", "error", "dpanic", "panic", "fatal"
destination: journald # logger destination: one of "stdout" (default), "journald"
timestamp: true
allowed_tags:
- "main:debug"
systemdnotify:
enabled: true

View file

@ -113,9 +113,10 @@ logger:
level: info
```
| Parameter | Type | Default value | Description |
|-----------|----------|---------------|---------------------------------------------------------------------------------------------------|
| `level` | `string` | `info` | Logging level.<br/>Possible values: `debug`, `info`, `warn`, `error`, `dpanic`, `panic`, `fatal` |
| Parameter | Type | Default value | Description |
|----------------|------------|---------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `level` | `string` | `info` | Logging level.<br/>Possible values: `debug`, `info`, `warn`, `error`, `dpanic`, `panic`, `fatal` |
| `allowed_tags` | `[]string` | | List of components allowed to produce log entries. Can be combined with logging level: `main:debug`. The resulting level for tag will be the most restrictive.<br/>Possible values: `main`, `morph`, `engine`, `blobovnicza`, `blobstor`, `fstree`, `gc`, `shard`, `writecache`, `deletesvc`, `getsvc`, `searchsvc`, `policer`, `replicator`. |
# `contracts` section
Contains override values for FrostFS side-chain contract hashes. Most of the time contract

View file

@ -110,7 +110,7 @@ func WithFullSizeLimit(lim uint64) Option {
// WithLogger returns an option to specify Blobovnicza's logger.
func WithLogger(l *logger.Logger) Option {
return func(c *cfg) {
c.log = l.With(zap.String("component", "Blobovnicza"))
c.log = l.With(zap.String("component", "Blobovnicza")).WithTag(logger.TagBlobovnicza)
}
}

View file

@ -91,7 +91,7 @@ func WithStorages(st []SubStorage) Option {
// WithLogger returns option to specify BlobStor's logger.
func WithLogger(l *logger.Logger) Option {
return func(c *cfg) {
c.log = l.With(zap.String("component", "BlobStor"))
c.log = l.With(zap.String("component", "BlobStor")).WithTag(logger.TagBlobstor)
}
}

View file

@ -53,6 +53,6 @@ func WithFileCounter(c FileCounter) Option {
func WithLogger(l *logger.Logger) Option {
return func(f *FSTree) {
f.log = l.With(zap.String("component", "FSTree"))
f.log = l.With(zap.String("component", "FSTree")).WithTag(logger.TagFSTree)
}
}

View file

@ -227,7 +227,7 @@ func New(opts ...Option) *StorageEngine {
// WithLogger returns option to set StorageEngine's logger.
func WithLogger(l *logger.Logger) Option {
return func(c *cfg) {
c.log = l
c.log = l.WithTag(logger.TagEngine)
}
}

View file

@ -473,7 +473,7 @@ func (s *Shard) collectExpiredTombstones(ctx context.Context, e Event) {
}()
epoch := e.(newEpoch).epoch
log := s.log.With(zap.Uint64("epoch", epoch))
log := s.log.With(zap.Uint64("epoch", epoch)).WithTag(logger.TagGC)
log.Debug(ctx, logs.ShardStartedExpiredTombstonesHandling)
defer log.Debug(ctx, logs.ShardFinishedExpiredTombstonesHandling)

View file

@ -200,8 +200,8 @@ func WithPiloramaOptions(opts ...pilorama.Option) Option {
// WithLogger returns option to set Shard's logger.
func WithLogger(l *logger.Logger) Option {
return func(c *cfg) {
c.log = l
c.gcCfg.log = l
c.log = l.WithTag(logger.TagShard)
c.gcCfg.log = l.WithTag(logger.TagGC)
}
}

View file

@ -43,7 +43,7 @@ type options struct {
// WithLogger sets logger.
func WithLogger(log *logger.Logger) Option {
return func(o *options) {
o.log = log.With(zap.String("component", "WriteCache"))
o.log = log.With(zap.String("component", "WriteCache")).WithTag(logger.TagWriteCache)
}
}

View file

@ -92,6 +92,6 @@ func New(gs *getsvc.Service,
// WithLogger returns option to specify Delete service's logger.
func WithLogger(l *logger.Logger) Option {
return func(c *cfg) {
c.log = l.With(zap.String("component", "objectSDK.Delete service"))
c.log = l.With(zap.String("component", "objectSDK.Delete service")).WithTag(logger.TagDeleteSvc)
}
}

View file

@ -53,6 +53,6 @@ func New(
// WithLogger returns option to specify Get service's logger.
func WithLogger(l *logger.Logger) Option {
return func(s *Service) {
s.log = l.With(zap.String("component", "Object.Get service"))
s.log = l.With(zap.String("component", "Object.Get service")).WithTag(logger.TagGetSvc)
}
}

View file

@ -145,6 +145,6 @@ func (s *Service) Head(ctx context.Context, req *objectV2.HeadRequest) (*objectV
func WithLogger(l *logger.Logger) Option {
return func(c *cfg) {
c.log = l.With(zap.String("component", "Object.Get V2 service"))
c.log = l.With(zap.String("component", "Object.Get V2 service")).WithTag(logger.TagGetSvc)
}
}

View file

@ -94,6 +94,6 @@ func New(e *engine.StorageEngine,
// WithLogger returns option to specify Get service's logger.
func WithLogger(l *logger.Logger) Option {
return func(c *cfg) {
c.log = l.With(zap.String("component", "Object.Search service"))
c.log = l.With(zap.String("component", "Object.Search service")).WithTag(logger.TagSearchSvc)
}
}

View file

@ -4,6 +4,7 @@ import (
"sync"
"time"
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/util/logger"
oid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object/id"
lru "github.com/hashicorp/golang-lru/v2"
"go.uber.org/zap"
@ -54,7 +55,7 @@ func New(opts ...Option) *Policer {
opts[i](c)
}
c.log = c.log.With(zap.String("component", "Object Policer"))
c.log = c.log.With(zap.String("component", "Object Policer")).WithTag(logger.TagPolicer)
cache, err := lru.New[oid.Address, time.Time](int(c.cacheSize))
if err != nil {

View file

@ -45,7 +45,7 @@ func New(opts ...Option) *Replicator {
opts[i](c)
}
c.log = c.log.With(zap.String("component", "Object Replicator"))
c.log = c.log.With(zap.String("component", "Object Replicator")).WithTag(logger.TagReplicator)
return &Replicator{
cfg: c,

View file

@ -14,6 +14,18 @@ const (
TagGrpcSvc
TagIr
TagProcessor
TagEngine
TagBlobovnicza
TagBlobstor
TagFSTree
TagGC
TagShard
TagWriteCache
TagDeleteSvc
TagGetSvc
TagSearchSvc
TagPolicer
TagReplicator
)
// tagToMask return bit mask for the tag, encoded in uint32.
@ -27,6 +39,30 @@ func tagToMask(str string) (uint32, error) {
return 1 << TagGrpcSvc, nil
case "ir":
return 1 << TagIr, nil
case "engine":
return 1 << TagEngine, nil
case "blobovnicza":
return 1 << TagBlobovnicza, nil
case "blobstor":
return 1 << TagBlobstor, nil
case "fstree":
return 1 << TagFSTree, nil
case "gc":
return 1 << TagGC, nil
case "shard":
return 1 << TagShard, nil
case "writecache":
return 1 << TagWriteCache, nil
case "deletesvc":
return 1 << TagDeleteSvc, nil
case "getsvc":
return 1 << TagGetSvc, nil
case "searchsvc":
return 1 << TagSearchSvc, nil
case "policer":
return 1 << TagPolicer, nil
case "replicator":
return 1 << TagReplicator, nil
case "processor":
return 1 << TagProcessor, nil
default: