Use local vars, not instance vars, in metricsHandler #10
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
When Falcon starts up, it creates an individual instance of metricsHandler for each metric type:
The same metricsHandler instance is used for every
/health
request.This, by itself, is not an issue. However, because the instance stores state (such as IP/hostname) in instances variables, these can get clobbered if we process multiple requests simultaneously.
By instance variables I mean usage of
self
:Here is you can reproduce this.
First, let's add some logging to show the issue.
I am going to use the following bash script to quickly make two requests against the exporter:
Now, let’s observe the logs:
We see a few things:
• Lines 1,2: Indeed, the very same metricsHandler instance processes both requests (this is evidenced by the id being identical). Again, this isn’t an issue unto itself; just saying it’s the same instance so we can’t use self safely.
• Lines 3,4: You can see that it scrapes foo even though the client asked for bar
• Lines 5,6: From collector.py, you can see that the collector is initialized for foo and IP 10.0.0.3 twice even though we had asked for bar on the second request.
fixes #9