mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2025-02-09 15:27:11 +00:00
vmalert: properly set group_name
and file
fields for recording rules (#7298)
This commit properly adds `group_name` and `file` fields for recording rules web api response at `/api/v1/rules`. Previously these fields were blank. Related issue https://github.com/victoriaMetrics/victoriaMetrics/issues/7297 Signed-off-by: Antoine Deschênes <antoine.deschenes@linux.com>
This commit is contained in:
parent
ac82b5aea6
commit
d656934d22
3 changed files with 53 additions and 2 deletions
|
@ -215,8 +215,10 @@ func recordingToAPI(rr *rule.RecordingRule) apiRule {
|
||||||
Updates: rule.GetAllRuleState(rr),
|
Updates: rule.GetAllRuleState(rr),
|
||||||
|
|
||||||
// encode as strings to avoid rounding
|
// encode as strings to avoid rounding
|
||||||
ID: fmt.Sprintf("%d", rr.ID()),
|
ID: fmt.Sprintf("%d", rr.ID()),
|
||||||
GroupID: fmt.Sprintf("%d", rr.GroupID),
|
GroupID: fmt.Sprintf("%d", rr.GroupID),
|
||||||
|
GroupName: rr.GroupName,
|
||||||
|
File: rr.File,
|
||||||
}
|
}
|
||||||
if lastState.Err != nil {
|
if lastState.Err != nil {
|
||||||
r.LastError = lastState.Err.Error()
|
r.LastError = lastState.Err.Error()
|
||||||
|
|
|
@ -1,9 +1,56 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
|
"github.com/VictoriaMetrics/VictoriaMetrics/app/vmalert/config"
|
||||||
|
"github.com/VictoriaMetrics/VictoriaMetrics/app/vmalert/datasource"
|
||||||
|
"github.com/VictoriaMetrics/VictoriaMetrics/app/vmalert/rule"
|
||||||
|
"reflect"
|
||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func TestRecordingToApi(t *testing.T) {
|
||||||
|
fq := &datasource.FakeQuerier{}
|
||||||
|
fq.Add(datasource.Metric{
|
||||||
|
Values: []float64{1}, Timestamps: []int64{0},
|
||||||
|
})
|
||||||
|
g := &rule.Group{
|
||||||
|
Name: "group",
|
||||||
|
File: "rules.yaml",
|
||||||
|
Concurrency: 1,
|
||||||
|
}
|
||||||
|
|
||||||
|
entriesLimit := 44
|
||||||
|
rr := rule.NewRecordingRule(fq, g, config.Rule{
|
||||||
|
ID: 1248,
|
||||||
|
Record: "record_name",
|
||||||
|
Expr: "up",
|
||||||
|
Labels: map[string]string{"label": "value"},
|
||||||
|
UpdateEntriesLimit: &entriesLimit,
|
||||||
|
})
|
||||||
|
|
||||||
|
expectedRes := apiRule{
|
||||||
|
Name: "record_name",
|
||||||
|
Query: "up",
|
||||||
|
Labels: map[string]string{"label": "value"},
|
||||||
|
Health: "ok",
|
||||||
|
Type: ruleTypeRecording,
|
||||||
|
DatasourceType: "prometheus",
|
||||||
|
ID: "1248",
|
||||||
|
GroupID: fmt.Sprintf("%d", g.ID()),
|
||||||
|
GroupName: "group",
|
||||||
|
File: "rules.yaml",
|
||||||
|
MaxUpdates: 44,
|
||||||
|
Updates: make([]rule.StateEntry, 0),
|
||||||
|
}
|
||||||
|
|
||||||
|
res := recordingToAPI(rr)
|
||||||
|
|
||||||
|
if !reflect.DeepEqual(res, expectedRes) {
|
||||||
|
t.Fatalf("expected to have: \n%v;\ngot: \n%v", expectedRes, res)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestUrlValuesToStrings(t *testing.T) {
|
func TestUrlValuesToStrings(t *testing.T) {
|
||||||
mapQueryParams := map[string][]string{
|
mapQueryParams := map[string][]string{
|
||||||
"param1": {"param1"},
|
"param1": {"param1"},
|
||||||
|
|
|
@ -18,6 +18,8 @@ See also [LTS releases](https://docs.victoriametrics.com/lts-releases/).
|
||||||
|
|
||||||
## tip
|
## tip
|
||||||
|
|
||||||
|
* BUGFIX: [vmalert](https://docs.victoriametrics.com/vmalert): properly set `group_name` and `file` fields for recording rules in `/api/v1/rules`.
|
||||||
|
|
||||||
## [v1.105.0](https://github.com/VictoriaMetrics/VictoriaMetrics/releases/tag/v1.105.0)
|
## [v1.105.0](https://github.com/VictoriaMetrics/VictoriaMetrics/releases/tag/v1.105.0)
|
||||||
|
|
||||||
Released at 2024-10-21
|
Released at 2024-10-21
|
||||||
|
|
Loading…
Reference in a new issue