From 960279589c09faedb5cd0b5c855239b8c08521bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Henri?= Date: Fri, 20 Oct 2023 17:38:43 +0000 Subject: [PATCH 1/4] Append grafonnet-lib without git submodules MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: João Henri --- .gitmodules | 3 - embeds/grafonnet-lib | 1 - embeds/grafonnet-lib/grafonnet-7.0/DOCS.md | 885 ++++++++++++++++++ .../grafonnet-7.0/dashboard.libsonnet | 87 ++ .../grafonnet-7.0/grafana.libsonnet | 21 + .../grafonnet-7.0/panel/gauge.libsonnet | 138 +++ .../grafonnet-7.0/panel/graph.libsonnet | 257 +++++ .../grafonnet-7.0/panel/row.libsonnet | 45 + .../grafonnet-7.0/panel/stat.libsonnet | 142 +++ .../grafonnet-7.0/panel/table.libsonnet | 134 +++ .../grafonnet-7.0/panel/text.libsonnet | 58 ++ .../grafonnet-7.0/target/prometheus.libsonnet | 21 + .../grafonnet-7.0/template/custom.libsonnet | 36 + .../template/datasource.libsonnet | 36 + .../grafonnet-7.0/template/query.libsonnet | 52 + .../grafonnet/alert_condition.libsonnet | 47 + .../grafonnet/alertlist.libsonnet | 43 + .../grafonnet/annotation.libsonnet | 40 + .../grafonnet/bar_gauge_panel.libsonnet | 47 + .../grafonnet/cloudmonitoring.libsonnet | 57 ++ .../grafonnet/cloudwatch.libsonnet | 51 + .../grafonnet/dashboard.libsonnet | 181 ++++ .../grafonnet/dashlist.libsonnet | 41 + .../grafonnet/elasticsearch.libsonnet | 51 + .../grafonnet/gauge_panel.libsonnet | 211 +++++ .../grafonnet-lib/grafonnet/grafana.libsonnet | 32 + .../grafonnet/graph_panel.libsonnet | 313 +++++++ .../grafonnet/graphite.libsonnet | 29 + .../grafonnet/heatmap_panel.libsonnet | 150 +++ .../grafonnet/influxdb.libsonnet | 104 ++ embeds/grafonnet-lib/grafonnet/link.libsonnet | 39 + .../grafonnet/log_panel.libsonnet | 56 ++ embeds/grafonnet-lib/grafonnet/loki.libsonnet | 22 + .../grafonnet/pie_chart_panel.libsonnet | 72 ++ .../grafonnet/pluginlist.libsonnet | 23 + .../grafonnet/prometheus.libsonnet | 38 + embeds/grafonnet-lib/grafonnet/row.libsonnet | 47 + .../grafonnet/singlestat.libsonnet | 181 ++++ embeds/grafonnet-lib/grafonnet/sql.libsonnet | 23 + .../grafonnet/stat_panel.libsonnet | 222 +++++ .../grafonnet/table_panel.libsonnet | 91 ++ .../grafonnet/template.libsonnet | 289 ++++++ embeds/grafonnet-lib/grafonnet/text.libsonnet | 43 + .../grafonnet/timepicker.libsonnet | 40 + .../grafonnet/transformation.libsonnet | 12 + 45 files changed, 4507 insertions(+), 4 deletions(-) delete mode 100644 .gitmodules delete mode 160000 embeds/grafonnet-lib create mode 100644 embeds/grafonnet-lib/grafonnet-7.0/DOCS.md create mode 100644 embeds/grafonnet-lib/grafonnet-7.0/dashboard.libsonnet create mode 100644 embeds/grafonnet-lib/grafonnet-7.0/grafana.libsonnet create mode 100644 embeds/grafonnet-lib/grafonnet-7.0/panel/gauge.libsonnet create mode 100644 embeds/grafonnet-lib/grafonnet-7.0/panel/graph.libsonnet create mode 100644 embeds/grafonnet-lib/grafonnet-7.0/panel/row.libsonnet create mode 100644 embeds/grafonnet-lib/grafonnet-7.0/panel/stat.libsonnet create mode 100644 embeds/grafonnet-lib/grafonnet-7.0/panel/table.libsonnet create mode 100644 embeds/grafonnet-lib/grafonnet-7.0/panel/text.libsonnet create mode 100644 embeds/grafonnet-lib/grafonnet-7.0/target/prometheus.libsonnet create mode 100644 embeds/grafonnet-lib/grafonnet-7.0/template/custom.libsonnet create mode 100644 embeds/grafonnet-lib/grafonnet-7.0/template/datasource.libsonnet create mode 100644 embeds/grafonnet-lib/grafonnet-7.0/template/query.libsonnet create mode 100644 embeds/grafonnet-lib/grafonnet/alert_condition.libsonnet create mode 100644 embeds/grafonnet-lib/grafonnet/alertlist.libsonnet create mode 100644 embeds/grafonnet-lib/grafonnet/annotation.libsonnet create mode 100644 embeds/grafonnet-lib/grafonnet/bar_gauge_panel.libsonnet create mode 100644 embeds/grafonnet-lib/grafonnet/cloudmonitoring.libsonnet create mode 100644 embeds/grafonnet-lib/grafonnet/cloudwatch.libsonnet create mode 100644 embeds/grafonnet-lib/grafonnet/dashboard.libsonnet create mode 100644 embeds/grafonnet-lib/grafonnet/dashlist.libsonnet create mode 100644 embeds/grafonnet-lib/grafonnet/elasticsearch.libsonnet create mode 100644 embeds/grafonnet-lib/grafonnet/gauge_panel.libsonnet create mode 100644 embeds/grafonnet-lib/grafonnet/grafana.libsonnet create mode 100644 embeds/grafonnet-lib/grafonnet/graph_panel.libsonnet create mode 100644 embeds/grafonnet-lib/grafonnet/graphite.libsonnet create mode 100644 embeds/grafonnet-lib/grafonnet/heatmap_panel.libsonnet create mode 100644 embeds/grafonnet-lib/grafonnet/influxdb.libsonnet create mode 100644 embeds/grafonnet-lib/grafonnet/link.libsonnet create mode 100644 embeds/grafonnet-lib/grafonnet/log_panel.libsonnet create mode 100644 embeds/grafonnet-lib/grafonnet/loki.libsonnet create mode 100644 embeds/grafonnet-lib/grafonnet/pie_chart_panel.libsonnet create mode 100644 embeds/grafonnet-lib/grafonnet/pluginlist.libsonnet create mode 100644 embeds/grafonnet-lib/grafonnet/prometheus.libsonnet create mode 100644 embeds/grafonnet-lib/grafonnet/row.libsonnet create mode 100644 embeds/grafonnet-lib/grafonnet/singlestat.libsonnet create mode 100644 embeds/grafonnet-lib/grafonnet/sql.libsonnet create mode 100644 embeds/grafonnet-lib/grafonnet/stat_panel.libsonnet create mode 100644 embeds/grafonnet-lib/grafonnet/table_panel.libsonnet create mode 100644 embeds/grafonnet-lib/grafonnet/template.libsonnet create mode 100644 embeds/grafonnet-lib/grafonnet/text.libsonnet create mode 100644 embeds/grafonnet-lib/grafonnet/timepicker.libsonnet create mode 100644 embeds/grafonnet-lib/grafonnet/transformation.libsonnet diff --git a/.gitmodules b/.gitmodules deleted file mode 100644 index 7a799a23f..000000000 --- a/.gitmodules +++ /dev/null @@ -1,3 +0,0 @@ -[submodule "embeds/grafonnet-lib"] - path = embeds/grafonnet-lib - url = https://github.com/grafana/grafonnet-lib.git diff --git a/embeds/grafonnet-lib b/embeds/grafonnet-lib deleted file mode 160000 index 302801965..000000000 --- a/embeds/grafonnet-lib +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 30280196507e0fe6fa978a3e0eaca3a62844f817 diff --git a/embeds/grafonnet-lib/grafonnet-7.0/DOCS.md b/embeds/grafonnet-lib/grafonnet-7.0/DOCS.md new file mode 100644 index 000000000..9e3c09f6d --- /dev/null +++ b/embeds/grafonnet-lib/grafonnet-7.0/DOCS.md @@ -0,0 +1,885 @@ +# Docs + +* [dashboard](#dashboard) +* [panel](#panel) + * [gauge.new](#panelGaugenew) + * [graph.new](#panelGraphnew) + * [row.new](#panelRownew) + * [stat.new](#panelStatnew) + * [table.new](#panelTablenew) + * [text.new](#panelTextnew) +* [target](#target) + * [prometheus.new](#targetPrometheusnew) +* [template](#template) + * [custom.new](#templateCustomnew) + * [datasource.new](#templateDatasourcenew) + * [query.new](#templateQuerynew) + +## dashboard + + + +### dashboard.new + +Instantiate a dashboard. + +* **description**: (type: string, default: `null`) + +* **editable**: (type: boolean, default: `true`) + +* **graphTooltip**: (type: integer, default: `0`) + +* **refresh**: (type: string, default: `null`) + +* **schemaVersion**: (type: integer, default: `25`) + +* **style**: (type: string, default: `"dark"`) + +* **tags**: (type: array, default: `[]`) + +* **timezone**: (type: string, default: `null`) + +* **title**: (type: string, default: `null`) + +* **uid**: (type: string, default: `null`) + + +#### #setTime + +* **from**: (type: string, default: `"now-6h"`) + +* **to**: (type: string, default: `"now"`) + +#### #setTimepicker + +* **hidden**: (type: boolean, default: `false`) + +* **refreshIntervals**: (type: array, default: `["5s","10s","30s","1m","5m","15m","30m","1h","2h","1d"]`) + + +#### #addAnnotation + +* **builtIn**: (type: integer, default: `0`) + +* **datasource**: (type: string, default: `"default"`) + +* **enable**: (type: boolean, default: `true`) + +* **hide**: (type: boolean, default: `false`) + +* **iconColor**: (type: string, default: `null`) + +* **name**: (type: string, default: `null`) + +* **rawQuery**: (type: string, default: `null`) + +* **showIn**: (type: integer, default: `0`) + +#### #addTemplate + +* **template**: (type: object) + + + +## panel + + + +### panel.gauge.new + + + +* **datasource**: (type: string, default: `"default"`) + +* **description**: (type: string, default: `null`) + +* **repeat**: (type: string, default: `null`) + +* **repeatDirection**: (type: string, default: `null`) + +* **title**: (type: string, default: `null`) + +* **transparent**: (type: boolean, default: `false`) + + +#### #setFieldConfig + +* **max**: (type: integer, default: `null`) + +* **min**: (type: integer, default: `null`) + +* **thresholdMode**: (type: string, default: `"absolute"`) + +* **unit**: (type: string, default: `null`) + +#### #setGridPos + +* **h**: (type: integer, default: `8`) + Panel height. +* **w**: (type: integer, default: `12`) + Panel width. +* **x**: (type: integer, default: `null`) + Panel x position. +* **y**: (type: integer, default: `null`) + Panel y position. +#### #setOptions + +* **calcs**: (type: array, default: `["mean"]`) + +* **fields**: (type: string, default: `null`) + +* **orientation**: (type: string, default: `"auto"`) + +* **showThresholdLabels**: (type: boolean, default: `false`) + +* **showThresholdMarkers**: (type: boolean, default: `true`) + +* **values**: (type: boolean, default: `false`) + + +#### #addDataLink + +* **targetBlank**: (type: boolean, default: `true`) + +* **title**: (type: string, default: `null`) + +* **url**: (type: string, default: `null`) + +#### #addPanelLink + +* **targetBlank**: (type: boolean, default: `true`) + +* **title**: (type: string, default: `null`) + +* **url**: (type: string, default: `null`) + +#### #addMapping + +* **from**: (type: string, default: `null`) + +* **id**: (type: integer, default: `null`) + +* **operator**: (type: string, default: `null`) + +* **text**: (type: string, default: `null`) + +* **to**: (type: string, default: `null`) + +* **type**: (type: integer, default: `null`) + +* **value**: (type: string, default: `null`) + +#### #addOverride + +* **matcher**: (type: oject, default: `null`) + +* **properties**: (type: array, default: `null`) + +#### #addThresholdStep + +* **color**: (type: string, default: `null`) + +* **value**: (type: integer, default: `null`) + +#### #addTarget + +* **target**: (type: object) + + + +### panel.graph.new + + + +* **bars**: (type: boolean, default: `false`) + Display values as a bar chart. +* **dashLength**: (type: integer, default: `10`) + Dashed line length. +* **dashes**: (type: boolean, default: `false`) + Show line with dashes. +* **datasource**: (type: string, default: `"default"`) + +* **decimals**: (type: integer, default: `null`) + Controls how many decimals are displayed for legend values and + graph hover tooltips. +* **description**: (type: string, default: `null`) + +* **fill**: (type: integer, default: `1`) + Amount of color fill for a series. Expects a value between 0 and 1. +* **fillGradient**: (type: integer, default: `0`) + Degree of gradient on the area fill. 0 is no gradient, 10 is a + steep gradient. +* **hiddenSeries**: (type: boolean, default: `false`) + Hide the series. +* **lines**: (type: boolean, default: `true`) + Display values as a line graph. +* **linewidth**: (type: integer, default: `1`) + The width of the line for a series. +* **nullPointMode**: (type: string, default: `"null"`) + How null values are displayed. + * 'null' - If there is a gap in the series, meaning a null value, + then the line in the graph will be broken and show the gap. + * 'null as zero' - If there is a gap in the series, meaning a null + value, then it will be displayed as a zero value in the graph + panel. + * 'connected' - If there is a gap in the series, meaning a null + value or values, then the line will skip the gap and connect to the + next non-null value. +* **percentage**: (type: boolean, default: `false`) + Available when `stack` is true. Each series is drawn as a percentage + of the total of all series. +* **pointradius**: (type: integer, default: `null`) + Controls how large the points are. +* **points**: (type: boolean, default: `false`) + Display points for values. +* **repeat**: (type: string, default: `null`) + +* **repeatDirection**: (type: string, default: `null`) + +* **spaceLength**: (type: integer, default: `10`) + Dashed line spacing when `dashes` is true. +* **stack**: (type: boolean, default: `false`) + Each series is stacked on top of another. +* **steppedLine**: (type: boolean, default: `false`) + Draws adjacent points as staircase. +* **timeFrom**: (type: string, default: `null`) + +* **timeShift**: (type: string, default: `null`) + +* **title**: (type: string, default: `null`) + +* **transparent**: (type: boolean, default: `false`) + + +#### #setGridPos + +* **h**: (type: integer, default: `8`) + Panel height. +* **w**: (type: integer, default: `12`) + Panel width. +* **x**: (type: integer, default: `null`) + Panel x position. +* **y**: (type: integer, default: `null`) + Panel y position. +#### #setLegend + +* **alignAsTable**: (type: boolean, default: `null`) + Whether to display legend in table. +* **avg**: (type: boolean, default: `false`) + Average of all values returned from the metric query. +* **current**: (type: boolean, default: `false`) + Last value returned from the metric query. +* **max**: (type: boolean, default: `false`) + Maximum of all values returned from the metric query. +* **min**: (type: boolean, default: `false`) + Minimum of all values returned from the metric query. +* **rightSide**: (type: boolean, default: `false`) + Display legend to the right. +* **show**: (type: boolean, default: `true`) + Show or hide the legend. +* **sideWidth**: (type: integer, default: `null`) + Available when `rightSide` is true. The minimum width for the legend in + pixels. +* **total**: (type: boolean, default: `false`) + Sum of all values returned from the metric query. +* **values**: (type: boolean, default: `true`) + +#### #setThresholds + +* **thresholdMode**: (type: string, default: `"absolute"`) + +#### #setTooltip + +* **shared**: (type: boolean, default: `true`) + * true - The hover tooltip shows all series in the graph. + Grafana highlights the series that you are hovering over in + bold in the series list in the tooltip. + * false - The hover tooltip shows only a single series, the one + that you are hovering over on the graph. +* **sort**: (type: integer, default: `2`) + * 0 (none) - The order of the series in the tooltip is + determined by the sort order in your query. For example, they + could be alphabetically sorted by series name. + * 1 (increasing) - The series in the hover tooltip are sorted + by value and in increasing order, with the lowest value at the + top of the list. + * 2 (decreasing) - The series in the hover tooltip are sorted + by value and in decreasing order, with the highest value at the + top of the list. +#### #setXaxis + +* **buckets**: (type: string, default: `null`) + +* **mode**: (type: string, default: `"time"`) + The display mode completely changes the visualization of the + graph panel. It’s like three panels in one. The main mode is + the time series mode with time on the X-axis. The other two + modes are a basic bar chart mode with series on the X-axis + instead of time and a histogram mode. + * 'time' - The X-axis represents time and that the data is + grouped by time (for example, by hour, or by minute). + * 'series' - The data is grouped by series and not by time. The + Y-axis still represents the value. + * 'histogram' - Converts the graph into a histogram. A histogram + is a kind of bar chart that groups numbers into ranges, often + called buckets or bins. Taller bars show that more data falls + in that range. +* **name**: (type: string, default: `null`) + +* **show**: (type: boolean, default: `true`) + Show or hide the axis. +#### #setYaxis + +* **align**: (type: boolean, default: `false`) + Align left and right Y-axes by value. +* **alignLevel**: (type: integer, default: `0`) + Available when align is true. Value to use for alignment of + left and right Y-axes, starting from Y=0. + +#### #addDataLink + +* **targetBlank**: (type: boolean, default: `true`) + +* **title**: (type: string, default: `null`) + +* **url**: (type: string, default: `null`) + +#### #addPanelLink + +* **targetBlank**: (type: boolean, default: `true`) + +* **title**: (type: string, default: `null`) + +* **url**: (type: string, default: `null`) + +#### #addOverride + +* **matcher**: (type: oject, default: `null`) + +* **properties**: (type: array, default: `null`) + +#### #addSeriesOverride + +* **alias**: (type: string, default: `null`) + Alias or regex matching the series you'd like to target. +* **bars**: (type: boolean, default: `null`) + +* **color**: (type: string, default: `null`) + +* **dashLength**: (type: integer, default: `null`) + +* **dashes**: (type: boolean, default: `null`) + +* **fill**: (type: integer, default: `null`) + +* **fillBelowTo**: (type: string, default: `null`) + +* **fillGradient**: (type: integer, default: `null`) + +* **hiddenSeries**: (type: boolean, default: `null`) + +* **hideTooltip**: (type: boolean, default: `null`) + +* **legend**: (type: boolean, default: `null`) + +* **lines**: (type: boolean, default: `null`) + +* **linewidth**: (type: integer, default: `null`) + +* **nullPointMode**: (type: string, default: `null`) + +* **pointradius**: (type: integer, default: `null`) + +* **points**: (type: boolean, default: `null`) + +* **spaceLength**: (type: integer, default: `null`) + +* **stack**: (type: integer, default: `null`) + +* **steppedLine**: (type: boolean, default: `null`) + +* **transform**: (type: string, default: `null`) + +* **yaxis**: (type: integer, default: `null`) + +* **zindex**: (type: integer, default: `null`) + +#### #addThresholdStep + +* **color**: (type: string, default: `null`) + +* **value**: (type: integer, default: `null`) + +#### #addTarget + +* **target**: (type: object) + +#### #addYaxis + +* **decimals**: (type: integer, default: `null`) + Defines how many decimals are displayed for Y value. +* **format**: (type: string, default: `"short"`) + The display unit for the Y value. +* **label**: (type: string, default: `null`) + The Y axis label. +* **logBase**: (type: integer, default: `1`) + The scale to use for the Y value - linear, or logarithmic. + * 1 - linear + * 2 - log (base 2) + * 10 - log (base 10) + * 32 - log (base 32) + * 1024 - log (base 1024) +* **max**: (type: integer, default: `null`) + The maximum Y value. +* **min**: (type: integer, default: `null`) + The minimum Y value. +* **show**: (type: boolean, default: `true`) + Show or hide the axis. + + +### panel.row.new + + + +* **collapse**: (type: boolean, default: `true`) + +* **collapsed**: (type: boolean, default: `true`) + +* **datasource**: (type: string, default: `null`) + +* **repeat**: (type: string, default: `null`) + +* **repeatIteration**: (type: string, default: `null`) + +* **showTitle**: (type: boolean, default: `true`) + +* **title**: (type: string, default: `null`) + +* **titleSize**: (type: string, default: `"h6"`) + + +#### #setGridPos + +* **h**: (type: integer, default: `8`) + Panel height. +* **w**: (type: integer, default: `12`) + Panel width. +* **x**: (type: integer, default: `null`) + Panel x position. +* **y**: (type: integer, default: `null`) + Panel y position. + +#### #addPanel + +* **panel**: (type: object) + + + +### panel.stat.new + + + +* **datasource**: (type: string, default: `"default"`) + +* **description**: (type: string, default: `null`) + +* **repeat**: (type: string, default: `null`) + +* **repeatDirection**: (type: string, default: `null`) + +* **title**: (type: string, default: `null`) + +* **transparent**: (type: boolean, default: `false`) + + +#### #setFieldConfig + +* **max**: (type: integer, default: `null`) + +* **min**: (type: integer, default: `null`) + +* **thresholdMode**: (type: string, default: `"absolute"`) + +* **unit**: (type: string, default: `null`) + +#### #setGridPos + +* **h**: (type: integer, default: `8`) + Panel height. +* **w**: (type: integer, default: `12`) + Panel width. +* **x**: (type: integer, default: `null`) + Panel x position. +* **y**: (type: integer, default: `null`) + Panel y position. +#### #setOptions + +* **calcs**: (type: array, default: `["mean"]`) + +* **colorMode**: (type: string, default: `"value"`) + +* **fields**: (type: string, default: `null`) + +* **graphMode**: (type: string, default: `"none"`) + +* **justifyMode**: (type: string, default: `"auto"`) + +* **orientation**: (type: string, default: `"auto"`) + +* **textMode**: (type: string, default: `"auto"`) + +* **values**: (type: boolean, default: `false`) + + +#### #addDataLink + +* **targetBlank**: (type: boolean, default: `true`) + +* **title**: (type: string, default: `null`) + +* **url**: (type: string, default: `null`) + +#### #addPanelLink + +* **targetBlank**: (type: boolean, default: `true`) + +* **title**: (type: string, default: `null`) + +* **url**: (type: string, default: `null`) + +#### #addMapping + +* **from**: (type: string, default: `null`) + +* **id**: (type: integer, default: `null`) + +* **operator**: (type: string, default: `null`) + +* **text**: (type: string, default: `null`) + +* **to**: (type: string, default: `null`) + +* **type**: (type: integer, default: `null`) + +* **value**: (type: string, default: `null`) + +#### #addOverride + +* **matcher**: (type: oject, default: `null`) + +* **properties**: (type: array, default: `null`) + +#### #addThresholdStep + +* **color**: (type: string, default: `null`) + +* **value**: (type: integer, default: `null`) + +#### #addTarget + +* **target**: (type: object) + + + +### panel.table.new + + + +* **datasource**: (type: string, default: `"default"`) + +* **description**: (type: string, default: `null`) + +* **repeat**: (type: string, default: `null`) + +* **repeatDirection**: (type: string, default: `null`) + +* **title**: (type: string, default: `null`) + +* **transparent**: (type: boolean, default: `false`) + + +#### #setFieldConfig + +* **displayName**: (type: string, default: `null`) + +* **max**: (type: integer, default: `null`) + +* **min**: (type: integer, default: `null`) + +* **thresholdMode**: (type: string, default: `"absolute"`) + +* **noValue**: (type: string, default: `null`) + +* **unit**: (type: string, default: `"short"`) + +* **width**: (type: integer, default: `null`) + +#### #setGridPos + +* **h**: (type: integer, default: `8`) + Panel height. +* **w**: (type: integer, default: `12`) + Panel width. +* **x**: (type: integer, default: `null`) + Panel x position. +* **y**: (type: integer, default: `null`) + Panel y position. +#### #setOptions + +* **showHeader**: (type: boolean, default: `true`) + + +#### #addDataLink + +* **targetBlank**: (type: boolean, default: `true`) + +* **title**: (type: string, default: `null`) + +* **url**: (type: string, default: `null`) + +#### #addPanelLink + +* **targetBlank**: (type: boolean, default: `true`) + +* **title**: (type: string, default: `null`) + +* **url**: (type: string, default: `null`) + +#### #addMapping + +* **from**: (type: string, default: `null`) + +* **id**: (type: integer, default: `null`) + +* **operator**: (type: string, default: `null`) + +* **text**: (type: string, default: `null`) + +* **to**: (type: string, default: `null`) + +* **type**: (type: integer, default: `null`) + +* **value**: (type: string, default: `null`) + +#### #addOverride + +* **matcher**: (type: oject, default: `null`) + +* **properties**: (type: array, default: `null`) + +#### #addThresholdStep + +* **color**: (type: string, default: `null`) + +* **value**: (type: integer, default: `null`) + +#### #addTarget + +* **target**: (type: object) + + + +### panel.text.new + + + +* **content**: (type: string, default: `null`) + +* **datasource**: (type: string, default: `"default"`) + +* **description**: (type: string, default: `null`) + +* **mode**: (type: string, default: `"markdown"`) + +* **repeat**: (type: string, default: `null`) + +* **repeatDirection**: (type: string, default: `null`) + +* **title**: (type: string, default: `null`) + +* **transparent**: (type: boolean, default: `false`) + + +#### #setGridPos + +* **h**: (type: integer, default: `8`) + Panel height. +* **w**: (type: integer, default: `12`) + Panel width. +* **x**: (type: integer, default: `null`) + Panel x position. +* **y**: (type: integer, default: `null`) + Panel y position. + +#### #addPanelLink + +* **targetBlank**: (type: boolean, default: `true`) + +* **title**: (type: string, default: `null`) + +* **url**: (type: string, default: `null`) + +#### #addTarget + +* **target**: (type: object) + + + + +## target + + + +### target.prometheus.new + + + +* **datasource**: (type: string, default: `"default"`) + +* **expr**: (type: string, default: `null`) + +* **format**: (type: string, default: `"time_series"`) + +* **instant**: (type: boolean, default: `null`) + +* **interval**: (type: string, default: `null`) + +* **intervalFactor**: (type: integer, default: `null`) + +* **legendFormat**: (type: string, default: `null`) + + + + + + +## template + + + +### template.custom.new + + + +* **allValue**: (type: string, default: `null`) + +* **hide**: (type: integer, default: `0`) + +* **includeAll**: (type: boolean, default: `false`) + +* **label**: (type: string, default: `null`) + +* **multi**: (type: boolean, default: `false`) + +* **name**: (type: string, default: `null`) + +* **query**: (type: string, default: `null`) + +* **queryValue**: (type: string, default: `""`) + +* **skipUrlSync**: (type: string, default: `false`) + + +#### #setCurrent + +* **selected**: (type: boolean, default: `false`) + +* **text**: (type: string, default: `null`) + +* **value**: (type: string, default: `null`) + + + + +### template.datasource.new + + + +* **hide**: (type: integer, default: `0`) + +* **includeAll**: (type: boolean, default: `false`) + +* **label**: (type: string, default: `null`) + +* **multi**: (type: boolean, default: `false`) + +* **name**: (type: string, default: `null`) + +* **query**: (type: string, default: `null`) + +* **refresh**: (type: integer, default: `1`) + +* **regex**: (type: string, default: `null`) + +* **skipUrlSync**: (type: string, default: `false`) + + +#### #setCurrent + +* **selected**: (type: boolean, default: `false`) + +* **text**: (type: string, default: `null`) + +* **value**: (type: string, default: `null`) + + + + +### template.query.new + + + +* **allValue**: (type: string, default: `null`) + +* **datasource**: (type: string, default: `null`) + +* **definition**: (type: string, default: `null`) + +* **hide**: (type: integer, default: `0`) + +* **includeAll**: (type: boolean, default: `false`) + +* **label**: (type: string, default: `null`) + +* **multi**: (type: boolean, default: `false`) + +* **name**: (type: string, default: `null`) + +* **query**: (type: string, default: `null`) + +* **refresh**: (type: integer, default: `0`) + +* **regex**: (type: string, default: `null`) + +* **skipUrlSync**: (type: string, default: `false`) + +* **sort**: (type: integer, default: `0`) + +* **tagValuesQuery**: (type: string, default: `null`) + +* **tags**: (type: array, default: `null`) + +* **tagsQuery**: (type: string, default: `null`) + +* **useTags**: (type: boolean, default: `false`) + + +#### #setCurrent + +* **selected**: (type: boolean, default: `null`) + +* **text**: (type: string, default: `null`) + +* **value**: (type: string, default: `null`) + + +#### #addOption + +* **selected**: (type: boolean, default: `true`) + +* **text**: (type: string, default: `null`) + +* **value**: (type: string, default: `null`) + + + diff --git a/embeds/grafonnet-lib/grafonnet-7.0/dashboard.libsonnet b/embeds/grafonnet-lib/grafonnet-7.0/dashboard.libsonnet new file mode 100644 index 000000000..faa25c651 --- /dev/null +++ b/embeds/grafonnet-lib/grafonnet-7.0/dashboard.libsonnet @@ -0,0 +1,87 @@ +// This file was generated by https://github.com/grafana/dashboard-spec + +{ + new( + description=null, + editable=true, + graphTooltip=0, + refresh=null, + schemaVersion=25, + style='dark', + tags=[], + timezone=null, + title=null, + uid=null, + ):: { + [if description != null then 'description']: description, + [if editable != null then 'editable']: editable, + [if graphTooltip != null then 'graphTooltip']: graphTooltip, + [if refresh != null then 'refresh']: refresh, + [if schemaVersion != null then 'schemaVersion']: schemaVersion, + [if style != null then 'style']: style, + [if tags != null then 'tags']: tags, + [if timezone != null then 'timezone']: timezone, + [if title != null then 'title']: title, + [if uid != null then 'uid']: uid, + + setTime( + from='now-6h', + to='now', + ):: self {} + + { time+: { [if from != null then 'from']: from } } + + { time+: { [if to != null then 'to']: to } } + , + + setTimepicker( + hidden=false, + refreshIntervals=['5s', '10s', '30s', '1m', '5m', '15m', '30m', '1h', '2h', '1d'], + ):: self {} + + { timepicker+: { [if hidden != null then 'hidden']: hidden } } + + { timepicker+: { [if refreshIntervals != null then 'refresh_intervals']: refreshIntervals } } + , + + + addTemplate( + template + ):: self {} + + { templating+: { list+: [ + template, + ] } }, + + addAnnotation( + builtIn=0, + datasource='default', + enable=true, + hide=false, + iconColor=null, + name=null, + rawQuery=null, + showIn=0, + ):: self {} + + { annotations+: { list+: [ + { + [if builtIn != null then 'builtIn']: builtIn, + [if datasource != null then 'datasource']: datasource, + [if enable != null then 'enable']: enable, + [if hide != null then 'hide']: hide, + [if iconColor != null then 'iconColor']: iconColor, + [if name != null then 'name']: name, + [if rawQuery != null then 'rawQuery']: rawQuery, + [if showIn != null then 'showIn']: showIn, + }, + ] } }, + + + panels: [], + _nextPanelID:: 2, + addPanel(panel):: self { + local nextPanelID = super._nextPanelID, + panels+: [ + panel { id: nextPanelID } + + if 'panels' in panel then { panels: std.mapWithIndex(function(i, p) p { id: nextPanelID + i + 1 }, panel.panels) } else {}, + ], + _nextPanelID:: nextPanelID + 1 + (if 'panels' in panel then std.length(panel.panels) else 0), + }, + addPanels(panels):: std.foldl(function(d, p) d.addPanel(p), panels, self), + }, +} diff --git a/embeds/grafonnet-lib/grafonnet-7.0/grafana.libsonnet b/embeds/grafonnet-lib/grafonnet-7.0/grafana.libsonnet new file mode 100644 index 000000000..28e65d1db --- /dev/null +++ b/embeds/grafonnet-lib/grafonnet-7.0/grafana.libsonnet @@ -0,0 +1,21 @@ +// This file was generated by https://github.com/grafana/dashboard-spec + +{ + dashboard:: import 'dashboard.libsonnet', + panel:: { + gauge:: import 'panel/gauge.libsonnet', + graph:: import 'panel/graph.libsonnet', + row:: import 'panel/row.libsonnet', + stat:: import 'panel/stat.libsonnet', + table:: import 'panel/table.libsonnet', + text:: import 'panel/text.libsonnet', + }, + target:: { + prometheus:: import 'target/prometheus.libsonnet', + }, + template:: { + custom:: import 'template/custom.libsonnet', + datasource:: import 'template/datasource.libsonnet', + query:: import 'template/query.libsonnet', + }, +} diff --git a/embeds/grafonnet-lib/grafonnet-7.0/panel/gauge.libsonnet b/embeds/grafonnet-lib/grafonnet-7.0/panel/gauge.libsonnet new file mode 100644 index 000000000..715c44458 --- /dev/null +++ b/embeds/grafonnet-lib/grafonnet-7.0/panel/gauge.libsonnet @@ -0,0 +1,138 @@ +// This file was generated by https://github.com/grafana/dashboard-spec + +{ + new( + datasource='default', + description=null, + repeat=null, + repeatDirection=null, + title=null, + transparent=false, + ):: { + [if datasource != null then 'datasource']: datasource, + [if description != null then 'description']: description, + [if repeat != null then 'repeat']: repeat, + [if repeatDirection != null then 'repeatDirection']: repeatDirection, + [if title != null then 'title']: title, + [if transparent != null then 'transparent']: transparent, + type: 'gauge', + + setFieldConfig( + max=null, + min=null, + thresholdMode='absolute', + unit=null, + ):: self {} + + { fieldConfig+: { defaults+: { [if max != null then 'max']: max } } } + + { fieldConfig+: { defaults+: { [if min != null then 'min']: min } } } + + { fieldConfig+: { defaults+: { thresholds+: { [if thresholdMode != null then 'mode']: thresholdMode } } } } + + { fieldConfig+: { defaults+: { [if unit != null then 'unit']: unit } } } + , + + setGridPos( + h=8, + w=12, + x=null, + y=null, + ):: self {} + + { gridPos+: { [if h != null then 'h']: h } } + + { gridPos+: { [if w != null then 'w']: w } } + + { gridPos+: { [if x != null then 'x']: x } } + + { gridPos+: { [if y != null then 'y']: y } } + , + + setOptions( + calcs=['mean'], + fields=null, + orientation='auto', + showThresholdLabels=false, + showThresholdMarkers=true, + values=false, + ):: self {} + + { options+: { reduceOptions+: { [if calcs != null then 'calcs']: calcs } } } + + { options+: { reduceOptions+: { [if fields != null then 'fields']: fields } } } + + { options+: { [if orientation != null then 'orientation']: orientation } } + + { options+: { [if showThresholdLabels != null then 'showThresholdLabels']: showThresholdLabels } } + + { options+: { [if showThresholdMarkers != null then 'showThresholdMarkers']: showThresholdMarkers } } + + { options+: { reduceOptions+: { [if values != null then 'values']: values } } } + , + + + addPanelLink( + targetBlank=true, + title=null, + url=null, + ):: self {} + + { links+: [ + { + [if targetBlank != null then 'targetBlank']: targetBlank, + [if title != null then 'title']: title, + [if url != null then 'url']: url, + }, + ] }, + + addDataLink( + targetBlank=true, + title=null, + url=null, + ):: self {} + + { fieldConfig+: { defaults+: { links+: [ + { + [if targetBlank != null then 'targetBlank']: targetBlank, + [if title != null then 'title']: title, + [if url != null then 'url']: url, + }, + ] } } }, + + addMapping( + from=null, + id=null, + operator=null, + text=null, + to=null, + type=null, + value=null, + ):: self {} + + { fieldConfig+: { defaults+: { mappings+: [ + { + [if from != null then 'from']: from, + [if id != null then 'id']: id, + [if operator != null then 'operator']: operator, + [if text != null then 'text']: text, + [if to != null then 'to']: to, + [if type != null then 'type']: type, + [if value != null then 'value']: value, + }, + ] } } }, + + addOverride( + matcher=null, + properties=null, + ):: self {} + + { fieldConfig+: { overrides+: [ + { + [if matcher != null then 'matcher']: matcher, + [if properties != null then 'properties']: properties, + }, + ] } }, + + addThresholdStep( + color=null, + value=null, + ):: self {} + + { fieldConfig+: { defaults+: { thresholds+: { steps+: [ + { + [if color != null then 'color']: color, + [if value != null then 'value']: value, + }, + ] } } } }, + + addTarget( + target + ):: self {} + + { targets+: [ + target, + ] }, + + }, +} diff --git a/embeds/grafonnet-lib/grafonnet-7.0/panel/graph.libsonnet b/embeds/grafonnet-lib/grafonnet-7.0/panel/graph.libsonnet new file mode 100644 index 000000000..34985a188 --- /dev/null +++ b/embeds/grafonnet-lib/grafonnet-7.0/panel/graph.libsonnet @@ -0,0 +1,257 @@ +// This file was generated by https://github.com/grafana/dashboard-spec + +{ + new( + bars=false, + dashLength=10, + dashes=false, + datasource='default', + decimals=null, + description=null, + fill=1, + fillGradient=0, + hiddenSeries=false, + lines=true, + linewidth=1, + nullPointMode='null', + percentage=false, + pointradius=null, + points=false, + repeat=null, + repeatDirection=null, + spaceLength=10, + stack=false, + steppedLine=false, + timeFrom=null, + timeShift=null, + title=null, + transparent=false, + ):: { + [if bars != null then 'bars']: bars, + [if dashLength != null then 'dashLength']: dashLength, + [if dashes != null then 'dashes']: dashes, + [if datasource != null then 'datasource']: datasource, + [if decimals != null then 'decimals']: decimals, + [if description != null then 'description']: description, + [if fill != null then 'fill']: fill, + [if fillGradient != null then 'fillGradient']: fillGradient, + [if hiddenSeries != null then 'hiddenSeries']: hiddenSeries, + [if lines != null then 'lines']: lines, + [if linewidth != null then 'linewidth']: linewidth, + [if nullPointMode != null then 'nullPointMode']: nullPointMode, + [if percentage != null then 'percentage']: percentage, + [if pointradius != null then 'pointradius']: pointradius, + [if points != null then 'points']: points, + [if repeat != null then 'repeat']: repeat, + [if repeatDirection != null then 'repeatDirection']: repeatDirection, + [if spaceLength != null then 'spaceLength']: spaceLength, + [if stack != null then 'stack']: stack, + [if steppedLine != null then 'steppedLine']: steppedLine, + [if timeFrom != null then 'timeFrom']: timeFrom, + [if timeShift != null then 'timeShift']: timeShift, + [if title != null then 'title']: title, + [if transparent != null then 'transparent']: transparent, + renderer: 'flot', + type: 'graph', + tooltip+: { value_type: 'individual' }, + + setGridPos( + h=8, + w=12, + x=null, + y=null, + ):: self {} + + { gridPos+: { [if h != null then 'h']: h } } + + { gridPos+: { [if w != null then 'w']: w } } + + { gridPos+: { [if x != null then 'x']: x } } + + { gridPos+: { [if y != null then 'y']: y } } + , + + setLegend( + alignAsTable=null, + avg=false, + current=false, + max=false, + min=false, + rightSide=false, + show=true, + sideWidth=null, + total=false, + values=true, + ):: self {} + + { legend+: { [if alignAsTable != null then 'alignAsTable']: alignAsTable } } + + { legend+: { [if avg != null then 'avg']: avg } } + + { legend+: { [if current != null then 'current']: current } } + + { legend+: { [if max != null then 'max']: max } } + + { legend+: { [if min != null then 'min']: min } } + + { legend+: { [if rightSide != null then 'rightSide']: rightSide } } + + { legend+: { [if show != null then 'show']: show } } + + { legend+: { [if sideWidth != null then 'sideWidth']: sideWidth } } + + { legend+: { [if total != null then 'total']: total } } + + { legend+: { [if values != null then 'values']: values } } + , + + setThresholds( + thresholdMode='absolute', + ):: self {} + + { thresholds+: { [if thresholdMode != null then 'mode']: thresholdMode } } + , + + setTooltip( + shared=true, + sort=2, + ):: self {} + + { tooltip+: { [if shared != null then 'shared']: shared } } + + { tooltip+: { [if sort != null then 'sort']: sort } } + , + + setXaxis( + buckets=null, + mode='time', + name=null, + show=true, + ):: self {} + + { xaxis+: { [if buckets != null then 'buckets']: buckets } } + + { xaxis+: { [if mode != null then 'mode']: mode } } + + { xaxis+: { [if name != null then 'name']: name } } + + { xaxis+: { [if show != null then 'show']: show } } + , + + setYaxis( + align=false, + alignLevel=0, + ):: self {} + + { yaxis+: { [if align != null then 'align']: align } } + + { yaxis+: { [if alignLevel != null then 'alignLevel']: alignLevel } } + , + + + addDataLink( + targetBlank=true, + title=null, + url=null, + ):: self {} + + { options+: { dataLinks+: [ + { + [if targetBlank != null then 'targetBlank']: targetBlank, + [if title != null then 'title']: title, + [if url != null then 'url']: url, + }, + ] } }, + + addPanelLink( + targetBlank=true, + title=null, + url=null, + ):: self {} + + { links+: [ + { + [if targetBlank != null then 'targetBlank']: targetBlank, + [if title != null then 'title']: title, + [if url != null then 'url']: url, + }, + ] }, + + addOverride( + matcher=null, + properties=null, + ):: self {} + + { fieldConfig+: { overrides+: [ + { + [if matcher != null then 'matcher']: matcher, + [if properties != null then 'properties']: properties, + }, + ] } }, + + addSeriesOverride( + alias=null, + bars=null, + color=null, + dashLength=null, + dashes=null, + fill=null, + fillBelowTo=null, + fillGradient=null, + hiddenSeries=null, + hideTooltip=null, + legend=null, + lines=null, + linewidth=null, + nullPointMode=null, + pointradius=null, + points=null, + spaceLength=null, + stack=null, + steppedLine=null, + transform=null, + yaxis=null, + zindex=null, + ):: self {} + + { seriesOverrides+: [ + { + [if alias != null then 'alias']: alias, + [if bars != null then 'bars']: bars, + [if color != null then 'color']: color, + [if dashLength != null then 'dashLength']: dashLength, + [if dashes != null then 'dashes']: dashes, + [if fill != null then 'fill']: fill, + [if fillBelowTo != null then 'fillBelowTo']: fillBelowTo, + [if fillGradient != null then 'fillGradient']: fillGradient, + [if hiddenSeries != null then 'hiddenSeries']: hiddenSeries, + [if hideTooltip != null then 'hideTooltip']: hideTooltip, + [if legend != null then 'legend']: legend, + [if lines != null then 'lines']: lines, + [if linewidth != null then 'linewidth']: linewidth, + [if nullPointMode != null then 'nullPointMode']: nullPointMode, + [if pointradius != null then 'pointradius']: pointradius, + [if points != null then 'points']: points, + [if spaceLength != null then 'spaceLength']: spaceLength, + [if stack != null then 'stack']: stack, + [if steppedLine != null then 'steppedLine']: steppedLine, + [if transform != null then 'transform']: transform, + [if yaxis != null then 'yaxis']: yaxis, + [if zindex != null then 'zindex']: zindex, + }, + ] }, + + addThresholdStep( + color=null, + value=null, + ):: self {} + + { thresholds+: { steps+: [ + { + [if color != null then 'color']: color, + [if value != null then 'value']: value, + }, + ] } }, + + addTarget( + target + ):: self {} + + { targets+: [ + target, + ] }, + + addYaxis( + decimals=null, + format='short', + label=null, + logBase=1, + max=null, + min=null, + show=true, + ):: self {} + + { yaxes+: [ + { + [if decimals != null then 'decimals']: decimals, + [if format != null then 'format']: format, + [if label != null then 'label']: label, + [if logBase != null then 'logBase']: logBase, + [if max != null then 'max']: max, + [if min != null then 'min']: min, + [if show != null then 'show']: show, + }, + ] }, + + }, +} diff --git a/embeds/grafonnet-lib/grafonnet-7.0/panel/row.libsonnet b/embeds/grafonnet-lib/grafonnet-7.0/panel/row.libsonnet new file mode 100644 index 000000000..e8a21d361 --- /dev/null +++ b/embeds/grafonnet-lib/grafonnet-7.0/panel/row.libsonnet @@ -0,0 +1,45 @@ +// This file was generated by https://github.com/grafana/dashboard-spec + +{ + new( + collapse=true, + collapsed=true, + datasource=null, + repeat=null, + repeatIteration=null, + showTitle=true, + title=null, + titleSize='h6', + ):: { + [if collapse != null then 'collapse']: collapse, + [if collapsed != null then 'collapsed']: collapsed, + [if datasource != null then 'datasource']: datasource, + [if repeat != null then 'repeat']: repeat, + [if repeatIteration != null then 'repeatIteration']: repeatIteration, + [if showTitle != null then 'showTitle']: showTitle, + [if title != null then 'title']: title, + [if titleSize != null then 'titleSize']: titleSize, + type: 'row', + + setGridPos( + h=8, + w=12, + x=null, + y=null, + ):: self {} + + { gridPos+: { [if h != null then 'h']: h } } + + { gridPos+: { [if w != null then 'w']: w } } + + { gridPos+: { [if x != null then 'x']: x } } + + { gridPos+: { [if y != null then 'y']: y } } + , + + + addPanel( + panel + ):: self {} + + { panels+: [ + panel, + ] }, + + }, +} diff --git a/embeds/grafonnet-lib/grafonnet-7.0/panel/stat.libsonnet b/embeds/grafonnet-lib/grafonnet-7.0/panel/stat.libsonnet new file mode 100644 index 000000000..a14c9380e --- /dev/null +++ b/embeds/grafonnet-lib/grafonnet-7.0/panel/stat.libsonnet @@ -0,0 +1,142 @@ +// This file was generated by https://github.com/grafana/dashboard-spec + +{ + new( + datasource='default', + description=null, + repeat=null, + repeatDirection=null, + title=null, + transparent=false, + ):: { + [if datasource != null then 'datasource']: datasource, + [if description != null then 'description']: description, + [if repeat != null then 'repeat']: repeat, + [if repeatDirection != null then 'repeatDirection']: repeatDirection, + [if title != null then 'title']: title, + [if transparent != null then 'transparent']: transparent, + type: 'stat', + + setFieldConfig( + max=null, + min=null, + thresholdMode='absolute', + unit=null, + ):: self {} + + { fieldConfig+: { defaults+: { [if max != null then 'max']: max } } } + + { fieldConfig+: { defaults+: { [if min != null then 'min']: min } } } + + { fieldConfig+: { defaults+: { thresholds+: { [if thresholdMode != null then 'mode']: thresholdMode } } } } + + { fieldConfig+: { defaults+: { [if unit != null then 'unit']: unit } } } + , + + setGridPos( + h=8, + w=12, + x=null, + y=null, + ):: self {} + + { gridPos+: { [if h != null then 'h']: h } } + + { gridPos+: { [if w != null then 'w']: w } } + + { gridPos+: { [if x != null then 'x']: x } } + + { gridPos+: { [if y != null then 'y']: y } } + , + + setOptions( + calcs=['mean'], + colorMode='value', + fields=null, + graphMode='none', + justifyMode='auto', + orientation='auto', + textMode='auto', + values=false, + ):: self {} + + { options+: { reduceOptions+: { [if calcs != null then 'calcs']: calcs } } } + + { options+: { [if colorMode != null then 'colorMode']: colorMode } } + + { options+: { reduceOptions+: { [if fields != null then 'fields']: fields } } } + + { options+: { [if graphMode != null then 'graphMode']: graphMode } } + + { options+: { [if justifyMode != null then 'justifyMode']: justifyMode } } + + { options+: { [if orientation != null then 'orientation']: orientation } } + + { options+: { [if textMode != null then 'textMode']: textMode } } + + { options+: { reduceOptions+: { [if values != null then 'values']: values } } } + , + + + addPanelLink( + targetBlank=true, + title=null, + url=null, + ):: self {} + + { links+: [ + { + [if targetBlank != null then 'targetBlank']: targetBlank, + [if title != null then 'title']: title, + [if url != null then 'url']: url, + }, + ] }, + + addDataLink( + targetBlank=true, + title=null, + url=null, + ):: self {} + + { fieldConfig+: { defaults+: { links+: [ + { + [if targetBlank != null then 'targetBlank']: targetBlank, + [if title != null then 'title']: title, + [if url != null then 'url']: url, + }, + ] } } }, + + addMapping( + from=null, + id=null, + operator=null, + text=null, + to=null, + type=null, + value=null, + ):: self {} + + { fieldConfig+: { defaults+: { mappings+: [ + { + [if from != null then 'from']: from, + [if id != null then 'id']: id, + [if operator != null then 'operator']: operator, + [if text != null then 'text']: text, + [if to != null then 'to']: to, + [if type != null then 'type']: type, + [if value != null then 'value']: value, + }, + ] } } }, + + addOverride( + matcher=null, + properties=null, + ):: self {} + + { fieldConfig+: { overrides+: [ + { + [if matcher != null then 'matcher']: matcher, + [if properties != null then 'properties']: properties, + }, + ] } }, + + addThresholdStep( + color=null, + value=null, + ):: self {} + + { fieldConfig+: { defaults+: { thresholds+: { steps+: [ + { + [if color != null then 'color']: color, + [if value != null then 'value']: value, + }, + ] } } } }, + + addTarget( + target + ):: self {} + + { targets+: [ + target, + ] }, + + }, +} diff --git a/embeds/grafonnet-lib/grafonnet-7.0/panel/table.libsonnet b/embeds/grafonnet-lib/grafonnet-7.0/panel/table.libsonnet new file mode 100644 index 000000000..981d1ea27 --- /dev/null +++ b/embeds/grafonnet-lib/grafonnet-7.0/panel/table.libsonnet @@ -0,0 +1,134 @@ +// This file was generated by https://github.com/grafana/dashboard-spec + +{ + new( + datasource='default', + description=null, + repeat=null, + repeatDirection=null, + title=null, + transparent=false, + ):: { + [if datasource != null then 'datasource']: datasource, + [if description != null then 'description']: description, + [if repeat != null then 'repeat']: repeat, + [if repeatDirection != null then 'repeatDirection']: repeatDirection, + [if title != null then 'title']: title, + [if transparent != null then 'transparent']: transparent, + type: 'table', + + setFieldConfig( + displayName=null, + max=null, + min=null, + thresholdMode='absolute', + noValue=null, + unit='short', + width=null, + ):: self {} + + { fieldConfig+: { defaults+: { [if displayName != null then 'displayName']: displayName } } } + + { fieldConfig+: { defaults+: { [if max != null then 'max']: max } } } + + { fieldConfig+: { defaults+: { [if min != null then 'min']: min } } } + + { fieldConfig+: { defaults+: { thresholds+: { [if thresholdMode != null then 'mode']: thresholdMode } } } } + + { fieldConfig+: { defaults+: { [if noValue != null then 'noValue']: noValue } } } + + { fieldConfig+: { defaults+: { [if unit != null then 'unit']: unit } } } + + { fieldConfig+: { defaults+: { custom+: { [if width != null then 'width']: width } } } } + , + + setGridPos( + h=8, + w=12, + x=null, + y=null, + ):: self {} + + { gridPos+: { [if h != null then 'h']: h } } + + { gridPos+: { [if w != null then 'w']: w } } + + { gridPos+: { [if x != null then 'x']: x } } + + { gridPos+: { [if y != null then 'y']: y } } + , + + setOptions( + showHeader=true, + ):: self {} + + { options+: { [if showHeader != null then 'showHeader']: showHeader } } + , + + + addDataLink( + targetBlank=true, + title=null, + url=null, + ):: self {} + + { fieldConfig+: { defaults+: { links+: [ + { + [if targetBlank != null then 'targetBlank']: targetBlank, + [if title != null then 'title']: title, + [if url != null then 'url']: url, + }, + ] } } }, + + addPanelLink( + targetBlank=true, + title=null, + url=null, + ):: self {} + + { links+: [ + { + [if targetBlank != null then 'targetBlank']: targetBlank, + [if title != null then 'title']: title, + [if url != null then 'url']: url, + }, + ] }, + + addMapping( + from=null, + id=null, + operator=null, + text=null, + to=null, + type=null, + value=null, + ):: self {} + + { fieldConfig+: { defaults+: { mappings+: [ + { + [if from != null then 'from']: from, + [if id != null then 'id']: id, + [if operator != null then 'operator']: operator, + [if text != null then 'text']: text, + [if to != null then 'to']: to, + [if type != null then 'type']: type, + [if value != null then 'value']: value, + }, + ] } } }, + + addOverride( + matcher=null, + properties=null, + ):: self {} + + { fieldConfig+: { overrides+: [ + { + [if matcher != null then 'matcher']: matcher, + [if properties != null then 'properties']: properties, + }, + ] } }, + + addThresholdStep( + color=null, + value=null, + ):: self {} + + { fieldConfig+: { defaults+: { thresholds+: { steps+: [ + { + [if color != null then 'color']: color, + [if value != null then 'value']: value, + }, + ] } } } }, + + addTarget( + target + ):: self {} + + { targets+: [ + target, + ] }, + + }, +} diff --git a/embeds/grafonnet-lib/grafonnet-7.0/panel/text.libsonnet b/embeds/grafonnet-lib/grafonnet-7.0/panel/text.libsonnet new file mode 100644 index 000000000..1c4c682ac --- /dev/null +++ b/embeds/grafonnet-lib/grafonnet-7.0/panel/text.libsonnet @@ -0,0 +1,58 @@ +// This file was generated by https://github.com/grafana/dashboard-spec + +{ + new( + content=null, + datasource='default', + description=null, + mode='markdown', + repeat=null, + repeatDirection=null, + title=null, + transparent=false, + ):: { + [if content != null then 'content']: content, + [if datasource != null then 'datasource']: datasource, + [if description != null then 'description']: description, + [if mode != null then 'mode']: mode, + [if repeat != null then 'repeat']: repeat, + [if repeatDirection != null then 'repeatDirection']: repeatDirection, + [if title != null then 'title']: title, + [if transparent != null then 'transparent']: transparent, + type: 'text', + + setGridPos( + h=8, + w=12, + x=null, + y=null, + ):: self {} + + { gridPos+: { [if h != null then 'h']: h } } + + { gridPos+: { [if w != null then 'w']: w } } + + { gridPos+: { [if x != null then 'x']: x } } + + { gridPos+: { [if y != null then 'y']: y } } + , + + + addPanelLink( + targetBlank=true, + title=null, + url=null, + ):: self {} + + { links+: [ + { + [if targetBlank != null then 'targetBlank']: targetBlank, + [if title != null then 'title']: title, + [if url != null then 'url']: url, + }, + ] }, + + addTarget( + target + ):: self {} + + { targets+: [ + target, + ] }, + + }, +} diff --git a/embeds/grafonnet-lib/grafonnet-7.0/target/prometheus.libsonnet b/embeds/grafonnet-lib/grafonnet-7.0/target/prometheus.libsonnet new file mode 100644 index 000000000..e6e5fa0f6 --- /dev/null +++ b/embeds/grafonnet-lib/grafonnet-7.0/target/prometheus.libsonnet @@ -0,0 +1,21 @@ +// This file was generated by https://github.com/grafana/dashboard-spec + +{ + new( + datasource='default', + expr=null, + format='time_series', + instant=null, + interval=null, + intervalFactor=null, + legendFormat=null, + ):: { + [if datasource != null then 'datasource']: datasource, + [if expr != null then 'expr']: expr, + [if format != null then 'format']: format, + [if instant != null then 'instant']: instant, + [if interval != null then 'interval']: interval, + [if intervalFactor != null then 'intervalFactor']: intervalFactor, + [if legendFormat != null then 'legendFormat']: legendFormat, + }, +} diff --git a/embeds/grafonnet-lib/grafonnet-7.0/template/custom.libsonnet b/embeds/grafonnet-lib/grafonnet-7.0/template/custom.libsonnet new file mode 100644 index 000000000..3755b6219 --- /dev/null +++ b/embeds/grafonnet-lib/grafonnet-7.0/template/custom.libsonnet @@ -0,0 +1,36 @@ +// This file was generated by https://github.com/grafana/dashboard-spec + +{ + new( + allValue=null, + hide=0, + includeAll=false, + label=null, + multi=false, + name=null, + query=null, + queryValue='', + skipUrlSync=false, + ):: { + [if allValue != null then 'allValue']: allValue, + [if hide != null then 'hide']: hide, + [if includeAll != null then 'includeAll']: includeAll, + [if label != null then 'label']: label, + [if multi != null then 'multi']: multi, + [if name != null then 'name']: name, + [if query != null then 'query']: query, + [if queryValue != null then 'queryValue']: queryValue, + [if skipUrlSync != null then 'skipUrlSync']: skipUrlSync, + type: 'custom', + + setCurrent( + selected=false, + text=null, + value=null, + ):: self {} + + { current+: { [if selected != null then 'selected']: selected } } + + { current+: { [if text != null then 'text']: text } } + + { current+: { [if value != null then 'value']: value } }, + + }, +} diff --git a/embeds/grafonnet-lib/grafonnet-7.0/template/datasource.libsonnet b/embeds/grafonnet-lib/grafonnet-7.0/template/datasource.libsonnet new file mode 100644 index 000000000..0bdaf834a --- /dev/null +++ b/embeds/grafonnet-lib/grafonnet-7.0/template/datasource.libsonnet @@ -0,0 +1,36 @@ +// This file was generated by https://github.com/grafana/dashboard-spec + +{ + new( + hide=0, + includeAll=false, + label=null, + multi=false, + name=null, + query=null, + refresh=1, + regex=null, + skipUrlSync=false, + ):: { + [if hide != null then 'hide']: hide, + [if includeAll != null then 'includeAll']: includeAll, + [if label != null then 'label']: label, + [if multi != null then 'multi']: multi, + [if name != null then 'name']: name, + [if query != null then 'query']: query, + [if refresh != null then 'refresh']: refresh, + [if regex != null then 'regex']: regex, + [if skipUrlSync != null then 'skipUrlSync']: skipUrlSync, + type: 'datasource', + + setCurrent( + selected=false, + text=null, + value=null, + ):: self {} + + { current+: { [if selected != null then 'selected']: selected } } + + { current+: { [if text != null then 'text']: text } } + + { current+: { [if value != null then 'value']: value } }, + + }, +} diff --git a/embeds/grafonnet-lib/grafonnet-7.0/template/query.libsonnet b/embeds/grafonnet-lib/grafonnet-7.0/template/query.libsonnet new file mode 100644 index 000000000..951cef753 --- /dev/null +++ b/embeds/grafonnet-lib/grafonnet-7.0/template/query.libsonnet @@ -0,0 +1,52 @@ +// This file was generated by https://github.com/grafana/dashboard-spec + +{ + new( + allValue=null, + datasource=null, + definition=null, + hide=0, + includeAll=false, + label=null, + multi=false, + name=null, + query=null, + refresh=0, + regex=null, + skipUrlSync=false, + sort=0, + tagValuesQuery=null, + tags=null, + tagsQuery=null, + useTags=false, + ):: { + [if allValue != null then 'allValue']: allValue, + [if datasource != null then 'datasource']: datasource, + [if definition != null then 'definition']: definition, + [if hide != null then 'hide']: hide, + [if includeAll != null then 'includeAll']: includeAll, + [if label != null then 'label']: label, + [if multi != null then 'multi']: multi, + [if name != null then 'name']: name, + [if query != null then 'query']: query, + [if refresh != null then 'refresh']: refresh, + [if regex != null then 'regex']: regex, + [if skipUrlSync != null then 'skipUrlSync']: skipUrlSync, + [if sort != null then 'sort']: sort, + [if tagValuesQuery != null then 'tagValuesQuery']: tagValuesQuery, + [if tags != null then 'tags']: tags, + [if tagsQuery != null then 'tagsQuery']: tagsQuery, + [if useTags != null then 'useTags']: useTags, + type: 'query', + + setCurrent( + selected=null, + text=null, + value=null, + ):: self {} + + { current+: { [if selected != null then 'selected']: selected } } + + { current+: { [if text != null then 'text']: text } } + + { current+: { [if value != null then 'value']: value } }, + + }, +} diff --git a/embeds/grafonnet-lib/grafonnet/alert_condition.libsonnet b/embeds/grafonnet-lib/grafonnet/alert_condition.libsonnet new file mode 100644 index 000000000..163d08282 --- /dev/null +++ b/embeds/grafonnet-lib/grafonnet/alert_condition.libsonnet @@ -0,0 +1,47 @@ +{ + /** + * Returns a new condition of alert of graph panel. + * Currently the only condition type that exists is a Query condition + * that allows to specify a query letter, time range and an aggregation function. + * + * @name alertCondition.new + * + * @param evaluatorParams Value of threshold + * @param evaluatorType Type of threshold + * @param operatorType Operator between conditions + * @param queryRefId The letter defines what query to execute from the Metrics tab + * @param queryTimeStart Begging of time range + * @param queryTimeEnd End of time range + * @param reducerParams Params of an aggregation function + * @param reducerType Name of an aggregation function + * + * @return A json that represents a condition of alert + */ + new( + evaluatorParams=[], + evaluatorType='gt', + operatorType='and', + queryRefId='A', + queryTimeEnd='now', + queryTimeStart='5m', + reducerParams=[], + reducerType='avg', + ):: + { + evaluator: { + params: if std.type(evaluatorParams) == 'array' then evaluatorParams else [evaluatorParams], + type: evaluatorType, + }, + operator: { + type: operatorType, + }, + query: { + params: [queryRefId, queryTimeStart, queryTimeEnd], + }, + reducer: { + params: if std.type(reducerParams) == 'array' then reducerParams else [reducerParams], + type: reducerType, + }, + type: 'query', + }, +} diff --git a/embeds/grafonnet-lib/grafonnet/alertlist.libsonnet b/embeds/grafonnet-lib/grafonnet/alertlist.libsonnet new file mode 100644 index 000000000..94df3603e --- /dev/null +++ b/embeds/grafonnet-lib/grafonnet/alertlist.libsonnet @@ -0,0 +1,43 @@ +{ + /** + * Creates an [Alert list panel](https://grafana.com/docs/grafana/latest/panels/visualizations/alert-list-panel/) + * + * @name alertlist.new + * + * @param title (default `''`) + * @param span (optional) + * @param show (default `'current'`) Whether the panel should display the current alert state or recent alert state changes. + * @param limit (default `10`) Sets the maximum number of alerts to list. + * @param sortOrder (default `'1'`) '1': alerting, '2': no_data, '3': pending, '4': ok, '5': paused + * @param stateFilter (optional) + * @param onlyAlertsOnDashboard (optional) Shows alerts only from the dashboard the alert list is in + * @param transparent (optional) Whether to display the panel without a background + * @param description (optional) + * @param datasource (optional) + */ + new( + title='', + span=null, + show='current', + limit=10, + sortOrder=1, + stateFilter=[], + onlyAlertsOnDashboard=true, + transparent=null, + description=null, + datasource=null, + ):: + { + [if transparent != null then 'transparent']: transparent, + title: title, + [if span != null then 'span']: span, + type: 'alertlist', + show: show, + limit: limit, + sortOrder: sortOrder, + [if show != 'changes' then 'stateFilter']: stateFilter, + onlyAlertsOnDashboard: onlyAlertsOnDashboard, + [if description != null then 'description']: description, + datasource: datasource, + }, +} diff --git a/embeds/grafonnet-lib/grafonnet/annotation.libsonnet b/embeds/grafonnet-lib/grafonnet/annotation.libsonnet new file mode 100644 index 000000000..955b029cb --- /dev/null +++ b/embeds/grafonnet-lib/grafonnet/annotation.libsonnet @@ -0,0 +1,40 @@ +{ + default:: + { + builtIn: 1, + datasource: '-- Grafana --', + enable: true, + hide: true, + iconColor: 'rgba(0, 211, 255, 1)', + name: 'Annotations & Alerts', + type: 'dashboard', + }, + + /** + * @name annotation.datasource + */ + + datasource( + name, + datasource, + expr=null, + enable=true, + hide=false, + iconColor='rgba(255, 96, 96, 1)', + tags=[], + type='tags', + builtIn=null, + ):: + { + datasource: datasource, + enable: enable, + [if expr != null then 'expr']: expr, + hide: hide, + iconColor: iconColor, + name: name, + showIn: 0, + tags: tags, + type: type, + [if builtIn != null then 'builtIn']: builtIn, + }, +} diff --git a/embeds/grafonnet-lib/grafonnet/bar_gauge_panel.libsonnet b/embeds/grafonnet-lib/grafonnet/bar_gauge_panel.libsonnet new file mode 100644 index 000000000..313e5a033 --- /dev/null +++ b/embeds/grafonnet-lib/grafonnet/bar_gauge_panel.libsonnet @@ -0,0 +1,47 @@ +{ + /** + * Create a [bar gauge panel](https://grafana.com/docs/grafana/latest/panels/visualizations/bar-gauge-panel/), + * + * @name barGaugePanel.new + * + * @param title Panel title. + * @param description (optional) Panel description. + * @param datasource (optional) Panel datasource. + * @param unit (optional) The unit of the data. + * @param thresholds (optional) An array of threashold values. + * + * @method addTarget(target) Adds a target object. + * @method addTargets(targets) Adds an array of targets. + */ + new( + title, + description=null, + datasource=null, + unit=null, + thresholds=[], + ):: { + type: 'bargauge', + title: title, + [if description != null then 'description']: description, + datasource: datasource, + targets: [ + ], + fieldConfig: { + defaults: { + unit: unit, + thresholds: { + mode: 'absolute', + steps: thresholds, + }, + }, + }, + _nextTarget:: 0, + addTarget(target):: self { + // automatically ref id in added targets. + local nextTarget = super._nextTarget, + _nextTarget: nextTarget + 1, + targets+: [target { refId: std.char(std.codepoint('A') + nextTarget) }], + }, + addTargets(targets):: std.foldl(function(p, t) p.addTarget(t), targets, self), + }, +} diff --git a/embeds/grafonnet-lib/grafonnet/cloudmonitoring.libsonnet b/embeds/grafonnet-lib/grafonnet/cloudmonitoring.libsonnet new file mode 100644 index 000000000..49cef5e1a --- /dev/null +++ b/embeds/grafonnet-lib/grafonnet/cloudmonitoring.libsonnet @@ -0,0 +1,57 @@ +{ + /** + * Creates a [Google Cloud Monitoring target](https://grafana.com/docs/grafana/latest/datasources/google-cloud-monitoring/) + * + * @name cloudmonitoring.target + * + * @param metric + * @param project + * @param filters (optional) + * @param groupBys (optional) + * @param period (default: `'cloud-monitoring-auto'`) + * @param crossSeriesReducer (default 'REDUCE_MAX') + * @param valueType (default 'INT64') + * @param perSeriesAligner (default 'ALIGN_DELTA') + * @param metricKind (default 'CUMULATIVE') + * @param unit (optional) + * @param alias (optional) + + * @return Panel target + */ + + target( + metric, + project, + filters=[], + groupBys=[], + period='cloud-monitoring-auto', + crossSeriesReducer='REDUCE_MAX', + valueType='INT64', + perSeriesAligner='ALIGN_DELTA', + metricKind='CUMULATIVE', + unit=1, + alias=null, + ):: { + metricQuery: { + [if alias != null then 'aliasBy']: alias, + alignmentPeriod: period, + crossSeriesReducer: crossSeriesReducer, + [if filters != null then 'filters']: filters, + [if groupBys != null then 'groupBys']: groupBys, + metricKind: metricKind, + metricType: metric, + perSeriesAligner: perSeriesAligner, + projectName: project, + unit: unit, + valueType: valueType, + }, + sloQuery: { + [if alias != null then 'aliasBy']: alias, + alignmentPeriod: period, + projectName: project, + selectorName: 'select_slo_health', + serviceId: '', + sloId: '', + }, + }, +} diff --git a/embeds/grafonnet-lib/grafonnet/cloudwatch.libsonnet b/embeds/grafonnet-lib/grafonnet/cloudwatch.libsonnet new file mode 100644 index 000000000..f56056f4e --- /dev/null +++ b/embeds/grafonnet-lib/grafonnet/cloudwatch.libsonnet @@ -0,0 +1,51 @@ +{ + /** + * Creates a [CloudWatch target](https://grafana.com/docs/grafana/latest/datasources/cloudwatch/) + * + * @name cloudwatch.target + * + * @param region + * @param namespace + * @param metric + * @param datasource (optional) + * @param statistic (default: `'Average'`) + * @param alias (optional) + * @param highResolution (default: `false`) + * @param period (default: `'auto'`) + * @param dimensions (optional) + * @param id (optional) + * @param expression (optional) + * @param hide (optional) + + * @return Panel target + */ + + target( + region, + namespace, + metric, + datasource=null, + statistic='Average', + alias=null, + highResolution=false, + period='auto', + dimensions={}, + id=null, + expression=null, + hide=null + ):: { + region: region, + namespace: namespace, + metricName: metric, + [if datasource != null then 'datasource']: datasource, + statistics: [statistic], + [if alias != null then 'alias']: alias, + highResolution: highResolution, + period: period, + dimensions: dimensions, + [if id != null then 'id']: id, + [if expression != null then 'expression']: expression, + [if hide != null then 'hide']: hide, + + }, +} diff --git a/embeds/grafonnet-lib/grafonnet/dashboard.libsonnet b/embeds/grafonnet-lib/grafonnet/dashboard.libsonnet new file mode 100644 index 000000000..1cc1bf320 --- /dev/null +++ b/embeds/grafonnet-lib/grafonnet/dashboard.libsonnet @@ -0,0 +1,181 @@ +local timepickerlib = import 'timepicker.libsonnet'; + +{ + /** + * Creates a [dashboard](https://grafana.com/docs/grafana/latest/features/dashboard/dashboards/) + * + * @name dashboard.new + * + * @param title The title of the dashboard + * @param editable (default: `false`) Whether the dashboard is editable via Grafana UI. + * @param style (default: `'dark'`) Theme of dashboard, `'dark'` or `'light'` + * @param tags (optional) Array of tags associated to the dashboard, e.g.`['tag1','tag2']` + * @param time_from (default: `'now-6h'`) + * @param time_to (default: `'now'`) + * @param timezone (default: `'browser'`) Timezone of the dashboard, `'utc'` or `'browser'` + * @param refresh (default: `''`) Auto-refresh interval, e.g. `'30s'` + * @param timepicker (optional) See timepicker API + * @param graphTooltip (default: `'default'`) `'default'` : no shared crosshair or tooltip (0), `'shared_crosshair'`: shared crosshair (1), `'shared_tooltip'`: shared crosshair AND shared tooltip (2) + * @param hideControls (default: `false`) + * @param schemaVersion (default: `14`) Version of the Grafana JSON schema, incremented each time an update brings changes. `26` for Grafana 7.1.5, `22` for Grafana 6.7.4, `16` for Grafana 5.4.5, `14` for Grafana 4.6.3. etc. + * @param uid (default: `''`) Unique dashboard identifier as a string (8-40), that can be chosen by users. Used to identify a dashboard to update when using Grafana REST API. + * @param description (optional) + * + * @method addTemplate(template) Add a template variable + * @method addTemplates(templates) Adds an array of template variables + * @method addAnnotation(annotation) Add an [annotation](https://grafana.com/docs/grafana/latest/dashboards/annotations/) + * @method addPanel(panel,gridPos) Appends a panel, with an optional grid position in grid coordinates, e.g. `gridPos={'x':0, 'y':0, 'w':12, 'h': 9}` + * @method addPanels(panels) Appends an array of panels + * @method addLink(link) Adds a [dashboard link](https://grafana.com/docs/grafana/latest/linking/dashboard-links/) + * @method addLinks(dashboardLink) Adds an array of [dashboard links](https://grafana.com/docs/grafana/latest/linking/dashboard-links/) + * @method addRequired(type, name, id, version) + * @method addInput(name, label, type, pluginId, pluginName, description, value) + * @method addRow(row) Adds a row. This is the legacy row concept from Grafana < 5, when rows were needed for layout. Rows should now be added via `addPanel`. + */ + new( + title, + editable=false, + style='dark', + tags=[], + time_from='now-6h', + time_to='now', + timezone='browser', + refresh='', + timepicker=timepickerlib.new(), + graphTooltip='default', + hideControls=false, + schemaVersion=14, + uid='', + description=null, + ):: { + local it = self, + _annotations:: [], + [if uid != '' then 'uid']: uid, + editable: editable, + [if description != null then 'description']: description, + gnetId: null, + graphTooltip: + if graphTooltip == 'shared_tooltip' then 2 + else if graphTooltip == 'shared_crosshair' then 1 + else if graphTooltip == 'default' then 0 + else graphTooltip, + hideControls: hideControls, + id: null, + links: [], + panels:: [], + refresh: refresh, + rows: [], + schemaVersion: schemaVersion, + style: style, + tags: tags, + time: { + from: time_from, + to: time_to, + }, + timezone: timezone, + timepicker: timepicker, + title: title, + version: 0, + addAnnotations(annotations):: self { + _annotations+:: annotations, + }, + addAnnotation(a):: self.addAnnotations([a]), + addTemplates(templates):: self { + templates+: templates, + }, + addTemplate(t):: self.addTemplates([t]), + templates:: [], + annotations: { list: it._annotations }, + templating: { list: it.templates }, + _nextPanel:: 2, + addRow(row):: + self { + // automatically number panels in added rows. + // https://github.com/kausalco/public/blob/master/klumps/grafana.libsonnet + local n = std.length(row.panels), + local nextPanel = super._nextPanel, + local panels = std.makeArray(n, function(i) + row.panels[i] { id: nextPanel + i }), + + _nextPanel: nextPanel + n, + rows+: [row { panels: panels }], + }, + addPanels(newpanels):: + self { + // automatically number panels in added rows. + // https://github.com/kausalco/public/blob/master/klumps/grafana.libsonnet + local n = std.foldl(function(numOfPanels, p) + (if 'panels' in p then + numOfPanels + 1 + std.length(p.panels) + else + numOfPanels + 1), newpanels, 0), + local nextPanel = super._nextPanel, + local _panels = std.makeArray( + std.length(newpanels), function(i) + newpanels[i] { + id: nextPanel + ( + if i == 0 then + 0 + else + if 'panels' in _panels[i - 1] then + (_panels[i - 1].id - nextPanel) + 1 + std.length(_panels[i - 1].panels) + else + (_panels[i - 1].id - nextPanel) + 1 + + ), + [if 'panels' in newpanels[i] then 'panels']: std.makeArray( + std.length(newpanels[i].panels), function(j) + newpanels[i].panels[j] { + id: 1 + j + + nextPanel + ( + if i == 0 then + 0 + else + if 'panels' in _panels[i - 1] then + (_panels[i - 1].id - nextPanel) + 1 + std.length(_panels[i - 1].panels) + else + (_panels[i - 1].id - nextPanel) + 1 + + ), + } + ), + } + ), + + _nextPanel: nextPanel + n, + panels+::: _panels, + }, + addPanel(panel, gridPos):: self.addPanels([panel { gridPos: gridPos }]), + addRows(rows):: std.foldl(function(d, row) d.addRow(row), rows, self), + addLink(link):: self { + links+: [link], + }, + addLinks(dashboardLinks):: std.foldl(function(d, t) d.addLink(t), dashboardLinks, self), + required:: [], + __requires: it.required, + addRequired(type, name, id, version):: self { + required+: [{ type: type, name: name, id: id, version: version }], + }, + inputs:: [], + __inputs: it.inputs, + addInput( + name, + label, + type, + pluginId=null, + pluginName=null, + description='', + value=null, + ):: self { + inputs+: [{ + name: name, + label: label, + type: type, + [if pluginId != null then 'pluginId']: pluginId, + [if pluginName != null then 'pluginName']: pluginName, + [if value != null then 'value']: value, + description: description, + }], + }, + }, +} diff --git a/embeds/grafonnet-lib/grafonnet/dashlist.libsonnet b/embeds/grafonnet-lib/grafonnet/dashlist.libsonnet new file mode 100644 index 000000000..436cb02b6 --- /dev/null +++ b/embeds/grafonnet-lib/grafonnet/dashlist.libsonnet @@ -0,0 +1,41 @@ +{ + /** + * Creates a [dashlist panel](https://grafana.com/docs/grafana/latest/panels/visualizations/dashboard-list-panel/). + * It requires the dashlist panel plugin in grafana, which is built-in. + * + * @name dashlist.new + * + * @param title The title of the dashlist panel. + * @param description (optional) Description of the panel + * @param query (optional) Query to search by + * @param tags (optional) Array of tag(s) to search by + * @param recent (default `true`) Displays recently viewed dashboards + * @param search (default `false`) Description of the panel + * @param starred (default `false`) Displays starred dashboards + * @param headings (default `true`) Chosen list selection(starred, recently Viewed, search) is shown as a heading + * @param limit (default `10`) Set maximum items in a list + * @return A json that represents a dashlist panel + */ + new( + title, + description=null, + query=null, + tags=[], + recent=true, + search=false, + starred=false, + headings=true, + limit=10, + ):: { + type: 'dashlist', + title: title, + query: if query != null then query else '', + tags: tags, + recent: recent, + search: search, + starred: starred, + headings: headings, + limit: limit, + [if description != null then 'description']: description, + }, +} diff --git a/embeds/grafonnet-lib/grafonnet/elasticsearch.libsonnet b/embeds/grafonnet-lib/grafonnet/elasticsearch.libsonnet new file mode 100644 index 000000000..769e1c708 --- /dev/null +++ b/embeds/grafonnet-lib/grafonnet/elasticsearch.libsonnet @@ -0,0 +1,51 @@ +{ + /** + * Creates an [Elasticsearch target](https://grafana.com/docs/grafana/latest/datasources/elasticsearch/) + * + * @name elasticsearch.target + * + * @param query + * @param timeField + * @param id (optional) + * @param datasource (optional) + * @param metrics (optional) + * @param bucketAggs (optional) + * @param alias (optional) + */ + target( + query, + timeField, + id=null, + datasource=null, + metrics=[{ + field: 'value', + id: null, + type: 'percentiles', + settings: { + percents: [ + '90', + ], + }, + }], + bucketAggs=[{ + field: 'timestamp', + id: null, + type: 'date_histogram', + settings: { + interval: '1s', + min_doc_count: 0, + trimEdges: 0, + }, + }], + alias=null, + ):: { + [if datasource != null then 'datasource']: datasource, + query: query, + id: id, + timeField: timeField, + bucketAggs: bucketAggs, + metrics: metrics, + alias: alias, + // TODO: generate bucket ids + }, +} diff --git a/embeds/grafonnet-lib/grafonnet/gauge_panel.libsonnet b/embeds/grafonnet-lib/grafonnet/gauge_panel.libsonnet new file mode 100644 index 000000000..40b367351 --- /dev/null +++ b/embeds/grafonnet-lib/grafonnet/gauge_panel.libsonnet @@ -0,0 +1,211 @@ +{ + /** + * Creates a [gauge panel](https://grafana.com/docs/grafana/latest/panels/visualizations/gauge-panel/). + * + * @name gaugePanel.new + * + * @param title Panel title. + * @param description (optional) Panel description. + * @param transparent (default `false`) Whether to display the panel without a background. + * @param datasource (optional) Panel datasource. + * @param allValues (default `false`) Show all values instead of reducing to one. + * @param valueLimit (optional) Limit of values in all values mode. + * @param reducerFunction (default `'mean'`) Function to use to reduce values to when using single value. + * @param fields (default `''`) Fields that should be included in the panel. + * @param showThresholdLabels (default `false`) Render the threshold values around the gauge bar. + * @param showThresholdMarkers (default `true`) Render the thresholds as an outer bar. + * @param unit (default `'percent'`) Panel unit field option. + * @param min (optional) Leave empty to calculate based on all values. + * @param max (optional) Leave empty to calculate based on all values. + * @param decimals Number of decimal places to show. + * @param displayName Change the field or series name. + * @param noValue (optional) What to show when there is no value. + * @param thresholdsMode (default `'absolute'`) 'absolute' or 'percentage'. + * @param repeat (optional) Name of variable that should be used to repeat this panel. + * @param repeatDirection (default `'h'`) 'h' for horizontal or 'v' for vertical. + * @param repeatMaxPerRow (optional) Maximum panels per row in repeat mode. + * @param pluginVersion (default `'7'`) Plugin version the panel should be modeled for. This has been tested with the default, '7', and '6.7'. + * + * @method addTarget(target) Adds a target object. + * @method addTargets(targets) Adds an array of targets. + * @method addLink(link) Adds a [panel link](https://grafana.com/docs/grafana/latest/linking/panel-links/). Argument format: `{ title: 'Link Title', url: 'https://...', targetBlank: true }`. + * @method addLinks(links) Adds an array of links. + * @method addThreshold(step) Adds a threshold step. Argument format: `{ color: 'green', value: 0 }`. + * @method addThresholds(steps) Adds an array of threshold steps. + * @method addMapping(mapping) Adds a value mapping. + * @method addMappings(mappings) Adds an array of value mappings. + * @method addDataLink(link) Adds a data link. + * @method addDataLinks(links) Adds an array of data links. + * @param timeFrom (optional) + */ + new( + title, + description=null, + transparent=false, + datasource=null, + allValues=false, + valueLimit=null, + reducerFunction='mean', + fields='', + showThresholdLabels=false, + showThresholdMarkers=true, + unit='percent', + min=0, + max=100, + decimals=null, + displayName=null, + noValue=null, + thresholdsMode='absolute', + repeat=null, + repeatDirection='h', + repeatMaxPerRow=null, + timeFrom=null, + pluginVersion='7', + ):: { + + type: 'gauge', + title: title, + [if description != null then 'description']: description, + transparent: transparent, + datasource: datasource, + targets: [], + links: [], + [if repeat != null then 'repeat']: repeat, + [if repeat != null then 'repeatDirection']: repeatDirection, + [if repeat != null then 'repeatMaxPerRow']: repeatMaxPerRow, + [if timeFrom != null then 'timeFrom']: timeFrom, + + // targets + _nextTarget:: 0, + addTarget(target):: self { + local nextTarget = super._nextTarget, + _nextTarget: nextTarget + 1, + targets+: [target { refId: std.char(std.codepoint('A') + nextTarget) }], + }, + addTargets(targets):: std.foldl(function(p, t) p.addTarget(t), targets, self), + + // links + addLink(link):: self { + links+: [link], + }, + addLinks(links):: std.foldl(function(p, l) p.addLink(l), links, self), + + pluginVersion: pluginVersion, + } + ( + + if pluginVersion >= '7' then { + options: { + reduceOptions: { + values: allValues, + [if allValues && valueLimit != null then 'limit']: valueLimit, + calcs: [ + reducerFunction, + ], + fields: fields, + }, + showThresholdLabels: showThresholdLabels, + showThresholdMarkers: showThresholdMarkers, + }, + fieldConfig: { + defaults: { + unit: unit, + [if min != null then 'min']: min, + [if max != null then 'max']: max, + [if decimals != null then 'decimals']: decimals, + [if displayName != null then 'displayName']: displayName, + [if noValue != null then 'noValue']: noValue, + thresholds: { + mode: thresholdsMode, + steps: [], + }, + mappings: [], + links: [], + }, + }, + + // thresholds + addThreshold(step):: self { + fieldConfig+: { defaults+: { thresholds+: { steps+: [step] } } }, + }, + + // mappings + _nextMapping:: 0, + addMapping(mapping):: self { + local nextMapping = super._nextMapping, + _nextMapping: nextMapping + 1, + fieldConfig+: { defaults+: { mappings+: [mapping { id: nextMapping }] } }, + }, + + // data links + addDataLink(link):: self { + fieldConfig+: { defaults+: { links+: [link] } }, + }, + + // Overrides + addOverride( + matcher=null, + properties=null, + ):: self { + fieldConfig+: { + overrides+: [ + { + [if matcher != null then 'matcher']: matcher, + [if properties != null then 'properties']: properties, + }, + ], + }, + }, + addOverrides(overrides):: std.foldl(function(p, o) p.addOverride(o.matcher, o.properties), overrides, self), + } else { + + options: { + fieldOptions: { + values: allValues, + [if allValues && valueLimit != null then 'limit']: valueLimit, + calcs: [ + reducerFunction, + ], + fields: fields, + defaults: { + unit: unit, + [if min != null then 'min']: min, + [if max != null then 'max']: max, + [if decimals != null then 'decimals']: decimals, + [if displayName != null then 'displayName']: displayName, + [if noValue != null then 'noValue']: noValue, + thresholds: { + mode: thresholdsMode, + steps: [], + }, + mappings: [], + links: [], + }, + }, + showThresholdLabels: showThresholdLabels, + showThresholdMarkers: showThresholdMarkers, + }, + + // thresholds + addThreshold(step):: self { + options+: { fieldOptions+: { defaults+: { thresholds+: { steps+: [step] } } } }, + }, + + // mappings + _nextMapping:: 0, + addMapping(mapping):: self { + local nextMapping = super._nextMapping, + _nextMapping: nextMapping + 1, + options+: { fieldOptions+: { defaults+: { mappings+: [mapping { id: nextMapping }] } } }, + }, + + // data links + addDataLink(link):: self { + options+: { fieldOptions+: { defaults+: { links+: [link] } } }, + }, + } + ) + { + addThresholds(steps):: std.foldl(function(p, s) p.addThreshold(s), steps, self), + addMappings(mappings):: std.foldl(function(p, m) p.addMapping(m), mappings, self), + addDataLinks(links):: std.foldl(function(p, l) p.addDataLink(l), links, self), + }, +} diff --git a/embeds/grafonnet-lib/grafonnet/grafana.libsonnet b/embeds/grafonnet-lib/grafonnet/grafana.libsonnet new file mode 100644 index 000000000..b94ddf391 --- /dev/null +++ b/embeds/grafonnet-lib/grafonnet/grafana.libsonnet @@ -0,0 +1,32 @@ +{ + alertlist:: import 'alertlist.libsonnet', + dashboard:: import 'dashboard.libsonnet', + template:: import 'template.libsonnet', + text:: import 'text.libsonnet', + timepicker:: import 'timepicker.libsonnet', + row:: import 'row.libsonnet', + link:: import 'link.libsonnet', + annotation:: import 'annotation.libsonnet', + graphPanel:: import 'graph_panel.libsonnet', + logPanel:: import 'log_panel.libsonnet', + tablePanel:: import 'table_panel.libsonnet', + singlestat:: import 'singlestat.libsonnet', + pieChartPanel:: import 'pie_chart_panel.libsonnet', + influxdb:: import 'influxdb.libsonnet', + prometheus:: import 'prometheus.libsonnet', + loki:: import 'loki.libsonnet', + sql:: import 'sql.libsonnet', + graphite:: import 'graphite.libsonnet', + alertCondition:: import 'alert_condition.libsonnet', + cloudmonitoring:: import 'cloudmonitoring.libsonnet', + cloudwatch:: import 'cloudwatch.libsonnet', + elasticsearch:: import 'elasticsearch.libsonnet', + heatmapPanel:: import 'heatmap_panel.libsonnet', + dashlist:: import 'dashlist.libsonnet', + pluginlist:: import 'pluginlist.libsonnet', + gauge:: error 'gauge is removed, migrate to gaugePanel', + gaugePanel:: import 'gauge_panel.libsonnet', + barGaugePanel:: import 'bar_gauge_panel.libsonnet', + statPanel:: import 'stat_panel.libsonnet', + transformation:: import 'transformation.libsonnet', +} diff --git a/embeds/grafonnet-lib/grafonnet/graph_panel.libsonnet b/embeds/grafonnet-lib/grafonnet/graph_panel.libsonnet new file mode 100644 index 000000000..872769579 --- /dev/null +++ b/embeds/grafonnet-lib/grafonnet/graph_panel.libsonnet @@ -0,0 +1,313 @@ +{ + /** + * Creates a [graph panel](https://grafana.com/docs/grafana/latest/panels/visualizations/graph-panel/). + * It requires the graph panel plugin in grafana, which is built-in. + * + * @name graphPanel.new + * + * @param title The title of the graph panel. + * @param description (optional) The description of the panel + * @param span (optional) Width of the panel + * @param datasource (optional) Datasource + * @param fill (default `1`) , integer from 0 to 10 + * @param fillGradient (default `0`) , integer from 0 to 10 + * @param linewidth (default `1`) Line Width, integer from 0 to 10 + * @param decimals (optional) Override automatic decimal precision for legend and tooltip. If null, not added to the json output. + * @param decimalsY1 (optional) Override automatic decimal precision for the first Y axis. If null, use decimals parameter. + * @param decimalsY2 (optional) Override automatic decimal precision for the second Y axis. If null, use decimals parameter. + * @param min_span (optional) Min span + * @param format (default `short`) Unit of the Y axes + * @param formatY1 (optional) Unit of the first Y axis + * @param formatY2 (optional) Unit of the second Y axis + * @param min (optional) Min of the Y axes + * @param max (optional) Max of the Y axes + * @param maxDataPoints (optional) If the data source supports it, sets the maximum number of data points for each series returned. + * @param labelY1 (optional) Label of the first Y axis + * @param labelY2 (optional) Label of the second Y axis + * @param x_axis_mode (default `'time'`) X axis mode, one of [time, series, histogram] + * @param x_axis_values (default `'total'`) Chosen value of series, one of [avg, min, max, total, count] + * @param x_axis_buckets (optional) Restricts the x axis to this amount of buckets + * @param x_axis_min (optional) Restricts the x axis to display from this value if supplied + * @param x_axis_max (optional) Restricts the x axis to display up to this value if supplied + * @param lines (default `true`) Display lines + * @param points (default `false`) Display points + * @param pointradius (default `5`) Radius of the points, allowed values are 0.5 or [1 ... 10] with step 1 + * @param bars (default `false`) Display bars + * @param staircase (default `false`) Display line as staircase + * @param dashes (default `false`) Display line as dashes + * @param stack (default `false`) Whether to stack values + * @param repeat (optional) Name of variable that should be used to repeat this panel. + * @param repeatDirection (default `'h'`) 'h' for horizontal or 'v' for vertical. + * @param legend_show (default `true`) Show legend + * @param legend_values (default `false`) Show values in legend + * @param legend_min (default `false`) Show min in legend + * @param legend_max (default `false`) Show max in legend + * @param legend_current (default `false`) Show current in legend + * @param legend_total (default `false`) Show total in legend + * @param legend_avg (default `false`) Show average in legend + * @param legend_alignAsTable (default `false`) Show legend as table + * @param legend_rightSide (default `false`) Show legend to the right + * @param legend_sideWidth (optional) Legend width + * @param legend_sort (optional) Sort order of legend + * @param legend_sortDesc (optional) Sort legend descending + * @param aliasColors (optional) Define color mappings for graphs + * @param thresholds (optional) An array of graph thresholds + * @param logBase1Y (default `1`) Value of logarithm base of the first Y axis + * @param logBase2Y (default `1`) Value of logarithm base of the second Y axis + * @param transparent (default `false`) Whether to display the panel without a background. + * @param value_type (default `'individual'`) Type of tooltip value + * @param shared_tooltip (default `true`) Allow to group or spit tooltips on mouseover within a chart + * @param percentage (defaut: false) show as percentages + * @param interval (defaut: null) A lower limit for the interval. + + * + * @method addTarget(target) Adds a target object. + * @method addTargets(targets) Adds an array of targets. + * @method addSeriesOverride(override) + * @method addYaxis(format,min,max,label,show,logBase,decimals) Adds a Y axis to the graph + * @method addAlert(alert) Adds an alert + * @method addLink(link) Adds a [panel link](https://grafana.com/docs/grafana/latest/linking/panel-links/) + * @method addLinks(links) Adds an array of links. + */ + new( + title, + span=null, + fill=1, + fillGradient=0, + linewidth=1, + decimals=null, + decimalsY1=null, + decimalsY2=null, + description=null, + min_span=null, + format='short', + formatY1=null, + formatY2=null, + min=null, + max=null, + labelY1=null, + labelY2=null, + x_axis_mode='time', + x_axis_values='total', + x_axis_buckets=null, + x_axis_min=null, + x_axis_max=null, + lines=true, + datasource=null, + points=false, + pointradius=5, + bars=false, + staircase=false, + height=null, + nullPointMode='null', + dashes=false, + stack=false, + repeat=null, + repeatDirection=null, + sort=0, + show_xaxis=true, + legend_show=true, + legend_values=false, + legend_min=false, + legend_max=false, + legend_current=false, + legend_total=false, + legend_avg=false, + legend_alignAsTable=false, + legend_rightSide=false, + legend_sideWidth=null, + legend_hideEmpty=null, + legend_hideZero=null, + legend_sort=null, + legend_sortDesc=null, + aliasColors={}, + thresholds=[], + links=[], + logBase1Y=1, + logBase2Y=1, + transparent=false, + value_type='individual', + shared_tooltip=true, + percentage=false, + maxDataPoints=null, + time_from=null, + time_shift=null, + interval=null + ):: { + title: title, + [if span != null then 'span']: span, + [if min_span != null then 'minSpan']: min_span, + [if decimals != null then 'decimals']: decimals, + type: 'graph', + datasource: datasource, + targets: [ + ], + [if description != null then 'description']: description, + [if height != null then 'height']: height, + renderer: 'flot', + yaxes: [ + self.yaxe( + if formatY1 != null then formatY1 else format, + min, + max, + decimals=(if decimalsY1 != null then decimalsY1 else decimals), + logBase=logBase1Y, + label=labelY1 + ), + self.yaxe( + if formatY2 != null then formatY2 else format, + min, + max, + decimals=(if decimalsY2 != null then decimalsY2 else decimals), + logBase=logBase2Y, + label=labelY2 + ), + ], + xaxis: { + show: show_xaxis, + mode: x_axis_mode, + name: null, + values: if x_axis_mode == 'series' then [x_axis_values] else [], + buckets: if x_axis_mode == 'histogram' then x_axis_buckets else null, + [if x_axis_min != null then 'min']: x_axis_min, + [if x_axis_max != null then 'max']: x_axis_max, + }, + lines: lines, + fill: fill, + fillGradient: fillGradient, + linewidth: linewidth, + dashes: dashes, + dashLength: 10, + spaceLength: 10, + points: points, + pointradius: pointradius, + bars: bars, + stack: stack, + percentage: percentage, + [if maxDataPoints != null then 'maxDataPoints']: maxDataPoints, + legend: { + show: legend_show, + values: legend_values, + min: legend_min, + max: legend_max, + current: legend_current, + total: legend_total, + alignAsTable: legend_alignAsTable, + rightSide: legend_rightSide, + sideWidth: legend_sideWidth, + avg: legend_avg, + [if legend_hideEmpty != null then 'hideEmpty']: legend_hideEmpty, + [if legend_hideZero != null then 'hideZero']: legend_hideZero, + [if legend_sort != null then 'sort']: legend_sort, + [if legend_sortDesc != null then 'sortDesc']: legend_sortDesc, + }, + nullPointMode: nullPointMode, + steppedLine: staircase, + tooltip: { + value_type: value_type, + shared: shared_tooltip, + sort: if sort == 'decreasing' then 2 else if sort == 'increasing' then 1 else sort, + }, + timeFrom: time_from, + timeShift: time_shift, + [if interval != null then 'interval']: interval, + [if transparent == true then 'transparent']: transparent, + aliasColors: aliasColors, + repeat: repeat, + [if repeatDirection != null then 'repeatDirection']: repeatDirection, + seriesOverrides: [], + thresholds: thresholds, + links: links, + yaxe( + format='short', + min=null, + max=null, + label=null, + show=true, + logBase=1, + decimals=null, + ):: { + label: label, + show: show, + logBase: logBase, + min: min, + max: max, + format: format, + [if decimals != null then 'decimals']: decimals, + }, + _nextTarget:: 0, + addTarget(target):: self { + // automatically ref id in added targets. + // https://github.com/kausalco/public/blob/master/klumps/grafana.libsonnet + local nextTarget = super._nextTarget, + _nextTarget: nextTarget + 1, + targets+: [target { refId: std.char(std.codepoint('A') + nextTarget) }], + }, + addTargets(targets):: std.foldl(function(p, t) p.addTarget(t), targets, self), + addSeriesOverride(override):: self { + seriesOverrides+: [override], + }, + resetYaxes():: self { + yaxes: [], + }, + addYaxis( + format='short', + min=null, + max=null, + label=null, + show=true, + logBase=1, + decimals=null, + ):: self { + yaxes+: [self.yaxe(format, min, max, label, show, logBase, decimals)], + }, + addAlert( + name, + executionErrorState='alerting', + forDuration='5m', + frequency='60s', + handler=1, + message='', + noDataState='no_data', + notifications=[], + alertRuleTags={}, + ):: self { + local it = self, + _conditions:: [], + alert: { + name: name, + conditions: it._conditions, + executionErrorState: executionErrorState, + 'for': forDuration, + frequency: frequency, + handler: handler, + noDataState: noDataState, + notifications: notifications, + message: message, + alertRuleTags: alertRuleTags, + }, + addCondition(condition):: self { + _conditions+: [condition], + }, + addConditions(conditions):: std.foldl(function(p, c) p.addCondition(c), conditions, it), + }, + addLink(link):: self { + links+: [link], + }, + addLinks(links):: std.foldl(function(p, t) p.addLink(t), links, self), + addOverride( + matcher=null, + properties=null, + ):: self { + fieldConfig+: { + overrides+: [ + { + [if matcher != null then 'matcher']: matcher, + [if properties != null then 'properties']: properties, + }, + ], + }, + }, + addOverrides(overrides):: std.foldl(function(p, o) p.addOverride(o.matcher, o.properties), overrides, self), + }, +} diff --git a/embeds/grafonnet-lib/grafonnet/graphite.libsonnet b/embeds/grafonnet-lib/grafonnet/graphite.libsonnet new file mode 100644 index 000000000..46a011335 --- /dev/null +++ b/embeds/grafonnet-lib/grafonnet/graphite.libsonnet @@ -0,0 +1,29 @@ +{ + /** + * Creates a [Graphite target](https://grafana.com/docs/grafana/latest/datasources/graphite/) + * + * @name graphite.target + * + * @param target Graphite Query. Nested queries are possible by adding the query reference (refId). + * @param targetFull (optional) Expanding the @target. Used in nested queries. + * @param hide (default `false`) Disable query on graph. + * @param textEditor (default `false`) Enable raw query mode. + * @param datasource (optional) Datasource. + + * @return Panel target + */ + target( + target, + targetFull=null, + hide=false, + textEditor=false, + datasource=null, + ):: { + target: target, + hide: hide, + textEditor: textEditor, + + [if targetFull != null then 'targetFull']: targetFull, + [if datasource != null then 'datasource']: datasource, + }, +} diff --git a/embeds/grafonnet-lib/grafonnet/heatmap_panel.libsonnet b/embeds/grafonnet-lib/grafonnet/heatmap_panel.libsonnet new file mode 100644 index 000000000..5e9a04c49 --- /dev/null +++ b/embeds/grafonnet-lib/grafonnet/heatmap_panel.libsonnet @@ -0,0 +1,150 @@ +{ + /** + * Creates a [heatmap panel](https://grafana.com/docs/grafana/latest/panels/visualizations/heatmap/). + * Requires the heatmap panel plugin in Grafana, which is built-in. + * + * @name heatmapPanel.new + * + * @param title The title of the heatmap panel + * @param description (optional) Description of panel + * @param datasource (optional) Datasource + * @param min_span (optional) Min span + * @param span (optional) Width of the panel + * @param cards_cardPadding (optional) How much padding to put between bucket cards + * @param cards_cardRound (optional) How much rounding should be applied to the bucket card shape + * @param color_cardColor (default `'#b4ff00'`) Hex value of color used when color_colorScheme is 'opacity' + * @param color_colorScale (default `'sqrt'`) How to scale the color range, 'linear' or 'sqrt' + * @param color_colorScheme (default `'interpolateOranges'`) TODO: document + * @param color_exponent (default `0.5`) TODO: document + * @param color_max (optional) The value for the end of the color range + * @param color_min (optional) The value for the beginning of the color range + * @param color_mode (default `'spectrum'`) How to display difference in frequency with color + * @param dataFormat (default `'timeseries'`) How to format the data + * @param highlightCards (default `true`) TODO: document + * @param hideZeroBuckets (default `false`) Whether or not to hide empty buckets, default is false + * @param legend_show (default `false`) Show legend + * @param minSpan (optional) Minimum span of the panel when repeated on a template variable + * @param repeat (optional) Variable used to repeat the heatmap panel + * @param repeatDirection (optional) Which direction to repeat the panel, 'h' for horizontal and 'v' for vertically + * @param tooltipDecimals (optional) The number of decimal places to display in the tooltip + * @param tooltip_show (default `true`) Whether or not to display a tooltip when hovering over the heatmap + * @param tooltip_showHistogram (default `false`) Whether or not to display a histogram in the tooltip + * @param xAxis_show (default `true`) Whether or not to show the X axis, default true + * @param xBucketNumber (optional) Number of buckets for the X axis + * @param xBucketSize (optional) Size of X axis buckets. Number or interval(10s, 15h, etc.) Has priority over xBucketNumber + * @param yAxis_decimals (optional) Override automatic decimal precision for the Y axis + * @param yAxis_format (default `'short'`) Unit of the Y axis + * @param yAxis_logBase (default `1`) Only if dataFormat is 'timeseries' + * @param yAxis_min (optional) Only if dataFormat is 'timeseries', min of the Y axis + * @param yAxis_max (optional) Only if dataFormat is 'timeseries', max of the Y axis + * @param yAxis_show (default `true`) Whether or not to show the Y axis + * @param yAxis_splitFactor (optional) TODO: document + * @param yBucketBound (default `'auto'`) Which bound ('lower' or 'upper') of the bucket to use + * @param yBucketNumber (optional) Number of buckets for the Y axis + * @param yBucketSize (optional) Size of Y axis buckets. Has priority over yBucketNumber + * @param maxDataPoints (optional) The maximum data points per series. Used directly by some data sources and used in calculation of auto interval. With streaming data this value is used for the rolling buffer. + * + * @method addTarget(target) Adds a target object. + * @method addTargets(targets) Adds an array of targets. + */ + new( + title, + datasource=null, + description=null, + cards_cardPadding=null, + cards_cardRound=null, + color_cardColor='#b4ff00', + color_colorScale='sqrt', + color_colorScheme='interpolateOranges', + color_exponent=0.5, + color_max=null, + color_min=null, + color_mode='spectrum', + dataFormat='timeseries', + highlightCards=true, + hideZeroBuckets=false, + legend_show=false, + minSpan=null, + span=null, + repeat=null, + repeatDirection=null, + tooltipDecimals=null, + tooltip_show=true, + tooltip_showHistogram=false, + xAxis_show=true, + xBucketNumber=null, + xBucketSize=null, + yAxis_decimals=null, + yAxis_format='short', + yAxis_logBase=1, + yAxis_min=null, + yAxis_max=null, + yAxis_show=true, + yAxis_splitFactor=null, + yBucketBound='auto', + yBucketNumber=null, + yBucketSize=null, + maxDataPoints=null, + ):: { + title: title, + type: 'heatmap', + [if description != null then 'description']: description, + datasource: datasource, + cards: { + cardPadding: cards_cardPadding, + cardRound: cards_cardRound, + }, + color: { + mode: color_mode, + cardColor: color_cardColor, + colorScale: color_colorScale, + exponent: color_exponent, + [if color_mode == 'spectrum' then 'colorScheme']: color_colorScheme, + [if color_max != null then 'max']: color_max, + [if color_min != null then 'min']: color_min, + }, + [if dataFormat != null then 'dataFormat']: dataFormat, + heatmap: {}, + hideZeroBuckets: hideZeroBuckets, + highlightCards: highlightCards, + legend: { + show: legend_show, + }, + [if minSpan != null then 'minSpan']: minSpan, + [if span != null then 'span']: span, + [if repeat != null then 'repeat']: repeat, + [if repeatDirection != null then 'repeatDirection']: repeatDirection, + tooltip: { + show: tooltip_show, + showHistogram: tooltip_showHistogram, + }, + [if tooltipDecimals != null then 'tooltipDecimals']: tooltipDecimals, + xAxis: { + show: xAxis_show, + }, + xBucketNumber: if dataFormat == 'timeseries' && xBucketSize != null then xBucketNumber else null, + xBucketSize: if dataFormat == 'timeseries' && xBucketSize != null then xBucketSize else null, + yAxis: { + decimals: yAxis_decimals, + [if dataFormat == 'timeseries' then 'logBase']: yAxis_logBase, + format: yAxis_format, + [if dataFormat == 'timeseries' then 'max']: yAxis_max, + [if dataFormat == 'timeseries' then 'min']: yAxis_min, + show: yAxis_show, + splitFactor: yAxis_splitFactor, + }, + yBucketBound: yBucketBound, + [if dataFormat == 'timeseries' then 'yBucketNumber']: yBucketNumber, + [if dataFormat == 'timeseries' then 'yBucketSize']: yBucketSize, + [if maxDataPoints != null then 'maxDataPoints']: maxDataPoints, + + _nextTarget:: 0, + addTarget(target):: self { + local nextTarget = super._nextTarget, + _nextTarget: nextTarget + 1, + targets+: [target { refId: std.char(std.codepoint('A') + nextTarget) }], + }, + addTargets(targets):: std.foldl(function(p, t) p.addTarget(t), targets, self), + }, + +} diff --git a/embeds/grafonnet-lib/grafonnet/influxdb.libsonnet b/embeds/grafonnet-lib/grafonnet/influxdb.libsonnet new file mode 100644 index 000000000..dd7c4fd4e --- /dev/null +++ b/embeds/grafonnet-lib/grafonnet/influxdb.libsonnet @@ -0,0 +1,104 @@ +{ + /** + * Creates an [InfluxDB target](https://grafana.com/docs/grafana/latest/datasources/influxdb/) + * + * @name influxdb.target + * + * @param query Raw InfluxQL statement + * + * @param alias (optional) 'Alias By' pattern + * @param datasource (optional) Datasource + * @param hide (optional) Disable query on graph + * + * @param rawQuery (optional) Enable/disable raw query mode + * + * @param policy (default: `'default'`) Tagged query 'From' policy + * @param measurement (optional) Tagged query 'From' measurement + * @param group_time (default: `'$__interval'`) 'Group by' time condition (if set to null, do not groups by time) + * @param group_tags (optional) 'Group by' tags list + * @param fill (default: `'none'`) 'Group by' missing values fill mode (works only with 'Group by time()') + * + * @param resultFormat (default: `'time_series'`) Format results as 'Time series' or 'Table' + * + * @return Panel target + */ + target( + query=null, + + alias=null, + datasource=null, + hide=null, + + rawQuery=null, + + policy='default', + measurement=null, + + group_time='$__interval', + group_tags=[], + fill='none', + + resultFormat='time_series', + ):: { + local it = self, + + [if alias != null then 'alias']: alias, + [if datasource != null then 'datasource']: datasource, + [if hide != null then 'hide']: hide, + + [if query != null then 'query']: query, + [if rawQuery != null then 'rawQuery']: rawQuery, + [if rawQuery == null && query != null then 'rawQuery']: true, + + policy: policy, + [if measurement != null then 'measurement']: measurement, + tags: [], + select: [], + groupBy: + if group_time != null then + [{ type: 'time', params: [group_time] }] + + [{ type: 'tag', params: [tag_name] } for tag_name in group_tags] + + [{ type: 'fill', params: [fill] }] + else + [{ type: 'tag', params: [tag_name] } for tag_name in group_tags], + + resultFormat: resultFormat, + + where(key, operator, value, condition=null):: self { + /* + * Adds query tag condition ('Where' section) + */ + tags: + if std.length(it.tags) == 0 then + [{ key: key, operator: operator, value: value }] + else + it.tags + [{ + key: key, + operator: operator, + value: value, + condition: if condition == null then 'AND' else condition, + }], + }, + + selectField(value):: self { + /* + * Adds InfluxDB selection ('field(value)' part of 'Select' statement) + */ + select+: [[{ params: [value], type: 'field' }]], + }, + + addConverter(type, params=[]):: self { + /* + * Appends converter (aggregation, selector, etc.) to last added selection + */ + local len = std.length(it.select), + select: + if len == 1 then + [it.select[0] + [{ params: params, type: type }]] + else if len > 1 then + it.select[0:(len - 1)] + [it.select[len - 1] + [{ params: params, type: type }]] + else + [], + }, + }, +} diff --git a/embeds/grafonnet-lib/grafonnet/link.libsonnet b/embeds/grafonnet-lib/grafonnet/link.libsonnet new file mode 100644 index 000000000..5e5ebd237 --- /dev/null +++ b/embeds/grafonnet-lib/grafonnet/link.libsonnet @@ -0,0 +1,39 @@ +{ + /** + * Creates [links](https://grafana.com/docs/grafana/latest/linking/linking-overview/) to navigate to other dashboards. + * + * @param title Human-readable label for the link. + * @param tags Limits the linked dashboards to only the ones with the corresponding tags. Otherwise, Grafana includes links to all other dashboards. + * @param asDropdown (default: `true`) Whether to use a dropdown (with an optional title). If `false`, displays the dashboard links side by side across the top of dashboard. + * @param includeVars (default: `false`) Whether to include template variables currently used as query parameters in the link. Any matching templates in the linked dashboard are set to the values from the link + * @param keepTime (default: `false`) Whether to include the current dashboard time range in the link (e.g. from=now-3h&to=now) + * @param icon (default: `'external link'`) Icon displayed with the link. + * @param url (default: `''`) URL of the link + * @param targetBlank (default: `false`) Whether the link will open in a new window. + * @param type (default: `'dashboards'`) + * + * @name link.dashboards + */ + dashboards( + title, + tags, + asDropdown=true, + includeVars=false, + keepTime=false, + icon='external link', + url='', + targetBlank=false, + type='dashboards', + ):: + { + asDropdown: asDropdown, + icon: icon, + includeVars: includeVars, + keepTime: keepTime, + tags: tags, + title: title, + type: type, + url: url, + targetBlank: targetBlank, + }, +} diff --git a/embeds/grafonnet-lib/grafonnet/log_panel.libsonnet b/embeds/grafonnet-lib/grafonnet/log_panel.libsonnet new file mode 100644 index 000000000..747ad5f33 --- /dev/null +++ b/embeds/grafonnet-lib/grafonnet/log_panel.libsonnet @@ -0,0 +1,56 @@ +{ + /** + * Creates a [log panel](https://grafana.com/docs/grafana/latest/panels/visualizations/logs-panel/). + * It requires the log panel plugin in grafana, which is built-in. + * + * @name logPanel.new + * + * @param title (default `''`) The title of the log panel. + * @param span (optional) Width of the panel + * @param datasource (optional) Datasource + * @showLabels (default `false`) Whether to show or hide labels + * @showTime (default `true`) Whether to show or hide time for each line + * @wrapLogMessage (default `true`) Whether to wrap log line to the next line + * @sortOrder (default `'Descending'`) sort log by time (can be 'Descending' or 'Ascending' ) + * + * @method addTarget(target) Adds a target object + * @method addTargets(targets) Adds an array of targets + */ + new( + title='', + datasource=null, + time_from=null, + time_shift=null, + showLabels=false, + showTime=true, + sortOrder='Descending', + wrapLogMessage=true, + span=12, + height=null, + ):: { + [if height != null then 'height']: height, + span: span, + datasource: datasource, + options: { + showLabels: showLabels, + showTime: showTime, + sortOrder: sortOrder, + wrapLogMessage: wrapLogMessage, + }, + targets: [ + ], + _nextTarget:: 0, + addTarget(target):: self { + // automatically ref id in added targets. + // https://github.com/kausalco/public/blob/master/klumps/grafana.libsonnet + local nextTarget = super._nextTarget, + _nextTarget: nextTarget + 1, + targets+: [target { refId: std.char(std.codepoint('A') + nextTarget) }], + }, + addTargets(targets):: std.foldl(function(p, t) p.addTarget(t), targets, self), + timeFrom: time_from, + timeShift: time_shift, + title: title, + type: 'logs', + }, +} diff --git a/embeds/grafonnet-lib/grafonnet/loki.libsonnet b/embeds/grafonnet-lib/grafonnet/loki.libsonnet new file mode 100644 index 000000000..a300f5a98 --- /dev/null +++ b/embeds/grafonnet-lib/grafonnet/loki.libsonnet @@ -0,0 +1,22 @@ +{ + /** + * Creates a [Loki target](https://grafana.com/docs/grafana/latest/datasources/loki/) + * + * @name loki.target + * + * @param expr + * @param hide (optional) Disable query on graph. + * @param legendFormat (optional) Defines the legend. Defaults to ''. + */ + target( + expr, + hide=null, + legendFormat='', + instant=null, + ):: { + [if hide != null then 'hide']: hide, + expr: expr, + legendFormat: legendFormat, + [if instant != null then 'instant']: instant, + }, +} diff --git a/embeds/grafonnet-lib/grafonnet/pie_chart_panel.libsonnet b/embeds/grafonnet-lib/grafonnet/pie_chart_panel.libsonnet new file mode 100644 index 000000000..11719e108 --- /dev/null +++ b/embeds/grafonnet-lib/grafonnet/pie_chart_panel.libsonnet @@ -0,0 +1,72 @@ +{ + /** + * Creates a pie chart panel. + * It requires the [pie chart panel plugin in grafana](https://grafana.com/grafana/plugins/grafana-piechart-panel), + * which needs to be explicitly installed. + * + * @name pieChartPanel.new + * + * @param title The title of the pie chart panel. + * @param description (default `''`) Description of the panel + * @param span (optional) Width of the panel + * @param min_span (optional) Min span + * @param datasource (optional) Datasource + * @param aliasColors (optional) Define color mappings + * @param pieType (default `'pie'`) Type of pie chart (one of pie or donut) + * @param showLegend (default `true`) Show legend + * @param showLegendPercentage (default `true`) Show percentage values in the legend + * @param legendType (default `'Right side'`) Type of legend (one of 'Right side', 'Under graph' or 'On graph') + * @param valueName (default `'current') Type of tooltip value + * @param repeat (optional) Variable used to repeat the pie chart + * @param repeatDirection (optional) Which direction to repeat the panel, 'h' for horizontal and 'v' for vertical + * @param maxPerRow (optional) Number of panels to display when repeated. Used in combination with repeat. + * @return A json that represents a pie chart panel + * + * @method addTarget(target) Adds a target object. + */ + new( + title, + description='', + span=null, + min_span=null, + datasource=null, + height=null, + aliasColors={}, + pieType='pie', + valueName='current', + showLegend=true, + showLegendPercentage=true, + legendType='Right side', + repeat=null, + repeatDirection=null, + maxPerRow=null, + ):: { + type: 'grafana-piechart-panel', + [if description != null then 'description']: description, + pieType: pieType, + title: title, + aliasColors: aliasColors, + [if span != null then 'span']: span, + [if min_span != null then 'minSpan']: min_span, + [if height != null then 'height']: height, + [if repeat != null then 'repeat']: repeat, + [if repeatDirection != null then 'repeatDirection']: repeatDirection, + [if maxPerRow != null then 'maxPerRow']: maxPerRow, + valueName: valueName, + datasource: datasource, + legend: { + show: showLegend, + values: true, + percentage: showLegendPercentage, + }, + legendType: legendType, + targets: [ + ], + _nextTarget:: 0, + addTarget(target):: self { + local nextTarget = super._nextTarget, + _nextTarget: nextTarget + 1, + targets+: [target { refId: std.char(std.codepoint('A') + nextTarget) }], + }, + }, +} diff --git a/embeds/grafonnet-lib/grafonnet/pluginlist.libsonnet b/embeds/grafonnet-lib/grafonnet/pluginlist.libsonnet new file mode 100644 index 000000000..d3f23ab0a --- /dev/null +++ b/embeds/grafonnet-lib/grafonnet/pluginlist.libsonnet @@ -0,0 +1,23 @@ +{ + /** + * Returns a new pluginlist panel that can be added in a row. + * It requires the pluginlist panel plugin in grafana, which is built-in. + * + * @name pluginlist.new + * + * @param title The title of the pluginlist panel. + * @param description (optional) Description of the panel + * @param limit (optional) Set maximum items in a list + * @return A json that represents a pluginlist panel + */ + new( + title, + description=null, + limit=null, + ):: { + type: 'pluginlist', + title: title, + [if limit != null then 'limit']: limit, + [if description != null then 'description']: description, + }, +} diff --git a/embeds/grafonnet-lib/grafonnet/prometheus.libsonnet b/embeds/grafonnet-lib/grafonnet/prometheus.libsonnet new file mode 100644 index 000000000..46b75b058 --- /dev/null +++ b/embeds/grafonnet-lib/grafonnet/prometheus.libsonnet @@ -0,0 +1,38 @@ +{ + /** + * Creates a [Prometheus target](https://grafana.com/docs/grafana/latest/datasources/prometheus/) + * to be added to panels. + * + * @name prometheus.target + * + * @param expr PromQL query to be exercised against Prometheus. Checkout [Prometheus documentation](https://prometheus.io/docs/prometheus/latest/querying/basics/). + * @param format (default `'time_series'`) Switch between `'table'`, `'time_series'` or `'heatmap'`. Table will only work in the Table panel. Heatmap is suitable for displaying metrics of the Histogram type on a Heatmap panel. Under the hood, it converts cumulative histograms to regular ones and sorts series by the bucket bound. + * @param intervalFactor (default `2`) + * @param legendFormat (default `''`) Controls the name of the time series, using name or pattern. For example `{{hostname}}` is replaced with the label value for the label `hostname`. + * @param datasource (optional) Name of the Prometheus datasource. Leave by default otherwise. + * @param interval (optional) Time span used to aggregate or group data points by time. By default Grafana uses an automatic interval calculated based on the width of the graph. + * @param instant (optional) Perform an "instant" query, to return only the latest value that Prometheus has scraped for the requested time series. Instant queries return results much faster than normal range queries. Use them to look up label sets. + * @param hide (optional) Set to `true` to hide the target from the panel. + * + * @return A Prometheus target to be added to panels. + */ + target( + expr, + format='time_series', + intervalFactor=2, + legendFormat='', + datasource=null, + interval=null, + instant=null, + hide=null, + ):: { + [if hide != null then 'hide']: hide, + [if datasource != null then 'datasource']: datasource, + expr: expr, + format: format, + intervalFactor: intervalFactor, + legendFormat: legendFormat, + [if interval != null then 'interval']: interval, + [if instant != null then 'instant']: instant, + }, +} diff --git a/embeds/grafonnet-lib/grafonnet/row.libsonnet b/embeds/grafonnet-lib/grafonnet/row.libsonnet new file mode 100644 index 000000000..b380192d0 --- /dev/null +++ b/embeds/grafonnet-lib/grafonnet/row.libsonnet @@ -0,0 +1,47 @@ +{ + /** + * Creates a [row](https://grafana.com/docs/grafana/latest/features/dashboard/dashboards/#rows). + * Rows are logical dividers within a dashboard and used to group panels together. + * + * @name row.new + * + * @param title The title of the row. + * @param showTitle (default `true` if title is set) Whether to show the row title + * @paral titleSize (default `'h6'`) The size of the title + * @param collapse (default `false`) The initial state of the row when opening the dashboard. Panels in a collapsed row are not load until the row is expanded. + * @param repeat (optional) Name of variable that should be used to repeat this row. It is recommended to use the variable in the row title as well. + * + * @method addPanels(panels) Appends an array of nested panels + * @method addPanel(panel,gridPos) Appends a nested panel, with an optional grid position in grid coordinates, e.g. `gridPos={'x':0, 'y':0, 'w':12, 'h': 9}` + */ + new( + title='Dashboard Row', + height=null, + collapse=false, + repeat=null, + showTitle=null, + titleSize='h6' + ):: { + collapse: collapse, + collapsed: collapse, + [if height != null then 'height']: height, + panels: [], + repeat: repeat, + repeatIteration: null, + repeatRowId: null, + showTitle: + if showTitle != null then + showTitle + else + title != 'Dashboard Row', + title: title, + type: 'row', + titleSize: titleSize, + addPanels(panels):: self { + panels+: panels, + }, + addPanel(panel, gridPos={}):: self { + panels+: [panel { gridPos: gridPos }], + }, + }, +} diff --git a/embeds/grafonnet-lib/grafonnet/singlestat.libsonnet b/embeds/grafonnet-lib/grafonnet/singlestat.libsonnet new file mode 100644 index 000000000..78428d252 --- /dev/null +++ b/embeds/grafonnet-lib/grafonnet/singlestat.libsonnet @@ -0,0 +1,181 @@ +{ + /** + * Creates a singlestat panel. + * + * @name singlestat.new + * + * @param title The title of the singlestat panel. + * @param format (default `'none'`) Unit + * @param description (default `''`) + * @param interval (optional) + * @param height (optional) + * @param datasource (optional) + * @param span (optional) + * @param min_span (optional) + * @param decimals (optional) + * @param valueName (default `'avg'`) + * @param valueFontSize (default `'80%'`) + * @param prefixFontSize (default `'50%'`) + * @param postfixFontSize (default `'50%'`) + * @param mappingType (default `1`) + * @param repeat (optional) + * @param repeatDirection (optional) + * @param prefix (default `''`) + * @param postfix (default `''`) + * @param colors (default `['#299c46','rgba(237, 129, 40, 0.89)','#d44a3a']`) + * @param colorBackground (default `false`) + * @param colorValue (default `false`) + * @param thresholds (default `''`) + * @param valueMaps (default `{value: 'null',op: '=',text: 'N/A'}`) + * @param rangeMaps (default `{value: 'null',op: '=',text: 'N/A'}`) + * @param transparent (optional) + * @param sparklineFillColor (default `'rgba(31, 118, 189, 0.18)'`) + * @param sparklineFull (default `false`) + * @param sparklineLineColor (default `'rgb(31, 120, 193)'`) + * @param sparklineShow (default `false`) + * @param gaugeShow (default `false`) + * @param gaugeMinValue (default `0`) + * @param gaugeMaxValue (default `100`) + * @param gaugeThresholdMarkers (default `true`) + * @param gaugeThresholdLabels (default `false`) + * @param timeFrom (optional) + * @param links (optional) + * @param tableColumn (default `''`) + * @param maxPerRow (optional) + * @param maxDataPoints (default `100`) + * + * @method addTarget(target) Adds a target object. + */ + new( + title, + format='none', + description='', + interval=null, + height=null, + datasource=null, + span=null, + min_span=null, + decimals=null, + valueName='avg', + valueFontSize='80%', + prefixFontSize='50%', + postfixFontSize='50%', + mappingType=1, + repeat=null, + repeatDirection=null, + prefix='', + postfix='', + colors=[ + '#299c46', + 'rgba(237, 129, 40, 0.89)', + '#d44a3a', + ], + colorBackground=false, + colorValue=false, + thresholds='', + valueMaps=[ + { + value: 'null', + op: '=', + text: 'N/A', + }, + ], + rangeMaps=[ + { + from: 'null', + to: 'null', + text: 'N/A', + }, + ], + transparent=null, + sparklineFillColor='rgba(31, 118, 189, 0.18)', + sparklineFull=false, + sparklineLineColor='rgb(31, 120, 193)', + sparklineShow=false, + gaugeShow=false, + gaugeMinValue=0, + gaugeMaxValue=100, + gaugeThresholdMarkers=true, + gaugeThresholdLabels=false, + timeFrom=null, + links=[], + tableColumn='', + maxPerRow=null, + maxDataPoints=100, + ):: + { + [if height != null then 'height']: height, + [if description != '' then 'description']: description, + [if repeat != null then 'repeat']: repeat, + [if repeatDirection != null then 'repeatDirection']: repeatDirection, + [if transparent != null then 'transparent']: transparent, + [if min_span != null then 'minSpan']: min_span, + title: title, + [if span != null then 'span']: span, + type: 'singlestat', + datasource: datasource, + targets: [ + ], + links: links, + [if decimals != null then 'decimals']: decimals, + maxDataPoints: maxDataPoints, + interval: interval, + cacheTimeout: null, + format: format, + prefix: prefix, + postfix: postfix, + nullText: null, + valueMaps: valueMaps, + [if maxPerRow != null then 'maxPerRow']: maxPerRow, + mappingTypes: [ + { + name: 'value to text', + value: 1, + }, + { + name: 'range to text', + value: 2, + }, + ], + rangeMaps: rangeMaps, + mappingType: + if mappingType == 'value' + then + 1 + else if mappingType == 'range' + then + 2 + else + mappingType, + nullPointMode: 'connected', + valueName: valueName, + prefixFontSize: prefixFontSize, + valueFontSize: valueFontSize, + postfixFontSize: postfixFontSize, + thresholds: thresholds, + [if timeFrom != null then 'timeFrom']: timeFrom, + colorBackground: colorBackground, + colorValue: colorValue, + colors: colors, + gauge: { + show: gaugeShow, + minValue: gaugeMinValue, + maxValue: gaugeMaxValue, + thresholdMarkers: gaugeThresholdMarkers, + thresholdLabels: gaugeThresholdLabels, + }, + sparkline: { + fillColor: sparklineFillColor, + full: sparklineFull, + lineColor: sparklineLineColor, + show: sparklineShow, + }, + tableColumn: tableColumn, + _nextTarget:: 0, + addTarget(target):: self { + local nextTarget = super._nextTarget, + _nextTarget: nextTarget + 1, + targets+: [target { refId: std.char(std.codepoint('A') + nextTarget) }], + }, + }, +} diff --git a/embeds/grafonnet-lib/grafonnet/sql.libsonnet b/embeds/grafonnet-lib/grafonnet/sql.libsonnet new file mode 100644 index 000000000..ab48543fe --- /dev/null +++ b/embeds/grafonnet-lib/grafonnet/sql.libsonnet @@ -0,0 +1,23 @@ +{ + /** + * Creates an SQL target. + * + * @name sql.target + * + * @param rawSql The SQL query + * @param datasource (optional) + * @param format (default `'time_series'`) + * @param alias (optional) + */ + target( + rawSql, + datasource=null, + format='time_series', + alias=null, + ):: { + [if datasource != null then 'datasource']: datasource, + format: format, + [if alias != null then 'alias']: alias, + rawSql: rawSql, + }, +} diff --git a/embeds/grafonnet-lib/grafonnet/stat_panel.libsonnet b/embeds/grafonnet-lib/grafonnet/stat_panel.libsonnet new file mode 100644 index 000000000..5d1e5e7f6 --- /dev/null +++ b/embeds/grafonnet-lib/grafonnet/stat_panel.libsonnet @@ -0,0 +1,222 @@ +{ + /** + * Creates a [stat panel](https://grafana.com/docs/grafana/latest/panels/visualizations/stat-panel/). + * + * @name statPanel.new + * + * @param title Panel title. + * @param description (optional) Panel description. + * @param transparent (default `false`) Whether to display the panel without a background. + * @param datasource (optional) Panel datasource. + * @param allValues (default `false`) Show all values instead of reducing to one. + * @param valueLimit (optional) Limit of values in all values mode. + * @param reducerFunction (default `'mean'`) Function to use to reduce values to when using single value. + * @param fields (default `''`) Fields that should be included in the panel. + * @param orientation (default `'auto'`) Stacking direction in case of multiple series or fields. + * @param colorMode (default `'value'`) 'value' or 'background'. + * @param graphMode (default `'area'`) 'none' or 'area' to enable sparkline mode. + * @param textMode (default `'auto'`) Control if name and value is displayed or just name. + * @param justifyMode (default `'auto'`) 'auto' or 'center'. + * @param unit (default `'none'`) Panel unit field option. + * @param min (optional) Leave empty to calculate based on all values. + * @param max (optional) Leave empty to calculate based on all values. + * @param decimals (optional) Number of decimal places to show. + * @param displayName (optional) Change the field or series name. + * @param noValue (optional) What to show when there is no value. + * @param thresholdsMode (default `'absolute'`) 'absolute' or 'percentage'. + * @param timeFrom (optional) Override the relative time range. + * @param repeat (optional) Name of variable that should be used to repeat this panel. + * @param repeatDirection (default `'h'`) 'h' for horizontal or 'v' for vertical. + * @param maxPerRow (optional) Maximum panels per row in repeat mode. + * @param pluginVersion (default `'7'`) Plugin version the panel should be modeled for. This has been tested with the default, '7', and '6.7'. + * + * @method addTarget(target) Adds a target object. + * @method addTargets(targets) Adds an array of targets. + * @method addLink(link) Adds a [panel link](https://grafana.com/docs/grafana/latest/linking/panel-links/). Argument format: `{ title: 'Link Title', url: 'https://...', targetBlank: true }`. + * @method addLinks(links) Adds an array of links. + * @method addThreshold(step) Adds a [threshold](https://grafana.com/docs/grafana/latest/panels/thresholds/) step. Argument format: `{ color: 'green', value: 0 }`. + * @method addThresholds(steps) Adds an array of threshold steps. + * @method addMapping(mapping) Adds a value mapping. + * @method addMappings(mappings) Adds an array of value mappings. + * @method addDataLink(link) Adds a data link. + * @method addDataLinks(links) Adds an array of data links. + */ + new( + title, + description=null, + transparent=false, + datasource=null, + allValues=false, + valueLimit=null, + reducerFunction='mean', + fields='', + orientation='auto', + colorMode='value', + graphMode='area', + textMode='auto', + justifyMode='auto', + unit='none', + min=null, + max=null, + decimals=null, + displayName=null, + noValue=null, + thresholdsMode='absolute', + timeFrom=null, + repeat=null, + repeatDirection='h', + maxPerRow=null, + pluginVersion='7', + ):: { + + type: 'stat', + title: title, + [if description != null then 'description']: description, + transparent: transparent, + datasource: datasource, + targets: [], + links: [], + [if repeat != null then 'repeat']: repeat, + [if repeat != null then 'repeatDirection']: repeatDirection, + [if timeFrom != null then 'timeFrom']: timeFrom, + [if repeat != null then 'maxPerRow']: maxPerRow, + + // targets + _nextTarget:: 0, + addTarget(target):: self { + local nextTarget = super._nextTarget, + _nextTarget: nextTarget + 1, + targets+: [target { refId: std.char(std.codepoint('A') + nextTarget) }], + }, + addTargets(targets):: std.foldl(function(p, t) p.addTarget(t), targets, self), + + // links + addLink(link):: self { + links+: [link], + }, + addLinks(links):: std.foldl(function(p, l) p.addLink(l), links, self), + + pluginVersion: pluginVersion, + } + ( + + if pluginVersion >= '7' then { + options: { + reduceOptions: { + values: allValues, + [if allValues && valueLimit != null then 'limit']: valueLimit, + calcs: [ + reducerFunction, + ], + fields: fields, + }, + orientation: orientation, + colorMode: colorMode, + graphMode: graphMode, + justifyMode: justifyMode, + textMode: textMode, + }, + fieldConfig: { + defaults: { + unit: unit, + [if min != null then 'min']: min, + [if max != null then 'max']: max, + [if decimals != null then 'decimals']: decimals, + [if displayName != null then 'displayName']: displayName, + [if noValue != null then 'noValue']: noValue, + thresholds: { + mode: thresholdsMode, + steps: [], + }, + mappings: [], + links: [], + }, + }, + + // thresholds + addThreshold(step):: self { + fieldConfig+: { defaults+: { thresholds+: { steps+: [step] } } }, + }, + + // mappings + _nextMapping:: 0, + addMapping(mapping):: self { + local nextMapping = super._nextMapping, + _nextMapping: nextMapping + 1, + fieldConfig+: { defaults+: { mappings+: [mapping { id: nextMapping }] } }, + }, + + // data links + addDataLink(link):: self { + fieldConfig+: { defaults+: { links+: [link] } }, + }, + + // Overrides + addOverride( + matcher=null, + properties=null, + ):: self { + fieldConfig+: { + overrides+: [ + { + [if matcher != null then 'matcher']: matcher, + [if properties != null then 'properties']: properties, + }, + ], + }, + }, + addOverrides(overrides):: std.foldl(function(p, o) p.addOverride(o.matcher, o.properties), overrides, self), + } else { + options: { + fieldOptions: { + values: allValues, + [if allValues && valueLimit != null then 'limit']: valueLimit, + calcs: [ + reducerFunction, + ], + fields: fields, + defaults: { + unit: unit, + [if min != null then 'min']: min, + [if max != null then 'max']: max, + [if decimals != null then 'decimals']: decimals, + [if displayName != null then 'displayName']: displayName, + [if noValue != null then 'noValue']: noValue, + thresholds: { + mode: thresholdsMode, + steps: [], + }, + mappings: [], + links: [], + }, + }, + orientation: orientation, + colorMode: colorMode, + graphMode: graphMode, + justifyMode: justifyMode, + }, + + // thresholds + addThreshold(step):: self { + options+: { fieldOptions+: { defaults+: { thresholds+: { steps+: [step] } } } }, + }, + + // mappings + _nextMapping:: 0, + addMapping(mapping):: self { + local nextMapping = super._nextMapping, + _nextMapping: nextMapping + 1, + options+: { fieldOptions+: { defaults+: { mappings+: [mapping { id: nextMapping }] } } }, + }, + + // data links + addDataLink(link):: self { + options+: { fieldOptions+: { defaults+: { links+: [link] } } }, + }, + } + + ) + { + addThresholds(steps):: std.foldl(function(p, s) p.addThreshold(s), steps, self), + addMappings(mappings):: std.foldl(function(p, m) p.addMapping(m), mappings, self), + addDataLinks(links):: std.foldl(function(p, l) p.addDataLink(l), links, self), + }, +} diff --git a/embeds/grafonnet-lib/grafonnet/table_panel.libsonnet b/embeds/grafonnet-lib/grafonnet/table_panel.libsonnet new file mode 100644 index 000000000..4c686b3d5 --- /dev/null +++ b/embeds/grafonnet-lib/grafonnet/table_panel.libsonnet @@ -0,0 +1,91 @@ +{ + /** + * Creates a [table panel](https://grafana.com/docs/grafana/latest/panels/visualizations/table-panel/) that can be added in a row. + * It requires the table panel plugin in grafana, which is built-in. + * + * @name table.new + * + * @param title The title of the graph panel. + * @param description (optional) Description of the panel + * @param span (optional) Width of the panel + * @param height (optional) Height of the panel + * @param datasource (optional) Datasource + * @param min_span (optional) Min span + * @param styles (optional) Array of styles for the panel + * @param columns (optional) Array of columns for the panel + * @param sort (optional) Sorting instruction for the panel + * @param transform (optional) Allow table manipulation to present data as desired + * @param transparent (default: 'false') Whether to display the panel without a background + * @param links (optional) Array of links for the panel. + * @return A json that represents a table panel + * + * @method addTarget(target) Adds a target object + * @method addTargets(targets) Adds an array of targets + * @method addColumn(field, style) Adds a column + * @method hideColumn(field) Hides a column + * @method addLink(link) Adds a link + * @method addTransformation(transformation) Adds a transformation object + * @method addTransformations(transformations) Adds an array of transformations + */ + new( + title, + description=null, + span=null, + min_span=null, + height=null, + datasource=null, + styles=[], + transform=null, + transparent=false, + columns=[], + sort=null, + time_from=null, + time_shift=null, + links=[], + ):: { + type: 'table', + title: title, + [if span != null then 'span']: span, + [if min_span != null then 'minSpan']: min_span, + [if height != null then 'height']: height, + datasource: datasource, + targets: [ + ], + styles: styles, + columns: columns, + timeFrom: time_from, + timeShift: time_shift, + links: links, + [if sort != null then 'sort']: sort, + [if description != null then 'description']: description, + [if transform != null then 'transform']: transform, + [if transparent == true then 'transparent']: transparent, + _nextTarget:: 0, + addTarget(target):: self { + local nextTarget = super._nextTarget, + _nextTarget: nextTarget + 1, + targets+: [target { refId: std.char(std.codepoint('A') + nextTarget) }], + }, + addTargets(targets):: std.foldl(function(p, t) p.addTarget(t), targets, self), + addColumn(field, style):: self { + local style_ = style { pattern: field }, + local column_ = { text: field, value: field }, + styles+: [style_], + columns+: [column_], + }, + hideColumn(field):: self { + styles+: [{ + alias: field, + pattern: field, + type: 'hidden', + }], + }, + addLink(link):: self { + links+: [link], + }, + addTransformation(transformation):: self { + transformations+: [transformation], + }, + addTransformations(transformations):: std.foldl(function(p, t) p.addTransformation(t), transformations, self), + }, +} diff --git a/embeds/grafonnet-lib/grafonnet/template.libsonnet b/embeds/grafonnet-lib/grafonnet/template.libsonnet new file mode 100644 index 000000000..be253e19a --- /dev/null +++ b/embeds/grafonnet-lib/grafonnet/template.libsonnet @@ -0,0 +1,289 @@ +{ + /** + * Creates a [template](https://grafana.com/docs/grafana/latest/variables/#templates) that can be added to a dashboard. + * + * @name template.new + * + * @param name Name of variable. + * @param datasource Template [datasource](https://grafana.com/docs/grafana/latest/variables/variable-types/add-data-source-variable/) + * @param query [Query expression](https://grafana.com/docs/grafana/latest/variables/variable-types/add-query-variable/) for the datasource. + * @param label (optional) Display name of the variable dropdown. If null, then the dropdown label will be the variable name. + * @param allValues (optional) Formatting for [multi-value variables](https://grafana.com/docs/grafana/latest/variables/formatting-multi-value-variables/#formatting-multi-value-variables) + * @param tagValuesQuery (default `''`) Group values into [selectable tags](https://grafana.com/docs/grafana/latest/variables/variable-value-tags/) + * @param current (default `null`) Can be `null`, `'all'` for all, or any other custom text value. + * @param hide (default `''`) `''`: the variable dropdown displays the variable Name or Label value. `'label'`: the variable dropdown only displays the selected variable value and a down arrow. Any other value: no variable dropdown is displayed on the dashboard. + * @param regex (default `''`) Regex expression to filter or capture specific parts of the names returned by your data source query. To see examples, refer to [Filter variables with regex](https://grafana.com/docs/grafana/latest/variables/filter-variables-with-regex/). + * @param refresh (default `'never'`) `'never'`: variables queries are cached and values are not updated. This is fine if the values never change, but problematic if they are dynamic and change a lot. `'load'`: Queries the data source every time the dashboard loads. This slows down dashboard loading, because the variable query needs to be completed before dashboard can be initialized. `'time'`: Queries the data source when the dashboard time range changes. Only use this option if your variable options query contains a time range filter or is dependent on the dashboard time range. + * @param includeAll (default `false`) Whether all value option is available or not. + * @param multi (default `false`) Whether multiple values can be selected or not from variable value list. + * @param sort (default `0`) `0`: Without Sort, `1`: Alphabetical (asc), `2`: Alphabetical (desc), `3`: Numerical (asc), `4`: Numerical (desc). + * + * @return A [template](https://grafana.com/docs/grafana/latest/variables/#templates) + */ + new( + name, + datasource, + query, + label=null, + allValues=null, + tagValuesQuery='', + current=null, + hide='', + regex='', + refresh='never', + includeAll=false, + multi=false, + sort=0, + ):: + { + allValue: allValues, + current: $.current(current), + datasource: datasource, + includeAll: includeAll, + hide: $.hide(hide), + label: label, + multi: multi, + name: name, + options: [], + query: query, + refresh: $.refresh(refresh), + regex: regex, + sort: sort, + tagValuesQuery: tagValuesQuery, + tags: [], + tagsQuery: '', + type: 'query', + useTags: false, + }, + /** + * Use an [interval variable](https://grafana.com/docs/grafana/latest/variables/variable-types/add-interval-variable/) to represent time spans such as '1m', '1h', '1d'. You can think of them as a dashboard-wide "group by time" command. Interval variables change how the data is grouped in the visualization. You can also use the Auto Option to return a set number of data points per time span. + * You can use an interval variable as a parameter to group by time (for InfluxDB), date histogram interval (for Elasticsearch), or as a summarize function parameter (for Graphite). + * + * @name template.interval + * + * @param name Variable name + * @param query Comma separated values without spacing of intervals available for selection. Add `'auto'` in the query to turn on the Auto Option. Ex: `'auto,5m,10m,20m'`. + * @param current Currently selected interval. Must be one of the values in the query. `'auto'` is allowed if defined in the query. + * @param hide (default `''`) `''`: the variable dropdown displays the variable Name or Label value. `'label'`: the variable dropdown only displays the selected variable value and a down arrow. Any other value: no variable dropdown is displayed on the dashboard. + * @param label (optional) Display name of the variable dropdown. If null, then the dropdown label will be the variable name. + * @param auto_count (default `300`) Valid only if `'auto'` is defined in query. Number of times the current time range will be divided to calculate the value, similar to the Max data points query option. For example, if the current visible time range is 30 minutes, then the auto interval groups the data into 30 one-minute increments. The default value is 30 steps. + * @param auto_min (default `'10s'`) Valid only if `'auto'` is defined in query. The minimum threshold below which the step count intervals will not divide the time. To continue the 30 minute example, if the minimum interval is set to `'2m'`, then Grafana would group the data into 15 two-minute increments. + * + * @return A new interval variable for templating. + */ + interval( + name, + query, + current, + hide='', + label=null, + auto_count=300, + auto_min='10s', + ):: + { + current: $.current(current), + hide: $.hide(hide), + label: label, + name: name, + query: std.join(',', std.filter($.filterAuto, std.split(query, ','))), + refresh: 2, + type: 'interval', + auto: std.count(std.split(query, ','), 'auto') > 0, + auto_count: auto_count, + auto_min: auto_min, + }, + hide(hide):: + if hide == '' then 0 else if hide == 'label' then 1 else 2, + current(current):: { + [if current != null then 'text']: current, + [if current != null then 'value']: if current == 'auto' then + '$__auto_interval' + else if current == 'all' then + '$__all' + else + current, + }, + /** + * Data [source variables](https://grafana.com/docs/grafana/latest/variables/variable-types/add-data-source-variable/) + * allow you to quickly change the data source for an entire dashboard. + * They are useful if you have multiple instances of a data source, perhaps in different environments. + * + * @name template.datasource + * + * @param name Data source variable name. Ex: `'PROMETHEUS_DS'`. + * @param query Type of data source. Ex: `'prometheus'`. + * @param current Ex: `'Prometheus'`. + * @param hide (default `''`) `''`: the variable dropdown displays the variable Name or Label value. `'label'`: the variable dropdown only displays the selected variable value and a down arrow. Any other value: no variable dropdown is displayed on the dashboard. + * @param label (optional) Display name of the variable dropdown. If null, then the dropdown label will be the variable name. + * @param regex (default `''`) Regex filter for which data source instances to choose from in the variable value drop-down list. Leave this field empty to display all instances. + * @param refresh (default `'load'`) `'never'`: Variables queries are cached and values are not updated. This is fine if the values never change, but problematic if they are dynamic and change a lot. `'load'`: Queries the data source every time the dashboard loads. This slows down dashboard loading, because the variable query needs to be completed before dashboard can be initialized. `'time'`: Queries the data source when the dashboard time range changes. Only use this option if your variable options query contains a time range filter or is dependent on the dashboard time range. + * + * @return A [data source variable](https://grafana.com/docs/grafana/latest/variables/variable-types/add-data-source-variable/). + */ + datasource( + name, + query, + current, + hide='', + label=null, + regex='', + refresh='load', + ):: { + current: $.current(current), + hide: $.hide(hide), + label: label, + name: name, + options: [], + query: query, + refresh: $.refresh(refresh), + regex: regex, + type: 'datasource', + }, + refresh(refresh):: if refresh == 'never' + then + 0 + else if refresh == 'load' + then + 1 + else if refresh == 'time' + then + 2 + else + refresh, + filterAuto(str):: str != 'auto', + /** + * Use a [custom variable](https://grafana.com/docs/grafana/latest/variables/variable-types/add-custom-variable/) + * for values that do not change. + * + * @name template.custom + * This might be numbers, strings, or even other variables. + * @param name Variable name + * @param query Comma separated without spacing list of selectable values. + * @param current Selected value + * @param refresh (default `'never'`) `'never'`: Variables queries are cached and values are not updated. This is fine if the values never change, but problematic if they are dynamic and change a lot. `'load'`: Queries the data source every time the dashboard loads. This slows down dashboard loading, because the variable query needs to be completed before dashboard can be initialized. `'time'`: Queries the data source when the dashboard time range changes. Only use this option if your variable options query contains a time range filter or is dependent on the dashboard time range. + * @param label (default `''`) Display name of the variable dropdown. If you don’t enter a display name, then the dropdown label will be the variable name. + * @param valuelabels (default `{}`) Display names for values defined in query. For example, if `query='new,old'`, then you may display them as follows `valuelabels={new: 'nouveau', old: 'ancien'}`. + * @param multi (default `false`) Whether multiple values can be selected or not from variable value list. + * @param allValues (optional) Formatting for [multi-value variables](https://grafana.com/docs/grafana/latest/variables/formatting-multi-value-variables/#formatting-multi-value-variables) + * @param includeAll (default `false`) Whether all value option is available or not. + * @param hide (default `''`) `''`: the variable dropdown displays the variable Name or Label value. `'label'`: the variable dropdown only displays the selected variable value and a down arrow. Any other value: no variable dropdown is displayed on the dashboard. + * + * @return A custom variable. + */ + custom( + name, + query, + current, + refresh='never', + label='', + valuelabels={}, + multi=false, + allValues=null, + includeAll=false, + hide='', + ):: + { + // self has dynamic scope, so self may not be myself below. + // '$' can't be used neither as this object is not top-level object. + local custom = self, + + allValue: allValues, + current: { + // Both 'all' and 'All' are accepted for consistency. + value: if includeAll && (current == 'All' || current == 'all') then + if multi then ['$__all'] else '$__all' + else + current, + text: if std.isArray(current) then + std.join(' + ', std.map(custom.valuelabel, current)) + else + custom.valuelabel(current), + [if multi then 'selected']: true, + }, + options: std.map(self.option, self.query_array(query)), + hide: $.hide(hide), + includeAll: includeAll, + label: label, + refresh: $.refresh(refresh), + multi: multi, + name: name, + query: query, + type: 'custom', + + valuelabel(value):: if value in valuelabels then + valuelabels[value] + else value, + + option(option):: { + text: custom.valuelabel(option), + value: if includeAll && option == 'All' then '$__all' else option, + [if multi then 'selected']: if multi && std.isArray(current) then + std.member(current, option) + else if multi then + current == option + else + null, + }, + query_array(query):: std.split( + if includeAll then 'All,' + query else query, ',' + ), + }, + /** + * [Text box variables](https://grafana.com/docs/grafana/latest/variables/variable-types/add-text-box-variable/) + * display a free text input field with an optional default value. + * This is the most flexible variable, because you can enter any value. + * Use this type of variable if you have metrics with high cardinality or if you want to + * update multiple panels in a dashboard at the same time. + * + * @name template.text + * + * @param name Variable name. + * @param label (default `''`) Display name of the variable dropdown. If you don’t enter a display name, then the dropdown label will be the variable name. + * + * @return A text box variable. + */ + text( + name, + label='' + ):: + { + current: { + selected: false, + text: '', + value: '', + }, + name: name, + label: label, + query: '', + type: 'textbox', + }, + /** + * [Ad hoc filters](https://grafana.com/docs/grafana/latest/variables/variable-types/add-ad-hoc-filters/) + * allow you to add key/value filters that are automatically added to all metric queries + * that use the specified data source. Unlike other variables, you do not use ad hoc filters in queries. + * Instead, you use ad hoc filters to write filters for existing queries. + * Note: Ad hoc filter variables only work with InfluxDB, Prometheus, and Elasticsearch data sources. + * + * @name template.adhoc + * + * @param name Variable name. + * @param datasource Target data source + * @param label (optional) Display name of the variable dropdown. If you don’t enter a display name, then the dropdown label will be the variable name. + * @param hide (default `''`) `''`: the variable dropdown displays the variable Name or Label value. `'label'`: the variable dropdown only displays the selected variable value and a down arrow. Any other value: no variable dropdown is displayed on the dashboard. + * + * @return An ad hoc filter + */ + adhoc( + name, + datasource, + label=null, + hide='', + ):: + { + datasource: datasource, + hide: $.hide(hide), + label: label, + name: name, + type: 'adhoc', + }, +} diff --git a/embeds/grafonnet-lib/grafonnet/text.libsonnet b/embeds/grafonnet-lib/grafonnet/text.libsonnet new file mode 100644 index 000000000..18020a678 --- /dev/null +++ b/embeds/grafonnet-lib/grafonnet/text.libsonnet @@ -0,0 +1,43 @@ +{ + /** + * Creates a [text panel](https://grafana.com/docs/grafana/latest/panels/visualizations/text-panel/). + * + * @name text.new + * + * @param title (default `''`) Panel title. + * @param description (optional) Panel description. + * @param datasource (optional) Panel datasource. + * @param span (optional) + * @param content (default `''`) + * @param mode (default `'markdown'`) Rendering of the content: 'markdown','html', ... + * @param transparent (optional) Whether to display the panel without a background. + * @param repeat (optional) Name of variable that should be used to repeat this panel. + * @param repeatDirection (default `'h'`) 'h' for horizontal or 'v' for vertical. + * @param repeatMaxPerRow (optional) Maximum panels per row in repeat mode. + */ + new( + title='', + span=null, + mode='markdown', + content='', + transparent=null, + description=null, + datasource=null, + repeat=null, + repeatDirection=null, + repeatMaxPerRow=null, + ):: + { + [if transparent != null then 'transparent']: transparent, + title: title, + [if span != null then 'span']: span, + type: 'text', + mode: mode, + content: content, + [if description != null then 'description']: description, + datasource: datasource, + [if repeat != null then 'repeat']: repeat, + [if repeat != null then 'repeatDirection']: repeatDirection, + [if repeat != null then 'maxPerRow']: repeatMaxPerRow, + }, +} diff --git a/embeds/grafonnet-lib/grafonnet/timepicker.libsonnet b/embeds/grafonnet-lib/grafonnet/timepicker.libsonnet new file mode 100644 index 000000000..9c18bef86 --- /dev/null +++ b/embeds/grafonnet-lib/grafonnet/timepicker.libsonnet @@ -0,0 +1,40 @@ +{ + /** + * Creates a Timepicker + * + * @name timepicker.new + * + * @param refresh_intervals (default: `['5s','10s','30s','1m','5m','15m','30m','1h','2h','1d']`) Array of time durations + * @param time_options (default: `['5m','15m','1h','6h','12h','24h','2d','7d','30d']`) Array of time durations + */ + new( + refresh_intervals=[ + '5s', + '10s', + '30s', + '1m', + '5m', + '15m', + '30m', + '1h', + '2h', + '1d', + ], + time_options=[ + '5m', + '15m', + '1h', + '6h', + '12h', + '24h', + '2d', + '7d', + '30d', + ], + nowDelay=null, + ):: { + refresh_intervals: refresh_intervals, + time_options: time_options, + [if nowDelay != null then 'nowDelay']: nowDelay, + }, +} diff --git a/embeds/grafonnet-lib/grafonnet/transformation.libsonnet b/embeds/grafonnet-lib/grafonnet/transformation.libsonnet new file mode 100644 index 000000000..5e62adeac --- /dev/null +++ b/embeds/grafonnet-lib/grafonnet/transformation.libsonnet @@ -0,0 +1,12 @@ +{ + /** + * @name transformation.new + */ + new( + id='', + options={} + ):: { + id: id, + options: options, + }, +} From cc122c9be62aef5696506decb1e1d50bf18592d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Henri?= Date: Fri, 20 Oct 2023 15:26:24 -0300 Subject: [PATCH 2/4] Remove git submodule mentions in CI and documentation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: João Henri --- .github/workflows/e2e.yaml | 4 +--- .github/workflows/pr-validation.yaml | 11 +---------- .github/workflows/release.yaml | 2 -- CONTRIBUTING.md | 4 +--- Makefile | 4 ---- embeds/README.md | 9 --------- 6 files changed, 3 insertions(+), 31 deletions(-) diff --git a/.github/workflows/e2e.yaml b/.github/workflows/e2e.yaml index 6615641f5..9e0ac99cd 100644 --- a/.github/workflows/e2e.yaml +++ b/.github/workflows/e2e.yaml @@ -48,10 +48,8 @@ jobs: env: KUBECONFIG: /home/runner/.kube/kind-grafana-operator-e2e steps: - - name: Clone repo and checkout submodules + - name: Clone repo and checkout uses: actions/checkout@v4 - with: - submodules: recursive - uses: actions/setup-go@v4 with: diff --git a/.github/workflows/pr-validation.yaml b/.github/workflows/pr-validation.yaml index bf1477561..56f645138 100644 --- a/.github/workflows/pr-validation.yaml +++ b/.github/workflows/pr-validation.yaml @@ -88,8 +88,6 @@ jobs: steps: - name: Clone repo uses: actions/checkout@v4 #v3.2.0 - with: - submodules: recursive - name: Setup go uses: actions/setup-go@v4 @@ -106,8 +104,6 @@ jobs: steps: - name: Clone repo uses: actions/checkout@v4 #v3.2.0 - with: - submodules: recursive - name: Setup go uses: actions/setup-go@v4 @@ -131,8 +127,6 @@ jobs: steps: - name: Clone repo uses: actions/checkout@v4 #v3.2.0 - with: - submodules: recursive - name: Setup go uses: actions/setup-go@v4 @@ -156,8 +150,6 @@ jobs: steps: - name: Clone repo uses: actions/checkout@v4 #v3.2.0 - with: - submodules: recursive - name: Setup go uses: actions/setup-go@v4 @@ -181,8 +173,7 @@ jobs: steps: - name: Clone repo uses: actions/checkout@v4 #v3.2.0 - with: - submodules: recursive + - name: Run Trivy vulnerability scanner uses: aquasecurity/trivy-action@master with: diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index 593e2be5c..ef00e20b3 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -68,8 +68,6 @@ jobs: steps: - name: Clone repo uses: actions/checkout@v4 - with: - submodules: recursive - name: Login to GitHub Container Registry uses: docker/login-action@v3 diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index c88336c4b..30a9b6cbb 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -6,8 +6,7 @@ Thank you for investing your time in contributing to our project. The operator uses unit tests and [Kuttl](https://kuttl.dev/) for e2e tests to make sure that the operator is working as intended, we use make to generate a number of docs and scripts for us. -The operator use a submodule for [grafonnet-lib](https://github.com/grafana/grafonnet-lib), -one of the first things you have to do is to run `make submodule`. +The operator embeds [grafonnet-lib](https://github.com/grafana/grafonnet-lib) inside `embeds/grafonnet-lib`. It used to be a git submodule, however, as that folder was only filled when the git submodule was initiated, the grafana-operator couldn't be imported externally. **NOTE:** please, run `make all` before opening a PR to make sure your changes are compliant with our standards and all automatically generated files (like CRDs) are up-to-date. @@ -22,7 +21,6 @@ As a part of the CI solution these settings will be validated, but all of them c Before pushing any code we recommend that you run the following make commands. ```shell -make submodule make test make code/golangci-lint ``` diff --git a/Makefile b/Makefile index e9750b36a..f17eb9668 100644 --- a/Makefile +++ b/Makefile @@ -88,10 +88,6 @@ test: manifests generate code/gofumpt api-docs vet envtest ## Run tests. build: generate code/gofumpt vet ## Build manager binary. go build -o bin/manager main.go -# Get submodules -submodule: - git submodule update --init --recursive - .PHONY: run run: manifests generate code/gofumpt vet ## Run a controller from your host. go run ./main.go diff --git a/embeds/README.md b/embeds/README.md index 6a349b2c9..1b9ab7bcf 100644 --- a/embeds/README.md +++ b/embeds/README.md @@ -5,12 +5,3 @@ This directory is used for embedding FS structs into go code. # Grafonnet The Grafonnet Jsonnet is used to allow users to define their dashboards using the jsonnet framework. - -To update the library, run: - -```shell -git submodule update -``` - -**Note**: the root level .gitignore will ignore everything apart from grafonnet/ and grafonnet-7.0/ directories. -be careful if you need to add other files than these two, update the project root .gitignore accordingly From 6c7df1034c7644b90099a061896a027278e30dc3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Henri?= Date: Tue, 24 Oct 2023 08:59:53 -0300 Subject: [PATCH 3/4] Exclude embeds/grafonnet-lib/ from lint check --- .github/workflows/pr-validation.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/pr-validation.yaml b/.github/workflows/pr-validation.yaml index 56f645138..99d900663 100644 --- a/.github/workflows/pr-validation.yaml +++ b/.github/workflows/pr-validation.yaml @@ -32,7 +32,7 @@ jobs: git check-attr --stdin linguist-generated | grep -Ev ': (set|true)$' | cut -d: -f1 | git check-attr --stdin linguist-vendored | grep -Ev ': (set|true)$' | cut -d: -f1 | git check-attr --stdin ignore-lint | grep -Ev ': (set|true)$' | cut -d: -f1 | - grep -Ev '^(vendor/|third_party/|LICENSES/|.git|bundle/)' | + grep -Ev '^(vendor/|third_party/|LICENSES/|.git|bundle/|embeds/grafonnet-lib/)' | grep -v api.md | xargs grep -nE " +$" | reviewdog -efm="%f:%l:%m" \ @@ -63,7 +63,7 @@ jobs: git check-attr --stdin linguist-generated | grep -Ev ': (set|true)$' | cut -d: -f1 | git check-attr --stdin linguist-vendored | grep -Ev ': (set|true)$' | cut -d: -f1 | git check-attr --stdin ignore-lint | grep -Ev ': (set|true)$' | cut -d: -f1 | - grep -Ev '^(vendor/|third_party/|LICENSES/|.git)' | + grep -Ev '^(vendor/|third_party/|LICENSES/|.git|embeds/grafonnet-lib/)' | grep -v '\.ai$' | grep -v '\.svg$') for x in $LINT_FILES; do From 6fb4b0db1aa44450be59a2c311fb16bb88e4ec5b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Henri?= Date: Tue, 31 Oct 2023 16:39:16 +0000 Subject: [PATCH 4/4] Remove grafonnet-lib from .gitignore MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: João Henri --- .gitignore | 5 ----- 1 file changed, 5 deletions(-) diff --git a/.gitignore b/.gitignore index 11a9eba1b..e1df15327 100644 --- a/.gitignore +++ b/.gitignore @@ -33,10 +33,5 @@ kube-apiserver-audit.log labs/benchmark/dashboards labs/benchmark/datasources -# Grafonnet embeds -/embeds/grafonnet-lib/* -!/embeds/grafonnet-lib/grafonnet -!/embeds/grafonnet-lib/grafonnet-7.0 - # kind artifacts kubeconfig