Skip to content

Commit

Permalink
Apply @dmitryax feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
antonjim-te committed Sep 22, 2023
1 parent 66fa58e commit 4b84a00
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 9 deletions.
2 changes: 1 addition & 1 deletion .chloggen/SampledLoggerTelemetry.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
2 changes: 1 addition & 1 deletion otelcol/unmarshaler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
Expand Down
2 changes: 1 addition & 1 deletion otelcol/unmarshaler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
Expand Down
13 changes: 9 additions & 4 deletions service/telemetry/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions service/telemetry/telemetry.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 4b84a00

Please sign in to comment.