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

[RHCLOUD-22813] Handle provided context.host_url in integration templates #3221

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

jessicarod7
Copy link
Member

@jessicarod7 jessicarod7 commented Dec 19, 2024

Jira issue

https://issues.redhat.com/browse/RHCLOUD-22813

Description

Currently, URLs in PagerDuty and Camel notifications are constructed by the PagerDutyTransformer, or one of three Qute templates, respectively. Each one has a slightly different way of handling URLs, and the Camel templates are not the ones currently shown in this repo.

This PR creates a new class, InsightsUrlsBuilder, which provides consistent construction of the two URLs for all integrations:

  • data.inventory_url represents a link to the specific host, cluster, or inventory item in the Console that generated the message. If data.context.host_url is provided, it will be used here.
  • data.application_url links back to the application that generated the event.

The PR will also make it easy to modify the URL format in a followup issue.

Database migration

A new migration file (V1.110.0) has been added. It takes the current templates used in the Notifications database, and updates them to use the new URLs.

These changes are now part of #3229.

Testing

  • Updated connector-pagerduty tests to emulate the new URL builder on the engine side.
  • Updated CamelProcessorTest implementers to use the new URLs in their Qute templates
  • Added a new test for PagerDuty and Camel to verify that data.context.host_url will always be used if present

Example

Using the following trimmed output from BaseTransformer:

{
  "bundle": "rhel",
  "application": "advisor",
  "event_type": "new-recommendation",
  "timestamp": "2024-12-19T15:21:45.129372",
  // trimmed
  "context": {
    "inventory_id": "6eaaa39c-55f7-4f45-81a9-84c75b1475d6",
    "hostname": "my-computer-jrodri",
    "display_name": "my-computer-jrodri",
    "host_url": "https://console.redhat.com/insights/inventory/some-unique-host-url-path",
    "tags": []
  },
  "events": [
    {
      // one event, trimmed
    },
    {
      // another event, trimmed
    }
  ],
  "source": {
    "application": {"display_name": "Advisor"},
    "bundle": {"display_name": "Red Hat Enterprise Linux"}
  }
  "environment_url": "https://console.redhat.com"
}

And the new Microsoft Teams template:

{"text":"{#if data.context.display_name??}[{data.context.display_name}]({data.inventory_url}) triggered {data.events.size()} event{#if data.events.size() \u003e 1}s{/if}{#else}{data.events.size()} event{#if data.events.size() \u003e 1}s{/if} triggered{/if} from {data.source.application.display_name} - {data.source.bundle.display_name}. [Open {data.source.application.display_name}]({data.application_url})"}

We generate this message:

[my-computer-jrodri](https://console.redhat.com/insights/inventory/some-unique-host-url-path) triggered 2 events from Advisor - Red Hat Enterprise Linux. [Open Advisor](https://console.redhat.com/insights/advisor)

Copy link
Contributor

@g-duval g-duval left a comment

Choose a reason for hiding this comment

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

Awesome work Jessica :)
Because tis PR will involve some braking changes, I think it should be split in two PRs for camel processor case, like:

  1. Introduce new entries into data source object
  2. Update Qute templates and remove deprecated data from data source object (like environnment_url)

WDYT?

@jessicarod7
Copy link
Member Author

Agree with splitting the PRs. I'll open a new one later today.

@g-duval
Copy link
Contributor

g-duval commented Jan 13, 2025

/retest

@g-duval
Copy link
Contributor

g-duval commented Jan 13, 2025

@jessicarod7 it looks like those changes breaks test_integration_pagerduty_event_triggered IQE test.
Could you please have a look and confirm if it was expected while waiting for a test case update?

@jessicarod7
Copy link
Member Author

wasn't expecting this one to fail, looking into it

Comment on lines +55 to +61
if (!displayName.isEmpty()) {
if (data.getString("bundle", "").equals("openshift")
&& data.getString("application", "").equals("advisor")) {
path = String.format("/openshift/insights/advisor/clusters/%s", displayName);
} else {
path = "/insights/inventory/";
if (!inventoryId.isEmpty()) {
Copy link
Member

@MikelAlejoBR MikelAlejoBR Jan 14, 2025

Choose a reason for hiding this comment

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

I would suggest using .isBlank() instead of .isEmpty(), in case we get sent a " " string by mistake.

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