Skip to content

Commit

Permalink
Add extra tags to Grafana annotations
Browse files Browse the repository at this point in the history
This adds the name and namespace tags to Grafana annotations.

This makes it possible to use this provider when one has multiple
Flux tenants writing to the same Grafana instance.
  • Loading branch information
Bill Franklin committed Aug 16, 2022
1 parent cef6398 commit 227bf37
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 0 deletions.
2 changes: 2 additions & 0 deletions internal/notifier/grafana.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ func (g *Grafana) Post(ctx context.Context, event events.Event) error {
for k, v := range event.Metadata {
sfields = append(sfields, fmt.Sprintf("%s: %s", k, v))
}
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
2 changes: 2 additions & 0 deletions internal/notifier/grafana_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ 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, "name: webapp", payload.Tags[3])
require.Equal(t, "namespace: gitops-system", payload.Tags[4])
}))
defer ts.Close()

Expand Down

0 comments on commit 227bf37

Please sign in to comment.