-
Notifications
You must be signed in to change notification settings - Fork 148
Add :clean_dir option and clean_pid method to DirectFileStore #173
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
Add :clean_dir option and clean_pid method to DirectFileStore #173
Conversation
831dda8
to
049948b
Compare
@@ -68,6 +80,7 @@ def validate_metric_settings(metric_settings) | |||
end | |||
|
|||
class MetricStore | |||
FILENAME_PREFIX = "prometheus_#{ Prometheus::Client::VERSION }" |
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 changed this from metric
to prometheus
to reduce the chance of deleting unrelated files.. thoughts?
@store_settings = { dir: dir } | ||
FileUtils.mkdir_p(dir) | ||
|
||
if clean_dir | ||
Dir.glob(File.join(dir, "#{ MetricStore::FILENAME_PREFIX }_*___*.bin")).each do |file_path| |
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.
This won't delete files from old versions of the gem.. thoughts?
1 similar comment
Signed-off-by: Stefan Sundin <stefan@stefansundin.com>
049948b
to
8537f5a
Compare
Hi @stefansundin, thank you for this PR! This looks quite good, and it seems to solve Issue #109. (@Sinjo RTYI) You mention you are replacing some currently existing code in your app that deletes these files... So i'm not sure whether this should be an option in the constructor, and instead it should be a static method that you call in your Unicorn startup script, before forking. We should also definitely add some documentation on this, things like your Thoughts? |
The relevant samples are linked in the PR description.
My puma config is using
I don't think it matters that much. You can also conditionally set this new argument the same way you would conditionally call a new method. I actually think we should consider making this the default behavior. As I noted above, I think everyone with forking processes will encounter this issue. As I wrote above, my hesitation is:
So if there is no use case to do this, current or future, then I would at least consider making it the default. You guys are the experts so I will let you make the call. :) |
@stefansundin After discussing this quite a bit, I don't think we should have this change. Having that flag in the constructor also feels a bit awkward as an interface. Having looked into that option, since we can't do it automatically because you may be calling post-fork, and thus since you still have to call a method manually on startup, we don't seem to be saving users much work. There's not that much difference in my opinion between having to call For this same reason, we can't make this the default, as much as i'd like to. It's too easy to inadvertently run after forking. What I think we should do instead is document this in the Would you prefer if I close this PR, and we tackle the documentation when we have time, or would you like to write that documentation section? As for your worker shutdown code, there might be a pretty big issue with it. If that runs when a worker ends but the whole server keep running... That code can be quite problematic. Unless all of your metrics are tagged with their If the hook only runs on server shutdown, however, that's safe, but i'm not sure I understand what's the use case for each worker to clean after itself, if the whole thing gets wiped after the server restarts. |
@dmagliola Ok. I think it would be better if you would update the README and other documentation. If you do it then there's less need to go back-and-forth between the two of us. As for the worker shutdown code, yes there are some gotchas. In my opinion, people already have to deal with most of these gotchas in a multi-server environment, where servers come and go very frequently. Feel free to close this after you've updated the docs. |
Hi Stefan, I agree with you. I'm not sure what's proper etiquette in terms of taking over other people's PRs, so I was suggesting some changes. |
Add an example on how to solve the "files are already there on startup" problem, based on @stefansundin 's proposal in PR #173
Add an example on how to solve the "files are already there on startup" problem, based on @stefansundin 's proposal in PR #173 Signed-off-by: Daniel Magliola <danielmagliola@gocardless.com>
Hi again,
As hinted in my other PR (#172), here's another one.
Currently, it is a bit of a problem that the gem doesn't help with keeping the directory clean. I'm sure everyone who attempts to use DirectFileStore will soon realize that metrics from old processes hang around when collecting the metrics. So I wouldn't be surprised if many people have worked around this by simply cleaning the directory first.
So the first change, adding a new
:clean_dir
option, will let me remove this piece of code from my app: stefansundin/github-activity@936d4d6#diff-d21913acbe4d1528a62c64cdec6d43d7R11-R14I was even thinking of making this the default, but I'm afraid to accidentally delete someone's files.. even though it should be unlikely. Is there any use case of possibly initializing two DirectFileStore's that use the same directory? I feel like that may be a bad idea for other reasons..
The second piece, the new
clean_pid
method, will let me simplify this part of my app: stefansundin/github-activity@936d4d6#diff-3f0c524806c4374c99a509efaffd3e8aR29-R32So I can change this:
to:
Thanks!