|
|
|
@ -157,13 +157,13 @@ func (alertRule *AlertRule) GetLabels(opts ...LabelOption) map[string]string { |
|
|
|
|
// Diff calculates diff between two alert rules. Returns nil if two rules are equal. Otherwise, returns cmputil.DiffReport
|
|
|
|
|
func (alertRule *AlertRule) Diff(rule *AlertRule, ignore ...string) cmputil.DiffReport { |
|
|
|
|
var reporter cmputil.DiffReporter |
|
|
|
|
ops := make([]cmp.Option, 0, 4) |
|
|
|
|
ops := make([]cmp.Option, 0, 5) |
|
|
|
|
|
|
|
|
|
// json.RawMessage is a slice of bytes and therefore cmp's default behavior is to compare it by byte, which is not really useful
|
|
|
|
|
var jsonCmp = cmp.Transformer("", func(in json.RawMessage) string { |
|
|
|
|
return string(in) |
|
|
|
|
}) |
|
|
|
|
ops = append(ops, cmp.Reporter(&reporter), cmpopts.IgnoreFields(AlertQuery{}, "modelProps"), jsonCmp) |
|
|
|
|
ops = append(ops, cmp.Reporter(&reporter), cmpopts.IgnoreFields(AlertQuery{}, "modelProps"), jsonCmp, cmpopts.EquateEmpty()) |
|
|
|
|
|
|
|
|
|
if len(ignore) > 0 { |
|
|
|
|
ops = append(ops, cmpopts.IgnoreFields(AlertRule{}, ignore...)) |
|
|
|
|