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

Add involved object reference as annotations for the grafana provider #1040

Merged
merged 1 commit into from
Feb 12, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions docs/spec/v1beta3/providers.md
Original file line number Diff line number Diff line change
Expand Up @@ -1270,6 +1270,11 @@ spec:
name: grafana-token
```

Besides the tag `flux` and the tag containing the reporting controller (e.g. `source-controller`),
the event metadata is also included as tags of the form `${metadataKey}: ${metadataValue}`, and
the tags `kind: ${event.InvolvedObject.Kind}`, `name: ${event.InvolvedObject.Name}` and
`namespace: ${event.InvolvedObject.Namespace}` are also included.

### GitHub dispatch

The `githubdispatch` provider generates GitHub events of type
Expand Down
5 changes: 4 additions & 1 deletion internal/notifier/grafana.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ type Grafana struct {
Password string
}

// GraphiteAnnotation represents a Grafana API annotation in Graphite format
// GraphitePayload represents a Grafana API annotation in Graphite format
type GraphitePayload struct {
When int64 `json:"when"` //optional unix timestamp (ms)
Text string `json:"text"`
Expand Down Expand Up @@ -75,6 +75,9 @@ func (g *Grafana) Post(ctx context.Context, event eventv1.Event) error {
value := strings.ReplaceAll(v, ":", "|")
sfields = append(sfields, fmt.Sprintf("%s: %s", key, value))
}
sfields = append(sfields, fmt.Sprintf("kind: %s", event.InvolvedObject.Kind))
sfields = append(sfields, fmt.Sprintf("name: %s", event.InvolvedObject.Name))
sfields = append(sfields, fmt.Sprintf("namespace: %s", event.InvolvedObject.Namespace))
payload := GraphitePayload{
When: event.Timestamp.Unix(),
Text: fmt.Sprintf("%s/%s.%s", strings.ToLower(event.InvolvedObject.Kind), event.InvolvedObject.Name, event.InvolvedObject.Namespace),
Expand Down
3 changes: 3 additions & 0 deletions internal/notifier/grafana_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ func TestGrafana_Post(t *testing.T) {
require.Equal(t, "flux", payload.Tags[0])
require.Equal(t, "source-controller", payload.Tags[1])
require.Equal(t, "test: metadata", payload.Tags[2])
require.Equal(t, "kind: GitRepository", payload.Tags[3])
require.Equal(t, "name: webapp", payload.Tags[4])
require.Equal(t, "namespace: gitops-system", payload.Tags[5])
}))
defer ts.Close()

Expand Down