From 8e4dacd5d2ca16fe93efcea0cdb4fdc61eb7af2b Mon Sep 17 00:00:00 2001 From: zhaowang Date: Wed, 16 Oct 2024 20:23:21 +0800 Subject: [PATCH] move the long scrape interval config and look back delta config to lint config check Signed-off-by: zhaowang --- cmd/promtool/main.go | 23 +++++++++++++---------- docs/command-line/promtool.md | 4 ++-- 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/cmd/promtool/main.go b/cmd/promtool/main.go index 107f26ac4..bd0211fcc 100644 --- a/cmd/promtool/main.go +++ b/cmd/promtool/main.go @@ -75,13 +75,16 @@ const ( lintOptionAll = "all" lintOptionDuplicateRules = "duplicate-rules" - lintOptionLongScrapeInterval = "long-scrape-inerval" + lintOptionLongScrapeInterval = "long-scrape-interval" lintOptionNone = "none" checkHealth = "/-/healthy" checkReadiness = "/-/ready" ) -var lintOptions = []string{lintOptionAll, lintOptionDuplicateRules, lintOptionNone} +var ( + lintRuleOptions = []string{lintOptionAll, lintOptionDuplicateRules, lintOptionNone} + lintConfigOptions = append(lintRuleOptions, lintOptionLongScrapeInterval) +) func main() { var ( @@ -114,8 +117,12 @@ func main() { checkConfigSyntaxOnly := checkConfigCmd.Flag("syntax-only", "Only check the config file syntax, ignoring file and content validation referenced in the config").Bool() checkConfigLint := checkConfigCmd.Flag( "lint", - "Linting checks to apply to the rules specified in the config. Available options are: "+strings.Join(lintOptions, ", ")+". Use --lint=none to disable linting", + "Linting checks to apply to the rules specified in the config. Available options are: "+strings.Join(lintConfigOptions, ", ")+". Use --lint=none to disable linting", ).Default(lintOptionDuplicateRules).String() + checkConfigLintLookbackDelta := checkConfigCmd.Flag( + "lint.lookback-delta", + "The maximum lookback duration. This config is only used for config linting checks.", + ).Default("5m").Duration() checkConfigLintFatal := checkConfigCmd.Flag( "lint-fatal", "Make lint errors exit with exit code 3.").Default("false").Bool() @@ -141,15 +148,11 @@ func main() { ).ExistingFiles() checkRulesLint := checkRulesCmd.Flag( "lint", - "Linting checks to apply. Available options are: "+strings.Join(lintOptions, ", ")+". Use --lint=none to disable linting", + "Linting checks to apply. Available options are: "+strings.Join(lintRuleOptions, ", ")+". Use --lint=none to disable linting", ).Default(lintOptionDuplicateRules).String() checkRulesLintFatal := checkRulesCmd.Flag( "lint-fatal", "Make lint errors exit with exit code 3.").Default("false").Bool() - checkRulesLintLookbackDelta := checkRulesCmd.Flag( - "lint.lookback-delta", - "The maximum lookback duration. This config is only used for rules linting checks.", - ).Default("5m").Duration() checkMetricsCmd := checkCmd.Command("metrics", checkMetricsUsage) checkMetricsExtended := checkCmd.Flag("extended", "Print extended information related to the cardinality of the metrics.").Bool() @@ -346,7 +349,7 @@ func main() { os.Exit(CheckSD(*sdConfigFile, *sdJobName, *sdTimeout, noDefaultScrapePort, prometheus.DefaultRegisterer)) case checkConfigCmd.FullCommand(): - os.Exit(CheckConfig(*agentMode, *checkConfigSyntaxOnly, newLintConfig(*checkConfigLint, *checkConfigLintFatal, *checkRulesLintLookbackDelta), *configFiles...)) + os.Exit(CheckConfig(*agentMode, *checkConfigSyntaxOnly, newLintConfig(*checkConfigLint, *checkConfigLintFatal, *checkConfigLintLookbackDelta), *configFiles...)) case checkServerHealthCmd.FullCommand(): os.Exit(checkErr(CheckServerStatus(serverURL, checkHealth, httpRoundTripper))) @@ -358,7 +361,7 @@ func main() { os.Exit(CheckWebConfig(*webConfigFiles...)) case checkRulesCmd.FullCommand(): - os.Exit(CheckRules(newLintConfig(*checkRulesLint, *checkRulesLintFatal, *checkRulesLintLookbackDelta), *ruleFiles...)) + os.Exit(CheckRules(newLintConfig(*checkRulesLint, *checkRulesLintFatal, 5*time.Minute), *ruleFiles...)) case checkMetricsCmd.FullCommand(): os.Exit(CheckMetrics(*checkMetricsExtended)) diff --git a/docs/command-line/promtool.md b/docs/command-line/promtool.md index e3a7e5f55..a37a8d34e 100644 --- a/docs/command-line/promtool.md +++ b/docs/command-line/promtool.md @@ -102,7 +102,8 @@ Check if the config files are valid or not. | Flag | Description | Default | | --- | --- | --- | | --syntax-only | Only check the config file syntax, ignoring file and content validation referenced in the config | | -| --lint | Linting checks to apply to the rules specified in the config. Available options are: all, duplicate-rules, none. Use --lint=none to disable linting | `duplicate-rules` | +| --lint | Linting checks to apply to the rules specified in the config. Available options are: all, duplicate-rules, none, long-scrape-interval. Use --lint=none to disable linting | `duplicate-rules` | +| --lint.lookback-delta | The maximum lookback duration. This config is only used for config linting checks. | `5m` | | --lint-fatal | Make lint errors exit with exit code 3. | `false` | | --agent | Check config file for Prometheus in Agent mode. | | @@ -177,7 +178,6 @@ Check if the rule files are valid or not. | --- | --- | --- | | --lint | Linting checks to apply. Available options are: all, duplicate-rules, none. Use --lint=none to disable linting | `duplicate-rules` | | --lint-fatal | Make lint errors exit with exit code 3. | `false` | -| --lint.lookback-delta | The maximum lookback duration. This config is only used for rules linting checks. | `5m` |