Skip to content
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

[WIP] Set team on Alert Group based on route #3459 #5320

Draft
wants to merge 9 commits into
base: dev
Choose a base branch
from

Conversation

mwheeler-ep
Copy link

What this PR does

Which issue(s) this PR closes

Related to [issue link here]

Checklist

  • Unit, integration, and e2e (if applicable) tests updated
  • Documentation added (or pr:no public docs PR label added if not required)
  • Added the relevant release notes label (see labels prefixed w/ release:). These labels dictate how your PR will
    show up in the autogenerated release notes.

@CLAassistant
Copy link

CLAassistant commented Dec 2, 2024

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you all sign our Contributor License Agreement before we can accept your contribution.
0 out of 2 committers have signed the CLA.

❌ actions-user
❌ mwheeler-ep
You have signed the CLA already but the status is still pending? Let us recheck it.


alert_group_2 = make_alert_group(alert_receive_channel_2)
make_alert(alert_group=alert_group_2, raw_request_data=alert_raw_request_data)
alert_group_0 = Alert.create(
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had to switch to Alert.create here so that the team gets assigned correctly and as expected for the test to work.

@@ -31,6 +31,13 @@
from apps.alerts.models import AlertReceiveChannel
from apps.user_management.models import Organization

def _get_teams_for_cache(organization):
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A helper that provides list of teams + the no_team team

if integration_response_time_metrics:
integration_response_time_metrics["team_name"] = team_data["team_name"]

cache.set(metric_alert_groups_total_key, metric_alert_groups_total, timeout=metrics_cache_timeout)
cache.set(metric_alert_groups_response_time_key, metric_alert_groups_response_time, timeout=metrics_cache_timeout)


def metrics_update_alert_groups_state_cache(states_diff: dict, organization_id: int):
def metrics_update_alert_groups_state_cache(states_diff: dict, organization: "Organization"):
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

moved to passing organization through so we can iterate over the teams easier

@@ -58,7 +58,7 @@ def test_calculate_and_cache_metrics_task(
metric_alert_groups_response_time_key = get_metric_alert_groups_response_time_key(organization.id)

expected_result_metric_alert_groups_total = {
alert_receive_channel_1.id: {
(alert_receive_channel_1.id, "no_team"): {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since moving to an index of channel + team many of the tests needed updating to reflect this

monkeypatch.setattr(cache, "get", metrics_cache)

# check cache update on update integration's team
alert_receive_channel.team = team
# alert_receive_channel.team = team
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this test is really needed or valid any more as we'll have a metric per integration per team so updating the team on a alert_receive_channel shouldn't really do anything.

@property
def available_teams_lookup_args(self):

def available_teams_lookup_args_with_field(self, field=TEAM_LOOKUP):
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wasn't sure the best way to approach this. When calculating the allowed teams in the alertgroup filter we need to both access the filters for the team and teams so being able to move this to a method was the easiest approach I could think of.

@@ -1540,7 +1540,7 @@ export interface components {
readonly status: number;
/** @description Generate a link for AlertGroup to declare Grafana Incident by click */
readonly declare_incident_link: string;
team: string | null;
teams: components['schemas']['FastTeam'][];
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was manually added as the autogeneration for me seemed to change a lot!

@mwheeler-ep mwheeler-ep force-pushed the alertgroup-teams-esc branch from 293e5e3 to 3a30cee Compare January 6, 2025 02:46
@mwheeler-ep mwheeler-ep force-pushed the alertgroup-teams-esc branch from 3a30cee to fec671b Compare January 6, 2025 02:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants