Skip to content

Commit c26f36b

Browse files
authored
feat: Support more panel types (#77)
* feat: Support "text" panel type * style: Format files * docs: Update documentation to add Text panel type
1 parent 6ed94a5 commit c26f36b

File tree

4 files changed

+389
-176
lines changed

4 files changed

+389
-176
lines changed

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

Lines changed: 15 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -228,20 +228,20 @@ func (q *AdvancedQueries) WithTimeFormat() *AdvancedQueries {
228228
}
229229

230230
type Panels struct {
231-
ID int `json:"id"`
232-
Name string `json:"name"`
233-
Description string `json:"description"`
234-
AxesConfiguration AxesConfiguration `json:"axesConfiguration"`
235-
LegendConfiguration LegendConfiguration `json:"legendConfiguration"`
236-
ApplyScopeToAll bool `json:"applyScopeToAll"`
237-
ApplySegmentationToAll bool `json:"applySegmentationToAll"`
238-
AdvancedQueries []*AdvancedQueries `json:"advancedQueries"`
239-
NumberThresholds NumberThresholds `json:"numberThresholds"`
240-
MarkdownSource interface{} `json:"markdownSource"`
241-
PanelTitleVisible bool `json:"panelTitleVisible"`
242-
TextAutosized bool `json:"textAutosized"`
243-
TransparentBackground bool `json:"transparentBackground"`
244-
Type PanelType `json:"type"`
231+
ID int `json:"id"`
232+
Name string `json:"name"`
233+
Description string `json:"description"`
234+
AxesConfiguration *AxesConfiguration `json:"axesConfiguration,omitempty"`
235+
LegendConfiguration *LegendConfiguration `json:"legendConfiguration,omitempty"`
236+
ApplyScopeToAll bool `json:"applyScopeToAll,omitempty"`
237+
ApplySegmentationToAll bool `json:"applySegmentationToAll,omitempty"`
238+
AdvancedQueries []*AdvancedQueries `json:"advancedQueries,omitempty"`
239+
NumberThresholds *NumberThresholds `json:"numberThresholds,omitempty"`
240+
MarkdownSource *string `json:"markdownSource,omitempty"`
241+
PanelTitleVisible bool `json:"panelTitleVisible"`
242+
TextAutosized bool `json:"textAutosized"`
243+
TransparentBackground bool `json:"transparentBackground"`
244+
Type PanelType `json:"type"`
245245
// Just a helper to the client, the actual field is in Dashboard
246246
Layout *Layout `json:"-"`
247247
}
@@ -251,64 +251,9 @@ type PanelType string
251251
const (
252252
PanelTypeTimechart PanelType = "advancedTimechart"
253253
PanelTypeNumber PanelType = "advancedNumber"
254+
PanelTypeText PanelType = "text"
254255
)
255256

256-
func NewPanel(name, description string, panelType PanelType) *Panels {
257-
newPanel := &Panels{
258-
ID: 0,
259-
Name: name,
260-
Description: description,
261-
Type: panelType,
262-
ApplyScopeToAll: false,
263-
ApplySegmentationToAll: false,
264-
AxesConfiguration: AxesConfiguration{
265-
Bottom: Bottom{Enabled: true},
266-
Left: Left{
267-
Enabled: true,
268-
DisplayName: nil,
269-
Unit: "auto",
270-
DisplayFormat: "auto",
271-
Decimals: "",
272-
MinValue: 0,
273-
MaxValue: "",
274-
MinInputFormat: "ns",
275-
MaxInputFormat: "ns",
276-
Scale: "linear",
277-
},
278-
Right: Right{
279-
Enabled: true,
280-
DisplayName: nil,
281-
Unit: "auto",
282-
DisplayFormat: "auto",
283-
Decimals: "",
284-
MinValue: 0,
285-
MaxValue: "",
286-
MinInputFormat: "1",
287-
MaxInputFormat: "1",
288-
Scale: "linear",
289-
},
290-
},
291-
LegendConfiguration: LegendConfiguration{
292-
Enabled: true,
293-
Position: "right",
294-
Layout: "table",
295-
ShowCurrent: true,
296-
Width: nil,
297-
Height: nil,
298-
},
299-
MarkdownSource: nil,
300-
PanelTitleVisible: false,
301-
TextAutosized: false,
302-
TransparentBackground: false,
303-
}
304-
305-
if newPanel.Type == PanelTypeNumber {
306-
newPanel.NumberThresholds.Values = []interface{}{} // These values must be not nil in case of type number
307-
newPanel.NumberThresholds.Base.Severity = "none"
308-
}
309-
return newPanel
310-
}
311-
312257
func (p *Panels) AddQueries(queries ...*AdvancedQueries) (*Panels, error) {
313258
if p.Type == PanelTypeNumber && len(p.AdvancedQueries)+len(queries) > 1 {
314259
return nil, fmt.Errorf("a panel of type 'number' can only contain one query")

0 commit comments

Comments
 (0)