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

integrations: Update Newrelic integrations. #29730

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

PieterCK
Copy link
Collaborator

@PieterCK PieterCK commented Apr 13, 2024

πŸ“„ PR Overview

Originally, this PR aims to resume the work done on #27779 by applying suggested changes by reviewer in the original PR and developing new tests. However, the scope of the PR has widened due to the New Relic changes reported in #29729.

This PR's scope is now to adjust the whole Zulip New Relic integration for the newest New Relic updates. It also includes new tests, new notifications as well as added new capabilities to the integration.

Fixes: #29729

πŸ› οΈ Updates & New Features Implemented

Updated New Relic Logo & Bot Avatar:

image

Updated New Relic Doc

Restructured to better follow changes in #29592
Adjusted the doc for the New Relic "workflow and destinations" update
Included documentation for new features and updated payload

BLOCKER : I encountered an error when trying to include an example of New Relic payload in a code block in the docs 'Recommended Base Payload Template' section, which could add improvements to the integration if used by the user. CZO detailing the error.
image

New Feature: Support for New Relic Custom Payload

User can now include New Relic webhook custom fields in their New Relic Zulip notification.

The details and guide on how to use this feature is already written in the new doc under "Displaying Custom Fields" section. For technical details, this feature is handled in generate_custom_field_message() .

notification with custom field "Your Custom Payload" :
image
relevant payload part for the notification above:
image

notification with a couple of incorrectly configured custom payload :
image
relevant payload part for the notification above:
image

Provided a "Recommended" base payload

The out of the box New Relic payloads is very minimal. To benefit from the newest features, a recommended base payload is provided in the integration doc.

default base payload:

{
	"id": {{ json issueId }},
	"issueUrl": {{ json issuePageUrl }},
	"title": {{ json annotations.title.[0] }},
	"priority": {{ json priority }},
	"impactedEntities": {{json entitiesData.names}},
	"totalIncidents": {{json totalIncidents}},
	"state": {{ json state }},
	"trigger": {{ json triggerEvent }},
	"isCorrelated": {{ json isCorrelated }},
	"createdAt": {{ createdAt }},
	"updatedAt": {{ updatedAt }},
	"sources": {{ json accumulations.source }},
	"alertPolicyNames": {{ json accumulations.policyName }},
	"alertConditionNames": {{ json accumulations.conditionName }},
	"workflowName": {{ json workflowName }}
}

provided base payload:

{
	"id": {{ json issueId }},
	"issueUrl": {{ json issuePageUrl }},
	"title": {{ json annotations.title.[0] }},
	"priority": {{ json priority }},
	"impactedEntities": {{json entitiesData.names}},
	"totalIncidents": {{json totalIncidents}},
	"state": {{ json state }},
	"trigger": {{ json triggerEvent }},
	"isCorrelated": {{ json isCorrelated }},
	"createdAt": {{ createdAt }},
        "closedAt": {{ json closedAt }},
	"updatedAt": {{ updatedAt }},
	"sources": {{ json accumulations.source }},
	"alertPolicyNames": {{ json accumulations.policyName }},
	"alertConditionNames": {{ json accumulations.conditionName }},
	"workflowName": {{ json workflowName }},
        "acknowledgedAt": {{ json acknowledgedAt }},
        "acknowedgedBy":{{ json acknowledgedBy }},
        "owner": {{ json owner }},
        "zulipCustomFields": {
            "yourCustomPayload": "somedata123"
         }
}

Note: added a couple of event time stamp fields, "owner" field and setup the "zulipCustomField" dict

Reworked Notification Topic Name Format

Changed notification topic name format to enable user to follow alerts based on priority and incident state

  • Old (current) topic name format:
    {alert_policies} {issue_id}
    e.g: "(Golden Signals, Computer Health)(123-039-932-0321-393)"

  • New topic name format:
    {state} {priority} priority
    e.g: "Activated Critical Priority"

The rationale is to enable the user to follow specific streams they want based on incident priority and state. The old format was also created when Alert Policy was a single value and not a list, which it is now.

New Feature: Added "Fallback" Notification

Added a very minimal notification format and a warning informing the integration might be outdated or the user has tampered the payload too much (omitting required field).

fallback notification:
image
payload for the notification above:
image

Redesigned Integration Notifications

The new notification is designed to better present the updated and new payloads from recent New Relic update. It is also being discussed with a couple of other members and user: CZO

notification with the default new relic payload:
image
image

Note: the "Updated" notifications are "Acknowledged" incidents, but the default payload doesn't provide enough data

notification with the payload we recommend and provided:
image
image

Note: the same "Updated" payload are now enriched with infos such as "Acknowledged By" field and the "ACKNOWLEDGED" action

variety of incident priority:

image

variety of incident priority (opened):
image

variety of incident states:
image
image

Note: Officially, there are 3 states: ACTIVATED, CLOSED, CREATED. But in practice, ACTIVATED and CREATED is used synonimously, so only ACTIVATED and CLOSED are displayed.

variety of incident actions beside Closed & Activated:
image

Note: Actions are infered by matching the provided timestamps (see determine_status()). All actions/ status: Activated, Closed, Updated and Acknowledged.
This is different from incident 'state' (previous point)

notification with some custom payload:

Note: to minimize redundancy, see the "New Feature: Support for New Relic Custom Payload" section above

fallback notification:

Note: to minimize redundancy, see the "New Feature: Added 'Fallback' Notification" section above

πŸ§‘β€πŸ­ Issues & Concerns Encountered

πŸ“– Helpful Resources

Self-review checklist
  • Self-reviewed the changes for clarity and maintainability
    (variable names, code reuse, readability, etc.).

Communicate decisions, questions, and potential concerns.

  • Explains differences from previous plans (e.g., issue description).
  • Highlights technical choices and bugs encountered.
  • Calls out remaining decisions and concerns.
  • Automated tests verify logic where appropriate.

Individual commits are ready for review (see commit discipline).

  • Each commit is a coherent idea.
  • Commit message(s) explain reasoning and motivation for changes.

Completed manual review and testing of the following:

  • Visual appearance of the changes.
  • Responsiveness and internationalization.
  • Strings and tooltips.
  • End-to-end functionality of buttons, interactions and flows.
  • Corner cases, error conditions, and easily imagined bugs.

@zulipbot
Copy link
Member

Hello @PieterCK, it seems like you have referenced #29729 in your pull request description, but you have not referenced them in your commit message description(s). Referencing an issue in a commit message automatically closes the corresponding issue when the commit is merged, which makes the issue tracker easier to manage.

Please run git commit --amend in your command line client to amend your commit message description with Fixes #29729..

An example of a correctly-formatted commit:

commit fabd5e450374c8dde65ec35f02140383940fe146
Author: zulipbot
Date:   Sat Mar 18 13:42:40 2017 -0700

    pull requests: Check PR commits reference when issue is referenced.

    Fixes #51.

To learn how to write a great commit message, please refer to our guide.

@PieterCK PieterCK force-pushed the issue-29729-integrations-update-newrelic-integration branch 2 times, most recently from 00b60f3 to 0c638b8 Compare April 13, 2024 14:28
@PieterCK PieterCK changed the title Issue 29729 integrations update newrelic integration integrations: Update Newrelic integrations. Apr 13, 2024
@PieterCK PieterCK force-pushed the issue-29729-integrations-update-newrelic-integration branch from 0c638b8 to 09f9475 Compare April 22, 2024 16:47
@zulipbot zulipbot added size: XL and removed size: S labels Apr 22, 2024
@PieterCK PieterCK force-pushed the issue-29729-integrations-update-newrelic-integration branch 6 times, most recently from e5e4521 to 92c05bf Compare April 23, 2024 02:58
@PieterCK PieterCK marked this pull request as ready for review April 23, 2024 03:01
@alya
Copy link
Contributor

alya commented Apr 23, 2024

Thank you for the detailed description and screenshots!

@alya
Copy link
Contributor

alya commented Apr 23, 2024

@laurynmm Are you up for doing the first round of review here? I skimmed the overview, but have not thought carefully about the details.

@alya alya added the maintainer review PR is ready for review by Zulip maintainers. label Apr 23, 2024
@PieterCK PieterCK force-pushed the issue-29729-integrations-update-newrelic-integration branch from 92c05bf to 0bdc1ec Compare May 7, 2024 09:05
@PieterCK PieterCK force-pushed the issue-29729-integrations-update-newrelic-integration branch 2 times, most recently from fac05c8 to 58942a3 Compare May 7, 2024 12:33
@PieterCK
Copy link
Collaborator Author

PieterCK commented May 7, 2024

Update: Resolved conflict

Copy link
Collaborator

@laurynmm laurynmm left a comment

Choose a reason for hiding this comment

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

@PieterCK - I did an initial review for this integration update. I didn't get through all of the change, but I figured you had enough feedback so far that you could go through my comments that I've got so far so this work can move forward.

Two notes not in review comments:

  • The svg file seems big, especially when compared to the one it's replacing.
  • The commit is from the original author, so you'll want to mark youself as the co-author. Or you'll want to update that so you're the author and mark the original author as a co-author.

Let me know if you have any questions about the above or about any of my comments. Thanks for taking on these extensive updates to this New Relic integration!

check_union,
)
from zerver.lib.webhooks.common import check_send_webhook_message, unix_milliseconds_to_timestamp
from zerver.models import UserProfile
from zerver.webhooks.newrelic import IncidentPrioritiesItems, IncidentStates, IncidentTimeStamps
Copy link
Collaborator

