-
Notifications
You must be signed in to change notification settings - Fork 60
feat(publisher): degrade PubSubPublisher to noop when GCP credentials are absent #388
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
julietshen
wants to merge
18
commits into
main
Choose a base branch
from
julietshen/noop-publisher-fallback
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 16 commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
05c0cdc
feat(publisher): degrade PubSubPublisher to noop when GCP credentials…
julietshen 0d5f06c
Merge branch 'main' into julietshen/noop-publisher-fallback
julietshen f7d7fd6
fix(publisher): address review feedback on noop fallback
julietshen 641717a
docs(changelog): note PubSubPublisher noop fallback
julietshen 3b40c28
test(publisher): force GCP creds in validation-exporter conftest
julietshen 749156e
test(publisher): scope forced-creds patch to function to stop leak
julietshen f0cee7c
feat(publisher): add DISABLE_GCP_PUBSUB opt-out, drop per-send noop m…
julietshen b678c6f
feat(async-publisher): degrade AsyncPubSubPublisher to noop without G…
julietshen e8e2770
docs(changelog): cover both sync and async publisher noop fallback
julietshen 362a860
test(publisher): point exporter conftest at renamed cred helper
julietshen 48cefda
feat(async-publisher): add DISABLE_GCP_PUBSUB opt-out, drop noop metric
julietshen 6cbe134
style(test): collapse test signature to satisfy ruff format
julietshen 2d40415
feat(publisher): emit startup configuration.errors metric on missing …
julietshen 6b84b57
refactor(publisher): move enable/disable decision into a make_publish…
julietshen e825f47
test: drop vestigial cred patch from exporter conftest
julietshen b1adab9
refactor(publisher): opt-in OSPREY_PUBSUB_ENABLED, catch creds error …
julietshen f0b8f6e
refactor(publisher): default OSPREY_PUBSUB_ENABLED to true, restore p…
julietshen 707a180
docs(changelog): scope the entry to the publisher noop, not full GCP-…
julietshen 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
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
53 changes: 53 additions & 0 deletions
53
osprey_worker/src/osprey/worker/lib/tests/test_publisher.py
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 |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| from unittest.mock import MagicMock, patch | ||
|
|
||
| import pytest | ||
| from google.auth.exceptions import DefaultCredentialsError | ||
| from osprey.worker.lib import publisher | ||
| from osprey.worker.lib.publisher import NullPublisher, PubSubPublisher, make_publisher | ||
|
|
||
|
|
||
| def _mock_config(pubsub_enabled: bool) -> MagicMock: | ||
| config = MagicMock() | ||
| config.instance.return_value.get_bool.return_value = pubsub_enabled | ||
| return config | ||
|
|
||
|
|
||
| def test_make_publisher_returns_null_when_pubsub_not_enabled() -> None: | ||
| config = _mock_config(pubsub_enabled=False) | ||
| with ( | ||
| patch('osprey.worker.lib.singletons.CONFIG', config), | ||
| patch.object(publisher, 'BatchPubsubPublisherClient') as client_cls, | ||
| patch.object(publisher, 'metrics') as metrics_mock, | ||
| ): | ||
| pub = make_publisher('proj', 'topic') | ||
| assert isinstance(pub, NullPublisher) | ||
| # Opt-in and default-off: no client is built and it is not a misconfiguration. | ||
| config.instance.return_value.get_bool.assert_called_once_with('OSPREY_PUBSUB_ENABLED', False) | ||
| assert not client_cls.called | ||
| metrics_mock.increment.assert_not_called() | ||
|
|
||
|
|
||
| def test_make_publisher_returns_pubsub_when_enabled_and_creds_present() -> None: | ||
| with ( | ||
| patch('osprey.worker.lib.singletons.CONFIG', _mock_config(pubsub_enabled=True)), | ||
| patch.object(publisher, 'BatchPubsubPublisherClient') as client_cls, | ||
| ): | ||
| pub = make_publisher('proj', 'topic') | ||
| assert isinstance(pub, PubSubPublisher) | ||
| assert client_cls.called | ||
|
|
||
|
|
||
| def test_make_publisher_falls_back_to_null_and_metric_when_creds_absent(caplog: pytest.LogCaptureFixture) -> None: | ||
| with ( | ||
| patch('osprey.worker.lib.singletons.CONFIG', _mock_config(pubsub_enabled=True)), | ||
| patch.object(publisher, 'BatchPubsubPublisherClient', side_effect=DefaultCredentialsError()), | ||
| patch.object(publisher, 'metrics') as metrics_mock, | ||
| ): | ||
| with caplog.at_level('WARNING', logger=publisher.logger.name): | ||
| pub = make_publisher('proj', 'topic') | ||
| assert isinstance(pub, NullPublisher) | ||
| assert 'credentials not detected' in caplog.text | ||
| metrics_mock.increment.assert_called_once_with( | ||
| 'configuration.errors', | ||
| tags=['project:proj', 'topic:topic', 'reason:gcp_credentials_missing'], | ||
| ) |
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
Oops, something went wrong.
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.