Skip to content

Commit

Permalink
Add configuration to setup collector logs via config file.
Browse files Browse the repository at this point in the history
Next PRs will use this configuration and it will deprecate/remove the flags.

Signed-off-by: Bogdan Drutu <[email protected]>
  • Loading branch information
bogdandrutu committed Sep 10, 2021
1 parent 82d1af4 commit fd8dead
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 6 deletions.
25 changes: 25 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,13 +153,38 @@ func (cfg *Config) validateServicePipelines() error {

// Service defines the configurable components of the service.
type Service struct {
Telemetry ServiceTelemetry

// Extensions are the ordered list of extensions configured for the service.
Extensions []ComponentID

// Pipelines are the set of data pipelines configured for the service.
Pipelines Pipelines
}

// ServiceTelemetry defines the configurable settings for service telemetry.
type ServiceTelemetry struct {
Logs ServiceTelemetryLogs `mapstructure:"logs"`
}

// ServiceTelemetryLogs defines the configurable settings for service telemetry logs.
// This MUST be compatible with zap.Config. Cannot use directly zap.Config because
// the collector uses mapstructure and not yaml tags.
type ServiceTelemetryLogs struct {
// Level is the minimum enabled logging level.
// Valid values are: "DEBUG", "INFO", "WARN", "ERROR", "DPANIC", "PANIC", "FATAL".
Level string `mapstructure:"level"`

// Development puts the logger in development mode, which changes the
// behavior of DPanicLevel and takes stacktraces more liberally.
Development bool `mapstructure:"development"`

// Encoding sets the logger's encoding. Valid values are "json" and
// "console", as well as any third-party encodings registered via
// RegisterEncoder.
Encoding string `mapstructure:"encoding"`
}

// Type is the component type as it is used in the config.
type Type string

Expand Down
3 changes: 3 additions & 0 deletions config/configunmarshaler/defaultunmarshaler.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ type configSettings struct {
}

type serviceSettings struct {
Telemetry config.ServiceTelemetry `mapstructure:"telemetry"`
Extensions []string `mapstructure:"extensions"`
Pipelines map[string]pipelineSettings `mapstructure:"pipelines"`
}
Expand Down Expand Up @@ -221,6 +222,8 @@ func unmarshalExtensions(exts map[string]map[string]interface{}, factories map[c

func unmarshalService(rawService serviceSettings) (config.Service, error) {
var ret config.Service
ret.Telemetry = rawService.Telemetry

ret.Extensions = make([]config.ComponentID, 0, len(rawService.Extensions))
for _, extIDStr := range rawService.Extensions {
id, err := config.NewIDFromString(extIDStr)
Expand Down
15 changes: 9 additions & 6 deletions config/configunmarshaler/defaultunmarshaler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,6 @@ func TestDecodeConfig(t *testing.T) {
assert.Equal(t, 3, len(cfg.Extensions))
assert.Equal(t, "some string", cfg.Extensions[config.NewIDWithName("exampleextension", "1")].(*testcomponents.ExampleExtensionCfg).ExtraSetting)

// Verify service.
assert.Equal(t, 2, len(cfg.Service.Extensions))
assert.Equal(t, config.NewIDWithName("exampleextension", "0"), cfg.Service.Extensions[0])
assert.Equal(t, config.NewIDWithName("exampleextension", "1"), cfg.Service.Extensions[1])

// Verify receivers
assert.Equal(t, 2, len(cfg.Receivers), "Incorrect receivers count")

Expand Down Expand Up @@ -101,7 +96,15 @@ func TestDecodeConfig(t *testing.T) {
cfg.Processors[config.NewID("exampleprocessor")],
"Did not load processor config correctly")

// Verify Pipelines
// Verify Service Telemetry
assert.Equal(t, config.ServiceTelemetry{Logs: config.ServiceTelemetryLogs{Level: "DEBUG", Development: true, Encoding: "console"}}, cfg.Service.Telemetry)

// Verify Service Extensions
assert.Equal(t, 2, len(cfg.Service.Extensions))
assert.Equal(t, config.NewIDWithName("exampleextension", "0"), cfg.Service.Extensions[0])
assert.Equal(t, config.NewIDWithName("exampleextension", "1"), cfg.Service.Extensions[1])

// Verify Service Pipelines
assert.Equal(t, 1, len(cfg.Service.Pipelines), "Incorrect pipelines count")

assert.Equal(t,
Expand Down
5 changes: 5 additions & 0 deletions config/configunmarshaler/testdata/valid-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ extensions:
extra: "some string"

service:
telemetry:
logs:
level: "DEBUG"
development: true
encoding: "console"
extensions: [exampleextension/0, exampleextension/1]
pipelines:
traces:
Expand Down

0 comments on commit fd8dead

Please sign in to comment.