Skip to content

Commit 022b97c

Browse files
authored
Merge pull request #1040 from fluxcd/grafana-annotations
Add involved object reference as annotations for the grafana provider
2 parents 7e14e41 + 7a34aee commit 022b97c

File tree

3 files changed

+12
-1
lines changed

3 files changed

+12
-1
lines changed

docs/spec/v1beta3/providers.md

+5
Original file line numberDiff line numberDiff line change
@@ -1270,6 +1270,11 @@ spec:
12701270
name: grafana-token
12711271
```
12721272

1273+
Besides the tag `flux` and the tag containing the reporting controller (e.g. `source-controller`),
1274+
the event metadata is also included as tags of the form `${metadataKey}: ${metadataValue}`, and
1275+
the tags `kind: ${event.InvolvedObject.Kind}`, `name: ${event.InvolvedObject.Name}` and
1276+
`namespace: ${event.InvolvedObject.Namespace}` are also included.
1277+
12731278
### GitHub dispatch
12741279

12751280
The `githubdispatch` provider generates GitHub events of type

internal/notifier/grafana.go

+4-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ type Grafana struct {
3636
Password string
3737
}
3838

39-
// GraphiteAnnotation represents a Grafana API annotation in Graphite format
39+
// GraphitePayload represents a Grafana API annotation in Graphite format
4040
type GraphitePayload struct {
4141
When int64 `json:"when"` //optional unix timestamp (ms)
4242
Text string `json:"text"`
@@ -75,6 +75,9 @@ func (g *Grafana) Post(ctx context.Context, event eventv1.Event) error {
7575
value := strings.ReplaceAll(v, ":", "|")
7676
sfields = append(sfields, fmt.Sprintf("%s: %s", key, value))
7777
}
78+
sfields = append(sfields, fmt.Sprintf("kind: %s", event.InvolvedObject.Kind))
79+
sfields = append(sfields, fmt.Sprintf("name: %s", event.InvolvedObject.Name))
80+
sfields = append(sfields, fmt.Sprintf("namespace: %s", event.InvolvedObject.Namespace))
7881
payload := GraphitePayload{
7982
When: event.Timestamp.Unix(),
8083
Text: fmt.Sprintf("%s/%s.%s", strings.ToLower(event.InvolvedObject.Kind), event.InvolvedObject.Name, event.InvolvedObject.Namespace),

internal/notifier/grafana_test.go

+3
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ func TestGrafana_Post(t *testing.T) {
4141
require.Equal(t, "flux", payload.Tags[0])
4242
require.Equal(t, "source-controller", payload.Tags[1])
4343
require.Equal(t, "test: metadata", payload.Tags[2])
44+
require.Equal(t, "kind: GitRepository", payload.Tags[3])
45+
require.Equal(t, "name: webapp", payload.Tags[4])
46+
require.Equal(t, "namespace: gitops-system", payload.Tags[5])
4447
}))
4548
defer ts.Close()
4649

0 commit comments

Comments
 (0)