-
Notifications
You must be signed in to change notification settings - Fork 187
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 intermittent issue with metrics tests #662
Conversation
60782e9
to
5c3ce0e
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.
Nice, looks good! Thanks for adding the better assertion message for when these fail.
LGTM in its current state. If you have time, can you try the fork suggestion to see if it works?
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.
Change looks good to me and it fixes the issue. My only concern is that if we ever decide to start looking at metrics in other tests, we will have to review it again.
On the other hand, if we move this test to the tests
folder and run it in isolation, the filter becomes redundant.
mountpoint-s3/src/metrics.rs
Outdated
const TEST_GAUGE: &str = "test_gauge"; | ||
const TEST_HISTOGRAM: &str = "test_histogram"; | ||
const TEST_METRICS: [&str; 3] = [TEST_COUNTER, TEST_GAUGE, TEST_HISTOGRAM]; | ||
|
||
#[test] | ||
fn basic_metrics() { | ||
let sink = Arc::new(MetricsSink::new()); | ||
let recorder = MetricsRecorder { sink: sink.clone() }; | ||
metrics::set_boxed_recorder(Box::new(recorder)).unwrap(); |
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 think the issue is actually with set_boxed_recorder
: this is global and supposed to be only called once. At the moment, this is indeed the only test that calls it, but as you noticed, other tests run in parallel may interfere with this one.
Should we move this test to the "integration tests", where it can be run in isolation?
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.
Daniel suggested using rusty_fork_test
which makes this test to run in a separate process preventing any global state from interfering with it.
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.
Yes, that works too. And it's probably better than my suggestion: no need to expose e.g. MetricsSink
.
5c3ce0e
to
572b89b
Compare
Signed-off-by: Andres Santana <[email protected]>
572b89b
to
2bfa549
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.
LGTM
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.
Nice!
Description of change
Fixes intermittent issues when testing metrics emission by using
rusty_fork_test
to make sure there isn't any global state interfering with this test.Relevant issues: N/A
Does this change impact existing behavior?
No
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license and I agree to the terms of the Developer Certificate of Origin (DCO).