Skip to content

Commit fd9fc8d

Browse files
committed
Better documentation for findRulesConfig
Fixes 029f17c
1 parent a9d2874 commit fd9fc8d

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

pkg/configs/db/postgres/postgres.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,11 +171,22 @@ func (d DB) SetRulesConfig(userID string, oldConfig, newConfig configs.RulesConf
171171
return updated, err
172172
}
173173

174+
// findRulesConfigs helps GetAllRulesConfigs and GetRulesConfigs retrieve the
175+
// set of all active rules configurations across all our users.
174176
func (d DB) findRulesConfigs(filter squirrel.Sqlizer) (map[string]configs.VersionedRulesConfig, error) {
175177
rows, err := d.Select("id", "owner_id", "config ->> 'rules_files'").
176178
Options("DISTINCT ON (owner_id)").
177179
From("configs").
178180
Where(filter).
181+
// `->>` gets a JSON object field as text. When a config row exists
182+
// and alertmanager config is provided but ruler config has not yet
183+
// been, the 'rules_files' key will have an empty JSON object as its
184+
// value. This is (probably) the most efficient way to test for a
185+
// non-empty `rules_files` key.
186+
//
187+
// This whole situation is way too complicated. See
188+
// https://github.com/weaveworks/cortex/issues/619 for the whole
189+
// story, and our plans to improve it.
179190
Where("config ->> 'rules_files' <> '{}'").
180191
OrderBy("owner_id, id DESC").
181192
Query()

0 commit comments

Comments
 (0)