Skip to content
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

Watch for config file changes in fileprovider #5945

Closed

Conversation

swiatekm
Copy link
Contributor

Description:
Make the file config provider watch for changes to the config file.

This is done via polling the file every second, with an additional grace period of two seconds for actually delivering updates to the collector. We're not using notification mechanisms provided by the OS because they're unreliable or annoyingly complex to make work for some popular use cases - most notably Kubernetes ConfigMaps. As we don't need frequent updates and our watched files are small, polling is both performant and easier to understand than, say, inotify.

This change is more complex than it technically needs to be because it tries to reasonably deal with misbehaving users. For example, it'll quietly accept a user calling .Shutdown before .Close:

r, err := provider.Retrieve("file:/path/to/config")
provider.Shutdown()
r.Close()

and r.Close() is even thread-safe. If we're ok with the above resulting in a panic or a deadlock, I can make both the provider and the filewatcher simpler.

Link to tracking Issue: #273

Testing:
Added additional tests for the provider and separate unit tests for the filewatcher. I also did a couple manual e2e tests of the more interesting edge cases, like network filesystems and deep symlink chains.

@swiatekm swiatekm force-pushed the configmap/fileprovider/watch-poll branch 5 times, most recently from f947437 to e46c443 Compare August 23, 2022 10:42
@codecov
Copy link

codecov bot commented Aug 23, 2022

Codecov Report

Merging #5945 (287c510) into main (62d41a8) will increase coverage by 0.05%.
The diff coverage is 96.22%.

@@            Coverage Diff             @@
##             main    #5945      +/-   ##
==========================================
+ Coverage   91.90%   91.95%   +0.05%     
==========================================
  Files         200      201       +1     
  Lines       12414    12568     +154     
==========================================
+ Hits        11409    11557     +148     
- Misses        793      797       +4     
- Partials      212      214       +2     
Impacted Files Coverage Δ
confmap/provider/fileprovider/filewatcher.go 93.10% <93.10%> (ø)
confmap/provider/fileprovider/provider.go 100.00% <100.00%> (ø)

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

@swiatekm swiatekm force-pushed the configmap/fileprovider/watch-poll branch 7 times, most recently from d4efd80 to 6fd2146 Compare August 23, 2022 15:04
@swiatekm swiatekm marked this pull request as ready for review August 23, 2022 15:24
@swiatekm swiatekm requested review from a team and bogdandrutu August 23, 2022 15:24
Copy link
Member

@TylerHelmuth TylerHelmuth left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I love this idea, but my gut says we should not make it a default for fileprovide initially. The current expectation for the file provide (and performance expectations) is that the file is not watched. It feels appropriate to either hide this capability behind a feature gate or as a different provider/flag. That way existing customers have to opt-in for now.

@swiatekm
Copy link
Contributor Author

I love this idea, but my gut says we should not make it a default for fileprovide initially. The current expectation for the file provide (and performance expectations) is that the file is not watched. It feels appropriate to either hide this capability behind a feature gate or as a different provider/flag. That way existing customers have to opt-in for now.

Sounds reasonable to me. It'd be pretty straightforward to gate this, considering all the new functionality is hidden behind a single conditional right now.

@swiatekm swiatekm force-pushed the configmap/fileprovider/watch-poll branch from 6fd2146 to 287c510 Compare August 23, 2022 18:11
@swiatekm
Copy link
Contributor Author

In all honesty, after thinking about it more, different usecases may want to have this enabled or disabled in general. In Kubernetes, for example, you typically want to treat Pods as immutable, and don't want them to quietly reload configuration just because you made a change to a ConfigMap. Arguably it should be the users' responsibility to make sure Kubernetes doesn't reload the file inside the Pod, but that's an obscure enough topic that I'm not confident in users not shooting themselves in the foot with it.

I think I'm going to open an issue about this so we can more carefully weigh the pros and cons. This probably applies more generally to configuration reloading for any provider, this one is simply the first in line to have it implemented.

@github-actions
Copy link
Contributor

github-actions bot commented Sep 8, 2022

This PR was marked stale due to lack of activity. It will be closed in 14 days.

@github-actions github-actions bot added the Stale label Sep 8, 2022
@bogdandrutu bogdandrutu removed the Stale label Sep 9, 2022
@github-actions
Copy link
Contributor

This PR was marked stale due to lack of activity. It will be closed in 14 days.

@github-actions
Copy link
Contributor

This PR was marked stale due to lack of activity. It will be closed in 14 days.

@github-actions
Copy link
Contributor

This PR was marked stale due to lack of activity. It will be closed in 14 days.

@github-actions github-actions bot added the Stale label Oct 25, 2022
}

func metadataEqual(first os.FileInfo, second os.FileInfo) bool {
return first.Size() == second.Size() && first.ModTime() == second.ModTime()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: some file file systems might be mounted with the norelatime option, which can lead to funny and unlikely bugs.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will it? It was my understanding that norelatime only affects access time, whereas I'm checking modification time here.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My mistake, you are right. this will only affect the access time.

@bogdandrutu bogdandrutu removed the Stale label Oct 25, 2022
@github-actions
Copy link
Contributor

github-actions bot commented Nov 9, 2022

This PR was marked stale due to lack of activity. It will be closed in 14 days.

@github-actions
Copy link
Contributor

github-actions bot commented Dec 8, 2022

This PR was marked stale due to lack of activity. It will be closed in 14 days.

@github-actions github-actions bot added the Stale label Dec 8, 2022
@github-actions
Copy link
Contributor

Closed as inactive. Feel free to reopen if this PR is still being worked on.

@github-actions github-actions bot closed this Dec 23, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants