Skip to content

Commit

Permalink
Update exporters
Browse files Browse the repository at this point in the history
  • Loading branch information
dhurley committed Sep 19, 2024
1 parent 26e7b58 commit 1ebc153
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 22 deletions.
11 changes: 5 additions & 6 deletions internal/collector/otelcol.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,9 @@ exporters:
{{ if gt (len .TLS.Key) 0 -}}key_file: "{{- .TLS.Key -}}"{{- end }}
{{- end }}
{{- end }}
{{- range $index, $prometheusExporter := .Exporters.PrometheusExporters }}
prometheus/{{$index}}:
endpoint: "{{ .Server.Host -}}:{{- .Server.Port }}"
namespace: "nginx-agent"
{{- if ne .Exporters.PrometheusExporter nil }}
prometheus:
endpoint: "{{ .Exporters.PrometheusExporter.Server.Host -}}:{{- .Exporters.PrometheusExporter.Server.Port }}"
{{- end }}
{{- if ne .Exporters.Debug nil }}
debug:
Expand Down Expand Up @@ -117,8 +116,8 @@ service:
{{- range $index, $otlpExporter := .Exporters.OtlpExporters }}
- otlp/{{$index}}
{{- end }}
{{- range $index, $prometheusExporter := .Exporters.PrometheusExporters }}
- prometheus/{{$index}}
{{- if ne .Exporters.PrometheusExporter nil }}
- prometheus
{{- end }}
{{- if ne .Exporters.Debug nil }}
- debug
Expand Down
18 changes: 8 additions & 10 deletions internal/collector/settings_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,16 +53,14 @@ func TestTemplateWrite(t *testing.T) {
actualConfPath := filepath.Join("/tmp/", "nginx-agent-otelcol-test.yaml")
cfg.Collector.ConfigPath = actualConfPath

cfg.Collector.Exporters.PrometheusExporters = append(
cfg.Collector.Exporters.PrometheusExporters,
config.PrometheusExporter{
Server: &config.ServerConfig{
Host: "localhost",
Port: 9876,
Type: 0,
},
TLS: nil,
})
cfg.Collector.Exporters.PrometheusExporter = &config.PrometheusExporter{
Server: &config.ServerConfig{
Host: "localhost",
Port: 9876,
Type: 0,
},
TLS: nil,
}

cfg.Collector.Exporters.Debug = &config.DebugExporter{}

Expand Down
6 changes: 3 additions & 3 deletions internal/config/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,9 @@ type (
}

Exporters struct {
OtlpExporters []OtlpExporter `yaml:"-" mapstructure:"otlp_exporters"`
Debug *DebugExporter `yaml:"-" mapstructure:"debug"`
PrometheusExporters []PrometheusExporter `yaml:"-" mapstructure:"prometheus_exporters"`
Debug *DebugExporter `yaml:"-" mapstructure:"debug"`
PrometheusExporter *PrometheusExporter `yaml:"-" mapstructure:"prometheus_exporter"`
OtlpExporters []OtlpExporter `yaml:"-" mapstructure:"otlp_exporters"`
}

OtlpExporter struct {
Expand Down
5 changes: 2 additions & 3 deletions test/config/collector/test-opentelemetry-collector-agent.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,8 @@ exporters:
max_elapsed_time: 10m
tls:
insecure: true
prometheus/0:
prometheus:
endpoint: "localhost:9876"
namespace: "nginx-agent"
debug:
verbosity: detailed
sampling_initial: 5
Expand Down Expand Up @@ -66,5 +65,5 @@ service:
- batch
exporters:
- otlp/0
- prometheus/0
- prometheus
- debug

0 comments on commit 1ebc153

Please sign in to comment.