Skip to content

Commit

Permalink
Merge pull request #192 from diurnalist/f/lint-annotations
Browse files Browse the repository at this point in the history
expose annotations to linter
  • Loading branch information
rgeyer authored Sep 25, 2024
2 parents f7ed83e + 2502434 commit 5af3c16
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 0 deletions.
12 changes: 12 additions & 0 deletions lint/lint.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,15 @@ func (t *Target) GetDataSource() (Datasource, error) {
return GetDataSource(t.Datasource)
}

type Annotation struct {
Name string `json:"name"`
Datasource interface{} `json:"datasource,omitempty"`
}

func (a *Annotation) GetDataSource() (Datasource, error) {
return GetDataSource(a.Datasource)
}

// Panel is a deliberately incomplete representation of the Dashboard -> Panel type in grafana.
// The properties which are extracted from JSON are only those used for linting purposes.
type Panel struct {
Expand Down Expand Up @@ -273,6 +282,9 @@ type Dashboard struct {
Templating struct {
List []Template `json:"list"`
} `json:"templating"`
Annotations struct {
List []Annotation `json:"list"`
} `json:"annotations"`
Rows []Row `json:"rows,omitempty"`
Panels []Panel `json:"panels,omitempty"`
Editable bool `json:"editable,omitempty"`
Expand Down
5 changes: 5 additions & 0 deletions lint/model_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,11 @@ func TestParseDashboard(t *testing.T) {
assert.NoError(t, err)
assert.Len(t, dashboard.GetPanels(), 4)
})
t.Run("Annotations", func(t *testing.T) {
dashboard, err := NewDashboard(sampleDashboard)
assert.NoError(t, err)
assert.Len(t, dashboard.Annotations.List, 1)
})
}

func TestParseTemplateValue(t *testing.T) {
Expand Down
15 changes: 15 additions & 0 deletions lint/testdata/dashboard.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,21 @@
"pluginId": "prom"
}
],
"annotations": {
"list": [
{
"builtIn": 1,
"datasource": {
"type": "grafana",
"uid": "-- Grafana --"
},
"enable": true,
"hide": true,
"name": "Annotations & Alerts",
"type": "dashboard"
}
]
},
"rows": [
{
"panels": [
Expand Down

0 comments on commit 5af3c16

Please sign in to comment.