-
Notifications
You must be signed in to change notification settings - Fork 807
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allowing rule backup for rules API HA (#5782)
* Allowing ruler replication to be configurable Signed-off-by: Emmanuel Lodovice <[email protected]> * Allow rules to be loaded to rulers as backup for List rules API HA Signed-off-by: Emmanuel Lodovice <[email protected]> * Add integration test for rulers API with backup enabled Signed-off-by: Emmanuel Lodovice <[email protected]> * Mark the entire feature as experimental and improve variable names Signed-off-by: Emmanuel Lodovice <[email protected]> * Rename backUpRuleGroups to setRuleGroups to make it code less confusing Signed-off-by: Emmanuel Lodovice <[email protected]> * Remove backup manager lock because its not needed Signed-off-by: Emmanuel Lodovice <[email protected]> * Improve code quality - Remove duplicate code and use better data structures - Make backup rule_group label match the prometheus rule_group label - Skip initialization when feature is not enabled Signed-off-by: Emmanuel Lodovice <[email protected]> * Store rulepb.RuleGroupList in rules backup instead of promRules.Group Signed-off-by: Emmanuel Lodovice <[email protected]> * Add GetReplicationSetForOperationWithNoQuorum ring method and use it in getShardedRules Signed-off-by: Emmanuel Lodovice <[email protected]> * Refactor getLocalRules to make the method shorter Signed-off-by: Emmanuel Lodovice <[email protected]> * Add new ring method to get all instances and created a new method in ruler to get Replicaset without requiring quorum Signed-off-by: Emmanuel Lodovice <[email protected]> * Fix flaky test due to sorting issue Signed-off-by: Emmanuel Lodovice <[email protected]> --------- Signed-off-by: Emmanuel Lodovice <[email protected]>
- Loading branch information
1 parent
44a5d25
commit 8f6da89
Showing
18 changed files
with
1,720 additions
and
145 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package ruler | ||
|
||
import ( | ||
"time" | ||
|
||
promRules "github.com/prometheus/prometheus/rules" | ||
) | ||
|
||
// mergeGroupStateDesc removes duplicates from the provided []*GroupStateDesc by keeping the GroupStateDesc with the | ||
// latest information. It uses the EvaluationTimestamp of the GroupStateDesc and the EvaluationTimestamp of the | ||
// ActiveRules in a GroupStateDesc to determine the which GroupStateDesc has the latest information. | ||
func mergeGroupStateDesc(in []*GroupStateDesc) []*GroupStateDesc { | ||
states := make(map[string]*GroupStateDesc) | ||
rgTime := make(map[string]time.Time) | ||
for _, state := range in { | ||
latestTs := state.EvaluationTimestamp | ||
for _, r := range state.ActiveRules { | ||
if latestTs.Before(r.EvaluationTimestamp) { | ||
latestTs = r.EvaluationTimestamp | ||
} | ||
} | ||
key := promRules.GroupKey(state.Group.Namespace, state.Group.Name) | ||
ts, ok := rgTime[key] | ||
if !ok || ts.Before(latestTs) { | ||
states[key] = state | ||
rgTime[key] = latestTs | ||
} | ||
} | ||
groups := make([]*GroupStateDesc, 0, len(states)) | ||
for _, state := range states { | ||
groups = append(groups, state) | ||
} | ||
return groups | ||
} |
Oops, something went wrong.