Skip to content

Commit

Permalink
Enable end users to provide multiple files for config location (#4727)
Browse files Browse the repository at this point in the history
Restriction (compatible with `--set`): Per flag entry can be defined only one location, to define multiple locations use multiple flag entries:

```bash
./otelcol --cofig=file:/path/to/first/file --config=file:/path/to/second/file
```
  • Loading branch information
bogdandrutu authored Jan 24, 2022
1 parent eb429c7 commit 6ab3c98
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 12 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
- Deprecate `configtelemetry.Level.Set()` (#4700)
- Remove support to some arches and platforms from `ocb` (opentelemetry-collector-builder) (#4710)
- Remove deprecated legacy path ("v1/trace") support for otlp http receiver (#4720)
- Change the `service.NewDefaultConfigProvider` to accept a slice of location strings (#4727).

## 🧰 Bug fixes 🧰

Expand All @@ -33,6 +34,7 @@
- Move `compression.go` into `confighttp.go` to internalize functions in `compression.go` file. (#4651)
- create `configcompression` package to manage compression methods in `confighttp` and `configgrpc`
- Add support for cgroupv2 memory limit (#4654)
- Enable end users to provide multiple files for config location (#4727)

## 🧰 Bug fixes 🧰

Expand Down
6 changes: 3 additions & 3 deletions service/collector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func TestCollector_StartAsGoRoutine(t *testing.T) {
set := CollectorSettings{
BuildInfo: component.NewDefaultBuildInfo(),
Factories: factories,
ConfigProvider: NewDefaultConfigProvider(path.Join("testdata", "otelcol-config.yaml"), nil),
ConfigProvider: NewDefaultConfigProvider([]string{path.Join("testdata", "otelcol-config.yaml")}, nil),
}
col, err := New(set)
require.NoError(t, err)
Expand Down Expand Up @@ -97,7 +97,7 @@ func TestCollector_Start(t *testing.T) {
BuildInfo: component.NewDefaultBuildInfo(),
Factories: factories,
ConfigProvider: NewDefaultConfigProvider(
path.Join("testdata", "otelcol-config.yaml"),
[]string{path.Join("testdata", "otelcol-config.yaml")},
[]string{"service.telemetry.metrics.address=localhost:" + strconv.FormatUint(uint64(metricsPort), 10)}),
LoggingOptions: []zap.Option{zap.Hooks(hook)},
})
Expand Down Expand Up @@ -157,7 +157,7 @@ func TestCollector_ReportError(t *testing.T) {
col, err := New(CollectorSettings{
BuildInfo: component.NewDefaultBuildInfo(),
Factories: factories,
ConfigProvider: NewDefaultConfigProvider(path.Join("testdata", "otelcol-config.yaml"), nil),
ConfigProvider: NewDefaultConfigProvider([]string{path.Join("testdata", "otelcol-config.yaml")}, nil),
})
require.NoError(t, err)

Expand Down
4 changes: 2 additions & 2 deletions service/config_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,9 @@ func NewConfigProvider(

// NewDefaultConfigProvider returns the default ConfigProvider, and it creates configuration from a file
// defined by the given configFile and overwrites fields using properties.
func NewDefaultConfigProvider(configFileName string, properties []string) ConfigProvider {
func NewDefaultConfigProvider(configLocations []string, properties []string) ConfigProvider {
return NewConfigProvider(
[]string{configFileName},
configLocations,
map[string]configmapprovider.Provider{
"file": configmapprovider.NewFile(),
"env": configmapprovider.NewEnv(),
Expand Down
13 changes: 6 additions & 7 deletions service/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,8 @@ import (
)

var (
defaultConfig = ""

// Command-line flag that control the configuration file.
configFlag = &defaultConfig
configFlag = new(stringArrayValue)
setFlag = new(stringArrayValue)
)

Expand All @@ -39,14 +37,15 @@ func (s *stringArrayValue) Set(val string) error {
}

func (s *stringArrayValue) String() string {
return "[" + strings.Join(s.values, ",") + "]"
return "[" + strings.Join(s.values, ", ") + "]"
}

func flags() *flag.FlagSet {
flagSet := new(flag.FlagSet)
featuregate.Flags(flagSet)

configFlag = flagSet.String("config", defaultConfig, "Path to the config file")
flagSet.Var(configFlag, "config", "Locations to the config file(s), note that only a"+
" single location can be set per flag entry e.g. `-config=file:/path/to/first --config=file:path/to/second`.")

flagSet.Var(setFlag, "set",
"Set arbitrary component config property. The component has to be defined in the config file and the flag"+
Expand All @@ -56,8 +55,8 @@ func flags() *flag.FlagSet {
return flagSet
}

func getConfigFlag() string {
return *configFlag
func getConfigFlag() []string {
return configFlag.values
}

func getSetFlag() []string {
Expand Down

0 comments on commit 6ab3c98

Please sign in to comment.