diff --git a/app/vmagent/main.go b/app/vmagent/main.go index bcff08e83f..df0fc9ee25 100644 --- a/app/vmagent/main.go +++ b/app/vmagent/main.go @@ -69,12 +69,19 @@ func main() { logger.Init() cgroup.UpdateGOMAXPROCSToCPUQuota() + if promscrape.IsDryRun() { + if err := promscrape.CheckConfig(); err != nil { + logger.Fatalf("error when checking -promscrape.config: %s", err) + } + logger.Infof("-promscrape.config is ok; exitting with 0 status code") + return + } if *dryRun { if err := remotewrite.CheckRelabelConfigs(); err != nil { logger.Fatalf("error when checking relabel configs: %s", err) } if err := promscrape.CheckConfig(); err != nil { - logger.Fatalf("error when checking Prometheus config: %s", err) + logger.Fatalf("error when checking -promscrape.config: %s", err) } logger.Infof("all the configs are ok; exitting with 0 status code") return diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index abbb0c8b51..02fb8c0707 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -20,6 +20,7 @@ See https://github.com/VictoriaMetrics/VictoriaMetrics/issues/851 Slow query logging is controlled with `-search.logSlowQueryDuration` command-line flag. * FEATURE: add `/tags/delSeries` handler from Graphite Tags API. See https://victoriametrics.github.io/#graphite-tags-api-usage * FEATURE: log metric name plus all its labels when the metric timestamp is out of the configured retention. This should simplify detecting the source of metrics with unexpected timestamps. +* FEATURE: add `-dryRun` command-line flag to single-node VictoriaMetrics in order to check config file pointed by `-promscrape.config`. * BUGFIX: properly parse Prometheus metrics with [exemplars](https://github.com/OpenObservability/OpenMetrics/blob/master/OpenMetrics.md#exemplars-1) such as `foo 123 # {bar="baz"} 1`. * BUGFIX: properly parse "infinity" values in [OpenMetrics format](https://github.com/OpenObservability/OpenMetrics/blob/master/OpenMetrics.md#abnf). diff --git a/lib/promscrape/config.go b/lib/promscrape/config.go index 1a8b1fdd2c..007ec267c1 100644 --- a/lib/promscrape/config.go +++ b/lib/promscrape/config.go @@ -5,7 +5,6 @@ import ( "fmt" "io/ioutil" "net/url" - "os" "path/filepath" "strings" "sync/atomic" @@ -134,16 +133,14 @@ func loadConfig(path string) (cfg *Config, data []byte, err error) { if err := cfgObj.parse(data, path); err != nil { return nil, nil, fmt.Errorf("cannot parse Prometheus config from %q: %w", path, err) } - if *dryRun { - // This is a dirty hack for checking Prometheus config only. - // See https://github.com/VictoriaMetrics/VictoriaMetrics/issues/362 - // and https://github.com/VictoriaMetrics/VictoriaMetrics/issues/508 for details. - logger.Infof("Success: the config at %q has no errors; exitting with 0 status code", path) - os.Exit(0) - } return &cfgObj, data, nil } +// IsDryRun returns true if -promscrape.config.dryRun command-line flag is set +func IsDryRun() bool { + return *dryRun +} + func (cfg *Config) parse(data []byte, path string) error { if err := unmarshalMaybeStrict(data, cfg); err != nil { return fmt.Errorf("cannot unmarshal data: %w", err)