From 227bf37d3695ca2d894b8dd8d1a9beb917d953c2 Mon Sep 17 00:00:00 2001 From: Bill Franklin Date: Tue, 16 Aug 2022 16:31:50 +0100 Subject: [PATCH] Add extra tags to Grafana annotations 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. --- internal/notifier/grafana.go | 2 ++ internal/notifier/grafana_test.go | 2 ++ 2 files changed, 4 insertions(+) diff --git a/internal/notifier/grafana.go b/internal/notifier/grafana.go index 899c97d5d..7753f8a21 100644 --- a/internal/notifier/grafana.go +++ b/internal/notifier/grafana.go @@ -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), diff --git a/internal/notifier/grafana_test.go b/internal/notifier/grafana_test.go index 6675cd907..37df5c680 100644 --- a/internal/notifier/grafana_test.go +++ b/internal/notifier/grafana_test.go @@ -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()