diff --git a/rules/manager.go b/rules/manager.go index da0964b46..15d26b14e 100644 --- a/rules/manager.go +++ b/rules/manager.go @@ -875,22 +875,27 @@ func (g *Group) Equals(ng *Group) bool { return false } } - - // compare source tenants ignoring their order - if len(g.sourceTenants) != len(ng.sourceTenants) { - return false - } - - thisSourceTenants := make(map[string]struct{}, len(g.sourceTenants)) - - for _, tenant := range g.sourceTenants { - thisSourceTenants[tenant] = struct{}{} - } - - for _, tenant := range ng.sourceTenants { - if _, ok := thisSourceTenants[tenant]; !ok { + { + // compare source tenants + if len(g.sourceTenants) != len(ng.sourceTenants) { return false } + + copyAndSort := func(x []string) []string { + copied := make([]string, len(x)) + copy(copied, x) + sort.Strings(copied) + return copied + } + + ngSourceTenantsCopy := copyAndSort(ng.sourceTenants) + gSourceTenantsCopy := copyAndSort(g.sourceTenants) + + for i := range ngSourceTenantsCopy { + if gSourceTenantsCopy[i] != ngSourceTenantsCopy[i] { + return false + } + } } return true