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

Alerting: Fix incorrect decoding for alert rules with % characters #76148

Merged
merged 9 commits into from Oct 19, 2023

Conversation

gillesdemey
Copy link
Member

What is this feature?

This PR fixes a crash in the front-end when trying to view the details for an alert rule that has a "%" character encoded in the alert rule name.

This can be traced to a bug in react-router (remix-run/history#505).

the rule editor was also affected, it didn't crash but also did not properly decode the rule identifier.

Special notes for your reviewer:

Some additional manual testing would be appreciated since I failed to successfully write a test to mock window.location

@gillesdemey gillesdemey requested a review from a team as a code owner October 6, 2023 20:21
@gillesdemey gillesdemey requested review from VikaCep, konrad147 and soniaAguilarPeiron and removed request for a team October 6, 2023 20:21
@grafana-delivery-bot grafana-delivery-bot bot added this to the 10.2.x milestone Oct 6, 2023
@gillesdemey
Copy link
Member Author

Tests are currently failing because they rely pretty heavily on mocked location data passed in to the ruler viewer – I'll need to find a way around that to unblock this PR.

@konrad147 konrad147 requested a review from a team as a code owner October 11, 2023 11:33
@konrad147 konrad147 requested review from ashharrison90 and removed request for a team October 11, 2023 11:33
@konrad147 konrad147 changed the title fixes incorrect decoding for alert rules with % characters Alerting: Fix incorrect decoding for alert rules with % characters Oct 11, 2023
@konrad147
Copy link
Contributor

/deploy-to-hg

@ephemeral-instances-bot
Copy link

  • Preparing your instance. A comment containing your instance's url will be added to this PR when the instance is ready.
  • Your instance will be ready in ~10 minutes.
  • Check the GitHub actions tab to follow the workflow progress
  • Slack channel: #proj-ephemeral-hg-instances
  • Building instance with alerting/fix-decode-alert-rule-name oss branch and main enterprise branch. How to choose a branch

@ephemeral-instances-bot
Copy link

Copy link
Member

@soniaAguilarPeiron soniaAguilarPeiron left a comment

Choose a reason for hiding this comment

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

LGTM!
Tested on my local ✅

Copy link
Contributor

@ashharrison90 ashharrison90 left a comment

Choose a reason for hiding this comment

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

// It was probably fixed in React-Router v6
type PathWithOptionalID = { id?: string };
export function getRuleIdFromPathname(params: PathWithOptionalID): string | undefined {
const { pathname = '' } = locationService.getLocation();
Copy link
Member Author

Choose a reason for hiding this comment

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

Now that we're patching the router, do we still need this workaround? Can we go back to using useParams()?

Copy link
Contributor

Choose a reason for hiding this comment

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

I need to verify. IIRC react-router-dom has the same bug. In this PR we only patch the history package so it doesn't break outgoing links, but it shouldn't affect parsing path params

Copy link
Member

Choose a reason for hiding this comment

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

It seems that react-router added a fix in here , and this fix was included in the v6.4.3 release

@soniaAguilarPeiron
Copy link
Member

I created this issue @ashharrison90 , should I assign to the Grafana Frontend platform project?

@ashharrison90
Copy link
Contributor

@soniaAguilarPeiron sure 👍

@soniaAguilarPeiron
Copy link
Member

  • are we confident this patch to history won't cause unintended behaviour elsewhere in the app?

@ashharrison90 This patch does the same as this fix , that has been merged to main. So, we believe it should not break anything. We tested locally and on the ephemeral instance. We cannot be 100% confident about not breaking anything, but we believe it should not.

@soniaAguilarPeiron
Copy link
Member

/deploy-to-hg

@ephemeral-instances-bot
Copy link

  • Preparing your instance. A comment containing your instance's url will be added to this PR when the instance is ready.
  • Your instance will be ready in ~10 minutes.
  • Check the GitHub actions tab to follow the workflow progress
  • Slack channel: #proj-ephemeral-hg-instances
  • Building instance with alerting/fix-decode-alert-rule-name oss branch and main enterprise branch. How to choose a branch

@ephemeral-instances-bot
Copy link

Copy link
Contributor

@konrad147 konrad147 left a comment

Choose a reason for hiding this comment

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

LGTM!

@soniaAguilarPeiron soniaAguilarPeiron merged commit 390408b into main Oct 19, 2023
16 checks passed
@soniaAguilarPeiron soniaAguilarPeiron deleted the alerting/fix-decode-alert-rule-name branch October 19, 2023 09:51
@grafana-delivery-bot grafana-delivery-bot bot modified the milestones: 10.2.x, 10.3.x Oct 19, 2023
@aangelisc aangelisc modified the milestones: 10.3.x, 10.2.3 Dec 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

None yet

5 participants