-
Notifications
You must be signed in to change notification settings - Fork 791
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactor Ruler, introduce MultiTenantManager interface #3019
Conversation
Signed-off-by: Ben Ye <yb532204897@gmail.com>
Signed-off-by: Ben Ye <yb532204897@gmail.com>
Signed-off-by: Marco Pracucci <marco@pracucci.com>
Signed-off-by: Marco Pracucci <marco@pracucci.com>
Signed-off-by: Annanay <annanayagarwal@gmail.com>
Signed-off-by: Annanay <annanayagarwal@gmail.com>
Signed-off-by: Annanay <annanayagarwal@gmail.com>
816d7bb
to
5d571cd
Compare
Signed-off-by: Annanay <annanayagarwal@gmail.com>
Signed-off-by: Annanay <annanayagarwal@gmail.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very good job! I patiently went through the diff and looks a no-op refactoring to me, except for the few comments I left.
Co-authored-by: Marco Pracucci <marco@pracucci.com> Signed-off-by: Annanay <annanayagarwal@gmail.com>
Signed-off-by: Annanay <annanayagarwal@gmail.com>
499bf72
to
a22a28d
Compare
Signed-off-by: Annanay <annanayagarwal@gmail.com>
Signed-off-by: Annanay <annanayagarwal@gmail.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have left few nit-picky comments, but overall LGTM.
Signed-off-by: Annanay <annanayagarwal@gmail.com>
Thanks for the reviews, @pracucci & @pstibrany! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks!
@@ -149,59 +139,64 @@ func (cfg *Config) RegisterFlags(f *flag.FlagSet) { | |||
f.DurationVar(&cfg.ResendDelay, "ruler.resend-delay", time.Minute, `Minimum amount of time to wait before resending an alert to Alertmanager.`) | |||
} | |||
|
|||
// MultiTenantManager is the interface of interaction with a Manager that is tenant aware. | |||
type MultiTenantManager interface { | |||
// SyncRuleGroups is used to sync the Manager with rules from the RuleStore. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the next PR, we can mention that ruleGroups
is per tenant.
// GetRules fetches rules for a particular tenant (userID). | ||
GetRules(userID string) []*promRules.Group | ||
// Stop stops all Manager components. | ||
Stop() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seeing Stop
method in the generic interface looks like an anti-pattern to me. As Ruler is not creating the manager, I don't think it should be one stopping it either.
(But that can be addressed in another PR)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree, we need the Stop()
function but I had a feeling the other function should be named StartOrSyncRuleGroups()
. That sounds a little long, but do you have any other suggestions?
@@ -149,59 +139,64 @@ func (cfg *Config) RegisterFlags(f *flag.FlagSet) { | |||
f.DurationVar(&cfg.ResendDelay, "ruler.resend-delay", time.Minute, `Minimum amount of time to wait before resending an alert to Alertmanager.`) | |||
} | |||
|
|||
// MultiTenantManager is the interface of interaction with a Manager that is tenant aware. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// MultiTenantManager is the interface of interaction with a Manager that is tenant aware. | |
// MultiTenantManager interface describes interaction between Ruler, that periodically | |
// loads rules from the store, and object that keeps rules in memory for each tenant. |
It sounds to me like "multi-tenant aware rules manager" :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
and object that keeps rules in memory for each tenant
The DefaultMultiTenantManager
uses a mapper to write rules to a file and passes file path to the Prometheus Manager. Maybe we can modify this to
// MultiTenantManager interface describes interaction between Ruler, that periodically
// loads rules from the store, and object that syncs rules to the Prometheus manager
// for every tenant.
What this PR does:
This PR refactors ruler package by introducing a
MultiTenantManager
interface. This is done for multiple reasons.First, it splits out the Ruler struct into distinct components, and the Ruler is seen as a module that ties together the rule storage, ring for sharding and Manager for evaluation and notification on the rules.
Secondly, it allows us to add custom functionality into the Ruler depending on custom fields present in the RuleGroup description, by overriding the
DefaultMultiTenantManager
. For ex: This brings flexibility in using different appenders based on special config fields present in the RuleGroup definition.Which issue(s) this PR fixes:
Fixes #
Checklist
Will drop draft status once:
CHANGELOG.md
updated - the order of entries should be[CHANGE]
,[FEATURE]
,[ENHANCEMENT]
,[BUGFIX]
/cc @jtlisi