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

Opsgenie Alerts cannot attach image url with external S3 configured #67177

Closed
oneoneonepig opened this issue Apr 25, 2023 · 11 comments · Fixed by #67324
Closed

Opsgenie Alerts cannot attach image url with external S3 configured #67177

oneoneonepig opened this issue Apr 25, 2023 · 11 comments · Fixed by #67324
Assignees
Labels
area/alerting Grafana Alerting
Milestone

Comments

@oneoneonepig
Copy link
Contributor

What happened:

Cannot create Opsgenie Alerts with S3 image url attached

What you expected to happen:

Opsgenie Alerts are created and image URL are attached in details section

How to reproduce it (as minimally and precisely as possible):

  1. Create a Grafana container
  2. Create a Grafana Image Renderer container
  3. Configure Grafana to use the Grafana Image Renderer by following the tutorial
  4. Configure panels, alert rules, contact points, notification policies, etc.
  5. Trigger an Grafana Alert
  6. An image is created in the S3 bucket
  7. Grafana log shows 422 Unprocessable Entity
  8. No Opsgenie Alert is created

Anything else we need to know?:

The following section is the error log found in Grafana

logger=alertmanager org=1 t=2023-04-25T03:52:08.926659281Z level=error component=alertmanager orgID=1 component=dispatcher msg="Notify for alerts failed" num_alerts=1 err="Opsgenie/opsgenie[0]: notify retry canceled due to unrecoverable error after 1 attempts: send notification to Opsgenie: webhook response status 422 Unprocessable Entity"

I've tried sending the alerts to MockAPI, then send the same payload to Opsgenie by directly invoking the Opsgenie Alerts API. It turns out that the detail section seems to only accept K/V with string value, does not accept array in the value.

grafana opsgenie alert image cannot send

Environment:

  • Grafana version: Grafana v9.4.3
  • Data source type & version: Prometheus 2.42.0
  • OS Grafana is installed on: Ubuntu 22.04.1 LTS Docker CE 23.0.1
  • User OS & Browser: Chrome Version 112.0.5615.138
  • Grafana plugins: External Grafana Image Renderer v3.7.0
@oneoneonepig
Copy link
Contributor Author

This seems like a beginner-friendly issue and I'm gonna start trying to fix it.

@vCra
Copy link

vCra commented Apr 25, 2023

Have started seeing this issue with Google Cloud storage, however I never got images from OG before. Having alerts not being able to go to OG is not good, so I think removing image_urls from the request should allow us to start receiving alerts

@vCra
Copy link

vCra commented Apr 25, 2023

This can probably be fixed by reverting #49379

@grobinson-grafana grobinson-grafana added the area/alerting Grafana Alerting label Apr 25, 2023
@grobinson-grafana grobinson-grafana modified the milestones: 9.4.x, 9.5.x Apr 25, 2023
@grobinson-grafana
Copy link
Contributor

@oneoneonepig thanks for working on the fix! @vCra if needed you can disable images in notifications until this is fixed (https://grafana.com/docs/grafana/latest/alerting/manage-notifications/images-in-notifications/#configuration). Looking at the code, the image_urls field will be omitted if there are no images.

@oneoneonepig
Copy link
Contributor Author

Indeed, it works as expected until I've configured image renderer

@grobinson-grafana
Copy link
Contributor

@oneoneonepig have you decided how to fix it? Is there anything I can do to help?

@oneoneonepig
Copy link
Contributor Author

If multiple images were attached, since the rule mentioned in the doc says that all images should be provided:

When multiple alerts are sent in a single notification a screenshot might be included for each alert. The order the images are shown is random.

I'll try to change from sending this:

details: {
    "image_urls":[
        "https://bucket_name.s3.region.amazonaws.com/image1.png",
        "https://bucket_name.s3.region.amazonaws.com/image2.png",
        "https://bucket_name.s3.region.amazonaws.com/image3.png"
    ]
}

to a comma separated value such as:

details: {
    "image_urls": "https://bucket_name.s3.region.amazonaws.com/image1.png, https://bucket_name.s3.region.amazonaws.com/image2.png, https://bucket_name.s3.region.amazonaws.com/image3.png"
}

The final result should show multiple clickable URLs. By directly invoking the Opsgenie Create Alert API, the results will be like this:

2023-04-26_09-51-16

@grobinson-grafana Thanks for asking! This will be my first attempt to build Grafana, I'll dig through the docs and let you know if I need any help or any doc improvements that I would like to add 🙂

oneoneonepig added a commit to oneoneonepig/alerting that referenced this issue Apr 26, 2023
@oneoneonepig
Copy link
Contributor Author

Hi @grobinson-grafana, seems like the corresponding code were refactored to grafana/alerting

In my forked repo, I have successfully patched the alerting library by joining the URLs into a single string, and it works like how I described above. Single image attached and two images attached scenarios are both tested, both were able to send Opsgenie Alerts successfully. The following screenshot is an example of two images attached alert:

opsgenie alert with multiple images attached
SNAG-20230426-152522-0000

The fix in my local dev is tested by directly modifying code under ~/go/pkg/mod/github.com/grafana/alerting@XXX/receivers/opsgenie/opsgenie.go, which apparently is not the correct way to fix the library.

Mind if I ask what is the correct way of sending the PR, should I send the patch to grafana/alerting? And what is the correct way to develop fixes if the code is in external libraries (to grafana/grafana, grafana/alerting seems to be external)?

Thanks for your help!

@grobinson-grafana
Copy link
Contributor

Hi @oneoneonepig! This looks great, well done! 🎉 Please send the fix to grafana/alerting. I will take care of updating grafana/grafana from there!

@oneoneonepig
Copy link
Contributor Author

Instead of directly changing the code under ~/go/pkg/mod/github.com/grafana/alerting, we've found a better (or the correct) development workflow when fixing libraries:

  1. Clone grafana/grafana
  2. Fork and clone grafana/alerting
  3. Use the replace directive. In grafana/go.mod file, add line replace github.com/grafana/alerting => ../alerting to reference local code
  4. Under grafana directory, run go mod tidy
  5. Fix the code in alerting directory and build Grafana by running make run under directory grafana
  6. Confirm the fix, commit to fork and create PR

@grobinson-grafana
Copy link
Contributor

That is 100% correct. I don't think we've documented this so I will make sure that's in CONTRIBUTING.md.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/alerting Grafana Alerting
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

5 participants