-
Notifications
You must be signed in to change notification settings - Fork 296
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
feat: allow setting direct paging importance for teams #5379
Merged
joeyorlando
merged 12 commits into
dev
from
jorlando/allow-setting-direct-paging-importance-for-teams
Jan 6, 2025
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
a3459a7
wip
joeyorlando 7efb55c
feat: allow setting importance when direct paging a team
joeyorlando 4870e6e
Merge branch 'dev' into jorlando/allow-setting-direct-paging-importan…
joeyorlando eda3728
mypy fix
joeyorlando 2352c63
Merge branch 'jorlando/allow-setting-direct-paging-importance-for-tea…
joeyorlando 9fd7d2e
fix test
joeyorlando d928b6d
comment about slack wording/placement
joeyorlando 0da4d79
feat: create direct paging integrations with two default routes (+ mi…
joeyorlando d624c7f
update `test_sync_teams_for_organization` test
joeyorlando 31af852
Merge pull request #5382 from grafana/jorlando/auto-create-direct-pag…
joeyorlando 8d03968
Update docs/sources/oncall-api-reference/escalation.md
joeyorlando 0205496
Merge branch 'dev' into jorlando/allow-setting-direct-paging-importan…
joeyorlando 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 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 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
84 changes: 84 additions & 0 deletions
84
engine/apps/alerts/migrations/0072_upsert_direct_paging_integration_routes.py
This file contains 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,84 @@ | ||
# Generated by Django 4.2.17 on 2024-12-20 14:19 | ||
|
||
import logging | ||
|
||
from django.db import migrations | ||
from django.db.models import Count | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
def upsert_direct_paging_integration_routes(apps, schema_editor): | ||
AlertReceiveChannel = apps.get_model("alerts", "AlertReceiveChannel") | ||
ChannelFilter = apps.get_model("alerts", "ChannelFilter") | ||
|
||
DIRECT_PAGING_INTEGRATION_TYPE = "direct_paging" | ||
IMPORTANT_FILTERING_TERM = "{{ payload.oncall.important }}" | ||
|
||
# Fetch all direct paging integrations | ||
logger.info("Fetching direct paging integrations which have not had their routes updated.") | ||
|
||
# Ignore updating Direct Paging integrations that have > 1 route, as this means that users have | ||
# gone ahead and created their own routes. We don't want to overwrite these. | ||
unedited_direct_paging_integrations = ( | ||
AlertReceiveChannel.objects | ||
.filter(integration=DIRECT_PAGING_INTEGRATION_TYPE) | ||
.annotate(num_routes=Count("channel_filters")) | ||
.filter(num_routes=1) | ||
) | ||
|
||
integration_count = unedited_direct_paging_integrations.count() | ||
if integration_count == 0: | ||
logger.info("No integrations found which meet this criteria. No routes will be upserted.") | ||
return | ||
|
||
logger.info(f"Found {integration_count} direct paging integrations that meet this criteria.") | ||
|
||
# Direct Paging Integrations are currently created with a single default route (order=0) | ||
# see AlertReceiveChannelManager.create_missing_direct_paging_integrations | ||
# | ||
# we first need to update this route to be order=1, and then we will subsequently bulk-create the | ||
# non-default route (order=0) which will have a filtering term set | ||
routes = ChannelFilter.objects.filter( | ||
alert_receive_channel__in=unedited_direct_paging_integrations, | ||
is_default=True, | ||
order=0, | ||
) | ||
|
||
logger.info( | ||
f"Swapping the order=0 value to order=1 for {routes.count()} Direct Paging Integrations default routes" | ||
) | ||
|
||
updated_rows = routes.update(order=1) | ||
logger.info(f"Swapped order=0 to order=1 for {updated_rows} Direct Paging Integrations default routes") | ||
|
||
# Bulk create the new non-default routes | ||
logger.info( | ||
f"Creating new non-default routes for {len(unedited_direct_paging_integrations)} Direct Paging Integrations" | ||
) | ||
created_objs = ChannelFilter.objects.bulk_create( | ||
[ | ||
ChannelFilter( | ||
alert_receive_channel=integration, | ||
filtering_term=IMPORTANT_FILTERING_TERM, | ||
filtering_term_type=1, # 1 = ChannelFilter.FILTERING_TERM_TYPE_JINJA2 | ||
is_default=False, | ||
order=0, | ||
) for integration in unedited_direct_paging_integrations | ||
], | ||
batch_size=5000, | ||
) | ||
logger.info(f"Created {len(created_objs)} new non-default routes for Direct Paging Integrations") | ||
|
||
logger.info("Migration for direct paging integration routes completed.") | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
("alerts", "0071_migrate_labels"), | ||
] | ||
|
||
operations = [ | ||
migrations.RunPython(upsert_direct_paging_integration_routes, migrations.RunPython.noop), | ||
] |
This file contains 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 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 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.
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.
this was merged/reviewed in #5382