mirror of
https://github.com/prymitive/karma
synced 2026-08-23 11:56:20 +00:00
fix(api): fix handling of clusters in silence responses
This commit is contained in:
committed by
Łukasz Mierzwa
parent
cf6f14cda9
commit
992d07e904
@@ -1024,9 +1024,9 @@ func TestVerifyAllGroups(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
am, foundAM := ur.Silences["843c4a11660fe38ea61e6960a29d4f4796da6488"]
|
||||
am, foundAM := ur.Silences["default"]
|
||||
if !foundAM {
|
||||
t.Errorf("[%s] Alertmanager cluster '843c4a11660fe38ea61e6960a29d4f4796da6488' (default) missing from silences", version)
|
||||
t.Errorf("[%s] Alertmanager cluster 'default' (default) missing from silences", version)
|
||||
} else if len(am) == 0 {
|
||||
t.Errorf("[%s] Silences mismatch, expected >0 but got %d", version, len(am))
|
||||
}
|
||||
|
||||
+7
-14
@@ -217,7 +217,7 @@ func alerts(c *gin.Context) {
|
||||
amNameToCluster := map[string]string{}
|
||||
silences := map[string]map[string]models.Silence{}
|
||||
for _, am := range alertmanager.GetAlertmanagers() {
|
||||
key := am.ClusterID()
|
||||
key := am.ClusterName()
|
||||
amNameToCluster[am.Name] = key
|
||||
_, found := silences[key]
|
||||
if !found {
|
||||
@@ -253,30 +253,23 @@ func alerts(c *gin.Context) {
|
||||
// only for alerts left after filtering
|
||||
alert.UpdateFingerprints()
|
||||
|
||||
var alertGridLabelValues []string
|
||||
alertGridLabelValues := map[string]bool{}
|
||||
switch gridLabel {
|
||||
case "@receiver":
|
||||
alertGridLabelValues = []string{alert.Receiver}
|
||||
alertGridLabelValues[alert.Receiver] = true
|
||||
case "@alertmanager":
|
||||
alertGridLabelValues = make([]string, 0, len(alert.Alertmanager))
|
||||
for _, am := range alert.Alertmanager {
|
||||
alertGridLabelValues = append(alertGridLabelValues, am.Name)
|
||||
alertGridLabelValues[am.Name] = true
|
||||
}
|
||||
case "@cluster":
|
||||
alertGridLabelValues = make([]string, 0, len(alert.Alertmanager))
|
||||
for _, am := range alert.Alertmanager {
|
||||
for _, upstream := range upstreams.Instances {
|
||||
if am.Name == upstream.Name {
|
||||
alertGridLabelValues = append(alertGridLabelValues, upstream.Cluster)
|
||||
}
|
||||
break
|
||||
}
|
||||
alertGridLabelValues[am.Cluster] = true
|
||||
}
|
||||
default:
|
||||
alertGridLabelValues = []string{alert.Labels[gridLabel]}
|
||||
alertGridLabelValues[alert.Labels[gridLabel]] = true
|
||||
}
|
||||
|
||||
for _, alertGridLabelValue := range alertGridLabelValues {
|
||||
for alertGridLabelValue, _ := range alertGridLabelValues {
|
||||
agCopy, found := perGridAlertGroup[alertGridLabelValue]
|
||||
if !found {
|
||||
agCopy = &models.AlertGroup{
|
||||
|
||||
@@ -102,7 +102,7 @@ func DedupSilences() []models.ManagedSilence {
|
||||
|
||||
for _, am := range upstreams {
|
||||
for id, silence := range am.Silences() {
|
||||
cluster := am.ClusterID()
|
||||
cluster := am.ClusterName()
|
||||
|
||||
if _, found := silenceByCluster[cluster]; !found {
|
||||
silenceByCluster[cluster] = map[string]models.Silence{}
|
||||
|
||||
@@ -478,18 +478,6 @@ func (am *Alertmanager) ClusterMemberNames() []string {
|
||||
return members
|
||||
}
|
||||
|
||||
// ClusterID returns the ID (sha1) of the cluster this Alertmanager instance
|
||||
// belongs to
|
||||
func (am *Alertmanager) ClusterID() string {
|
||||
members := am.ClusterMemberNames()
|
||||
id, err := slices.StringSliceToSHA1(members)
|
||||
if err != nil {
|
||||
log.Errorf("slices.StringSliceToSHA1 error: %s", err)
|
||||
return am.Name
|
||||
}
|
||||
return id
|
||||
}
|
||||
|
||||
func (am *Alertmanager) ClusterName() string {
|
||||
am.lock.RLock()
|
||||
if am.clusterName != "" {
|
||||
|
||||
Reference in New Issue
Block a user