fix: do not require config file for --version and --help - #459
Open
ricardbejarano wants to merge 1 commit into
Open
fix: do not require config file for --version and --help#459ricardbejarano wants to merge 1 commit into
ricardbejarano wants to merge 1 commit into
Conversation
The config.file flag used ExistingFile() on its default value, so kingpin validated that config.yml existed while parsing flags. This made `--version` and `--help` fail with "path 'config.yml' does not exist" whenever no config file was present, contrary to how other Prometheus exporters behave. Use String() instead; a missing config file is still reported clearly at startup by LoadConfig (os.ReadFile), so no real configuration error is masked. Fixes prometheus-community#292
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
json_exporter --version(and--help) fail when no config file is present:The
--config.fileflag is defined with.Default("config.yml").ExistingFile(), so kingpin validates thatconfig.ymlexists while parsing flags — before the--version/--helpactions run. This diverges from other Prometheus exporters, where informational flags work without a config file.Change
Replace
.ExistingFile()with.String()for theconfig.fileflag. A missing config file is still reported clearly at startup byLoadConfig(os.ReadFile), which already surfaces the error and exits non-zero, so no genuine configuration error is masked.Fixes #292
Testing
--version/--help, which requires exercising the process entry point (the exporter useskingpin.Version/kingpin.HelpFlagthat callos.Exit). Manual verification: with the fix,--versionand--helpsucceed with noconfig.ymlpresent, while starting the exporter without a config still fails atLoadConfigwithopen config.yml: no such file or directory.