From 4b84a009cb8669f7a7d4f57fb951d8ba8247948f Mon Sep 17 00:00:00 2001 From: Antonio Jimenez Date: Fri, 22 Sep 2023 09:08:48 +0200 Subject: [PATCH] Apply @dmitryax feedback --- .chloggen/SampledLoggerTelemetry.yaml | 2 +- otelcol/unmarshaler.go | 2 +- otelcol/unmarshaler_test.go | 2 +- service/telemetry/config.go | 13 +++++++++---- service/telemetry/telemetry.go | 4 ++-- 5 files changed, 14 insertions(+), 9 deletions(-) diff --git a/.chloggen/SampledLoggerTelemetry.yaml b/.chloggen/SampledLoggerTelemetry.yaml index 9bf416d6a4c..8fa0defd6b8 100644 --- a/.chloggen/SampledLoggerTelemetry.yaml +++ b/.chloggen/SampledLoggerTelemetry.yaml @@ -7,7 +7,7 @@ change_type: enhancement component: service/telemetry exporter/exporterhelper # A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`). -note: "Update default sampling logger configuration in the telemetry configuration." +note: "Enable sampling logging by default and apply it to all components." # One or more tracking issues or pull requests related to the change issues: [8134] diff --git a/otelcol/unmarshaler.go b/otelcol/unmarshaler.go index 0fa0c2725e9..66b2a87a0c6 100644 --- a/otelcol/unmarshaler.go +++ b/otelcol/unmarshaler.go @@ -48,7 +48,7 @@ func unmarshal(v *confmap.Conf, factories Factories) (*configSettings, error) { Encoding: "console", Sampling: &telemetry.LogsSamplingConfig{ Enabled: true, - Tick: 1 * time.Second, + Tick: 10 * time.Second, Initial: 10, Thereafter: 100, }, diff --git a/otelcol/unmarshaler_test.go b/otelcol/unmarshaler_test.go index 2e0213081ae..1e7881a8a0d 100644 --- a/otelcol/unmarshaler_test.go +++ b/otelcol/unmarshaler_test.go @@ -47,7 +47,7 @@ func TestUnmarshalEmptyAllSections(t *testing.T) { Encoding: "console", Sampling: &telemetry.LogsSamplingConfig{ Enabled: true, - Tick: 1 * time.Second, + Tick: 10 * time.Second, Initial: 10, Thereafter: 100, }, diff --git a/service/telemetry/config.go b/service/telemetry/config.go index 15796f510f4..6168be0d08d 100644 --- a/service/telemetry/config.go +++ b/service/telemetry/config.go @@ -99,10 +99,15 @@ type LogsConfig struct { // global CPU and I/O load that logging puts on your process while attempting // to preserve a representative subset of your logs. type LogsSamplingConfig struct { - Enabled bool `mapstructure:"enabled"` - Tick time.Duration `mapstructure:"tick"` - Initial int `mapstructure:"initial"` - Thereafter int `mapstructure:"thereafter"` + // Enabled enable sampling logging + Enabled bool `mapstructure:"enabled"` + // Tick represents the interval in seconds that the logger apply each sampling. + Tick time.Duration `mapstructure:"tick"` + // Initial represents the first M messages logged each Tick. + Initial int `mapstructure:"initial"` + // Thereafter represents the N messages logged after Initial and the rest are dropped, during each Tick. + // If Thereafter is zero, the Core will drop all log entries after the first M messages each Tick. + Thereafter int `mapstructure:"thereafter"` } // MetricsConfig exposes the common Telemetry configuration for one component. diff --git a/service/telemetry/telemetry.go b/service/telemetry/telemetry.go index 9c145844ad1..56dec2da0a6 100644 --- a/service/telemetry/telemetry.go +++ b/service/telemetry/telemetry.go @@ -85,8 +85,8 @@ func newLogger(cfg LogsConfig, options []zap.Option) (*zap.Logger, error) { } func newSampledLogger(logger *zap.Logger, sc *LogsSamplingConfig) *zap.Logger { - // Create a logger that samples all messages to sc.Tick per second initially, - // and sc.Initial/sc.Thereafter of messages after that. + // Create a logger that samples every Nth message after the first M messages every S seconds + // where N = sc.Thereafter, M = sc.Initial, S = sc.Tick. opts := zap.WrapCore(func(core zapcore.Core) zapcore.Core { return zapcore.NewSamplerWithOptions( core,