Repository: VictoriaMetrics/VictoriaMetrics
Pull request #7392 (2024-10-30 09:25:19)

Sets default interval for unittest input_series
### Describe Your Changes
Currently it is not optional option, but if user forgot to set, it defaults to 0, which cause unexpected behavior.

This change sets default = evaluation_interval similar to promtool behavior.

https://prometheus.io/docs/prometheus/2.55/configuration/unit_testing_rules/#test_group
### Checklist

The following checks are **mandatory**:

- [x] My change adheres [VictoriaMetrics contributing guidelines](https://docs.victoriametrics.com/contributing/).


codecov[bot]: ## [Codecov](https://app.codecov.io/gh/VictoriaMetrics/VictoriaMetrics/pull/7392?dropdown=coverage&src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=VictoriaMetrics) Report
Attention: Patch coverage is `0%` with `3 lines` in your changes missing coverage. Please review.
> Project coverage is 60.55%. Comparing base [(`8aaa828`)](https://app.codecov.io/gh/VictoriaMetrics/VictoriaMetrics/commit/8aaa828ba3f49a43cb8de89a0bcae160f7988c14?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=VictoriaMetrics) to head [(`c379240`)](https://app.codecov.io/gh/VictoriaMetrics/VictoriaMetrics/commit/c379240c5b25ae998196abc9636232d6ea1d6d9c?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=VictoriaMetrics).
> Report is 1697 commits behind head on master.

| [Files with missing lines](https://app.codecov.io/gh/VictoriaMetrics/VictoriaMetrics/pull/7392?dropdown=coverage&src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=VictoriaMetrics) | Patch % | Lines |
|---|---|---|
| [app/vmalert-tool/unittest/unittest.go](https://app.codecov.io/gh/VictoriaMetrics/VictoriaMetrics/pull/7392?src=pr&el=tree&filepath=app%2Fvmalert-tool%2Funittest%2Funittest.go&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=VictoriaMetrics#diff-YXBwL3ZtYWxlcnQtdG9vbC91bml0dGVzdC91bml0dGVzdC5nbw==) | 0.00% | [2 Missing and 1 partial :warning: ](https://app.codecov.io/gh/VictoriaMetrics/VictoriaMetrics/pull/7392?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=VictoriaMetrics) |

<details><summary>Additional details and impacted files</summary>


```diff
@@            Coverage Diff             @@
##           master    #7392      +/-   ##
==========================================
+ Coverage   60.37%   60.55%   +0.17%     
==========================================
  Files         411      644     +233     
  Lines       76609   108430   +31821     
==========================================
+ Hits        46253    65658   +19405     
- Misses      27794    39227   +11433     
- Partials     2562     3545     +983     
```

</details>

[:umbrella: View full report in Codecov by Sentry](https://app.codecov.io/gh/VictoriaMetrics/VictoriaMetrics/pull/7392?dropdown=coverage&src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=VictoriaMetrics).   
:loudspeaker: Have feedback on the report? [Share it here](https://about.codecov.io/codecov-pr-comment-feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=VictoriaMetrics).


Patch:
diff --git a/docs/vmalert-tool.md b/docs/vmalert-tool.md
index 7f41ea931..24dc55827 100644
--- a/docs/vmalert-tool.md
+++ b/docs/vmalert-tool.md
@@ -40,7 +40,7 @@ which aren't always backward compatible with [PromQL](https://prometheus.io/docs
 >by default, rules execution is sequential within one group, but persistence of execution results to remote storage is asynchronous. Hence, user shouldn’t rely on chaining of recording rules when result of previous recording rule is reused in the next one;
 
 For example, you have recording rule A and alerting rule B in the same group, and rule B's expression is based on A's results.
-Rule B won't get the latest data of A, since data didn't persist to remote storage yet. 
+Rule B won't get the latest data of A, since data didn't persist to remote storage yet.
 The workaround is to divide them in two groups and put groupA in front of groupB (or use `group_eval_order` to define the evaluation order).
 In this way, vmalert-tool makes sure that the results of groupA must be written to storage before evaluating groupB:
 
@@ -54,7 +54,7 @@ groups:
   rules:
   - alert: B
     expr: A >= 0.75
-    for: 1m 
+    for: 1m
 ```
 
 ### Test file format
@@ -84,7 +84,7 @@ tests:
 
 ```yaml
 # Interval between samples for input series
-interval: <duration>
+[ interval: <duration> | default = evaluation_interval ]
 # Time series to persist into the database according to configured <interval> before running tests.
 input_series:
   [ - <series> ]


Test patch:
diff --git a/app/vmalert-tool/unittest/unittest.go b/app/vmalert-tool/unittest/unittest.go
index 64fd0a9cc..17b9b8cc7 100644
--- a/app/vmalert-tool/unittest/unittest.go
+++ b/app/vmalert-tool/unittest/unittest.go
@@ -270,6 +270,9 @@ func (tg *testGroup) test(evalInterval time.Duration, groupOrderMap map[string]i
 	// tear down vmstorage and clean the data dir
 	defer tearDown()
 
+	if tg.Interval == nil {
+		tg.Interval = promutils.NewDuration(evalInterval)
+	}
 	err := writeInputSeries(tg.InputSeries, tg.Interval, testStartTime, testPromWriteHTTPPath)
 	if err != nil {
 		return []error{err}