Skip to content

Add pyrra_url annotations#1522

Merged
metalmatze merged 3 commits intomainfrom
fix-grouping-test-annotations
Mar 30, 2026
Merged

Add pyrra_url annotations#1522
metalmatze merged 3 commits intomainfrom
fix-grouping-test-annotations

Conversation

@metalmatze
Copy link
Copy Markdown
Member

This PR adds a new pyrra_url annotation to all generated alert rules. This feature allows users to navigate directly from alerts to the corresponding SLO dashboard in Pyrra, improving the incident response workflow.

Changes

  • Added pyrra_url annotation to all ErrorBudgetBurn alerts
  • The URL includes:
    • The SLO name in the query expression
    • A time range (from=now-1h&to=now)
    • Grouping parameters that match the SLO's configuration (e.g., job, handler, namespace)

Closes #1091

@metalmatze metalmatze requested a review from Copilot July 7, 2025 20:38
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR adds a new pyrra_url annotation to all generated alert rules, allowing users to link directly from an alert to its SLO dashboard in Pyrra.

  • Changed Burnrates (and related) signatures to accept an external URL.
  • Updated commonRuleAnnotations to construct and include pyrra_url.
  • Propagated the external URL through CLI commands, filesystem, Kubernetes controller, and generator.
  • Augmented existing tests and added TestObjective_PyrraURLAnnotation.

Reviewed Changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
slo/rules.go Extended Burnrates and commonRuleAnnotations to add pyrra_url.
slo/rules_test.go Updated expected annotations and added a test for Pyrra URL.
main.go Passed CLI ExternalURL into rule‐generation functions.
kubernetes/controllers/servicelevelobjective.go Added PyrraExternalURL field and threaded it into rule creation.
kubernetes.go Wired PyrraExternalURL through cmdKubernetes.
generate.go Expanded cmdGenerate to accept and pass ExternalURL.
filesystem.go Expanded cmdFilesystem and writeRuleFile to propagate ExternalURL.
Comments suppressed due to low confidence (2)

slo/rules_test.go:2094

  • Tests cover the base URL case but not scenarios where Grouping() returns labels. Add a test case to verify that grouping parameters appear correctly in the pyrra_url.
func TestObjective_PyrraURLAnnotation(t *testing.T) {

slo/rules.go:609

  • [nitpick] The method accepts externalURL as a string and reparses it. Consider accepting a *url.URL to avoid repeated parsing and improve type safety.
func (o Objective) commonRuleAnnotations(externalURL string) map[string]string {

Comment thread slo/rules.go Outdated

externalURLParsed, err := url.Parse(externalURL)
if err != nil {
return nil
Copy link

Copilot AI Jul 7, 2025

Choose a reason for hiding this comment

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

Returning nil on URL parse error will drop any existing annotations. Instead, log the error and continue without adding pyrra_url (or return the existing annotations map).

Suggested change
return nil
fmt.Printf("Error parsing external URL: %v\n", err)
// Continue without adding pyrra_url
return annotations

Copilot uses AI. Check for mistakes.
Comment thread slo/rules.go Outdated
Comment on lines +648 to +650
groups = append(groups, l+"=%22{{$labels."+l+"}}%22")
}
annotations["pyrra_url"] += "&grouping=%7B" + strings.Join(groups, ",") + "%7D"
Copy link

Copilot AI Jul 7, 2025

Choose a reason for hiding this comment

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

[nitpick] Manually appending URL-encoded grouping parameters is error-prone. Consider adding grouping via url.Values and let Encode() handle proper escaping.

Suggested change
groups = append(groups, l+"=%22{{$labels."+l+"}}%22")
}
annotations["pyrra_url"] += "&grouping=%7B" + strings.Join(groups, ",") + "%7D"
groups = append(groups, l+"={{$labels."+l+"}}")
}
groupingParams := url.Values{}
groupingParams.Add("grouping", "{"+strings.Join(groups, ",")+"}")
annotations["pyrra_url"] += "&" + groupingParams.Encode()

Copilot uses AI. Check for mistakes.
Add proper pyrra_url annotations with grouping parameters to all grouping test cases
in slo/rules_test.go. The annotations now include URL-encoded grouping parameters
that match the labels used in the sum by expressions:

This ensures consistency with the already-fixed http-ratio-grouping test case.
@metalmatze metalmatze force-pushed the fix-grouping-test-annotations branch from d391b73 to 7eeed91 Compare March 29, 2026 22:42
…on error

Use url.QueryEscape for the grouping query parameter while preserving
Prometheus Go template expressions ({{$labels.<name>}}) unencoded so
they can be templated at alert time.

Return existing annotations instead of nil when external URL parsing
fails to avoid dropping propagated annotations.
@metalmatze metalmatze force-pushed the fix-grouping-test-annotations branch from 93f2f28 to 16d4468 Compare March 30, 2026 17:05
@metalmatze metalmatze merged commit 03b0d69 into main Mar 30, 2026
9 checks passed
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.

Feature - Add link to Pyrra in alerts

2 participants