-
Notifications
You must be signed in to change notification settings - Fork 9.3k
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
fix (auto-reload): failing to auto-reload on changes to rule and scrape config files #15675
base: main
Are you sure you want to change the base?
Conversation
Fixes prometheus#15673 An issue was reported in the CNCF Slack regarding the new auto-reload feature in Prometheus 3.0 failing to reload on changes to rule files and scrape config files. Signed-off-by: Cody Kaczynski <[email protected]>
6ea1aef
to
42cb1dd
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.
I am not very familiar with this code, but I am left wondering why it calls filepath.Join()
rather than config.JoinDir()
which is used when reading the config.
@@ -49,10 50,15 @@ func GenerateChecksum(yamlFilePath string) (string, error) { | |||
dir := filepath.Dir(yamlFilePath) | |||
|
|||
for i, file := range config.RuleFiles { | |||
config.RuleFiles[i] = filepath.Join(dir, file) | |||
if !strings.Contains(config.RuleFiles[i], dir) { |
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.
why config.RuleFiles[i]
and not file
?
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 actually am not sure what the exact value of file
is but I figured it would get us close enough to detect changes if we used the value supplied in the config.
I suppose file
might make more sense here though considering globs being used in the config.
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.
You got me thinking, and I'll try it out to see how it works because now I'm concerned that it would reload for every file that had changes (which I didn't test). I really hope it doesn't do that heh
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.
As for config.JoinDir()
, I had no idea that was there, so thanks! My modifications were only what we had there. Curious to know what the difference/benefit would be of changing this code to use config.JoinDir()
instead.
for i, file := range config.ScrapeConfigFiles { | ||
config.ScrapeConfigFiles[i] = filepath.Join(dir, file) | ||
if !strings.Contains(config.ScrapeConfigFiles[i], dir) { |
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.
similar: why not file
?
Fixes #15673
An issue was reported in the CNCF Slack regarding the new auto-reload feature in Prometheus 3.0 failing to reload on changes to rule files and scrape config files if they aren't in the same directory as
prometheus.yml
.This change verifies that
dir
does not exist in the specified rule/scrape_config_file string before setting it.The previous behavior resulted in paths like this:
When we want this:
Configuration example:
Logs of it working as intended:
After collecting that, I do think it could be nice to specify which file was updated instead of only returning
filename=/etc/prometheus/prometheus.yml
, but that's in reloadConfig and maybe shouldn't be touched in this PR