Skip to content

Commit 19ac8d1

Browse files
committed
added agent config var
1 parent c904afa commit 19ac8d1

File tree

6 files changed

+22
-7
lines changed

6 files changed

+22
-7
lines changed

internal/config/config.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -755,6 +755,14 @@ func registerCollectorFlags(fs *flag.FlagSet) {
755755
"The path to the Opentelemetry Collector configuration file.",
756756
)
757757

758+
fs.StringSlice(
759+
CollectorAdditionalConfigPathsKey,
760+
[]string{},
761+
"Paths to additional OpenTelemetry Collector configuration files. The order of the configuration files"+
762+
" determines which config file takes priority. The last config file will take precedent over other files "+
763+
"if they have the same setting. Paths to configuration files must be absolute",
764+
)
765+
758766
fs.String(
759767
CollectorLogLevelKey,
760768
DefCollectorLogLevel,
@@ -1054,6 +1062,7 @@ func resolveCollector(allowedDirs []string) (*Collector, error) {
10541062

10551063
col := &Collector{
10561064
ConfigPath: viperInstance.GetString(CollectorConfigPathKey),
1065+
AdditionalPaths: viperInstance.GetStringSlice(CollectorAdditionalConfigPathsKey),
10571066
Exporters: exporters,
10581067
Processors: resolveProcessors(),
10591068
Receivers: receivers,

internal/config/config_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1112,6 +1112,7 @@ func createConfig() *Config {
11121112
},
11131113
Collector: &Collector{
11141114
ConfigPath: "/etc/nginx-agent/nginx-agent-otelcol.yaml",
1115+
AdditionalPaths: []string{"/configs/my_config.yaml", "/etc/nginx-agent/nginx-agent-otelcol.yaml"},
11151116
Exporters: Exporters{
11161117
OtlpExporters: map[string]*OtlpExporter{
11171118
"default": {

internal/config/defaults.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -85,13 +85,13 @@ const (
8585
DefFileWatcherMonitoringFrequency = 5 * time.Second
8686

8787
// Collector defaults
88-
DefCollectorConfigPath = "/etc/nginx-agent/opentelemetry-collector-agent.yaml"
89-
DefCollectorLogLevel = "INFO"
90-
DefCollectorLogPath = "/var/log/nginx-agent/opentelemetry-collector-agent.log"
91-
DefCollectorTLSCertPath = "/var/lib/nginx-agent/cert.pem"
92-
DefCollectorTLSKeyPath = "/var/lib/nginx-agent/key.pem"
93-
DefCollectorTLSCAPath = "/var/lib/nginx-agent/ca.pem"
94-
DefCollectorTLSSANNames = "127.0.0.1,::1,localhost"
88+
DefCollectorConfigPath = "/etc/nginx-agent/opentelemetry-collector-agent.yaml"
89+
DefCollectorLogLevel = "INFO"
90+
DefCollectorLogPath = "/var/log/nginx-agent/opentelemetry-collector-agent.log"
91+
DefCollectorTLSCertPath = "/var/lib/nginx-agent/cert.pem"
92+
DefCollectorTLSKeyPath = "/var/lib/nginx-agent/key.pem"
93+
DefCollectorTLSCAPath = "/var/lib/nginx-agent/ca.pem"
94+
DefCollectorTLSSANNames = "127.0.0.1,::1,localhost"
9595

9696
DefCollectorMetricsBatchProcessorSendBatchSize = 1000
9797
DefCollectorMetricsBatchProcessorSendBatchMaxSize = 1000

internal/config/flags.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ var (
4848
ClientBackoffMultiplierKey = pre(ClientRootKey) + "backoff_multiplier"
4949

5050
CollectorConfigPathKey = pre(CollectorRootKey) + "config_path"
51+
CollectorAdditionalConfigPathsKey = pre(CollectorRootKey) + "additional_config_paths"
5152
CollectorExportersKey = pre(CollectorRootKey) + "exporters"
5253
CollectorDebugExporterKey = pre(CollectorExportersKey) + "debug"
5354
CollectorPrometheusExporterKey = pre(CollectorExportersKey) + "prometheus"

internal/config/testdata/nginx-agent.conf

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,9 @@ auxiliary_command:
9494

9595
collector:
9696
config_path: "/etc/nginx-agent/nginx-agent-otelcol.yaml"
97+
additional_config_paths:
98+
- "/configs/my_config.yaml"
99+
- /etc/nginx-agent/nginx-agent-otelcol.yaml
97100
receivers:
98101
otlp:
99102
"default":

internal/config/types.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ type (
106106

107107
Collector struct {
108108
ConfigPath string `yaml:"config_path" mapstructure:"config_path"`
109+
AdditionalPaths []string `yaml:"additional_config_paths" mapstructure:"additional_config_paths"`
109110
Log *Log `yaml:"log" mapstructure:"log"`
110111
Exporters Exporters `yaml:"exporters" mapstructure:"exporters"`
111112
Extensions Extensions `yaml:"extensions" mapstructure:"extensions"`

0 commit comments

Comments
 (0)