mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Alerting: Use stable identifier of a group when export to HCL (#90196)
* change the rule-group to be hashed when exporting to HCL Signed-off-by: Aviv Guiser <avivguiser@gmail.com> --------- Signed-off-by: Aviv Guiser <avivguiser@gmail.com>
This commit is contained in:
parent
a61cd94a70
commit
96c3e9c550
@ -4,6 +4,7 @@ import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"hash/fnv"
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
@ -587,11 +588,15 @@ func exportResponse(c *contextmodel.ReqContext, body definitions.AlertingFileExp
|
||||
func exportHcl(download bool, body definitions.AlertingFileExport) response.Response {
|
||||
resources := make([]hcl.Resource, 0, len(body.Groups)+len(body.ContactPoints)+len(body.Policies)+len(body.MuteTimings))
|
||||
convertToResources := func() error {
|
||||
for idx, group := range body.Groups {
|
||||
for _, group := range body.Groups {
|
||||
gr := group
|
||||
sum := fnv.New64()
|
||||
_, _ = sum.Write([]byte(gr.Name))
|
||||
_, _ = sum.Write([]byte(gr.FolderUID))
|
||||
hash := sum.Sum64()
|
||||
resources = append(resources, hcl.Resource{
|
||||
Type: "grafana_rule_group",
|
||||
Name: fmt.Sprintf("rule_group_%04d", idx),
|
||||
Name: fmt.Sprintf("rule_group_%016x", hash),
|
||||
Body: &gr,
|
||||
})
|
||||
}
|
||||
|
@ -760,7 +760,7 @@ func TestProvisioningApi(t *testing.T) {
|
||||
insertRule(t, sut, rule1)
|
||||
insertRule(t, sut, createTestAlertRule("rule2", 1))
|
||||
|
||||
expectedResponse := `resource "grafana_rule_group" "rule_group_0000" {
|
||||
expectedResponse := `resource "grafana_rule_group" "rule_group_cc0954af8a53fa18" {
|
||||
org_id = 1
|
||||
name = "my-cool-group"
|
||||
folder_uid = "folder-uid"
|
||||
|
@ -1,4 +1,4 @@
|
||||
resource "grafana_rule_group" "rule_group_0000" {
|
||||
resource "grafana_rule_group" "rule_group_d3e8424bfbf66bc3" {
|
||||
org_id = 1
|
||||
name = "group101"
|
||||
folder_uid = "e4584834-1a87-4dff-8913-8a4748dfca79"
|
||||
|
Loading…
Reference in New Issue
Block a user