Request for `dry-run` feature
k0ste opened this issue · 1 comments
With dry-run
feature we will can to put ipmi_exporter
configuration and perform syntax test (exporter can run with this YAML) before restart with new configuration (useful for IaC's)
For example, this YAML seems legit
---
- modules:
intel:
collectors:
- ipmi
But
[root@mon ipmi_exporter]# ./ipmi_exporter --web.listen-address=":9222" --log.level=debug --config.file=ipmi.yml
ts=2022-08-12T14:33:02.890Z caller=main.go:107 level=info msg="Starting ipmi_exporter" version="(version=1.6.1, branch=HEAD, revision=344b8b4a565a9ced936aad4d4ac9a29892515cba)"
ts=2022-08-12T14:33:02.890Z caller=main.go:111 level=error msg="Error parsing config file" error="yaml: unmarshal errors:\n line 2: cannot unmarshal !!seq into main.plain"
[root@mon ipmi_exporter]# echo $?
1
Will be nice if we can check it, like ./ipmi_exporter --config.file=/path/to/file.yaml --dry-run
and check for non-zero exit-code
I am not really convinced that this is necessary, to be honest. I don't know of any other exporter that has this. Also, either you write your config file manually, in which case you should test it manually, or you generate it, in which case you should test the implementation to not generate structurally broken files (like the snippet above). Once that is verified, there is no reason why a generator would generate broken files, unless you're doing really funky things.
If for some reason you really have a need to automatically test config files, you could still do so, e.g. using timeout
:
$ timeout 1s ./ipmi_exporter --config.file=ipmi_remote.yml &> /dev/null; echo $?
124
$ timeout 1s ./ipmi_exporter --config.file=broken.yml &> /dev/null; echo $?
1
Would that do the trick for you?