From 1e7ba7b22c67800f49d4695ea9215fa71424b124 Mon Sep 17 00:00:00 2001 From: Michael Governanti Date: Fri, 19 Jul 2024 12:19:20 -0400 Subject: [PATCH 1/9] add color, fieldMinMax, and thresholdType parameters to class GaugePanel() --- grafanalib/core.py | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/grafanalib/core.py b/grafanalib/core.py index 79849fea..e5ec6be6 100644 --- a/grafanalib/core.py +++ b/grafanalib/core.py @@ -3452,6 +3452,7 @@ class GaugePanel(Panel): :param allValue: If All values should be shown or a Calculation :param calc: Calculation to perform on metrics + :param color: color mode :param dataLinks: list of data links hooked to datapoints on the graph :param decimals: override automatic decimal precision for legend/tooltips :param format: defines value units @@ -3463,23 +3464,26 @@ class GaugePanel(Panel): :param thresholdLabel: label for gauge. Template Variables: "$__series_namei" "$__field_name" "$__cell_{N} / $__calc" :param thresholdMarkers: option to show marker of level on gauge + :param thresholdType: threshold mode :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)) calc = attr.ib(default=GAUGE_CALC_MEAN) + color = attr.ib(default=None) dataLinks = attr.ib(default=attr.Factory(list)) decimals = attr.ib(default=None) + fieldMinMax = attr.ib(default=None) format = attr.ib(default='none') label = attr.ib(default=None) limit = attr.ib(default=None) - max = attr.ib(default=100) - min = attr.ib(default=0) + max = attr.ib(default=0) + min = attr.ib(default=100) rangeMaps = attr.ib(default=attr.Factory(list)) thresholdLabels = attr.ib(default=False, validator=instance_of(bool)) thresholdMarkers = attr.ib(default=True, validator=instance_of(bool)) + thresholdType = attr.ib(default='absolute') thresholds = attr.ib( default=attr.Factory( lambda: [ @@ -3489,8 +3493,8 @@ 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( @@ -3498,7 +3502,9 @@ def to_json_data(self): 'fieldConfig': { 'defaults': { 'calcs': [self.calc], + 'color': self.color, 'decimals': self.decimals, + 'fieldMinMax': self.fieldMinMax, 'max': self.max, 'min': self.min, 'title': self.label, @@ -3508,9 +3514,6 @@ def to_json_data(self): 'mappings': self.valueMaps, 'override': {}, 'values': self.allValues, - 'custom': { - 'neutral': self.neutral, - }, }, 'showThresholdLabels': self.thresholdLabels, 'showThresholdMarkers': self.thresholdMarkers, From 3e2abf1da8efcb953f4f4eb33d86aeaad079d162 Mon Sep 17 00:00:00 2001 From: Michael Governanti Date: Fri, 19 Jul 2024 12:21:30 -0400 Subject: [PATCH 2/9] add color, fieldMinMax, and thresholdType parameters to class GaugePanel() --- grafanalib/core.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/grafanalib/core.py b/grafanalib/core.py index e5ec6be6..d3495706 100644 --- a/grafanalib/core.py +++ b/grafanalib/core.py @@ -3455,6 +3455,7 @@ class GaugePanel(Panel): :param color: color mode :param dataLinks: list of data links hooked to datapoints on the graph :param decimals: override automatic decimal precision for legend/tooltips + :param fieldMinMax: force disable/enable min max values :param format: defines value units :param labels: option to show gauge level labels :param limit: limit of number of values to show when not Calculating @@ -3467,6 +3468,7 @@ class GaugePanel(Panel): :param thresholdType: threshold mode :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)) @@ -3478,8 +3480,8 @@ class GaugePanel(Panel): format = attr.ib(default='none') label = attr.ib(default=None) limit = attr.ib(default=None) - max = attr.ib(default=0) - min = attr.ib(default=100) + max = attr.ib(default=100) + min = attr.ib(default=0) rangeMaps = attr.ib(default=attr.Factory(list)) thresholdLabels = attr.ib(default=False, validator=instance_of(bool)) thresholdMarkers = attr.ib(default=True, validator=instance_of(bool)) @@ -3493,8 +3495,8 @@ 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( @@ -3514,6 +3516,9 @@ def to_json_data(self): 'mappings': self.valueMaps, 'override': {}, 'values': self.allValues, + 'custom': { + 'neutral': self.neutral, + }, }, 'showThresholdLabels': self.thresholdLabels, 'showThresholdMarkers': self.thresholdMarkers, From 7ff57bd3b1c4730c5d8fa558c37574641f84df27 Mon Sep 17 00:00:00 2001 From: Michael Governanti Date: Fri, 19 Jul 2024 12:28:50 -0400 Subject: [PATCH 3/9] updated change log --- CHANGELOG.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index ea76aedc..4a82638f 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -14,6 +14,7 @@ x.x.x ? * Fix mappings for Table * Added support for AWS Cross-Account in CloudwatchMetricsTarget * Added `LokiTarget` +* Added `color`, `fieldMinMax`, and `thresholdType` option for `GaugePanel` 0.7.1 2024-01-12 ================ From 21a4f0d6d985dc6130162a4b7ecafa8fa716eecc Mon Sep 17 00:00:00 2001 From: Michael Governanti Date: Mon, 22 Jul 2024 10:19:04 -0400 Subject: [PATCH 4/9] add thresholds and thresholdType to self.panel_josn.fieldConfig --- grafanalib/core.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/grafanalib/core.py b/grafanalib/core.py index d3495706..ca4bd1f3 100644 --- a/grafanalib/core.py +++ b/grafanalib/core.py @@ -3515,6 +3515,8 @@ def to_json_data(self): 'limit': self.limit, 'mappings': self.valueMaps, 'override': {}, + 'thresholds': self.thresholds, + 'thresholdType': self.thresholdType, 'values': self.allValues, 'custom': { 'neutral': self.neutral, From 7ff8f3e6040defaecceafdfae8c2abf4ff34173b Mon Sep 17 00:00:00 2001 From: Michael Governanti Date: Mon, 22 Jul 2024 16:01:03 -0400 Subject: [PATCH 5/9] took thresholds back out of the return dict since it triggers the iteration error --- grafanalib/core.py | 1 - 1 file changed, 1 deletion(-) diff --git a/grafanalib/core.py b/grafanalib/core.py index ca4bd1f3..9caf4b2a 100644 --- a/grafanalib/core.py +++ b/grafanalib/core.py @@ -3515,7 +3515,6 @@ def to_json_data(self): 'limit': self.limit, 'mappings': self.valueMaps, 'override': {}, - 'thresholds': self.thresholds, 'thresholdType': self.thresholdType, 'values': self.allValues, 'custom': { From d01b36239d54b7aba16eb760753d5cb36cbad532 Mon Sep 17 00:00:00 2001 From: Michael Governanti Date: Mon, 22 Jul 2024 16:08:40 -0400 Subject: [PATCH 6/9] added transformations option to class Stat, organized the return of BarGauge to match the standard fielfConfig schema --- grafanalib/core.py | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/grafanalib/core.py b/grafanalib/core.py index 9caf4b2a..32a9820f 100644 --- a/grafanalib/core.py +++ b/grafanalib/core.py @@ -588,6 +588,7 @@ class Target(object): target = attr.ib(default="") instant = attr.ib(validator=instance_of(bool), default=False) datasource = attr.ib(default=None) + range = attr.ib(validator=instance_of(bool), default=False) def to_json_data(self): return { @@ -605,6 +606,7 @@ def to_json_data(self): 'step': self.step, 'instant': self.instant, 'datasource': self.datasource, + 'range': self.range, } @@ -2811,6 +2813,7 @@ class Stat(Panel): fields = attr.ib(default="") textMode = attr.ib(default='auto') thresholds = attr.ib(default="") + transformations = attr.ib(default=attr.Factory(list), validator=instance_of(list)) def to_json_data(self): return self.panel_json( @@ -2840,6 +2843,7 @@ def to_json_data(self): 'values': False } }, + 'transformations': self.transformations, 'type': STAT_TYPE, } ) @@ -3360,6 +3364,7 @@ class BarGauge(Panel): :param allValue: If All values should be shown or a Calculation :param calc: Calculation to perform on metrics + :param color: color mode :param dataLinks: list of data links hooked to datapoints on the graph :param decimals: override automatic decimal precision for legend/tooltips :param displayMode: style to display bar gauge in @@ -3379,6 +3384,7 @@ class BarGauge(Panel): allValues = attr.ib(default=False, validator=instance_of(bool)) calc = attr.ib(default=GAUGE_CALC_MEAN) + color = attr.ib(default=None) dataLinks = attr.ib(default=attr.Factory(list)) decimals = attr.ib(default=None) displayMode = attr.ib( @@ -3419,28 +3425,28 @@ class BarGauge(Panel): def to_json_data(self): return self.panel_json( { - 'options': { - 'displayMode': self.displayMode, - 'fieldOptions': { + 'fieldConfig': { + 'defaults': { 'calcs': [self.calc], - 'defaults': { - 'decimals': self.decimals, - 'max': self.max, - 'min': self.min, - 'title': self.label, - 'unit': self.format, - 'links': self.dataLinks, - }, + 'color': self.color, + 'decimals': self.decimals, + 'max': self.max, + 'min': self.min, + 'title': self.label, + 'unit': self.format, + 'links': self.dataLinks, 'limit': self.limit, 'mappings': self.valueMaps, 'override': {}, - 'thresholds': self.thresholds, 'values': self.allValues, }, - 'orientation': self.orientation, 'showThresholdLabels': self.thresholdLabels, 'showThresholdMarkers': self.thresholdMarkers, }, + 'options': { + 'displayMode': self.displayMode, + 'orientation': self.orientation, + }, 'type': BARGAUGE_TYPE, } ) From 5f3462b81af3fcad4a1b21b8b3c28e93797efa18 Mon Sep 17 00:00:00 2001 From: Michael Governanti Date: Tue, 23 Jul 2024 15:18:43 -0400 Subject: [PATCH 7/9] added TempoTarget and TempoFilter classes to target Tempo queries --- CHANGELOG.rst | 1 + grafanalib/core.py | 48 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 4a82638f..72dc02af 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -15,6 +15,7 @@ x.x.x ? * Added support for AWS Cross-Account in CloudwatchMetricsTarget * Added `LokiTarget` * Added `color`, `fieldMinMax`, and `thresholdType` option for `GaugePanel` +* Added `TempoTarget` and `TempoFilter` to target Tempo queries 0.7.1 2024-01-12 ================ diff --git a/grafanalib/core.py b/grafanalib/core.py index 32a9820f..bd6ec668 100644 --- a/grafanalib/core.py +++ b/grafanalib/core.py @@ -633,6 +633,54 @@ def to_json_data(self): } +@attr.s +class TempoTarget(Target): + """ + Metric target to support Tempo queries + """ + + filters = attr.ib(default=attr.Factory(list), validator=instance_of(list)) + limit = attr.ib(default="") + queryType = attr.ib(default="") + tableType = attr.ib(default="") + + def to_json_data(self): + """Override the Target to_json_data to add addtional fields. + """ + super_json = super(TempoTarget, self).to_json_data() + super_json["filters"] = self.filters + super_json["limit"] = self.limit + super_json["queryType"] = self.queryType + super_json["tableType"] = self.tableType + return super_json + +@attr.s +class TempoFilter(object): + """ + Constructor for Tempo filtering + """ + + id = attr.ib(default="") + dataSource = attr.ib(default=None) + operator = attr.ib(default="") + scope = attr.ib(default="") + tag = attr.ib(default="") + value = attr.ib(default="") + #value = attr.ib(default=attr.Factory(list), validator=instance_of(list)) + valueType = attr.ib(default="") + + def to_json_data(self): + return { + 'id': self.id, + 'dataSource': self.dataSource, + 'operator': self.operator, + 'scope': self.scope, + 'tag': self.tag, + 'value': self.value, + 'valueType': self.valueType, + } + + @attr.s class SqlTarget(Target): """ From 76c56180ceb97b1cb715233214785c7eb9149f3c Mon Sep 17 00:00:00 2001 From: Michael Governanti Date: Wed, 24 Jul 2024 16:18:22 -0400 Subject: [PATCH 8/9] added white space around classes and removed commented out value option from TempFilter --- grafanalib/core.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/grafanalib/core.py b/grafanalib/core.py index bd6ec668..c41004a6 100644 --- a/grafanalib/core.py +++ b/grafanalib/core.py @@ -654,6 +654,7 @@ def to_json_data(self): super_json["tableType"] = self.tableType return super_json + @attr.s class TempoFilter(object): """ @@ -666,7 +667,6 @@ class TempoFilter(object): scope = attr.ib(default="") tag = attr.ib(default="") value = attr.ib(default="") - #value = attr.ib(default=attr.Factory(list), validator=instance_of(list)) valueType = attr.ib(default="") def to_json_data(self): From 544fce58602e94949a82a193ee2f5832de723ab7 Mon Sep 17 00:00:00 2001 From: Michael Governanti Date: Tue, 30 Jul 2024 10:05:25 -0400 Subject: [PATCH 9/9] added 'LibraryPanel' class --- grafanalib/core.py | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/grafanalib/core.py b/grafanalib/core.py index c41004a6..22c01b08 100644 --- a/grafanalib/core.py +++ b/grafanalib/core.py @@ -2083,6 +2083,35 @@ def to_json_data(self): return self.panel_json(graph_object) +@attr.s +class LibraryPanel(object): + title = attr.ib(default="") + gridPos = attr.ib(default=None) + id = attr.ib(default=None) + libraryPanel = attr.ib(default="") + + def to_json_data(self): + return self.panel_json( + { + #'gridPos': self.gridPos, + 'id': self.id, + 'libraryPanel': self.libraryPanel, + } + ) + + def _map_panels(self, f): + return f(self) + + def panel_json(self, overrides): + res = { + 'gridPos': self.gridPos, + 'id': self.id, + 'libraryPanel': self.libraryPanel, + } + _deep_update(res, overrides) + return res + + @attr.s class RowPanel(Panel): """