From dc2df719958680e5be171972c1f92076809d4691 Mon Sep 17 00:00:00 2001 From: Jan Seidl Date: Tue, 16 Jul 2024 14:47:57 +0200 Subject: [PATCH] Neutral option for GaugePanel (#649) * Some targets (Influx for example) use alias insted of legendFormat (which is Prometheus 'alias'). This commit setup both of them by legendFormat. * Added `neutral` option for `GaugePanel` (supported by Grafana 9.3.0 - https://github.com/grafana/grafana/discussions/38273) --------- Co-authored-by: JamesGibo <22477854+JamesGibo@users.noreply.github.com> --- CHANGELOG.rst | 2 ++ grafanalib/core.py | 7 +++++++ 2 files changed, 9 insertions(+) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 04c6510c..efa486c8 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -6,6 +6,8 @@ Changelog x.x.x ? ======= +* Added `neutral` option for `GaugePanel` (supported by Grafana 9.3.0 - https://github.com/grafana/grafana/discussions/38273) +* Added support `alias` via the `legendFormat` option for `Target` * **Breaking change:** Fixed spelling errors for temperature units, corrected 'CELSUIS' to 'CELSIUS' and 'FARENHEIT' to 'FAHRENHEIT'. * Added ``tooltipSort`` parameter to PieChartv2 panel * Fix mappings for Table diff --git a/grafanalib/core.py b/grafanalib/core.py index 4515965d..79849fea 100644 --- a/grafanalib/core.py +++ b/grafanalib/core.py @@ -573,6 +573,7 @@ class Target(object): Metric to show. :param target: Graphite way to select data + :param legendFormat: Target alias. Prometheus use legendFormat, other like Influx use alias. This set legendFormat as well as alias. """ expr = attr.ib(default="") @@ -598,6 +599,7 @@ def to_json_data(self): 'interval': self.interval, 'intervalFactor': self.intervalFactor, 'legendFormat': self.legendFormat, + 'alias': self.legendFormat, 'metric': self.metric, 'refId': self.refId, 'step': self.step, @@ -3463,6 +3465,7 @@ class GaugePanel(Panel): :param thresholdMarkers: option to show marker of level on gauge :param thresholds: single stat thresholds :param valueMaps: the list of value to text mappings + :param neutral: neutral point of gauge, leave empty to use Min as neutral point """ allValues = attr.ib(default=False, validator=instance_of(bool)) @@ -3487,6 +3490,7 @@ class GaugePanel(Panel): validator=instance_of(list), ) valueMaps = attr.ib(default=attr.Factory(list)) + neutral = attr.ib(default=None) def to_json_data(self): return self.panel_json( @@ -3504,6 +3508,9 @@ def to_json_data(self): 'mappings': self.valueMaps, 'override': {}, 'values': self.allValues, + 'custom': { + 'neutral': self.neutral, + }, }, 'showThresholdLabels': self.thresholdLabels, 'showThresholdMarkers': self.thresholdMarkers,