Choose a reason for hiding this comment

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

So, generally in our webhook integrations, these would be defined here in the view file.

NOTIFICATION_HEADER = "{priority_symbol} {priority} **priority [issue]({incident_url}) has been **{status}** at** <time: {time_updated_str} >"

NOTIFICATION_BODY_TEMPLATE = """
| :file: **Incident Details** |
Copy link
Collaborator

Choose a reason for hiding this comment

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

For headers and titles in Zulip, we usually only capitalize the first word (e.g. Recent conversations). So here and throughout the templates, I'd update this to be **Incident details**.

TOPIC_TEMPLATE = "{state} {priority} priority"

FALL_BACK_NOTIFICATION_TEMPLATE = """
```spoiler :danger: An [Incident](https://one.newrelic.com/alerts-ai) has been updated
Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe simplify to :danger: [Incident](link) updated

Try to reset the payload template to the default from
New Relic if you're unsure.
Please reach out to the team if you think this integration
is outdated: [CZO](https://chat.zulip.org/#narrow/stream/127-integrations).
Copy link
Collaborator

Choose a reason for hiding this comment

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

"CZO" is mostly used internally. It'd be better to use "the Zulip development community". Maybe ...

Please reach out in [the Zulip development community](link) if you think this integration is out-of-date.
Integration last updated: **{integration_last_updated}**

> *Last updated: **{integration_last_updated}***
```
"""
FALL_BACK_TOPIC_TEMPLATE = "Incident Alerts"
Copy link
Collaborator

Choose a reason for hiding this comment

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

Again "Incident alerts" vs both words being capitalized.

"incident_url": payload.get("issueUrl", "https://one.newrelic.com/alerts-ai").tame(
check_string
),
"total_incidents": payload["totalIncidents"].tame(check_union([check_int, check_string])),
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is there an example fixture / payload where "totalIncidents" is a string?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

No, it's supposed to only be an int. I'll also update the test fixtures.

new relic template payload:
image

check_string
),
"total_incidents": payload["totalIncidents"].tame(check_union([check_int, check_string])),
"state": payload.get("state").tame(check_string_in(IncidentStates.as_list(target="name"))),
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think this can just be a list of strings defined as a constant above.


def get_iso_timestamp_str(payload: WildValue, event_type: IncidentTimeStamps) -> Optional[str]:
unix_time = payload.get(event_type.value, "N/A").tame(
check_none_or(check_union([check_int, check_string]))
Copy link
Collaborator

Choose a reason for hiding this comment

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

Since "N/A" is being set as the default ... can this be None?

Copy link
Collaborator Author

@PieterCK PieterCK May 17, 2024

Choose a reason for hiding this comment

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

Yes, check_none_or should be safe to remove.

check_none_or(check_union([check_int, check_string]))
)

if unix_time == "N/A":
Copy link
Collaborator

Choose a reason for hiding this comment

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

It seems like "N/A" might be returned as an actual value from the New Relic payload, correct? At least the generated fixtures have some with that string value.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes they use the string "N/A" instead of None or false

created_at = get_iso_timestamp_str(payload, IncidentTimeStamps.CREATED)
closed_at = get_iso_timestamp_str(payload, IncidentTimeStamps.CLOSED)

if acknowledged_at and updated_at == acknowledged_at:
Copy link
Collaborator

Choose a reason for hiding this comment

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

What if both acknowledged_at and updated_at are None? I think we need to assert or check that updated_at isn't None before assuming such.

@PieterCK PieterCK force-pushed the issue-29729-integrations-update-newrelic-integration branch 4 times, most recently from 8b3d932 to 4aa40a2 Compare May 18, 2024 13:07
@PieterCK PieterCK force-pushed the issue-29729-integrations-update-newrelic-integration branch 4 times, most recently from e4f66b2 to 3a9ef92 Compare May 18, 2024 13:20
Add new features to the integration, updated media files
such as logo and bot avatar, updated doc, updated test
fixtures and deleted legacy codes.

Fixes zulip#29729

Co-authored-by: Pieter CK <pieterceka123@gmail.com>
@PieterCK PieterCK force-pushed the issue-29729-integrations-update-newrelic-integration branch from 3a9ef92 to 22c700c Compare May 20, 2024 04:11
@PieterCK
Copy link
Collaborator Author

PieterCK commented May 20, 2024

Hi @laurynmm, thanks for doing an initial code review for this PR. I've addressed your comments and updated the commit for this PR. Let me know if any recent changes fail to address your concerns. Looking forward to more reviews!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
maintainer review PR is ready for review by Zulip maintainers. size: XL
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Adjust New Relic Integration for the "Workflows and Destinations" update
4 participants