Skip to content

Commit 3b2bf34

Browse files
authored
Add AllValue to the grafana variables
1 parent c433c59 commit 3b2bf34

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed

observability-lib/grafana/builder_test.go

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,37 @@ func TestBuilder_AddVars(t *testing.T) {
154154
}
155155
require.Len(t, o.Dashboard.Templating.List, 1)
156156
})
157+
158+
t.Run("AddVars adds variables with AllValue to the dashboard", func(t *testing.T) {
159+
builder := grafana.NewBuilder(&grafana.BuilderOptions{
160+
Name: "Dashboard Name",
161+
})
162+
163+
variable := grafana.NewQueryVariable(&grafana.QueryVariableOptions{
164+
VariableOption: &grafana.VariableOption{
165+
Name: "Variable Name",
166+
Label: "Variable Label",
167+
},
168+
Query: "query",
169+
Datasource: grafana.NewDataSource("Prometheus", "").Name,
170+
IncludeAll: true,
171+
AllValue: ".*",
172+
})
173+
174+
builder.AddVars(variable)
175+
o, err := builder.Build()
176+
if err != nil {
177+
t.Errorf("Error building dashboard: %v", err)
178+
}
179+
require.Len(t, o.Dashboard.Templating.List, 1)
180+
181+
// Verify the AllValue is set correctly
182+
varModel := o.Dashboard.Templating.List[0]
183+
require.NotNil(t, varModel.AllValue)
184+
require.Equal(t, ".*", *varModel.AllValue)
185+
require.NotNil(t, varModel.IncludeAll)
186+
require.True(t, *varModel.IncludeAll)
187+
})
157188
}
158189

159190
func TestBuilder_AddRow(t *testing.T) {

observability-lib/grafana/variables.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ type QueryVariableOptions struct {
8787
Sort dashboard.VariableSort
8888
Refresh *dashboard.VariableRefresh
8989
IncludeAll bool
90+
AllValue string
9091
QueryWithType map[string]any
9192
}
9293

@@ -112,7 +113,8 @@ func NewQueryVariable(options *QueryVariableOptions) *dashboard.QueryVariableBui
112113
Sort(options.Sort).
113114
Refresh(*options.Refresh).
114115
Multi(options.Multi).
115-
IncludeAll(options.IncludeAll)
116+
IncludeAll(options.IncludeAll).
117+
AllValue(options.AllValue)
116118

117119
if options.Query != "" {
118120
variable.Query(dashboard.StringOrMap{String: cog.ToPtr[string](options.Query)})

0 commit comments

Comments
 (0)