promtool: generate rulesLintConfig when --lint=none is set (#17414)

* Correctly generate rulesLintConfig when --lint=none is set (#17399)

If I run promtool check config --lint=none I get:

```
Checking rules.yml
  FAILED:
rules.yml: unset nameValidationScheme
```

This is because passing --lint=none stops newConfigLintConfig from generating rulesLintConfig which is needed for validation.
It means that defaults are used then, one of which is unset value for metric name validation, causing this error.
Fix this by handling --lint=none case correctly and still generating rulesLintConfig.

---------

Signed-off-by: Lukasz Mierzwa <l.mierzwa@gmail.com>
Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com>
Co-authored-by: Łukasz Mierzwa <l.mierzwa@gmail.com>
This commit is contained in:
Arve Knudsen 2025-10-28 14:34:52 +01:00 committed by GitHub
parent 436ae330ff
commit 92ccadc96d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 10 additions and 5 deletions

View File

@ -476,13 +476,15 @@ type rulesLintConfig struct {
}
func newRulesLintConfig(stringVal string, fatal, ignoreUnknownFields bool, nameValidationScheme model.ValidationScheme) rulesLintConfig {
items := strings.Split(stringVal, ",")
ls := rulesLintConfig{
fatal: fatal,
ignoreUnknownFields: ignoreUnknownFields,
nameValidationScheme: nameValidationScheme,
}
for _, setting := range items {
if stringVal == "" {
return ls
}
for _, setting := range strings.Split(stringVal, ",") {
switch setting {
case lintOptionAll:
ls.all = true
@ -534,9 +536,7 @@ func newConfigLintConfig(optionsStr string, fatal, ignoreUnknownFields bool, nam
rulesOptions = nil
}
if len(rulesOptions) > 0 {
c.rulesLintConfig = newRulesLintConfig(strings.Join(rulesOptions, ","), fatal, ignoreUnknownFields, nameValidationScheme)
}
c.rulesLintConfig = newRulesLintConfig(strings.Join(rulesOptions, ","), fatal, ignoreUnknownFields, nameValidationScheme)
return c
}

View File

@ -1,3 +1,5 @@
scrape_configs:
- job_name: too_long_scrape_interval_test
scrape_interval: 10m
rule_files:
- prometheus-config.rules.good.yml

View File

@ -0,0 +1,3 @@
groups:
- name: rules
rules: []