From b5b32c65b0857f461f1254a8f1e2f9de05a266fb Mon Sep 17 00:00:00 2001 From: Aliaksandr Valialkin Date: Mon, 7 Dec 2020 13:15:42 +0200 Subject: [PATCH] lib/promscrape: do not enable strict config parsing when `-promscrape.config.dryRun` command-line flag is passed Strict parsing for -promscrape.config can be enabled by passing `-promscrape.config.strictParse` command-line flag. Updates https://github.com/VictoriaMetrics/VictoriaMetrics/issues/944 --- docs/CHANGELOG.md | 1 + lib/promscrape/config.go | 9 +++++---- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index 6f7487c91..3734f9d66 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -7,6 +7,7 @@ some apps improperly put multiple whitespace chars. This workaround allows accepting data from such apps. * BUGFIX: prevent from duplicate `name` tag returned from `/tags/autoComplete/tags` handler. See https://github.com/VictoriaMetrics/VictoriaMetrics/issues/942 +* BUGFIX: do not enable strict parsing for `-promscrape.config` if `-promscrape.config.dryRun` comand-line flag is set. Strict parsing can be enabled with `-promscrape.config.strictParse` command-line flag. See https://github.com/VictoriaMetrics/VictoriaMetrics/issues/944 # [v1.49.0](https://github.com/VictoriaMetrics/VictoriaMetrics/releases/tag/v1.49.0) diff --git a/lib/promscrape/config.go b/lib/promscrape/config.go index 007ec267c..1a3b2ed20 100644 --- a/lib/promscrape/config.go +++ b/lib/promscrape/config.go @@ -27,11 +27,12 @@ import ( ) var ( - strictParse = flag.Bool("promscrape.config.strictParse", false, "Whether to allow only supported fields in '-promscrape.config'. "+ - "This option may be used for errors detection in '-promscrape.config' file") + strictParse = flag.Bool("promscrape.config.strictParse", false, "Whether to allow only supported fields in -promscrape.config . "+ + "By default unsupported fields are silently skipped") dryRun = flag.Bool("promscrape.config.dryRun", false, "Checks -promscrape.config file for errors and unsupported fields and then exits. "+ "Returns non-zero exit code on parsing errors and emits these errors to stderr. "+ - "Pass -loggerLevel=ERROR if you don't need to see info messages in the output") + "See also -promscrape.config.strictParse command-line flag. "+ + "Pass -loggerLevel=ERROR if you don't need to see info messages in the output.") dropOriginalLabels = flag.Bool("promscrape.dropOriginalLabels", false, "Whether to drop original labels for scrape targets at /targets and /api/v1/targets pages. "+ "This may be needed for reducing memory usage when original labels for big number of scrape targets occupy big amounts of memory. "+ "Note that this reduces debuggability for improper per-target relabeling configs") @@ -164,7 +165,7 @@ func (cfg *Config) parse(data []byte, path string) error { func unmarshalMaybeStrict(data []byte, dst interface{}) error { data = envtemplate.Replace(data) var err error - if *strictParse || *dryRun { + if *strictParse { err = yaml.UnmarshalStrict(data, dst) } else { err = yaml.Unmarshal(data, dst)