Skip to content

Commit

Permalink
Update extensions config for Otel collector
Browse files Browse the repository at this point in the history
  • Loading branch information
dhurley committed Sep 16, 2024
1 parent 70a78e7 commit 268d805
Show file tree
Hide file tree
Showing 10 changed files with 66 additions and 37 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 13 additions & 4 deletions internal/collector/otelcol.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,22 @@ exporters:
{{- end }}
{{- end }}

{{- if ne .Extensions nil }}
extensions:
{{- if ne .Extensions.Health nil }}
health_check:
{{- if .Health }}
endpoint: "{{ .Health.Host -}}:{{- .Health.Port }}"
{{- else }}
endpoint: "localhost:13133"
endpoint: "{{ .Extensions.Health.Server.Host -}}:{{- .Extensions.Health.Server.Port }}"
{{- if ne .Extensions.Health.Path "" }}
path: "{{ .Extensions.Health.Path -}}"
{{- end }}
{{- if ne .Extensions.Health.TLS nil }}
tls:
ca_cert: "{{ .Extensions.Health.Server.TLS.Ca -}}"
cert_file: "{{ .Extensions.Health.Server.TLS.Cert -}}"
key_file: "{{ .Extensions.Health.Server.TLS.Key -}}"
{{- end }}
{{- end }}
{{- end }}

service:
{{- if .Log.Path}}
Expand Down
16 changes: 8 additions & 8 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -344,20 +344,20 @@ func resolveCollector(allowedDirs []string) (*Collector, error) {
}

var (
err error
exporters []Exporter
processors []Processor
receivers Receivers
healthCheck ServerConfig
log Log
err error
exporters []Exporter
processors []Processor
receivers Receivers
extensions Extensions
log Log
)

err = errors.Join(
err,
resolveMapStructure(CollectorExportersKey, &exporters),
resolveMapStructure(CollectorProcessorsKey, &processors),
resolveMapStructure(CollectorReceiversKey, &receivers),
resolveMapStructure(CollectorHealthKey, &healthCheck),
resolveMapStructure(CollectorExtensionsKey, &extensions),
resolveMapStructure(CollectorLogKey, &log),
)
if err != nil {
Expand All @@ -377,7 +377,7 @@ func resolveCollector(allowedDirs []string) (*Collector, error) {
Exporters: exporters,
Processors: processors,
Receivers: receivers,
Health: &healthCheck,
Extensions: extensions,
Log: &log,
}

Expand Down
18 changes: 11 additions & 7 deletions internal/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func TestResolveConfig(t *testing.T) {
assert.True(t, viperInstance.IsSet(CollectorExportersKey))
assert.True(t, viperInstance.IsSet(CollectorProcessorsKey))
assert.True(t, viperInstance.IsSet(CollectorReceiversKey))
assert.True(t, viperInstance.IsSet(CollectorHealthKey))
assert.True(t, viperInstance.IsSet(CollectorExtensionsKey))

actual, err := ResolveConfig()
require.NoError(t, err)
Expand All @@ -69,7 +69,7 @@ func TestResolveConfig(t *testing.T) {
assert.NotEmpty(t, actual.Collector.Receivers)
assert.NotEmpty(t, actual.Collector.Processors)
assert.NotEmpty(t, actual.Collector.Exporters)
assert.NotEmpty(t, actual.Collector.Health)
assert.NotEmpty(t, actual.Collector.Extensions)

assert.Equal(t, 10*time.Second, actual.Client.Timeout)

Expand Down Expand Up @@ -225,7 +225,7 @@ func TestResolveCollector(t *testing.T) {
viperInstance.Set(CollectorReceiversKey, test.expected.Receivers)
viperInstance.Set(CollectorProcessorsKey, test.expected.Processors)
viperInstance.Set(CollectorExportersKey, test.expected.Exporters)
viperInstance.Set(CollectorHealthKey, test.expected.Health)
viperInstance.Set(CollectorExtensionsKey, test.expected.Extensions)
viperInstance.Set(CollectorLogKey, test.expected.Log)

actual, err := resolveCollector(testDefault.AllowedDirectories)
Expand Down Expand Up @@ -394,10 +394,14 @@ func getAgentConfig() *Config {
},
},
},
Health: &ServerConfig{
Host: "localhost",
Port: 1337,
Type: 0,
Extensions: Extensions{
Health: Health{
Server: &ServerConfig{
Host: "localhost",
Port: 1337,
Type: 0,
},
},
},
Log: &Log{
Level: "INFO",
Expand Down
2 changes: 1 addition & 1 deletion internal/config/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ var (
CollectorConfigPathKey = pre(CollectorRootKey) + "config_path"
CollectorExportersKey = pre(CollectorRootKey) + "exporters"
CollectorProcessorsKey = pre(CollectorRootKey) + "processors"
CollectorHealthKey = pre(CollectorRootKey) + "health"
CollectorExtensionsKey = pre(CollectorRootKey) + "extensions"
CollectorReceiversKey = pre(CollectorRootKey) + "receivers"
CollectorLogKey = pre(CollectorRootKey) + "log"
CollectorLogLevelKey = pre(CollectorLogKey) + "level"
Expand Down
9 changes: 5 additions & 4 deletions internal/config/testdata/nginx-agent.conf
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,10 @@ collector:
cert: /path/to/server-cert.pem
key: /path/to/server-key.pem
ca: /path/to/server-cert.pem
health:
host: "127.0.0.1"
port: 1234
type: 0
extensions:
health:
server:
host: "127.0.0.1"
port: 1234

config_dirs: "/etc/nginx:/usr/local/etc/nginx:/var/run/nginx:/usr/share/nginx/modules:/var/log/nginx:invalid/path"
22 changes: 16 additions & 6 deletions internal/config/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,22 @@ type (
}

Collector struct {
ConfigPath string `yaml:"-" mapstructure:"config_path"`
Log *Log `yaml:"-" mapstructure:"log"`
Exporters []Exporter `yaml:"-" mapstructure:"exporters"`
Health *ServerConfig `yaml:"-" mapstructure:"health"`
Processors []Processor `yaml:"-" mapstructure:"processors"`
Receivers Receivers `yaml:"-" mapstructure:"receivers"`
ConfigPath string `yaml:"-" mapstructure:"config_path"`
Log *Log `yaml:"-" mapstructure:"log"`
Exporters []Exporter `yaml:"-" mapstructure:"exporters"`
Extensions Extensions `yaml:"-" mapstructure:"extensions"`
Processors []Processor `yaml:"-" mapstructure:"processors"`
Receivers Receivers `yaml:"-" mapstructure:"receivers"`
}

Extensions struct {
Health Health `yaml:"-" mapstructure:"health"`
}

Health struct {
Server *ServerConfig `yaml:"-" mapstructure:"server"`
TLS *TLSConfig `yaml:"-" mapstructure:"tls"`
Path string `yaml:"-" mapstructure:"path"`
}

// OTel Collector Exporter configuration.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ exporters:
verbosity: detailed
sampling_initial: 5
sampling_thereafter: 200

extensions:
health_check:
endpoint: "localhost:1337"
Expand Down
12 changes: 8 additions & 4 deletions test/types/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,14 @@ func AgentConfig() *config.Config {
InitialDelay: time.Second,
},
},
Health: &config.ServerConfig{
Host: "localhost",
Port: randomPort3,
Type: 0,
Extensions: config.Extensions{
Health: config.Health{
Server: &config.ServerConfig{
Host: "localhost",
Port: randomPort3,
Type: 0,
},
},
},
Log: &config.Log{
Level: "INFO",
Expand Down

0 comments on commit 268d805

Please sign in to comment.