Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion cmd/cortex/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,19 @@ func parseConfigFileParameter() string {
fs := flag.NewFlagSet(os.Args[0], flag.ContinueOnError)
fs.SetOutput(ioutil.Discard)
fs.StringVar(&configFile, configFileOption, "", "") // usage not used in this function.
_ = fs.Parse(os.Args[1:])

// Try to find -config.file option in the flags. As Parsing stops on the first error, eg. unknown flag, we simply
// try remaining parameters until we find config flag, or there are no params left.
// (ContinueOnError just means that flag.Parse doesn't call panic or os.Exit, but it returns error, which we ignore)
args := os.Args[1:]
for len(args) > 0 {
_ = fs.Parse(args)
if configFile != "" {
// found (!)
break
}
args = args[1:]
}

return configFile
}
Expand Down
8 changes: 7 additions & 1 deletion cmd/cortex/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@ func TestFlagParsing(t *testing.T) {
stderrMessage: "-unknown.flag",
},

"new flag, with config": {
arguments: []string{"-mem-ballast-size-bytes=100000"},
yaml: "target: ingester",
stdoutMessage: "target: ingester",
},

"config with wrong argument override": {
yaml: "target: ingester",
arguments: []string{"-target=unknown"},
Expand Down Expand Up @@ -90,7 +96,7 @@ func testSingle(t *testing.T, arguments []string, yaml string, stdoutMessage, st
_, err = tempFile.WriteString(yaml)
require.NoError(t, err)

arguments = append([]string{"-" + configFileOption, tempFile.Name()}, arguments...)
arguments = append(arguments, "-"+configFileOption, tempFile.Name())
}

arguments = append([]string{"./cortex"}, arguments...)
Expand Down