mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2024-12-04 16:51:11 +01:00
app/vmalert-tool: print an error message if no rule group is found under 'rule_files'
Both vmalert and vmalert-tool support multiple `rule_files` and use directory as a file, so it's ok if some files don't contain any rule group. But vmalert-tool should warn the user if no rule group is found in any of the `rule_files`. Related issue: https://github.com/VictoriaMetrics/VictoriaMetrics/issues/7663
This commit is contained in:
parent
9c35807368
commit
000a918f38
4
app/vmalert-tool/unittest/testdata/failed-test-with-missing-rulefile.yaml
vendored
Normal file
4
app/vmalert-tool/unittest/testdata/failed-test-with-missing-rulefile.yaml
vendored
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
rule_files:
|
||||||
|
- non-existing-file.yaml
|
||||||
|
|
||||||
|
tests: []
|
@ -96,8 +96,8 @@ func UnitTest(files []string, disableGroupLabel bool, externalLabels []string, e
|
|||||||
var failed bool
|
var failed bool
|
||||||
for fileName, file := range testfiles {
|
for fileName, file := range testfiles {
|
||||||
if err := ruleUnitTest(fileName, file, labels); err != nil {
|
if err := ruleUnitTest(fileName, file, labels); err != nil {
|
||||||
fmt.Println(" FAILED")
|
fmt.Println("FAILED")
|
||||||
fmt.Printf("\nfailed to run unit test for file %q: \n%v", fileName, err)
|
fmt.Printf("failed to run unit test for file %q: \n%v", fileName, err)
|
||||||
failed = true
|
failed = true
|
||||||
} else {
|
} else {
|
||||||
fmt.Println(" SUCCESS")
|
fmt.Println(" SUCCESS")
|
||||||
@ -108,7 +108,7 @@ func UnitTest(files []string, disableGroupLabel bool, externalLabels []string, e
|
|||||||
}
|
}
|
||||||
|
|
||||||
func ruleUnitTest(filename string, content []byte, externalLabels map[string]string) []error {
|
func ruleUnitTest(filename string, content []byte, externalLabels map[string]string) []error {
|
||||||
fmt.Println("\nUnit Testing: ", filename)
|
fmt.Println("\n\nUnit Testing: ", filename)
|
||||||
var unitTestInp unitTestFile
|
var unitTestInp unitTestFile
|
||||||
if err := yaml.UnmarshalStrict(content, &unitTestInp); err != nil {
|
if err := yaml.UnmarshalStrict(content, &unitTestInp); err != nil {
|
||||||
return []error{fmt.Errorf("failed to unmarshal file: %w", err)}
|
return []error{fmt.Errorf("failed to unmarshal file: %w", err)}
|
||||||
@ -138,6 +138,9 @@ func ruleUnitTest(filename string, content []byte, externalLabels map[string]str
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return []error{fmt.Errorf("failed to parse `rule_files`: %w", err)}
|
return []error{fmt.Errorf("failed to parse `rule_files`: %w", err)}
|
||||||
}
|
}
|
||||||
|
if len(testGroups) == 0 {
|
||||||
|
return []error{fmt.Errorf("found no rule group in %v", unitTestInp.RuleFiles)}
|
||||||
|
}
|
||||||
|
|
||||||
var errs []error
|
var errs []error
|
||||||
for _, t := range unitTestInp.Tests {
|
for _, t := range unitTestInp.Tests {
|
||||||
|
@ -24,7 +24,8 @@ func TestUnitTest_Failure(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// failing test
|
f([]string{"./testdata/failed-test-with-missing-rulefile.yaml"})
|
||||||
|
|
||||||
f([]string{"./testdata/failed-test.yaml"})
|
f([]string{"./testdata/failed-test.yaml"})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -37,6 +37,7 @@ See also [LTS releases](https://docs.victoriametrics.com/lts-releases/).
|
|||||||
* BUGFIX: [vmui](https://docs.victoriametrics.com/#vmui): fix for `showLegend` and `alias` flags in predefined panels. [See this issue](https://github.com/VictoriaMetrics/VictoriaMetrics/issues/7565)
|
* BUGFIX: [vmui](https://docs.victoriametrics.com/#vmui): fix for `showLegend` and `alias` flags in predefined panels. [See this issue](https://github.com/VictoriaMetrics/VictoriaMetrics/issues/7565)
|
||||||
* BUGFIX: [vmalert](https://docs.victoriametrics.com/vmalert): improve the correctness of alert [state restoration](https://docs.victoriametrics.com/vmalert/#alerts-state-on-restarts). Previously, it could result in false-positive alerts if alert was resolved shortly before vmalert restart.
|
* BUGFIX: [vmalert](https://docs.victoriametrics.com/vmalert): improve the correctness of alert [state restoration](https://docs.victoriametrics.com/vmalert/#alerts-state-on-restarts). Previously, it could result in false-positive alerts if alert was resolved shortly before vmalert restart.
|
||||||
* BUGFIX: [vmalert-tool](https://docs.victoriametrics.com/vmalert-tool/): exit immediately with error message if no test file is found under specified `-files`.
|
* BUGFIX: [vmalert-tool](https://docs.victoriametrics.com/vmalert-tool/): exit immediately with error message if no test file is found under specified `-files`.
|
||||||
|
* BUGFIX: [vmalert-tool](https://docs.victoriametrics.com/vmalert-tool/): print an error message if no rule group is found in `rule_files`.
|
||||||
* BUGFIX: `vmselect` in [VictoriaMetrics cluster](https://docs.victoriametrics.com/cluster-victoriametrics/): Properly handle [multitenant](https://docs.victoriametrics.com/cluster-victoriametrics/#multitenancy-via-labels) query request errors and correctly perform search for available tenants. See [this issue](https://github.com/VictoriaMetrics/VictoriaMetrics/issues/7549) for details. This is follow-up after [v1.106.1](https://github.com/VictoriaMetrics/VictoriaMetrics/releases/tag/v1.106.1) release changes.
|
* BUGFIX: `vmselect` in [VictoriaMetrics cluster](https://docs.victoriametrics.com/cluster-victoriametrics/): Properly handle [multitenant](https://docs.victoriametrics.com/cluster-victoriametrics/#multitenancy-via-labels) query request errors and correctly perform search for available tenants. See [this issue](https://github.com/VictoriaMetrics/VictoriaMetrics/issues/7549) for details. This is follow-up after [v1.106.1](https://github.com/VictoriaMetrics/VictoriaMetrics/releases/tag/v1.106.1) release changes.
|
||||||
* BUGFIX: `vmselect` in [VictoriaMetrics cluster](https://docs.victoriametrics.com/cluster-victoriametrics/): properly set `multitenant` cache expiration duration with `search.tenantCacheExpireDuration`. Previously flag always used default value.
|
* BUGFIX: `vmselect` in [VictoriaMetrics cluster](https://docs.victoriametrics.com/cluster-victoriametrics/): properly set `multitenant` cache expiration duration with `search.tenantCacheExpireDuration`. Previously flag always used default value.
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user