mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2024-11-21 14:44:00 +00:00
app/vmagent: add -dryRun
option for checking all the configs mentioned in command-line flags without running vmagent
Updates https://github.com/VictoriaMetrics/VictoriaMetrics/issues/362
This commit is contained in:
parent
d1a9d8aa1c
commit
f9847352b4
3 changed files with 39 additions and 0 deletions
|
@ -40,6 +40,8 @@ var (
|
||||||
"Telnet put messages and HTTP /api/put messages are simultaneously served on TCP port. "+
|
"Telnet put messages and HTTP /api/put messages are simultaneously served on TCP port. "+
|
||||||
"Usually :4242 must be set. Doesn't work if empty")
|
"Usually :4242 must be set. Doesn't work if empty")
|
||||||
opentsdbHTTPListenAddr = flag.String("opentsdbHTTPListenAddr", "", "TCP address to listen for OpentTSDB HTTP put requests. Usually :4242 must be set. Doesn't work if empty")
|
opentsdbHTTPListenAddr = flag.String("opentsdbHTTPListenAddr", "", "TCP address to listen for OpentTSDB HTTP put requests. Usually :4242 must be set. Doesn't work if empty")
|
||||||
|
dryRun = flag.Bool("dryRun", false, "Whether to check only config files without running vmagent. The following files are checked: "+
|
||||||
|
"-promscrape.config, -remoteWrite.relabelConfig, -remoteWrite.urlRelabelConfig . See also -promscrape.config.dryRun")
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
@ -55,6 +57,19 @@ func main() {
|
||||||
envflag.Parse()
|
envflag.Parse()
|
||||||
buildinfo.Init()
|
buildinfo.Init()
|
||||||
logger.Init()
|
logger.Init()
|
||||||
|
|
||||||
|
if *dryRun {
|
||||||
|
flag.Set("promscrape.config.strictParse", "true")
|
||||||
|
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.Infof("all the configs are ok; exitting with 0 status code")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
logger.Infof("starting vmagent at %q...", *httpListenAddr)
|
logger.Infof("starting vmagent at %q...", *httpListenAddr)
|
||||||
startTime := time.Now()
|
startTime := time.Now()
|
||||||
remotewrite.Init()
|
remotewrite.Init()
|
||||||
|
|
|
@ -32,6 +32,21 @@ var (
|
||||||
"Disk usage is unlimited if the value is set to 0")
|
"Disk usage is unlimited if the value is set to 0")
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// CheckRelabelConfigs checks -remoteWrite.relabelConfig and -remoteWrite.urlRelabelConfig.
|
||||||
|
func CheckRelabelConfigs() error {
|
||||||
|
if *relabelConfigPathGlobal != "" {
|
||||||
|
if _, err := promrelabel.LoadRelabelConfigs(*relabelConfigPathGlobal); err != nil {
|
||||||
|
return fmt.Errorf("cannot load -remoteWrite.relabelConfig=%q: %s", *relabelConfigPathGlobal, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for _, path := range *relabelConfigPaths {
|
||||||
|
if _, err := promrelabel.LoadRelabelConfigs(path); err != nil {
|
||||||
|
return fmt.Errorf("cannot load relabel configs from -remoteWrite.urlRelabelConfig=%q: %s", path, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
var rwctxs []*remoteWriteCtx
|
var rwctxs []*remoteWriteCtx
|
||||||
|
|
||||||
// Init initializes remotewrite.
|
// Init initializes remotewrite.
|
||||||
|
|
|
@ -37,6 +37,15 @@ var (
|
||||||
"See https://prometheus.io/docs/prometheus/latest/configuration/configuration/#scrape_config for details")
|
"See https://prometheus.io/docs/prometheus/latest/configuration/configuration/#scrape_config for details")
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// CheckConfig checks -promscrape.config for errors and unsupported options.
|
||||||
|
func CheckConfig() error {
|
||||||
|
if *promscrapeConfigFile == "" {
|
||||||
|
return fmt.Errorf("missing -promscrape.config option")
|
||||||
|
}
|
||||||
|
_, _, err := loadConfig(*promscrapeConfigFile)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
// Init initializes Prometheus scraper with config from the `-promscrape.config`.
|
// Init initializes Prometheus scraper with config from the `-promscrape.config`.
|
||||||
//
|
//
|
||||||
// Scraped data is passed to pushData.
|
// Scraped data is passed to pushData.
|
||||||
|
|
Loading…
Reference in a new issue