-
Notifications
You must be signed in to change notification settings - Fork 866
fix(sdk): force_flush returns meaningful bool on MetricReader #5085
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
Open
ravitheja4531-cell
wants to merge
13
commits into
open-telemetry:main
Choose a base branch
from
ravitheja4531-cell:fix/force-flush-return-meaningful-bool
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 12 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
9e0c780
fix(sdk): force_flush returns meaningful bool on MetricReader
ravitheja4531-cell 5680779
test(sdk): add tests for force_flush meaningful bool return (#5020)
ravitheja4531-cell 1644453
Merge branch 'main' into fix/force-flush-return-meaningful-bool
ravitheja4531-cell b282129
Merge branch 'main' into fix/force-flush-return-meaningful-bool
ravitheja4531-cell 9f369e9
Merge branch 'main' into fix/force-flush-return-meaningful-bool
ravitheja4531-cell 3533f03
fix(sdk): address final review feedback - soften docstring, fix chang…
ravitheja4531-cell 7f10555
Merge branch 'main' into fix/force-flush-return-meaningful-bool
lzchen ec604fe
fix(sdk): use explicit return None for consistency in collect()
ravitheja4531-cell 17bab68
fix(sdk): move patch import to top level, fix trailing whitespace
ravitheja4531-cell b45fe1d
fix(sdk): suppress broad-exception-caught lint warning
ravitheja4531-cell 260e72b
Merge branch 'main' into fix/force-flush-return-meaningful-bool
emdneto f24411a
fix(sdk): move pmr.shutdown inside patch context to fix test isolation
ravitheja4531-cell 719f80c
Merge branch 'main' into fix/force-flush-return-meaningful-bool
lzchen File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,7 +20,7 @@ | |
| from logging import WARNING | ||
| from time import sleep, time_ns | ||
| from typing import Optional, cast | ||
| from unittest.mock import Mock | ||
| from unittest.mock import Mock, patch | ||
|
|
||
| import pytest | ||
|
|
||
|
|
@@ -360,3 +360,52 @@ def test_metric_reader_metrics(self): | |
| self.assertTrue(name.startswith("periodic_metric_reader/")) | ||
|
|
||
| mp.shutdown() | ||
|
|
||
| def test_force_flush_returns_true_on_success(self): | ||
| exporter = FakeMetricsExporter() | ||
| pmr = self._create_periodic_reader(metrics, exporter) | ||
| result = pmr.force_flush(timeout_millis=5_000) | ||
| self.assertTrue(result) | ||
| pmr.shutdown() | ||
|
|
||
| def test_force_flush_returns_false_on_export_failure(self): | ||
| exporter = FakeMetricsExporter() | ||
| exporter.export = Mock(return_value=MetricExportResult.FAILURE) | ||
| pmr = self._create_periodic_reader(metrics, exporter) | ||
| result = pmr.force_flush(timeout_millis=5_000) | ||
| self.assertFalse(result) | ||
| pmr.shutdown() | ||
|
|
||
| def test_force_flush_skips_exporter_flush_when_collect_fails(self): | ||
| exporter = FakeMetricsExporter() | ||
| exporter.force_flush = Mock(return_value=True) | ||
| pmr = PeriodicExportingMetricReader( | ||
| exporter, export_interval_millis=math.inf | ||
| ) | ||
| # No collect callback registered → collect returns None → force_flush | ||
| # on base treats None as not-False (success), so wire up a failing one | ||
| exporter.export = Mock(return_value=MetricExportResult.FAILURE) | ||
|
|
||
| def _collect_failure(reader, timeout_millis): | ||
| return metrics | ||
|
|
||
| pmr._set_collect_callback(_collect_failure) | ||
| exporter.export = Mock(return_value=MetricExportResult.FAILURE) | ||
| result = pmr.force_flush(timeout_millis=5_000) | ||
| self.assertFalse(result) | ||
| exporter.force_flush.assert_not_called() | ||
| pmr.shutdown() | ||
|
|
||
| def test_detach_called_on_export_failure(self): | ||
| """detach(token) must run in finally even when export returns FAILURE.""" | ||
|
|
||
| exporter = FakeMetricsExporter() | ||
| exporter.export = Mock(return_value=MetricExportResult.FAILURE) | ||
| pmr = self._create_periodic_reader(metrics, exporter) | ||
|
|
||
| with patch( | ||
| "opentelemetry.sdk.metrics._internal.export.detach" | ||
| ) as mock_detach: | ||
|
ravitheja4531-cell marked this conversation as resolved.
|
||
| pmr.force_flush(timeout_millis=5_000) | ||
| pmr.shutdown() | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is not the correct fix for the test.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Un-resolving the comment since the fix is still not correct. |
||
| self.assertTrue(mock_detach.called) | ||
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.
Uh oh!
There was an error while loading. Please reload this page.