From 9ec9d3938be8cac90a5ab091e5986268c15526f6 Mon Sep 17 00:00:00 2001 From: zzxwill Date: Fri, 13 Aug 2021 18:17:09 +0800 Subject: [PATCH] Support Loki logs typed panel Added another panel type - Loki logs --- panel.go | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/panel.go b/panel.go index 9a7d201f..803a21f0 100644 --- a/panel.go +++ b/panel.go @@ -38,6 +38,7 @@ const ( RowType BarGaugeType HeatmapType + LogsType ) const MixedSource = "-- Mixed --" @@ -59,6 +60,7 @@ type ( *AlertlistPanel *BarGaugePanel *HeatmapPanel + *LogsPanel *CustomPanel } panelType int8 @@ -173,6 +175,10 @@ type ( } `json:"threshold"` } `json:"defaults"` } + LogsPanel struct { + CommonPanel + Targets []Target `json:"targets,omitempty"` + } Options struct { Orientation string `json:"orientation"` TextMode string `json:"textMode"` @@ -973,6 +979,12 @@ func (p *Panel) UnmarshalJSON(b []byte) (err error) { if err = json.Unmarshal(b, &rowpanel); err == nil { p.RowPanel = &rowpanel } + case "logs": + var logsPanel LogsPanel + p.OfType = LogsType + if err = json.Unmarshal(b, &logsPanel); err == nil { + p.LogsPanel = &logsPanel + } default: var custom = make(CustomPanel) p.OfType = CustomType @@ -1052,6 +1064,12 @@ func (p *Panel) MarshalJSON() ([]byte, error) { HeatmapPanel }{p.CommonPanel, *p.HeatmapPanel} return json.Marshal(outHeatmap) + case LogsType: + var outLogs = struct { + CommonPanel + LogsPanel + }{p.CommonPanel, *p.LogsPanel} + return json.Marshal(outLogs) case CustomType: var outCustom = struct { CommonPanel