Skip to content

Commit a9d2874

Browse files
committed
Specialized implementation of Equal for RulesConfig
Fixes 6d4f8be
1 parent 4585474 commit a9d2874

File tree

3 files changed

+18
-4
lines changed

3 files changed

+18
-4
lines changed

pkg/configs/configs.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,22 @@ func (v View) GetVersionedRulesConfig() *VersionedRulesConfig {
4444
// RulesConfig are the set of rules files for a particular organization.
4545
type RulesConfig map[string]string
4646

47+
// Equal compares two RulesConfigs for equality.
48+
//
49+
// instance Eq RulesConfig
50+
func (c RulesConfig) Equal(o RulesConfig) bool {
51+
if len(o) != len(c) {
52+
return false
53+
}
54+
for k, v1 := range c {
55+
v2, ok := o[k]
56+
if !ok || v1 != v2 {
57+
return false
58+
}
59+
}
60+
return true
61+
}
62+
4763
// Parse rules from the Cortex configuration.
4864
//
4965
// Strongly inspired by `loadGroups` in Prometheus.

pkg/configs/db/memory/memory.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package memory
22

33
import (
44
"database/sql"
5-
"reflect"
65

76
"github.com/weaveworks/cortex/pkg/configs"
87
)
@@ -77,7 +76,7 @@ func (d *DB) SetRulesConfig(userID string, oldConfig, newConfig configs.RulesCon
7776
if !ok {
7877
return true, d.SetConfig(userID, configs.Config{RulesFiles: newConfig})
7978
}
80-
if !reflect.DeepEqual(c.Config.RulesFiles, oldConfig) {
79+
if !oldConfig.Equal(c.Config.RulesFiles) {
8180
return false, nil
8281
}
8382
return true, d.SetConfig(userID, configs.Config{

pkg/configs/db/postgres/postgres.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import (
44
"database/sql"
55
"encoding/json"
66
"errors"
7-
"reflect"
87

98
"github.com/Masterminds/squirrel"
109
"github.com/go-kit/kit/log/level"
@@ -159,7 +158,7 @@ func (d DB) SetRulesConfig(userID string, oldConfig, newConfig configs.RulesConf
159158
// The supplied oldConfig must match the current config. If no config
160159
// exists, then oldConfig must be nil. Otherwise, it must exactly
161160
// equal the existing config.
162-
if !((err == sql.ErrNoRows && oldConfig == nil) || reflect.DeepEqual(current.Config.RulesFiles, oldConfig)) {
161+
if !((err == sql.ErrNoRows && oldConfig == nil) || oldConfig.Equal(current.Config.RulesFiles)) {
163162
return nil
164163
}
165164
new := configs.Config{

0 commit comments

Comments
 (0)