Skip to content

Commit

Permalink
Support links to dashboards in yaml decoder
Browse files Browse the repository at this point in the history
  • Loading branch information
K-Phoen committed Mar 12, 2023
1 parent 9a2a84c commit 818cff3
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 0 deletions.
5 changes: 5 additions & 0 deletions decoder/dashboard.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ type DashboardModel struct {
TagsAnnotation []dashboard.TagAnnotation `yaml:"tags_annotations,omitempty"`
Variables []DashboardVariable `yaml:",omitempty"`
ExternalLinks []DashboardExternalLink `yaml:"external_links,omitempty"`
DashboardLinks []DashboardInternalLink `yaml:"dashboard_links,omitempty"`

Rows []DashboardRow
}
Expand Down Expand Up @@ -52,6 +53,10 @@ func (d *DashboardModel) ToBuilder() (dashboard.Builder, error) {
opts = append(opts, dashboard.ExternalLinks(externalLink.toModel()))
}

for _, dashboardLink := range d.DashboardLinks {
opts = append(opts, dashboard.DashboardLinks(dashboardLink.toModel()))
}

if d.AutoRefresh != "" {
opts = append(opts, dashboard.AutoRefresh(d.AutoRefresh))
}
Expand Down
25 changes: 25 additions & 0 deletions decoder/dashboardlink.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package decoder

import (
"github.com/K-Phoen/grabana/dashboard"
)

type DashboardInternalLink struct {
Title string `yaml:"title"`
Tags []string `yaml:"tags"`
AsDropdown bool `yaml:"as_dropdown,omitempty"`
IncludeTimeRange bool `yaml:"include_time_range,omitempty"`
IncludeVariableValues bool `yaml:"include_variable_values,omitempty"`
OpenInNewTab bool `yaml:"open_in_new_tab,omitempty"`
}

func (l DashboardInternalLink) toModel() dashboard.DashboardLink {
return dashboard.DashboardLink{
Title: l.Title,
Tags: l.Tags,
AsDropdown: l.AsDropdown,
IncludeTimeRange: l.IncludeTimeRange,
IncludeVariableValues: l.IncludeVariableValues,
OpenInNewTab: l.OpenInNewTab,
}
}
29 changes: 29 additions & 0 deletions decoder/dashboardlink_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package decoder

import (
"testing"

"github.com/stretchr/testify/require"
)

func TestDashboardLink(t *testing.T) {
req := require.New(t)

yamlLink := DashboardInternalLink{
Title: "joe",
Tags: []string{"my-service"},
AsDropdown: true,
IncludeTimeRange: true,
IncludeVariableValues: true,
OpenInNewTab: true,
}

model := yamlLink.toModel()

req.Equal("joe", model.Title)
req.ElementsMatch([]string{"my-service"}, model.Tags)
req.True(model.AsDropdown)
req.True(model.IncludeTimeRange)
req.True(model.IncludeVariableValues)
req.True(model.OpenInNewTab)
}

0 comments on commit 818cff3

Please sign in to comment.