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

Mattermost incoming event handler #5273

Open
wants to merge 2 commits into
base: matiasb/mattermost-chatops
Choose a base branch
from

Conversation

ravishankar15
Copy link
Contributor

What this PR does

Handles the incoming event from the alert group message

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.

@ravishankar15 ravishankar15 requested a review from a team as a code owner November 20, 2024 16:44
Remove print

Add migrations
@ravishankar15 ravishankar15 force-pushed the mattermost-incoming-event-handler branch from c8f2f84 to 26520ca Compare November 20, 2024 16:56
@ravishankar15
Copy link
Contributor Author

Hi @matiasb Please take a look at the incoming event handler changes for the alert message actions from mattermost.

Copy link
Contributor

@matiasb matiasb left a comment

Choose a reason for hiding this comment

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

Looking good! A few comments/questions inline.

@@ -94,6 +95,7 @@ def _make_actions(id, name, token):
"url": create_engine_url("api/internal/v1/mattermost/event/"),
"context": {
"action": id,
"alert": self.alert_group.pk,
Copy link
Contributor

Choose a reason for hiding this comment

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

It may be better to use the public primary key here instead

return

def _get_alert_group(self) -> typing.Optional[AlertGroup]:
return self._get_alert_group_from_event() or self._get_alert_group_from_message()
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do we need both ways to get the alert group? (shouldn't we always have the event context?)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yup first had only the message thing later added the context implementation should have removed the message thing. I don't see a need to have both

handler = AlertGroupActionHandler(event=event, user=user)
handler.process()
alert_group.refresh_from_db()
assert alert_group.acknowledged
Copy link
Contributor

Choose a reason for hiding this comment

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

Should the action_source in the log record be set to Mattermost?


token = MattermostEventAuthenticator.create_token(organization=organization)
event = make_mattermost_event(
EventAction.ACKNOWLEDGE,
Copy link
Contributor

Choose a reason for hiding this comment

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

It would be nice to also check other actions end with the expected alert group state too (parametrizing the test?).



@pytest.mark.django_db
def test_mattermost_alert_group_event_acknowledge(
Copy link
Contributor

Choose a reason for hiding this comment

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

Double-checking, all these tests should be exercising the actions handler too, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yup it does, I have parameterised the event tests as well.

response = client.post(url, event, format="json")
alert_group.refresh_from_db()
assert not alert_group.acknowledged
assert not alert_group.resolved
Copy link
Contributor

Choose a reason for hiding this comment

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

maybe check for alert_group.state for the expected final state instead?

@ravishankar15
Copy link
Contributor Author

Hi @matiasb I have addressed the review comments

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.

2 participants