Skip to content

Commit

Permalink
fix(alerting): add a proper compare func for location in mute timings (
Browse files Browse the repository at this point in the history
  • Loading branch information
JohnnyQQQQ authored Feb 8, 2024
1 parent 74d7cd2 commit 4dc1ebb
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
10 changes: 9 additions & 1 deletion pkg/services/ngalert/api/api_alertmanager_guards.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package api
import (
"encoding/json"
"fmt"
"time"

"github.com/google/go-cmp/cmp"
"github.com/google/go-cmp/cmp/cmpopts"
Expand Down Expand Up @@ -137,7 +138,14 @@ func checkMuteTimes(currentConfig apimodels.GettableUserConfig, newConfig apimod
return fmt.Errorf("cannot delete provisioned mute time '%s'", muteTime.Name)
}
reporter := cmputil.DiffReporter{}
options := []cmp.Option{cmp.Reporter(&reporter), cmpopts.EquateEmpty()}
options := []cmp.Option{
cmp.Reporter(&reporter),
cmp.Comparer(func(a, b *time.Location) bool {
// Check if both are nil or both have the same string representation
return (a == nil && b == nil) || (a != nil && b != nil && a.String() == b.String())
}),
cmpopts.EquateEmpty(),
}
timesEqual := cmp.Equal(muteTime.TimeIntervals, postedMT.TimeIntervals, options...)
if !timesEqual {
return fmt.Errorf("cannot save provisioned mute time '%s'", muteTime.Name)
Expand Down
2 changes: 2 additions & 0 deletions pkg/services/ngalert/api/api_alertmanager_guards_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package api

import (
"testing"
"time"

amConfig "github.com/prometheus/alertmanager/config"
"github.com/prometheus/alertmanager/pkg/labels"
Expand Down Expand Up @@ -563,6 +564,7 @@ func defaultInterval(t *testing.T) []timeinterval.TimeInterval {
t.Helper()
return []timeinterval.TimeInterval{
{
Location: &timeinterval.Location{Location: time.Local},
Years: []timeinterval.YearRange{
{
InclusiveRange: timeinterval.InclusiveRange{
Expand Down

0 comments on commit 4dc1ebb

Please sign in to comment.