mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Alerting: Use stable identifier of a group,contact point,mute timing when export to HCL (#90917)
--------- Signed-off-by: Aviv Guiser <avivguiser@gmail.com>
This commit is contained in:
parent
338b318bf4
commit
93aa5a56ad
@ -4,7 +4,6 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"hash/fnv"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
@ -592,24 +591,22 @@ func exportHcl(download bool, body definitions.AlertingFileExport) response.Resp
|
|||||||
convertToResources := func() error {
|
convertToResources := func() error {
|
||||||
for _, group := range body.Groups {
|
for _, group := range body.Groups {
|
||||||
gr := group
|
gr := group
|
||||||
sum := fnv.New64()
|
hash := getHash([]string{gr.Name, gr.FolderUID})
|
||||||
_, _ = sum.Write([]byte(gr.Name))
|
|
||||||
_, _ = sum.Write([]byte(gr.FolderUID))
|
|
||||||
hash := sum.Sum64()
|
|
||||||
resources = append(resources, hcl.Resource{
|
resources = append(resources, hcl.Resource{
|
||||||
Type: "grafana_rule_group",
|
Type: "grafana_rule_group",
|
||||||
Name: fmt.Sprintf("rule_group_%016x", hash),
|
Name: fmt.Sprintf("rule_group_%016x", hash),
|
||||||
Body: &gr,
|
Body: &gr,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
for idx, cp := range body.ContactPoints {
|
for _, cp := range body.ContactPoints {
|
||||||
upd, err := ContactPointFromContactPointExport(cp)
|
upd, err := ContactPointFromContactPointExport(cp)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("failed to convert contact points to HCL:%w", err)
|
return fmt.Errorf("failed to convert contact points to HCL:%w", err)
|
||||||
}
|
}
|
||||||
|
hash := getHash([]string{upd.Name})
|
||||||
resources = append(resources, hcl.Resource{
|
resources = append(resources, hcl.Resource{
|
||||||
Type: "grafana_contact_point",
|
Type: "grafana_contact_point",
|
||||||
Name: fmt.Sprintf("contact_point_%d", idx),
|
Name: fmt.Sprintf("contact_point_%016x", hash),
|
||||||
Body: &upd,
|
Body: &upd,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -623,14 +620,15 @@ func exportHcl(download bool, body definitions.AlertingFileExport) response.Resp
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
for idx, mt := range body.MuteTimings {
|
for _, mt := range body.MuteTimings {
|
||||||
mthcl, err := MuteTimingIntervalToMuteTimeIntervalHclExport(mt)
|
mthcl, err := MuteTimingIntervalToMuteTimeIntervalHclExport(mt)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("failed to convert mute timing [%s] to HCL:%w", mt.Name, err)
|
return fmt.Errorf("failed to convert mute timing [%s] to HCL:%w", mt.Name, err)
|
||||||
}
|
}
|
||||||
|
hash := getHash([]string{mthcl.Name})
|
||||||
resources = append(resources, hcl.Resource{
|
resources = append(resources, hcl.Resource{
|
||||||
Type: "grafana_mute_timing",
|
Type: "grafana_mute_timing",
|
||||||
Name: fmt.Sprintf("mute_timing_%d", idx+1),
|
Name: fmt.Sprintf("mute_timing_%016x", hash),
|
||||||
Body: mthcl,
|
Body: mthcl,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
resource "grafana_mute_timing" "mute_timing_1" {
|
resource "grafana_mute_timing" "mute_timing_9e85e7a27b8f12ca" {
|
||||||
name = "interval"
|
name = "interval"
|
||||||
}
|
}
|
||||||
resource "grafana_mute_timing" "mute_timing_2" {
|
resource "grafana_mute_timing" "mute_timing_b469bb50150a4298" {
|
||||||
name = "full-interval"
|
name = "full-interval"
|
||||||
|
|
||||||
intervals {
|
intervals {
|
||||||
|
@ -5,6 +5,7 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"hash/fnv"
|
||||||
"io"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
@ -230,3 +231,12 @@ func containsProvisionedAlerts(provenances map[string]ngmodels.Provenance, rules
|
|||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func getHash(hashSlice []string) uint64 {
|
||||||
|
sum := fnv.New64()
|
||||||
|
for _, str := range hashSlice {
|
||||||
|
_, _ = sum.Write([]byte(str))
|
||||||
|
}
|
||||||
|
hash := sum.Sum64()
|
||||||
|
return hash
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user