Skip to content

Commit 37a8e9b

Browse files
feat(dashboard) add format options for query (#258)
* build(deps): bump golang.org/x/text from 0.3.7 to 0.3.8 Bumps [golang.org/x/text](https://github.com/golang/text) from 0.3.7 to 0.3.8. - [Release notes](https://github.com/golang/text/releases) - [Commits](golang/text@v0.3.7...v0.3.8) --- updated-dependencies: - dependency-name: golang.org/x/text dependency-type: indirect ... Signed-off-by: dependabot[bot] <[email protected]> * feat(dashboard): add query options to panel schema * feat(dashboard): add query options tests * feat(dashboard): add query options docs * feat(dashboard): small test change * feat(dashboard): small test change * feat(dashboard): update example usage --------- Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
1 parent 648b868 commit 37a8e9b

File tree

6 files changed

+609
-86
lines changed

6 files changed

+609
-86
lines changed

go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,8 @@ require (
7272
golang.org/x/crypto v0.0.0-20220517005047-85d78b3ac167 // indirect
7373
golang.org/x/net v0.0.0-20220111093109-d55c255bac03 // indirect
7474
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c // indirect
75-
golang.org/x/sys v0.0.0-20220503163025-988cb79eb6c6 // indirect
76-
golang.org/x/text v0.3.7 // indirect
75+
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f // indirect
76+
golang.org/x/text v0.3.8 // indirect
7777
google.golang.org/appengine v1.6.7 // indirect
7878
google.golang.org/genproto v0.0.0-20220111164026-67b88f271998 // indirect
7979
google.golang.org/grpc v1.48.0 // indirect

go.sum

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1208,8 +1208,9 @@ golang.org/x/sys v0.0.0-20211019181941-9d821ace8654/go.mod h1:oPkhp1MJrh7nUepCBc
12081208
golang.org/x/sys v0.0.0-20211124211545-fe61309f8881/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
12091209
golang.org/x/sys v0.0.0-20211205182925-97ca703d548d/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
12101210
golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
1211-
golang.org/x/sys v0.0.0-20220503163025-988cb79eb6c6 h1:nonptSpoQ4vQjyraW20DXPAglgQfVnM9ZC6MmNLMR60=
12121211
golang.org/x/sys v0.0.0-20220503163025-988cb79eb6c6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
1212+
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f h1:v4INt8xihDGvnrfjMDVXGxw9wrfxYyCjk0KbXjhR55s=
1213+
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
12131214
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1 h1:v+OssWQX+hTHEmOBgwxdZxK4zHq3yOs8F9J7mk0PY8E=
12141215
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
12151216
golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
@@ -1220,8 +1221,9 @@ golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
12201221
golang.org/x/text v0.3.4/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
12211222
golang.org/x/text v0.3.5/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
12221223
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
1223-
golang.org/x/text v0.3.7 h1:olpwvP2KacW1ZWvsR7uQhoyTYvKAupfQrRGBFM352Gk=
12241224
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
1225+
golang.org/x/text v0.3.8 h1:nAL+RVCQ9uMn3vJZbV+MRnydTJFPf8qqY42YiA6MrqY=
1226+
golang.org/x/text v0.3.8/go.mod h1:E6s5w1FMmriuDzIBO73fBruAKo1PCIq6d2Q6DHfQ8WQ=
12251227
golang.org/x/time v0.0.0-20180412165947-fbb02b2291d2/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
12261228
golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
12271229
golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=

sysdig/internal/client/monitor/model/dashboard.go

Lines changed: 126 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -94,71 +94,104 @@ const (
9494
)
9595

9696
type Format struct {
97-
Unit FormatUnit `json:"unit"`
98-
InputFormat string `json:"inputFormat"`
99-
DisplayFormat string `json:"displayFormat"`
100-
Decimals interface{} `json:"decimals"`
101-
YAxis string `json:"yAxis"`
97+
Unit FormatUnit `json:"unit"`
98+
InputFormat *string `json:"inputFormat"`
99+
DisplayFormat *string `json:"displayFormat"`
100+
Decimals *int `json:"decimals"`
101+
YAxis *string `json:"yAxis"`
102+
MinInterval *string `json:"minInterval"`
103+
NullValueDisplayMode *string `json:"nullValueDisplayMode"`
104+
}
105+
106+
func NewFormat(
107+
unit FormatUnit,
108+
inputFormat string,
109+
displayFormat string,
110+
decimals int,
111+
yAxis string,
112+
minInterval string,
113+
nullValueDisplayMode string) *Format {
114+
return &Format{
115+
Unit: unit,
116+
InputFormat: &inputFormat,
117+
DisplayFormat: &displayFormat,
118+
Decimals: &decimals,
119+
YAxis: &yAxis,
120+
MinInterval: &minInterval,
121+
NullValueDisplayMode: &nullValueDisplayMode,
122+
}
102123
}
103124

104125
func newPercentFormat() Format {
105-
return Format{
106-
Unit: FormatUnitPercentage,
107-
InputFormat: "0-100",
108-
DisplayFormat: "auto",
109-
Decimals: nil,
110-
YAxis: "auto",
111-
}
126+
return *NewFormat(
127+
FormatUnitPercentage,
128+
"0-100",
129+
"auto",
130+
0,
131+
"auto",
132+
"",
133+
"nullGap",
134+
)
112135
}
113136

114137
func newDataFormat() Format {
115-
return Format{
116-
Unit: FormatUnitData,
117-
InputFormat: "B",
118-
DisplayFormat: "auto",
119-
Decimals: nil,
120-
YAxis: "auto",
121-
}
138+
return *NewFormat(
139+
FormatUnitData,
140+
"B",
141+
"auto",
142+
0,
143+
"auto",
144+
"",
145+
"nullGap",
146+
)
122147
}
123148

124149
func newDataRateFormat() Format {
125-
return Format{
126-
Unit: FormatUnitDataRate,
127-
InputFormat: "B/s",
128-
DisplayFormat: "auto",
129-
Decimals: nil,
130-
YAxis: "auto",
131-
}
150+
return *NewFormat(
151+
FormatUnitDataRate,
152+
"B/s",
153+
"auto",
154+
0,
155+
"auto",
156+
"",
157+
"nullGap",
158+
)
132159
}
133160

134161
func newNumberFormat() Format {
135-
return Format{
136-
Unit: FormatUnitNumber,
137-
InputFormat: "1",
138-
DisplayFormat: "auto",
139-
Decimals: nil,
140-
YAxis: "auto",
141-
}
162+
return *NewFormat(
163+
FormatUnitNumber,
164+
"1",
165+
"auto",
166+
0,
167+
"auto",
168+
"",
169+
"nullGap",
170+
)
142171
}
143172

144173
func newNumberRateFormat() Format {
145-
return Format{
146-
Unit: FormatUnitNumberRate,
147-
InputFormat: "/s",
148-
DisplayFormat: "auto",
149-
Decimals: nil,
150-
YAxis: "auto",
151-
}
174+
return *NewFormat(
175+
FormatUnitNumberRate,
176+
"/s",
177+
"auto",
178+
0,
179+
"auto",
180+
"",
181+
"nullGap",
182+
)
152183
}
153184

154185
func newTimeFormat() Format {
155-
return Format{
156-
Unit: FormatUnitTime,
157-
InputFormat: "ns",
158-
DisplayFormat: "auto",
159-
Decimals: nil,
160-
YAxis: "auto",
161-
}
186+
return *NewFormat(
187+
FormatUnitTime,
188+
"ns",
189+
"auto",
190+
0,
191+
"auto",
192+
"",
193+
"nullGap",
194+
)
162195
}
163196

164197
type AdvancedQueries struct {
@@ -197,33 +230,73 @@ func (q *AdvancedQueries) Enable(val bool) *AdvancedQueries {
197230
return q
198231
}
199232

200-
func (q *AdvancedQueries) WithPercentFormat() *AdvancedQueries {
233+
func (q *AdvancedQueries) updateFormat(f *Format) {
234+
if f == nil {
235+
return
236+
}
237+
238+
if f.Unit != "" {
239+
q.Format.Unit = f.Unit
240+
}
241+
242+
if f.DisplayFormat != nil {
243+
q.Format.DisplayFormat = f.DisplayFormat
244+
}
245+
246+
if f.InputFormat != nil {
247+
q.Format.InputFormat = f.InputFormat
248+
}
249+
250+
if f.Decimals != nil {
251+
q.Format.Decimals = f.Decimals
252+
}
253+
254+
if f.YAxis != nil {
255+
q.Format.YAxis = f.YAxis
256+
}
257+
258+
if f.NullValueDisplayMode != nil {
259+
q.Format.NullValueDisplayMode = f.NullValueDisplayMode
260+
}
261+
262+
if f.MinInterval != nil {
263+
q.Format.MinInterval = f.MinInterval
264+
}
265+
}
266+
267+
func (q *AdvancedQueries) WithPercentFormat(f *Format) *AdvancedQueries {
201268
q.Format = newPercentFormat()
269+
q.updateFormat(f)
202270
return q
203271
}
204272

205-
func (q *AdvancedQueries) WithDataFormat() *AdvancedQueries {
273+
func (q *AdvancedQueries) WithDataFormat(f *Format) *AdvancedQueries {
206274
q.Format = newDataFormat()
275+
q.updateFormat(f)
207276
return q
208277
}
209278

210-
func (q *AdvancedQueries) WithDataRateFormat() *AdvancedQueries {
279+
func (q *AdvancedQueries) WithDataRateFormat(f *Format) *AdvancedQueries {
211280
q.Format = newDataRateFormat()
281+
q.updateFormat(f)
212282
return q
213283
}
214284

215-
func (q *AdvancedQueries) WithNumberFormat() *AdvancedQueries {
285+
func (q *AdvancedQueries) WithNumberFormat(f *Format) *AdvancedQueries {
216286
q.Format = newNumberFormat()
287+
q.updateFormat(f)
217288
return q
218289
}
219290

220-
func (q *AdvancedQueries) WithNumberRateFormat() *AdvancedQueries {
291+
func (q *AdvancedQueries) WithNumberRateFormat(f *Format) *AdvancedQueries {
221292
q.Format = newNumberRateFormat()
293+
q.updateFormat(f)
222294
return q
223295
}
224296

225-
func (q *AdvancedQueries) WithTimeFormat() *AdvancedQueries {
297+
func (q *AdvancedQueries) WithTimeFormat(f *Format) *AdvancedQueries {
226298
q.Format = newTimeFormat()
299+
q.updateFormat(f)
227300
return q
228301
}
229302

0 commit comments

Comments
 (0)