fix(agent): watch for changes in configuration files in config directories#10379
fix(agent): watch for changes in configuration files in config directories#10379conorevans wants to merge 6 commits intoinfluxdata:masterfrom
Conversation
|
Thanks so much for the pull request! |
Signed-off-by: Conor Evans <coevans@tcd.ie>
|
!signed-cla |
cmd/telegraf/telegraf.go
Outdated
|
|
||
| // configDirFiles returns a slice made up of filepaths correspoding | ||
| // to config files defined in any of the config directories. | ||
| func configDirFiles() sliceFlags { |
There was a problem hiding this comment.
I think it would probably make more sense for this to return []string rather than sliceFlags as in this context it's not to do with the flags.
There was a problem hiding this comment.
I think so too. I don't see any place where the existing sliceFlags methods (String and Set) are called. It looks like they may be left over from a previous refactor. Let's get rid of them.
There was a problem hiding this comment.
sliceFlags is used because of flag.Var so I think it will break stuff when removed..
There was a problem hiding this comment.
You're right @Hipska, good catch! I will fix this in the upcoming week (have got a new laptop without env fully set up)
cmd/telegraf/telegraf.go
Outdated
| } | ||
|
|
||
| if info.IsDir() { | ||
| // skip Kubernetes mounts, preventing loading the same config twice |
There was a problem hiding this comment.
I didn't remove this check. I don't immediately know if it also applies in this context, so I have to look a bit more. If it is necessary, the comment should probably be updated anyway. Happy for you to weigh in.
There was a problem hiding this comment.
I think in this case since we're looking only for regular files, we should skip all directories (not just "..").
If there's a directory called "xyz.conf" we wouldn't want the function to append it to configs and return it.
|
👍 This pull request doesn't change the Telegraf binary size 📦 Looks like new artifacts were built from this PR. Expand this list to get them here ! 🐯Artifact URLs |
|
@conorevans This PR is still named |
|
Hi @sjwang90 as an external contributor, I marked it as draft to show it needed some early feedback (in case the approach I took was terrible). I left some comments as to the things I though maintainers might like to comment on, but it's remained inactive. I can remove the |
|
Yeah - go ahead and remove the draft title and I'll mention it to the maintainers to do a review. |
|
@sjwang90 @Hipska @conorevans Hi all! Any chance to make this PR merged? I'll be glad to help if any help is needed. |
…onfigs-in-directories
|
Hi @iarkhanhelsky thanks to @sjwang90 and @reimda pushing this forward I will look to make their requested changes and update this. |
conorevans
left a comment
There was a problem hiding this comment.
hi sorry for delay my laptop is pretty terrible atm and was not having a fun time trying to fix git state (i wanted to squash my commits, hence the lazy last commit message)
Signed-off-by: Conor Evans <coevans@tcd.ie>
|
Does this code also watch for new files added into the dierctory? |
It only watches the files that were in the directory when telegraf loads its config. You would need to restart or sighup telegraf to watch new files. |
|
@conorevans If you fix the failing tests we can get this merged, thank you for your hard work! It is failing with: Looks like we need to keep the fConfigs to be |
… flag.Value interface
|
Download PR build artifacts for linux_amd64.tar.gz, darwin_amd64.tar.gz, and windows_amd64.zip. 📦 Click here to get additional PR build artifactsArtifact URLs |
| return nil | ||
| } | ||
|
|
||
| if err := filepath.Walk(dir, walkfn); err != nil { |
There was a problem hiding this comment.
@srebhan and I reviewed this and had the thought that walking the config dir here might not get the same list of configuration files as the code in config/config.go that initially loaded the files.
Instead of walking the path, could we change Config.LoadConfig to save the list of files? Then we know exactly which files to watch and there's no chance for difference or for a race condition. (Like if a file is added to the dir right after Config.LoadDirectory completes but before this code runs)
There was a problem hiding this comment.
That's a good point. I don't think I quite have the bandwidth to implement that change - would a Telegraf maintainer be able to take over?
There was a problem hiding this comment.
@conorevans thank you for working on this, it seems another community member has helped take this over: #12127 if you have time could you check if this change works for you by using the artifacts posted by the bot? thanks!
|
Closing as this PR has been replaced by: #12127 |
Signed-off-by: Conor Evans coevans@tcd.ie
Required for all PRs:
resolves #9985
The
walkfnis virtually identical toconfig.LoadDirectory()- I chose duplication over abstraction, as I think the scope for the latter is limited and undesirable.