[#740] logs: Add Loki
Signed-off-by: Alexander Chuprov <a.chuprov@yadro.com>
This commit is contained in:
parent
c1ec6e33b4
commit
364f835b7e
4 changed files with 61 additions and 3 deletions
|
@ -62,6 +62,7 @@ import (
|
||||||
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/util"
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/util"
|
||||||
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/util/logger"
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/util/logger"
|
||||||
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/util/state"
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/util/state"
|
||||||
|
"git.frostfs.info/TrueCloudLab/frostfs-observability/logging/lokicore"
|
||||||
"git.frostfs.info/TrueCloudLab/frostfs-observability/tracing"
|
"git.frostfs.info/TrueCloudLab/frostfs-observability/tracing"
|
||||||
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/netmap"
|
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/netmap"
|
||||||
objectSDK "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object"
|
objectSDK "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object"
|
||||||
|
@ -72,6 +73,7 @@ import (
|
||||||
"github.com/panjf2000/ants/v2"
|
"github.com/panjf2000/ants/v2"
|
||||||
"go.etcd.io/bbolt"
|
"go.etcd.io/bbolt"
|
||||||
"go.uber.org/zap"
|
"go.uber.org/zap"
|
||||||
|
"go.uber.org/zap/zapcore"
|
||||||
"google.golang.org/grpc"
|
"google.golang.org/grpc"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -577,6 +579,12 @@ func initCfg(appCfg *config.Config) *cfg {
|
||||||
logPrm.SamplingHook = c.metricsCollector.LogMetrics().GetSamplingHook()
|
logPrm.SamplingHook = c.metricsCollector.LogMetrics().GetSamplingHook()
|
||||||
log, err := logger.NewLogger(logPrm)
|
log, err := logger.NewLogger(logPrm)
|
||||||
fatalOnErr(err)
|
fatalOnErr(err)
|
||||||
|
if loggerconfig.ToLokiConfig(appCfg).Enabled {
|
||||||
|
log.Logger = log.Logger.WithOptions(zap.WrapCore(func(core zapcore.Core) zapcore.Core {
|
||||||
|
lokiCore := lokicore.New(core, loggerconfig.ToLokiConfig(appCfg))
|
||||||
|
return lokiCore
|
||||||
|
}))
|
||||||
|
}
|
||||||
|
|
||||||
c.internals = initInternals(appCfg, log)
|
c.internals = initInternals(appCfg, log)
|
||||||
|
|
||||||
|
|
|
@ -1,12 +1,21 @@
|
||||||
package loggerconfig
|
package loggerconfig
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"os"
|
||||||
|
"time"
|
||||||
|
|
||||||
"git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-node/config"
|
"git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-node/config"
|
||||||
|
"git.frostfs.info/TrueCloudLab/frostfs-observability/logging/lokicore/loki"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
// LevelDefault is a default logger level.
|
// LevelDefault is a default logger level.
|
||||||
LevelDefault = "info"
|
LevelDefault = "info"
|
||||||
|
subsection = "logger"
|
||||||
|
lokiSubsection = "loki"
|
||||||
|
AddressDefault = "localhost:3100"
|
||||||
|
BatchEntriesNumberDefault = 100
|
||||||
|
BatchWaitDefault = time.Second
|
||||||
)
|
)
|
||||||
|
|
||||||
// Level returns the value of "level" config parameter
|
// Level returns the value of "level" config parameter
|
||||||
|
@ -15,7 +24,7 @@ const (
|
||||||
// Returns LevelDefault if the value is not a non-empty string.
|
// Returns LevelDefault if the value is not a non-empty string.
|
||||||
func Level(c *config.Config) string {
|
func Level(c *config.Config) string {
|
||||||
v := config.StringSafe(
|
v := config.StringSafe(
|
||||||
c.Sub("logger"),
|
c.Sub(subsection),
|
||||||
"level",
|
"level",
|
||||||
)
|
)
|
||||||
if v != "" {
|
if v != "" {
|
||||||
|
@ -24,3 +33,44 @@ func Level(c *config.Config) string {
|
||||||
|
|
||||||
return LevelDefault
|
return LevelDefault
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ToLokiConfig extracts loki config.
|
||||||
|
func ToLokiConfig(c *config.Config) loki.Config {
|
||||||
|
hostname, _ := os.Hostname()
|
||||||
|
return loki.Config{
|
||||||
|
Enabled: config.BoolSafe(c.Sub(subsection).Sub(lokiSubsection), "enabled"),
|
||||||
|
BatchWait: getBatchWait(c),
|
||||||
|
BatchEntriesNumber: getBatchEntriesNumber(c),
|
||||||
|
Endpoint: getEndpoint(c),
|
||||||
|
Labels: map[string]string{
|
||||||
|
"hostname": hostname,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func getBatchWait(c *config.Config) time.Duration {
|
||||||
|
v := config.DurationSafe(c.Sub(subsection).Sub(lokiSubsection), "max_batch_delay")
|
||||||
|
if v > 0 {
|
||||||
|
return v
|
||||||
|
}
|
||||||
|
|
||||||
|
return BatchWaitDefault
|
||||||
|
}
|
||||||
|
|
||||||
|
func getBatchEntriesNumber(c *config.Config) int {
|
||||||
|
v := config.IntSafe(c.Sub(subsection).Sub(lokiSubsection), "max_batch_size")
|
||||||
|
if v > 0 {
|
||||||
|
return int(v)
|
||||||
|
}
|
||||||
|
|
||||||
|
return BatchEntriesNumberDefault
|
||||||
|
}
|
||||||
|
|
||||||
|
func getEndpoint(c *config.Config) string {
|
||||||
|
v := config.StringSafe(c.Sub(subsection).Sub(lokiSubsection), "endpoint")
|
||||||
|
if v != "" {
|
||||||
|
return v
|
||||||
|
}
|
||||||
|
|
||||||
|
return AddressDefault
|
||||||
|
}
|
||||||
|
|
2
go.mod
2
go.mod
|
@ -5,7 +5,7 @@ go 1.20
|
||||||
require (
|
require (
|
||||||
git.frostfs.info/TrueCloudLab/frostfs-api-go/v2 v2.16.1-0.20231031104748-498877e378fd
|
git.frostfs.info/TrueCloudLab/frostfs-api-go/v2 v2.16.1-0.20231031104748-498877e378fd
|
||||||
git.frostfs.info/TrueCloudLab/frostfs-contract v0.18.1-0.20231102065436-9ed3845aa989
|
git.frostfs.info/TrueCloudLab/frostfs-contract v0.18.1-0.20231102065436-9ed3845aa989
|
||||||
git.frostfs.info/TrueCloudLab/frostfs-observability v0.0.0-20230531082742-c97d21411eb6
|
git.frostfs.info/TrueCloudLab/frostfs-observability v0.0.0-20231101111734-b3ad3335ff65
|
||||||
git.frostfs.info/TrueCloudLab/frostfs-sdk-go v0.0.0-20231101144515-6fbe1595cb3d
|
git.frostfs.info/TrueCloudLab/frostfs-sdk-go v0.0.0-20231101144515-6fbe1595cb3d
|
||||||
git.frostfs.info/TrueCloudLab/hrw v1.2.1
|
git.frostfs.info/TrueCloudLab/hrw v1.2.1
|
||||||
git.frostfs.info/TrueCloudLab/policy-engine v0.0.0-20231101082425-5eee1a733432
|
git.frostfs.info/TrueCloudLab/policy-engine v0.0.0-20231101082425-5eee1a733432
|
||||||
|
|
BIN
go.sum
BIN
go.sum
Binary file not shown.
Loading…
Reference in a new issue