-
Notifications
You must be signed in to change notification settings - Fork 812
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
Removing Stale alert manager templates files #4495
Removing Stale alert manager templates files #4495
Conversation
e9a7172
to
ca09f05
Compare
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!
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.
Seems ok; I'm not very familiar with this feature.
Is there any danger that there could be a file there for some other reason?
Could someone remove a template, then decide to use it again but you deleted it?
var userTemplateDir = filepath.Join(am.getTenantDirectory(cfg.User), templatesDir) | ||
var filesToRemove = make(map[string]string) | ||
|
||
if oldTemplateFiles, err := ioutil.ReadDir(userTemplateDir); err == nil { |
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 think this deserves a comment like "first we list all the files, then we will remove those from the list that are in use, then we will remove the files that are never used".
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.
Is there any danger that there could be a file there for some other reason?
I dont think so. Cortex expose an api to configure alert manager for a tenant and this API receives the template files and the prometheus AlertManager configuration on the same request. On a regular prometheus alert manager, the config file are stored in the filesystem and referenced by the configuration. Cortex implementation receives both on the same request, drops the templates files on the filesystem and reference them on the alert manager config. The folder where cortex drops the file is exclusive for a given tenant/alert manager.
Could someone remove a template, then decide to use it again but you deleted it?
As we configure the templates and the alert manager on the same request, we should never have a alert manager configuration that uses a template that is not defined in the same request.
I think this deserves a comment like "first we list all the files, then we will remove those from the list that are in use, then we will remove the files that are never used".
Make sense.
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.
Added the comments
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.
Looks good, just a minor suggestion.
f33bf7d
to
412be4a
Compare
Signed-off-by: Alan Protasio <[email protected]>
Co-authored-by: Steve Simpson <[email protected]> Signed-off-by: Alan Protasio <[email protected]>
Co-authored-by: Steve Simpson <[email protected]> Signed-off-by: Alan Protasio <[email protected]>
Co-authored-by: Steve Simpson <[email protected]> Signed-off-by: Alan Protasio <[email protected]>
412be4a
to
c408466
Compare
Signed-off-by: Alan Protasio <[email protected]>
c408466
to
1b31f5a
Compare
@stevesg done! :D |
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.
Nice! Looks good to me.
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.
Thanks!
* Removing Stale alert manager templates files Signed-off-by: Alan Protasio <[email protected]> * Update pkg/alertmanager/multitenant.go Co-authored-by: Steve Simpson <[email protected]> Signed-off-by: Alan Protasio <[email protected]> * Update pkg/alertmanager/multitenant.go Co-authored-by: Steve Simpson <[email protected]> Signed-off-by: Alan Protasio <[email protected]> * Update pkg/alertmanager/multitenant.go Co-authored-by: Steve Simpson <[email protected]> Signed-off-by: Alan Protasio <[email protected]> * Address comments Signed-off-by: Alan Protasio <[email protected]> Co-authored-by: Steve Simpson <[email protected]> Signed-off-by: Manish Kumar Gupta <[email protected]>
* Removing Stale alert manager templates files Signed-off-by: Alan Protasio <[email protected]> * Update pkg/alertmanager/multitenant.go Co-authored-by: Steve Simpson <[email protected]> Signed-off-by: Alan Protasio <[email protected]> * Update pkg/alertmanager/multitenant.go Co-authored-by: Steve Simpson <[email protected]> Signed-off-by: Alan Protasio <[email protected]> * Update pkg/alertmanager/multitenant.go Co-authored-by: Steve Simpson <[email protected]> Signed-off-by: Alan Protasio <[email protected]> * Address comments Signed-off-by: Alan Protasio <[email protected]> Co-authored-by: Steve Simpson <[email protected]> Signed-off-by: Alvin Lin <[email protected]>
What this PR does:
Currently, if we remove a template file from the alert manager config, this file will continue to be dangling in the filesystem. This PR just introduce a code to remove those dangling files.
Leaving these files there is problematic as removing some files from the config will not trigger the AlertManager reload - as the hasChanged will not be true - or when we are using patterns as below:
Which issue(s) this PR fixes:
Fixes #
Checklist
CHANGELOG.md
updated - the order of entries should be[CHANGE]
,[FEATURE]
,[ENHANCEMENT]
,[BUGFIX]