Add pyrra_url annotations#1522
Merged
metalmatze merged 3 commits intomainfrom Mar 30, 2026
Merged
Conversation
There was a problem hiding this comment.
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
commonRuleAnnotationsto construct and includepyrra_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
externalURLas a string and reparses it. Consider accepting a*url.URLto avoid repeated parsing and improve type safety.
func (o Objective) commonRuleAnnotations(externalURL string) map[string]string {
|
|
||
| externalURLParsed, err := url.Parse(externalURL) | ||
| if err != nil { | ||
| return nil |
There was a problem hiding this comment.
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 |
Comment on lines
+648
to
+650
| groups = append(groups, l+"=%22{{$labels."+l+"}}%22") | ||
| } | ||
| annotations["pyrra_url"] += "&grouping=%7B" + strings.Join(groups, ",") + "%7D" |
There was a problem hiding this comment.
[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() |
d683136 to
d391b73
Compare
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.
d391b73 to
7eeed91
Compare
…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.
93f2f28 to
16d4468
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR adds a new
pyrra_urlannotation 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
pyrra_urlannotation to all ErrorBudgetBurn alertsCloses #1091