From 9660005e7f2308fe183fb34f801a7b16c49407d4 Mon Sep 17 00:00:00 2001 From: joewangprc <44234289+joewangprc@users.noreply.github.com> Date: Wed, 12 Jul 2023 22:54:54 +0800 Subject: [PATCH 01/18] Add color support in Stat(panel) (#602) * add color in Stat(Panel) * add color in Stat(Panel) --- grafanalib/core.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/grafanalib/core.py b/grafanalib/core.py index ed109763..038ae912 100644 --- a/grafanalib/core.py +++ b/grafanalib/core.py @@ -2711,6 +2711,7 @@ class Stat(Panel): """ alignment = attr.ib(default='auto') + color = attr.ib(default=None) colorMode = attr.ib(default='value') decimals = attr.ib(default=None) format = attr.ib(default='none') @@ -2729,6 +2730,7 @@ def to_json_data(self): { 'fieldConfig': { 'defaults': { + 'color': self.color, 'custom': {}, 'decimals': self.decimals, 'mappings': self.mappings, From 29423493ccdb80941a4b295d22e8ec89cd6c41df Mon Sep 17 00:00:00 2001 From: giloup933 Date: Wed, 12 Jul 2023 09:57:32 -0500 Subject: [PATCH 02/18] add unit to tables and hide flag to es targets (#604) * add unit to tables and hide flag to es targets * Update CHANGELOG.rst --------- Co-authored-by: Gil Popilski --- CHANGELOG.rst | 3 +++ grafanalib/core.py | 7 +++++-- grafanalib/elasticsearch.py | 3 +++ 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 7c480404..f9486255 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -17,6 +17,9 @@ Changelog .. _`Bar_Chart`: https://grafana.com/docs/grafana/latest/panels-visualizations/visualizations/bar-chart/ .. _`RateMetricAgg`: https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-metrics-rate-aggregation.html +* Added unit parameter to the Table class in core +* Added a hide parameter to ElasticsearchTarget + 0.7.0 (2022-10-02) ================== diff --git a/grafanalib/core.py b/grafanalib/core.py index 038ae912..67a08839 100644 --- a/grafanalib/core.py +++ b/grafanalib/core.py @@ -3196,6 +3196,7 @@ class Table(Panel): :param mappings: To assign colors to boolean or string values, use Value mappings :param overrides: To override the base characteristics of certain data :param showHeader: Show the table header + :param unit: units """ align = attr.ib(default='auto', validator=instance_of(str)) @@ -3207,7 +3208,8 @@ class Table(Panel): mappings = attr.ib(default=attr.Factory(list)) overrides = attr.ib(default=attr.Factory(list)) showHeader = attr.ib(default=True, validator=instance_of(bool)) - span = attr.ib(default=6) + span = attr.ib(default=6), + unit = attr.ib(default='', validator=instance_of(str)) @classmethod def with_styled_columns(cls, columns, styles=None, **kwargs): @@ -3229,8 +3231,9 @@ def to_json_data(self): 'custom': { 'align': self.align, 'displayMode': self.displayMode, - 'filterable': self.filterable + 'filterable': self.filterable, }, + 'unit': self.unit }, 'overrides': self.overrides }, diff --git a/grafanalib/elasticsearch.py b/grafanalib/elasticsearch.py index 35f1a9d4..bf4cb297 100644 --- a/grafanalib/elasticsearch.py +++ b/grafanalib/elasticsearch.py @@ -363,6 +363,7 @@ class ElasticsearchTarget(object): :param query: query :param refId: target reference id :param timeField: name of the elasticsearch time field + :param hide: show/hide the target result in the final panel display """ alias = attr.ib(default=None) @@ -373,6 +374,7 @@ class ElasticsearchTarget(object): query = attr.ib(default="", validator=instance_of(str)) refId = attr.ib(default="", validator=instance_of(str)) timeField = attr.ib(default="@timestamp", validator=instance_of(str)) + hide = attr.ib(default=False, validator=instance_of(bool)) def _map_bucket_aggs(self, f): return attr.evolve(self, bucketAggs=list(map(f, self.bucketAggs))) @@ -407,6 +409,7 @@ def to_json_data(self): 'query': self.query, 'refId': self.refId, 'timeField': self.timeField, + 'hide': self.hide, } From 0dce0f660415b1396b85baf590a9d5b26d6f1ffd Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 17 Jul 2023 13:28:29 +0100 Subject: [PATCH 03/18] Bump actions/setup-python from 4.6.1 to 4.7.0 (#609) Bumps [actions/setup-python](https://github.com/actions/setup-python) from 4.6.1 to 4.7.0. - [Release notes](https://github.com/actions/setup-python/releases) - [Commits](https://github.com/actions/setup-python/compare/v4.6.1...v4.7.0) --- updated-dependencies: - dependency-name: actions/setup-python dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- .github/workflows/check-sphinx-and-links.yml | 2 +- .github/workflows/publish-to-pypi.yml | 2 +- .github/workflows/run-tests.yml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/check-sphinx-and-links.yml b/.github/workflows/check-sphinx-and-links.yml index 68d12c7c..36a12b9c 100644 --- a/.github/workflows/check-sphinx-and-links.yml +++ b/.github/workflows/check-sphinx-and-links.yml @@ -9,7 +9,7 @@ jobs: steps: - uses: actions/checkout@v3 - name: Set up Python - uses: actions/setup-python@v4.6.1 + uses: actions/setup-python@v4.7.0 with: python-version: 3.8 diff --git a/.github/workflows/publish-to-pypi.yml b/.github/workflows/publish-to-pypi.yml index 5da24847..6d07b6f9 100644 --- a/.github/workflows/publish-to-pypi.yml +++ b/.github/workflows/publish-to-pypi.yml @@ -9,7 +9,7 @@ jobs: steps: - uses: actions/checkout@v3 - name: Set up Python 3.7 - uses: actions/setup-python@v4.6.1 + uses: actions/setup-python@v4.7.0 with: python-version: 3.7 - name: Build a binary wheel and a source tarball diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index 61314c17..278ae6be 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -12,7 +12,7 @@ jobs: steps: - uses: actions/checkout@v3 - name: Set up Python - uses: actions/setup-python@v4.6.1 + uses: actions/setup-python@v4.7.0 with: python-version: ${{ matrix.python }} - name: Run tests From 0bca6de80ddf00d3ead299f869690265b23dc9e7 Mon Sep 17 00:00:00 2001 From: Emir Karamehmetoglu Date: Fri, 18 Aug 2023 16:15:56 +0200 Subject: [PATCH 04/18] Update python compatibility in README (#610) python 3.11 is part of tests so README should not mislead about only supporting up to python 3.10 --- README.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.rst b/README.rst index 5762d975..4daab8f7 100644 --- a/README.rst +++ b/README.rst @@ -57,7 +57,7 @@ Support This library is in its very early stages. We'll probably make changes that break backwards compatibility, although we'll try hard not to. -grafanalib works with Python 3.6 through 3.10. +grafanalib works with Python 3.6 through 3.11. Developing ========== From 571d765782a328f46ca34397c0ffa5622c2e39ec Mon Sep 17 00:00:00 2001 From: Git-Lior <22118580+Git-Lior@users.noreply.github.com> Date: Fri, 18 Aug 2023 17:16:25 +0300 Subject: [PATCH 05/18] Added support for Azure Data Explorer datasource plugin (#611) --- CHANGELOG.rst | 1 + grafanalib/azuredataexplorer.py | 41 ++++++++++++++++++++++ grafanalib/tests/test_azuredataexplorer.py | 18 ++++++++++ 3 files changed, 60 insertions(+) create mode 100644 grafanalib/azuredataexplorer.py create mode 100644 grafanalib/tests/test_azuredataexplorer.py diff --git a/CHANGELOG.rst b/CHANGELOG.rst index f9486255..1677b035 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -13,6 +13,7 @@ Changelog * Extended SqlTarget to support parsing queries from files * Fix AlertCondition backwards compatibility (``useNewAlerts`` default to ``False``) * Added RateMetricAgg_ for ElasticSearch +* Added support for Azure Data Explorer datasource plugin (https://github.com/grafana/azure-data-explorer-datasource) .. _`Bar_Chart`: https://grafana.com/docs/grafana/latest/panels-visualizations/visualizations/bar-chart/ .. _`RateMetricAgg`: https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-metrics-rate-aggregation.html diff --git a/grafanalib/azuredataexplorer.py b/grafanalib/azuredataexplorer.py new file mode 100644 index 00000000..9589d25a --- /dev/null +++ b/grafanalib/azuredataexplorer.py @@ -0,0 +1,41 @@ +"""Helpers to create Azure Data Explorer specific Grafana queries.""" + +import attr + +TIME_SERIES_RESULT_FORMAT = 'time_series' +TABLE_RESULT_FORMAT = 'table' +ADX_TIME_SERIES_RESULT_FORMAT = 'time_series_adx_series' + + +@attr.s +class AzureDataExplorerTarget(object): + """ + Generates Azure Data Explorer target JSON structure. + + Link to Azure Data Explorer datasource Grafana plugin: + https://grafana.com/grafana/plugins/grafana-azure-data-explorer-datasource/ + + Azure Data Explorer docs on query language (KQL): + https://learn.microsoft.com/en-us/azure/data-explorer/kusto/query/ + + :param database: Database to execute query on + :param query: Query in Kusto Query Language (KQL) + :param resultFormat: Output format of the query result + :param alias: legend alias + :param refId: target reference id + """ + + database = attr.ib(default="") + query = attr.ib(default="") + resultFormat = attr.ib(default=TIME_SERIES_RESULT_FORMAT) + alias = attr.ib(default="") + refId = attr.ib(default="") + + def to_json_data(self): + return { + 'database': self.database, + 'query': self.query, + 'resultFormat': self.resultFormat, + 'alias': self.alias, + 'refId': self.refId + } diff --git a/grafanalib/tests/test_azuredataexplorer.py b/grafanalib/tests/test_azuredataexplorer.py new file mode 100644 index 00000000..ed0c3c59 --- /dev/null +++ b/grafanalib/tests/test_azuredataexplorer.py @@ -0,0 +1,18 @@ +import grafanalib.core as G +import grafanalib.azuredataexplorer as A +from grafanalib import _gen +from io import StringIO + + +def test_serialization_azuredataexplorer_metrics_target(): + """Serializing a graph doesn't explode.""" + graph = G.Graph( + title="Azure Data Explorer graph", + dataSource="default", + targets=[ + A.AzureDataExplorerTarget() + ], + ) + stream = StringIO() + _gen.write_dashboard(graph, stream) + assert stream.getvalue() != '' From 1fa5421973d8e342054f6f1898df88ad9f8cb6e0 Mon Sep 17 00:00:00 2001 From: davaffy <58271442+davaffy@users.noreply.github.com> Date: Fri, 18 Aug 2023 16:32:23 +0200 Subject: [PATCH 06/18] GAUGE_CALC_TOTAL should be 'sum' and not 'total' (#614) --- CHANGELOG.rst | 1 + grafanalib/core.py | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 1677b035..0bd49d96 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -20,6 +20,7 @@ Changelog * Added unit parameter to the Table class in core * Added a hide parameter to ElasticsearchTarget +* Fix value literal GAUGE_CALC_TOTAL to sum instead of total 0.7.0 (2022-10-02) ================== diff --git a/grafanalib/core.py b/grafanalib/core.py index 67a08839..42465d06 100644 --- a/grafanalib/core.py +++ b/grafanalib/core.py @@ -276,7 +276,7 @@ def to_json_data(self): GAUGE_CALC_MIN = 'min' GAUGE_CALC_MAX = 'max' GAUGE_CALC_MEAN = 'mean' -GAUGE_CALC_TOTAL = 'total' +GAUGE_CALC_TOTAL = 'sum' GAUGE_CALC_COUNT = 'count' GAUGE_CALC_RANGE = 'range' GAUGE_CALC_DELTA = 'delta' From b0d81c97b2e8980c4bb5d2b155a31a7b0a47cedb Mon Sep 17 00:00:00 2001 From: Peter Darvasi <142215070+DP3t3r@users.noreply.github.com> Date: Fri, 18 Aug 2023 16:36:17 +0200 Subject: [PATCH 07/18] Added axisSoftMin and axisSoftMax options to TimeSeries (#617) * added axisSoftMin and axisSoftMax to TimeSeries * Update CHANGELOG.rst --------- Co-authored-by: JamesGibo <22477854+JamesGibo@users.noreply.github.com> --- CHANGELOG.rst | 1 + grafanalib/core.py | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 0bd49d96..af9c2c7d 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -13,6 +13,7 @@ Changelog * Extended SqlTarget to support parsing queries from files * Fix AlertCondition backwards compatibility (``useNewAlerts`` default to ``False``) * Added RateMetricAgg_ for ElasticSearch +* added axisSoftMin and axisSoftMax options for TimeSeries * Added support for Azure Data Explorer datasource plugin (https://github.com/grafana/azure-data-explorer-datasource) .. _`Bar_Chart`: https://grafana.com/docs/grafana/latest/panels-visualizations/visualizations/bar-chart/ diff --git a/grafanalib/core.py b/grafanalib/core.py index 42465d06..037ef7c1 100644 --- a/grafanalib/core.py +++ b/grafanalib/core.py @@ -2222,6 +2222,8 @@ class TimeSeries(Panel): :param valueMin: Minimum value for Panel :param valueMax: Maximum value for Panel :param valueDecimals: Number of display decimals + :param axisSoftMin: soft minimum Y axis value + :param axisSoftMax: soft maximum Y axis value """ axisPlacement = attr.ib(default='auto', validator=instance_of(str)) @@ -2278,6 +2280,8 @@ class TimeSeries(Panel): valueMin = attr.ib(default=None, validator=attr.validators.optional(instance_of(int))) valueMax = attr.ib(default=None, validator=attr.validators.optional(instance_of(int))) valueDecimals = attr.ib(default=None, validator=attr.validators.optional(instance_of(int))) + axisSoftMin = attr.ib(default=None, validator=attr.validators.optional(instance_of(int))) + axisSoftMax = attr.ib(default=None, validator=attr.validators.optional(instance_of(int))) def to_json_data(self): return self.panel_json( @@ -2312,6 +2316,8 @@ def to_json_data(self): 'thresholdsStyle': { 'mode': self.thresholdsStyleMode }, + 'axisSoftMin': self.axisSoftMin, + 'axisSoftMax': self.axisSoftMax }, 'mappings': self.mappings, "min": self.valueMin, From 1430308b004a6b3afe18015ff78cec5e991a28f8 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 4 Sep 2023 14:53:17 +0100 Subject: [PATCH 08/18] Bump sphinx-rtd-theme from 1.2.2 to 1.3.0 (#620) Bumps [sphinx-rtd-theme](https://github.com/readthedocs/sphinx_rtd_theme) from 1.2.2 to 1.3.0. - [Changelog](https://github.com/readthedocs/sphinx_rtd_theme/blob/master/docs/changelog.rst) - [Commits](https://github.com/readthedocs/sphinx_rtd_theme/compare/1.2.2...1.3.0) --- updated-dependencies: - dependency-name: sphinx-rtd-theme dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- docs/requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/requirements.txt b/docs/requirements.txt index a3f75dea..ec903057 100644 --- a/docs/requirements.txt +++ b/docs/requirements.txt @@ -1,2 +1,2 @@ sphinx == 6.1.3 -sphinx_rtd_theme == 1.2.2 \ No newline at end of file +sphinx_rtd_theme == 1.3.0 \ No newline at end of file From bc85259bf774d88d6355cd7f181b34c0eea981dd Mon Sep 17 00:00:00 2001 From: JamesGibo <22477854+JamesGibo@users.noreply.github.com> Date: Mon, 4 Sep 2023 15:36:56 +0100 Subject: [PATCH 09/18] Bump CI python version to 3.9 (#624) --- .github/workflows/check-sphinx-and-links.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/check-sphinx-and-links.yml b/.github/workflows/check-sphinx-and-links.yml index 36a12b9c..82296302 100644 --- a/.github/workflows/check-sphinx-and-links.yml +++ b/.github/workflows/check-sphinx-and-links.yml @@ -11,7 +11,7 @@ jobs: - name: Set up Python uses: actions/setup-python@v4.7.0 with: - python-version: 3.8 + python-version: 3.9 - name: "Install prerequisites" run: | From 51091b0b974798ba8580fc18493a6244e2968cb4 Mon Sep 17 00:00:00 2001 From: JamesGibo <22477854+JamesGibo@users.noreply.github.com> Date: Thu, 7 Sep 2023 14:35:13 +0100 Subject: [PATCH 10/18] Fix sphinx 7.2.5 ci build (#625) * Fix sphinx 7.2.5 ci build * Use newer sphinx docker image and upgrade pip --- .github/workflows/check-sphinx-and-links.yml | 16 ++++++---------- docs/requirements.txt | 4 ++-- 2 files changed, 8 insertions(+), 12 deletions(-) diff --git a/.github/workflows/check-sphinx-and-links.yml b/.github/workflows/check-sphinx-and-links.yml index 82296302..802a8f8c 100644 --- a/.github/workflows/check-sphinx-and-links.yml +++ b/.github/workflows/check-sphinx-and-links.yml @@ -8,21 +8,17 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 - - name: Set up Python - uses: actions/setup-python@v4.7.0 - with: - python-version: 3.9 - - - name: "Install prerequisites" - run: | - pip3 install -r docs/requirements.txt - - uses: ammaraskar/sphinx-action@master + # - uses: ammaraskar/sphinx-action@master + # Using fork of sphinx-action to support python version > 3.9 + # As sphinx-action not updated the sphinx docker image it uses + - uses: erpcya/sphinx-action@feature/#update-sphinx-base-image with: docs-folder: "docs/" pre-build-command: | + pip3 install --upgrade pip sphinx-apidoc -f grafanalib -o docs/api - python setup.py install --user + python3 setup.py install --user build-command: "make html" - name: Link Checker diff --git a/docs/requirements.txt b/docs/requirements.txt index ec903057..ade78463 100644 --- a/docs/requirements.txt +++ b/docs/requirements.txt @@ -1,2 +1,2 @@ -sphinx == 6.1.3 -sphinx_rtd_theme == 1.3.0 \ No newline at end of file +sphinx == 7.2.5 +sphinx_rtd_theme == 1.3.0 From 1e8452e7c14b26ed5ce110f9efee3b8c324be585 Mon Sep 17 00:00:00 2001 From: JamesGibo <22477854+JamesGibo@users.noreply.github.com> Date: Thu, 7 Sep 2023 14:41:47 +0100 Subject: [PATCH 11/18] Bump pypi build to use python 3.10 (#626) --- .github/workflows/publish-to-pypi.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/publish-to-pypi.yml b/.github/workflows/publish-to-pypi.yml index 6d07b6f9..a89c33c7 100644 --- a/.github/workflows/publish-to-pypi.yml +++ b/.github/workflows/publish-to-pypi.yml @@ -5,13 +5,13 @@ on: push jobs: build-n-publish: name: Build and publish Python 🐍 distributions 📦 to PyPI - runs-on: ubuntu-20.04 + runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 - - name: Set up Python 3.7 + - name: Set up Python 3.10 uses: actions/setup-python@v4.7.0 with: - python-version: 3.7 + python-version: '3.10' - name: Build a binary wheel and a source tarball run: >- pip install wheel; From 019b34b9e268caafaa0ef25efe8387071426b9ed Mon Sep 17 00:00:00 2001 From: Git-Lior <22118580+Git-Lior@users.noreply.github.com> Date: Thu, 7 Sep 2023 17:04:11 +0300 Subject: [PATCH 12/18] Added sortBy parameter to Table panel (#612) --- CHANGELOG.rst | 1 + grafanalib/core.py | 20 +++++++++++++++++++- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index af9c2c7d..cf0c30de 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -15,6 +15,7 @@ Changelog * Added RateMetricAgg_ for ElasticSearch * added axisSoftMin and axisSoftMax options for TimeSeries * Added support for Azure Data Explorer datasource plugin (https://github.com/grafana/azure-data-explorer-datasource) +* Added ``sortBy`` parameter to Table panel .. _`Bar_Chart`: https://grafana.com/docs/grafana/latest/panels-visualizations/visualizations/bar-chart/ .. _`RateMetricAgg`: https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-metrics-rate-aggregation.html diff --git a/grafanalib/core.py b/grafanalib/core.py index 037ef7c1..4192806b 100644 --- a/grafanalib/core.py +++ b/grafanalib/core.py @@ -3185,6 +3185,18 @@ def to_json_data(self): } +@attr.s +class TableSortByField(object): + displayName = attr.ib(default="") + desc = attr.ib(default=False) + + def to_json_data(self): + return { + 'displayName': self.displayName, + 'desc': self.desc, + } + + @attr.s class Table(Panel): """Generates Table panel json structure @@ -3203,6 +3215,7 @@ class Table(Panel): :param overrides: To override the base characteristics of certain data :param showHeader: Show the table header :param unit: units + :param sortBy: Sort rows by table fields """ align = attr.ib(default='auto', validator=instance_of(str)) @@ -3216,6 +3229,10 @@ class Table(Panel): showHeader = attr.ib(default=True, validator=instance_of(bool)) span = attr.ib(default=6), unit = attr.ib(default='', validator=instance_of(str)) + sortBy = attr.ib(default=attr.Factory(list), validator=attr.validators.deep_iterable( + member_validator=instance_of(TableSortByField), + iterable_validator=instance_of(list) + )) @classmethod def with_styled_columns(cls, columns, styles=None, **kwargs): @@ -3247,7 +3264,8 @@ def to_json_data(self): 'mappings': self.mappings, 'minSpan': self.minSpan, 'options': { - 'showHeader': self.showHeader + 'showHeader': self.showHeader, + 'sortBy': self.sortBy }, 'type': TABLE_TYPE, } From 38065f645fc578e5853984f4dc31bd795d05040e Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 11 Sep 2023 14:29:47 +0100 Subject: [PATCH 13/18] Bump actions/checkout from 3 to 4 (#628) Bumps [actions/checkout](https://github.com/actions/checkout) from 3 to 4. - [Release notes](https://github.com/actions/checkout/releases) - [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md) - [Commits](https://github.com/actions/checkout/compare/v3...v4) --- updated-dependencies: - dependency-name: actions/checkout dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- .github/workflows/check-sphinx-and-links.yml | 2 +- .github/workflows/publish-to-pypi.yml | 2 +- .github/workflows/run-tests.yml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/check-sphinx-and-links.yml b/.github/workflows/check-sphinx-and-links.yml index 802a8f8c..2df41d56 100644 --- a/.github/workflows/check-sphinx-and-links.yml +++ b/.github/workflows/check-sphinx-and-links.yml @@ -7,7 +7,7 @@ jobs: docs: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 # - uses: ammaraskar/sphinx-action@master # Using fork of sphinx-action to support python version > 3.9 diff --git a/.github/workflows/publish-to-pypi.yml b/.github/workflows/publish-to-pypi.yml index a89c33c7..eb4c1b28 100644 --- a/.github/workflows/publish-to-pypi.yml +++ b/.github/workflows/publish-to-pypi.yml @@ -7,7 +7,7 @@ jobs: name: Build and publish Python 🐍 distributions 📦 to PyPI runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Set up Python 3.10 uses: actions/setup-python@v4.7.0 with: diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index 278ae6be..1c15cda9 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -10,7 +10,7 @@ jobs: matrix: python: ['3.8', '3.9', '3.10', '3.11'] steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Set up Python uses: actions/setup-python@v4.7.0 with: From f5da3c720b69de4b81df28dbd8d8f6fa6a3eddca Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 29 Sep 2023 12:08:31 +0100 Subject: [PATCH 14/18] Bump sphinx from 7.2.5 to 7.2.6 (#630) Bumps [sphinx](https://github.com/sphinx-doc/sphinx) from 7.2.5 to 7.2.6. - [Release notes](https://github.com/sphinx-doc/sphinx/releases) - [Changelog](https://github.com/sphinx-doc/sphinx/blob/master/CHANGES.rst) - [Commits](https://github.com/sphinx-doc/sphinx/compare/v7.2.5...v7.2.6) --- updated-dependencies: - dependency-name: sphinx dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- docs/requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/requirements.txt b/docs/requirements.txt index ade78463..a6006f35 100644 --- a/docs/requirements.txt +++ b/docs/requirements.txt @@ -1,2 +1,2 @@ -sphinx == 7.2.5 +sphinx == 7.2.6 sphinx_rtd_theme == 1.3.0 From 6f36ce6d4d41ad612d3e07f7e0498bb3f49bcd85 Mon Sep 17 00:00:00 2001 From: Padraic Calpin Date: Fri, 29 Sep 2023 16:11:20 +0100 Subject: [PATCH 15/18] Main improved dashboard links (#622) * Add missing options, functionality to DashboardLink Includes the ability to create direct links or a list of dashboard links, extra options like includeVars and targetBlank. * Add docstring to DashboardLink, remove the unused `dashboard` param Removing this parameter is a breaking change... It didn't actually impact the generated link, other than acting as an alias to 'title' in some cases. If preferred, I can restore it to retain that alias behaviour, and perhaps add a warning log message? * Update changelog * Fix the DashboardLink type param in docstrings * Fix the field name for URL in DashboardLinks * Correct type annotations for py37, py38 * Fix flake8 warnigns in docstring for DashboardLink * Add tests for DashboardLink * Fix flake8 complaints in tests/test_core.py --- CHANGELOG.rst | 4 ++ grafanalib/core.py | 69 +++++++++++++++++++++++++++++------ grafanalib/tests/test_core.py | 34 +++++++++++++++++ 3 files changed, 95 insertions(+), 12 deletions(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index cf0c30de..b9c80561 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -5,6 +5,10 @@ Changelog 0.x.x (?) ================== +* Extended DashboardLink to support links to dashboards and urls, as per the docs_ + +.. _`docs`: https://grafana.com/docs/grafana/latest/dashboards/build-dashboards/manage-dashboard-links/#dashboard-links + * Added ... * Added Minimum option for Timeseries * Added Maximum option for Timeseries diff --git a/grafanalib/core.py b/grafanalib/core.py index 4192806b..f9c3409e 100644 --- a/grafanalib/core.py +++ b/grafanalib/core.py @@ -5,13 +5,14 @@ encourage it by way of some defaults. Rather, they are ways of building arbitrary Grafana JSON. """ - +from __future__ import annotations import itertools import math import string import warnings from numbers import Number +from typing import Literal import attr from attr.validators import in_, instance_of @@ -74,7 +75,7 @@ def to_json_data(self): FLOT = 'flot' ABSOLUTE_TYPE = 'absolute' -DASHBOARD_TYPE = 'dashboard' +DASHBOARD_TYPE = Literal['dashboards', 'link'] ROW_TYPE = 'row' GRAPH_TYPE = 'graph' DISCRETE_TYPE = 'natel-discrete-panel' @@ -300,6 +301,9 @@ def to_json_data(self): DEFAULT_AUTO_COUNT = 30 DEFAULT_MIN_AUTO_INTERVAL = '10s' +DASHBOARD_LINK_ICON = Literal['bolt', 'cloud', 'dashboard', 'doc', + 'external link', 'info', 'question'] + @attr.s class Mapping(object): @@ -875,24 +879,65 @@ def to_json_data(self): @attr.s class DashboardLink(object): - dashboard = attr.ib() - uri = attr.ib() - keepTime = attr.ib( + """Create a link to other dashboards, or external resources. + + Dashboard Links come in two flavours; a list of dashboards, or a direct + link to an arbitrary URL. These are controlled by the ``type`` parameter. + A dashboard list targets a given set of tags, whereas for a link you must + also provide the URL. + + See `the documentation ` + for more information. + + :param asDropdown: Controls if the list appears in a dropdown rather than + tiling across the dashboard. Affects 'dashboards' type only. Defaults + to False + :param icon: Set the icon, from a predefined list. See + ``grafanalib.core.DASHBOARD_LINK_ICON`` for allowed values. Affects + the 'link' type only. Defaults to 'external link' + :param includeVars: Controls if data variables from the current dashboard + are passed as query parameters to the linked target. Defaults to False + :param keepTime: Controls if the current time range is passed as query + parameters to the linked target. Defaults to False + :param tags: A list of tags used to select dashboards for the link. + Affects the 'dashboards' type only. Defaults to an empty list + :param targetBlank: Controls if the link opens in a new tab. Defaults + to False + :param tooltip: Tooltip text that appears when hovering over the link. + Affects the 'link' type only. Defaults to an empty string + :param type: Controls the type of DashboardLink generated. Must be + one of 'dashboards' or 'link'. + :param uri: The url target of the external link. Affects the 'link' + type only. + """ + asDropdown: bool = attr.ib(default=False, validator=instance_of(bool)) + icon: DASHBOARD_LINK_ICON = attr.ib(default='external link', + validator=in_(DASHBOARD_LINK_ICON.__args__)) + includeVars: bool = attr.ib(default=False, validator=instance_of(bool)) + keepTime: bool = attr.ib( default=True, validator=instance_of(bool), ) - title = attr.ib(default=None) - type = attr.ib(default=DASHBOARD_TYPE) + tags: list[str] = attr.ib(factory=list, validator=instance_of(list)) + targetBlank: bool = attr.ib(default=False, validator=instance_of(bool)) + title: str = attr.ib(default="") + tooltip: str = attr.ib(default="", validator=instance_of(str)) + type: DASHBOARD_TYPE = attr.ib(default='dashboards', + validator=in_(DASHBOARD_TYPE.__args__)) + uri: str = attr.ib(default="", validator=instance_of(str)) def to_json_data(self): - title = self.dashboard if self.title is None else self.title return { - 'dashUri': self.uri, - 'dashboard': self.dashboard, + 'asDropdown': self.asDropdown, + 'icon': self.icon, + 'includeVars': self.includeVars, 'keepTime': self.keepTime, - 'title': title, + 'tags': self.tags, + 'targetBlank': self.targetBlank, + 'title': self.title, + 'tooltip': self.tooltip, 'type': self.type, - 'url': self.uri, + 'url': self.uri } diff --git a/grafanalib/tests/test_core.py b/grafanalib/tests/test_core.py index 2b03610b..02885796 100644 --- a/grafanalib/tests/test_core.py +++ b/grafanalib/tests/test_core.py @@ -1190,3 +1190,37 @@ def test_sql_target_with_source_files(): assert t.to_json_data()["targets"][0].rawQuery is True assert t.to_json_data()["targets"][0].rawSql == "SELECT example\nFROM test\nWHERE example='example' AND example_date BETWEEN '1970-01-01' AND '1971-01-01';\n" print(t.to_json_data()["targets"][0]) + + +class TestDashboardLink(): + + def test_validators(self): + with pytest.raises(ValueError): + G.DashboardLink( + type='dashboard', + ) + with pytest.raises(ValueError): + G.DashboardLink( + icon='not an icon' + ) + + def test_initialisation(self): + dl = G.DashboardLink().to_json_data() + assert dl['asDropdown'] is False + assert dl['icon'] == 'external link' + assert dl['includeVars'] is False + assert dl['keepTime'] is True + assert not dl['tags'] + assert dl['targetBlank'] is False + assert dl['title'] == "" + assert dl['tooltip'] == "" + assert dl['type'] == 'dashboards' + assert dl['url'] == "" + + url = 'https://grafana.com' + dl = G.DashboardLink( + uri=url, + type='link' + ).to_json_data() + assert dl['url'] == url + assert dl['type'] == 'link' From 1a0a0e847df5fa9c9b8ca9a69f3d77028ac5133d Mon Sep 17 00:00:00 2001 From: Vinit Bhat <99.bhatvinit@gmail.com> Date: Fri, 29 Sep 2023 20:43:20 +0530 Subject: [PATCH 16/18] added tooltipSort to TimeSeries Panel (#631) --- CHANGELOG.rst | 1 + grafanalib/core.py | 6 +++++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index b9c80561..8aa74ed8 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -20,6 +20,7 @@ Changelog * added axisSoftMin and axisSoftMax options for TimeSeries * Added support for Azure Data Explorer datasource plugin (https://github.com/grafana/azure-data-explorer-datasource) * Added ``sortBy`` parameter to Table panel +* Added ``tooltipSort`` parameter to TimeSeries panel .. _`Bar_Chart`: https://grafana.com/docs/grafana/latest/panels-visualizations/visualizations/bar-chart/ .. _`RateMetricAgg`: https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-metrics-rate-aggregation.html diff --git a/grafanalib/core.py b/grafanalib/core.py index f9c3409e..cf7826a1 100644 --- a/grafanalib/core.py +++ b/grafanalib/core.py @@ -2262,6 +2262,8 @@ class TimeSeries(Panel): :param thresholds: single stat thresholds :param tooltipMode: When you hover your cursor over the visualization, Grafana can display tooltips single (Default), multi, none + :param tooltipSort: To sort the tooltips + none (Default), asc, desc :param unit: units :param thresholdsStyleMode: thresholds style mode off (Default), area, line, line+area :param valueMin: Minimum value for Panel @@ -2319,6 +2321,7 @@ class TimeSeries(Panel): showPoints = attr.ib(default='auto', validator=instance_of(str)) stacking = attr.ib(factory=dict, validator=instance_of(dict)) tooltipMode = attr.ib(default='single', validator=instance_of(str)) + tooltipSort = attr.ib(default='none', validator=instance_of(str)) unit = attr.ib(default='', validator=instance_of(str)) thresholdsStyleMode = attr.ib(default='off', validator=instance_of(str)) @@ -2379,7 +2382,8 @@ def to_json_data(self): 'calcs': self.legendCalcs }, 'tooltip': { - 'mode': self.tooltipMode + 'mode': self.tooltipMode, + 'sort': self.tooltipSort } }, 'type': TIMESERIES_TYPE, From c82a6794b5cdd19acbd60de3a7465226f40c4a7e Mon Sep 17 00:00:00 2001 From: Padraic Calpin Date: Fri, 29 Sep 2023 16:17:03 +0100 Subject: [PATCH 17/18] Main add graph unit (#632) * Add the Unit field to Graph Panels * Update changelog for Graph Panel --- CHANGELOG.rst | 1 + grafanalib/core.py | 8 +++++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 8aa74ed8..1fbbe8fd 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -10,6 +10,7 @@ Changelog .. _`docs`: https://grafana.com/docs/grafana/latest/dashboards/build-dashboards/manage-dashboard-links/#dashboard-links * Added ... +* Add Unit option for Graph panel * Added Minimum option for Timeseries * Added Maximum option for Timeseries * Added Number of decimals displays option for Timeseries diff --git a/grafanalib/core.py b/grafanalib/core.py index cf7826a1..e1d68890 100644 --- a/grafanalib/core.py +++ b/grafanalib/core.py @@ -2104,7 +2104,7 @@ class Graph(Panel): :param stack: Each series is stacked on top of another :param percentage: Available when Stack is selected. Each series is drawn as a percentage of the total of all series :param thresholds: List of GraphThresholds - Only valid when alert not defined - + :param unit: Set Y Axis Unit """ alert = attr.ib(default=None) @@ -2138,6 +2138,7 @@ class Graph(Panel): validator=instance_of(Tooltip), ) thresholds = attr.ib(default=attr.Factory(list)) + unit = attr.ib(default='', validator=instance_of(str)) xAxis = attr.ib(default=attr.Factory(XAxis), validator=instance_of(XAxis)) try: yAxes = attr.ib( @@ -2157,6 +2158,11 @@ def to_json_data(self): 'aliasColors': self.aliasColors, 'bars': self.bars, 'error': self.error, + 'fieldConfig': { + 'defaults': { + 'unit': self.unit + }, + }, 'fill': self.fill, 'grid': self.grid, 'isNew': self.isNew, From 65b751378e5b0d48249e0f750a365db9babb98d2 Mon Sep 17 00:00:00 2001 From: Maksym Miedviediev Date: Tue, 2 Jan 2024 16:20:29 +0100 Subject: [PATCH 18/18] chore : update version --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 3108e480..985480da 100644 --- a/setup.py +++ b/setup.py @@ -15,7 +15,7 @@ def local_file(name): # Versions should comply with PEP440. For a discussion on single-sourcing # the version across setup.py and the project code, see # https://packaging.python.org/en/latest/guides/single-sourcing-package-version/ - version='0.7.0', + version='0.7.0.post3', description='Library for building Grafana dashboards', long_description=open(README).read(), url='https://github.com/weaveworks/grafanalib',