Repository navigation
fix: Remind creators to move INC-team action items #419
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 6 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
c236714
Notify creators once about action items filed in the incident team
spalmurray 6cc37bd
Use supported Linear filters to exclude existing reminders
spalmurray bf7d322
Isolate malformed action items from the reminder sweep
spalmurray 656c6c9
Include comment-free action items in the team reminder sweep
spalmurray 885de98
Process capped reminder batches so large backlogs can drain
spalmurray b61f240
Skip team reminders when Linear identifier sync is disabled
spalmurray cb8cd02
Keep team reminder failures informational and clarify fetch failures
spalmurray 429c482
Run SLO reminders before the misfiled action item sweep
spalmurray 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
217 changes: 217 additions & 0 deletions
217
src/firetower/incidents/tests/test_action_item_team_reminders.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,217 @@ | ||
| from unittest.mock import MagicMock, patch | ||
| from uuid import UUID | ||
|
|
||
| import pytest | ||
|
|
||
| from firetower.incidents.tasks.action_items import ( | ||
| MISFILED_ACTION_ITEM_REMINDER_MARKER, | ||
| _remind_misfiled_action_item_creators, | ||
| send_action_item_reminder, | ||
| ) | ||
|
|
||
| LINEAR = {"TEAM_ID": "incident-team", "SYNC_IDENTIFIERS": True} | ||
| ISSUE = { | ||
| "id": "issue-1", | ||
| "identifier": "INC-2508", | ||
| "creator": {"id": "creator-id", "displayName": "Leander Rodrigues"}, | ||
| } | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def service(settings): | ||
| settings.PROJECT_KEY = "INC" | ||
| settings.LINEAR = LINEAR | ||
| service = MagicMock() | ||
| service.get_misfiled_action_items.return_value = [ISSUE] | ||
| service.create_comment.return_value = True | ||
| with patch( | ||
| "firetower.incidents.tasks.action_items.LinearService", return_value=service | ||
| ): | ||
| yield service | ||
|
|
||
|
|
||
| def test_mentions_creator_and_explains_move(service): | ||
| _remind_misfiled_action_item_creators(LINEAR) | ||
|
|
||
| service.get_misfiled_action_items.assert_called_once_with( | ||
| "incident-team", MISFILED_ACTION_ITEM_REMINDER_MARKER | ||
| ) | ||
| args, kwargs = service.create_comment.call_args | ||
| assert args[0] == ISSUE["id"] | ||
| assert "@[Leander Rodrigues](creator-id)" in args[1] | ||
| assert MISFILED_ACTION_ITEM_REMINDER_MARKER in args[1] | ||
| assert "created in the INC team" in args[1] | ||
| assert "move it to the relevant actioning team" in args[1] | ||
| assert "keeping it as a child" in args[1] | ||
| assert UUID(kwargs["comment_id"]).version == 4 | ||
|
|
||
|
|
||
| @pytest.mark.parametrize("issues", [[], [ISSUE]]) | ||
| def test_logs_candidate_count(service, caplog, issues): | ||
| service.get_misfiled_action_items.return_value = issues | ||
|
|
||
| with caplog.at_level("INFO", logger="firetower.incidents.tasks.action_items"): | ||
| _remind_misfiled_action_item_creators(LINEAR) | ||
|
|
||
| assert ( | ||
| f"Found {len(issues)} misfiled action items without a team reminder " | ||
| "in Linear team incident-team" | ||
| ) in caplog.text | ||
|
|
||
|
|
||
| @pytest.mark.parametrize("success", [True, False]) | ||
| def test_logs_posted_reminder_only_on_success(service, caplog, success): | ||
| service.create_comment.return_value = success | ||
|
|
||
| with caplog.at_level("INFO", logger="firetower.incidents.tasks.action_items"): | ||
| _remind_misfiled_action_item_creators(LINEAR) | ||
|
|
||
| assert ("Posted team reminder for action item issue-1" in caplog.text) is success | ||
|
|
||
|
|
||
| def test_skips_issues_with_existing_reminder_on_later_runs(service): | ||
| service.get_misfiled_action_items.side_effect = [[ISSUE], []] | ||
|
|
||
| _remind_misfiled_action_item_creators(LINEAR) | ||
| _remind_misfiled_action_item_creators(LINEAR) | ||
|
|
||
| service.create_comment.assert_called_once() | ||
|
|
||
|
|
||
| def test_comment_id_is_stable_across_retries(service): | ||
| service.create_comment.side_effect = [TimeoutError("response lost"), True] | ||
|
|
||
| _remind_misfiled_action_item_creators(LINEAR) | ||
| _remind_misfiled_action_item_creators(LINEAR) | ||
|
|
||
| calls = service.create_comment.call_args_list | ||
| assert len(calls) == 2 | ||
| assert calls[0].kwargs["comment_id"] == calls[1].kwargs["comment_id"] | ||
|
|
||
|
|
||
| def test_comment_ids_differ_between_issues(service): | ||
| service.get_misfiled_action_items.return_value = [ | ||
| ISSUE, | ||
| {**ISSUE, "id": "issue-2", "identifier": "INC-2509"}, | ||
| ] | ||
|
|
||
| _remind_misfiled_action_item_creators(LINEAR) | ||
|
|
||
| calls = service.create_comment.call_args_list | ||
| assert calls[0].kwargs["comment_id"] != calls[1].kwargs["comment_id"] | ||
|
|
||
|
|
||
| def test_handles_missing_creator(service): | ||
| service.get_misfiled_action_items.return_value = [{**ISSUE, "creator": None}] | ||
|
|
||
| _remind_misfiled_action_item_creators(LINEAR) | ||
|
|
||
| body = service.create_comment.call_args.args[1] | ||
| assert "Hi, this action item" in body | ||
| assert "@[" not in body | ||
|
|
||
|
|
||
| @pytest.mark.parametrize("config", [{}, {"TEAM_ID": ""}]) | ||
| def test_skips_when_team_is_not_configured(service, config): | ||
| _remind_misfiled_action_item_creators({**config, "SYNC_IDENTIFIERS": True}) | ||
|
|
||
| service.get_misfiled_action_items.assert_not_called() | ||
| service.create_comment.assert_not_called() | ||
|
|
||
|
|
||
| @pytest.mark.parametrize("config", [{}, {"SYNC_IDENTIFIERS": False}]) | ||
| def test_skips_when_identifier_sync_is_disabled(service, config): | ||
| with patch("firetower.incidents.tasks.action_items.LinearService") as client: | ||
| _remind_misfiled_action_item_creators({"TEAM_ID": "incident-team", **config}) | ||
|
|
||
| client.assert_not_called() | ||
| service.get_misfiled_action_items.assert_not_called() | ||
| service.create_comment.assert_not_called() | ||
|
|
||
|
|
||
| @pytest.mark.parametrize("failure", [None, RuntimeError("Linear unavailable")]) | ||
| def test_does_not_post_when_lookup_fails(service, failure): | ||
| if isinstance(failure, Exception): | ||
| service.get_misfiled_action_items.side_effect = failure | ||
| else: | ||
| service.get_misfiled_action_items.return_value = failure | ||
|
|
||
| _remind_misfiled_action_item_creators(LINEAR) | ||
|
|
||
| service.create_comment.assert_not_called() | ||
|
|
||
|
|
||
| @pytest.mark.parametrize("failure", [False, RuntimeError("Linear unavailable")]) | ||
| def test_continues_after_a_comment_failure(service, failure): | ||
| service.get_misfiled_action_items.return_value = [ | ||
| ISSUE, | ||
| {**ISSUE, "id": "issue-2", "identifier": "INC-2509"}, | ||
| ] | ||
| service.create_comment.side_effect = [failure, True] | ||
|
|
||
| _remind_misfiled_action_item_creators(LINEAR) | ||
|
|
||
| assert service.create_comment.call_count == 2 | ||
|
|
||
|
|
||
| @pytest.mark.parametrize( | ||
| "malformed", | ||
| [ | ||
| None, | ||
| {}, | ||
| {**ISSUE, "creator": {"id": "creator-id"}}, | ||
| {**ISSUE, "creator": {"displayName": "Leander Rodrigues"}}, | ||
| ], | ||
| ) | ||
| def test_continues_after_malformed_issue_data(service, malformed): | ||
| service.get_misfiled_action_items.return_value = [malformed, ISSUE] | ||
|
|
||
| _remind_misfiled_action_item_creators(LINEAR) | ||
|
|
||
| service.create_comment.assert_called_once() | ||
| assert service.create_comment.call_args.args[0] == ISSUE["id"] | ||
|
|
||
|
|
||
| def test_initialization_failure_does_not_escape(service): | ||
| with patch( | ||
| "firetower.incidents.tasks.action_items.LinearService", | ||
| side_effect=RuntimeError("initialization failed"), | ||
| ): | ||
| _remind_misfiled_action_item_creators(LINEAR) | ||
|
|
||
| service.create_comment.assert_not_called() | ||
|
|
||
|
|
||
| def test_malformed_issue_does_not_block_slo_sweep(service, settings): | ||
| settings.LINEAR = {**LINEAR, "ACTION_ITEM_NAG_COMMENT_HIGH_PRIORITY": "SLO nag"} | ||
| service.get_misfiled_action_items.return_value = [ | ||
| {**ISSUE, "creator": {"id": "creator-id"}} | ||
| ] | ||
| incident = MagicMock() | ||
| incident.action_items.filter.return_value = [] | ||
| with ( | ||
| patch("firetower.incidents.tasks.action_items.Incident") as incident_model, | ||
| patch( | ||
| "firetower.incidents.tasks.action_items.sync_action_items_from_linear" | ||
| ) as sync, | ||
| ): | ||
| incident_model.objects.filter.return_value.exclude.return_value = [incident] | ||
|
|
||
| send_action_item_reminder() | ||
|
|
||
| sync.assert_called_once_with(incident) | ||
| service.create_comment.assert_not_called() | ||
|
|
||
|
|
||
| def test_uses_configured_incident_team_key(service, settings): | ||
| settings.PROJECT_KEY = "TESTINC" | ||
|
|
||
| _remind_misfiled_action_item_creators(LINEAR) | ||
|
|
||
| assert "created in the TESTINC team" in service.create_comment.call_args.args[1] | ||
|
|
||
|
|
||
| def test_cron_sweeps_even_without_slo_nag_configuration(service): | ||
| send_action_item_reminder() | ||
|
|
||
| service.create_comment.assert_called_once() |
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.
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.