Repository navigation
fix(logs): report a multiplexer outage once, with its cause #351
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
Merged
Merged
Changes from all commits
Commits
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
64 changes: 64 additions & 0 deletions
64
tests/ccgram/session_protocol/test_runtime_outage_logging.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,64 @@ | ||
| """A backend outage must log its edges, not once per retry. | ||
|
|
||
| The poll loop retries every second. Logging a full traceback for every failed | ||
| attempt buried the journal under identical stacks during a one-minute | ||
| multiplexer hiccup and hid the errors around it. | ||
| """ | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| import asyncio | ||
| from tempfile import TemporaryFile | ||
| from unittest.mock import AsyncMock, MagicMock | ||
|
|
||
| import pytest | ||
|
|
||
| from ccgram.session_protocol.models import ProtocolError | ||
| from ccgram.session_protocol.runtime import ProtocolRuntime | ||
|
|
||
|
|
||
| def _sleeper(iterations: int) -> AsyncMock: | ||
| """Sleep *iterations* times, then cancel the loop like a shutdown would.""" | ||
| return AsyncMock(side_effect=[None] * iterations + [asyncio.CancelledError()]) | ||
|
|
||
|
|
||
| async def test_repeated_outage_logs_one_warning(service, backend, store, monkeypatch): | ||
| backend.unavailable = True | ||
| logger = MagicMock() | ||
| with TemporaryFile() as lock: | ||
| monkeypatch.setattr("ccgram.session_protocol.runtime.logger", logger) | ||
| monkeypatch.setattr( | ||
| "ccgram.session_protocol.runtime.asyncio.sleep", _sleeper(4) | ||
| ) | ||
| runtime = ProtocolRuntime(store, service, lock) | ||
| with pytest.raises(asyncio.CancelledError): | ||
| await runtime.poll("") | ||
| assert logger.warning.call_count == 1 | ||
| message, error = logger.warning.call_args.args | ||
| assert "source unavailable" in message | ||
| assert "offline" in str(error) | ||
|
|
||
|
|
||
| async def test_recovery_logs_once_after_an_outage(service, store, monkeypatch): | ||
| attempts = {"count": 0} | ||
|
|
||
| async def refresh() -> None: | ||
| attempts["count"] += 1 | ||
| if attempts["count"] == 1: | ||
| raise ProtocolError(503, "backend_unavailable", "offline") | ||
|
|
||
| monkeypatch.setattr(service, "refresh", refresh) | ||
| logger = MagicMock() | ||
| with TemporaryFile() as lock: | ||
| monkeypatch.setattr("ccgram.session_protocol.runtime.logger", logger) | ||
| monkeypatch.setattr( | ||
| "ccgram.session_protocol.runtime.asyncio.sleep", _sleeper(3) | ||
| ) | ||
| runtime = ProtocolRuntime(store, service, lock) | ||
| with pytest.raises(asyncio.CancelledError): | ||
| await runtime.poll("") | ||
| assert logger.warning.call_count == 1 | ||
| recovered = [ | ||
| call for call in logger.info.call_args_list if "recovered" in call.args[0] | ||
| ] | ||
| assert len(recovered) == 1 |
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
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.
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.
pollreports recovery before queued hooks finish. During a transcript outage,refresh()can succeed because_update()catches the error, while queued permission hooks still fail in_match_hook(). With several such hooks queued, successive passes emit “recovered” followed by another warning and traceback for the same outage.Move the recovery message and flag reset after the hook loop, and add a test with failing queued hooks.