Skip to content

Instantly share code, notes, and snippets.

@andreasjansson
Created October 25, 2021 22:11
Show Gist options
  • Save andreasjansson/dad1a3efea7d7643838c962d65740e20 to your computer and use it in GitHub Desktop.
Save andreasjansson/dad1a3efea7d7643838c962d65740e20 to your computer and use it in GitHub Desktop.
@@ -38,6 +38,8 @@ const (
RowType
BarGaugeType
HeatmapType
+ TimeseriesType
+ StateTimelineType
)
const MixedSource = "-- Mixed --"
@@ -59,6 +61,8 @@ type (
*AlertlistPanel
*BarGaugePanel
*HeatmapPanel
+ *TimeseriesPanel
+ *StateTimelinePanel
*CustomPanel
}
panelType int8
@@ -358,6 +362,12 @@ type (
YBucketNumber *float64 `json:"yBucketNumber"`
YBucketSize *float64 `json:"yBucketSize"`
}
+ TimeseriesPanel struct {
+ Targets []Target `json:"targets,omitempty"`
+ }
+ StateTimelinePanel struct {
+ Targets []Target `json:"targets,omitempty"`
+ }
CustomPanel map[string]interface{}
)
@@ -774,6 +784,10 @@ func (p *Panel) ResetTargets() {
p.BarGaugePanel.Targets = nil
case HeatmapType:
p.HeatmapPanel.Targets = nil
+ case TimeseriesType:
+ p.TimeseriesPanel.Targets = nil
+ case StateTimelineType:
+ p.StateTimelinePanel.Targets = nil
}
}
@@ -793,6 +807,10 @@ func (p *Panel) AddTarget(t *Target) {
p.TablePanel.Targets = append(p.TablePanel.Targets, *t)
case HeatmapType:
p.HeatmapPanel.Targets = append(p.HeatmapPanel.Targets, *t)
+ case TimeseriesType:
+ p.TimeseriesPanel.Targets = append(p.TimeseriesPanel.Targets, *t)
+ case StateTimelineType:
+ p.StateTimelinePanel.Targets = append(p.StateTimelinePanel.Targets, *t)
}
// TODO check for existing refID
}
@@ -820,6 +838,10 @@ func (p *Panel) SetTarget(t *Target) {
setTarget(t, &p.TablePanel.Targets)
case HeatmapType:
setTarget(t, &p.HeatmapPanel.Targets)
+ case TimeseriesType:
+ setTarget(t, &p.TimeseriesPanel.Targets)
+ case StateTimelineType:
+ setTarget(t, &p.StateTimelinePanel.Targets)
}
}
@@ -851,6 +873,10 @@ func (p *Panel) RepeatDatasourcesForEachTarget(dsNames ...string) {
repeatDS(dsNames, &p.TablePanel.Targets)
case HeatmapType:
repeatDS(dsNames, &p.HeatmapPanel.Targets)
+ case TimeseriesType:
+ repeatDS(dsNames, &p.TimeseriesPanel.Targets)
+ case StateTimelineType:
+ repeatDS(dsNames, &p.StateTimelinePanel.Targets)
}
}
@@ -885,6 +911,10 @@ func (p *Panel) RepeatTargetsForDatasources(dsNames ...string) {
repeatTarget(dsNames, &p.TablePanel.Targets)
case HeatmapType:
repeatTarget(dsNames, &p.HeatmapPanel.Targets)
+ case TimeseriesType:
+ repeatTarget(dsNames, &p.TimeseriesPanel.Targets)
+ case StateTimelineType:
+ repeatTarget(dsNames, &p.StateTimelinePanel.Targets)
}
}
@@ -904,6 +934,10 @@ func (p *Panel) GetTargets() *[]Target {
return &p.BarGaugePanel.Targets
case HeatmapType:
return &p.HeatmapPanel.Targets
+ case TimeseriesType:
+ return &p.TimeseriesPanel.Targets
+ case StateTimelineType:
+ return &p.StateTimelinePanel.Targets
default:
return nil
}
@@ -973,6 +1007,18 @@ func (p *Panel) UnmarshalJSON(b []byte) (err error) {
if err = json.Unmarshal(b, &rowpanel); err == nil {
p.RowPanel = &rowpanel
}
+ case "timeseries":
+ var timeseries TimeseriesPanel
+ p.OfType = TimeseriesType
+ if err = json.Unmarshal(b, &timeseries); err == nil {
+ p.TimeseriesPanel = &timeseries
+ }
+ case "state-timeline":
+ var stateTimeline StateTimelinePanel
+ p.OfType = StateTimelineType
+ if err = json.Unmarshal(b, &stateTimeline); err == nil {
+ p.StateTimelinePanel = &stateTimeline
+ }
default:
var custom = make(CustomPanel)
p.OfType = CustomType
@@ -1052,6 +1098,18 @@ func (p *Panel) MarshalJSON() ([]byte, error) {
HeatmapPanel
}{p.CommonPanel, *p.HeatmapPanel}
return json.Marshal(outHeatmap)
+ case TimeseriesType:
+ var outTimeseries = struct {
+ CommonPanel
+ TimeseriesPanel
+ }{p.CommonPanel, *p.TimeseriesPanel}
+ return json.Marshal(outTimeseries)
+ case StateTimelineType:
+ var outStateTimeline = struct {
+ CommonPanel
+ StateTimelinePanel
+ }{p.CommonPanel, *p.StateTimelinePanel}
+ return json.Marshal(outStateTimeline)
case CustomType:
var outCustom = struct {
CommonPanel
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment