Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for Azure Data Explorer datasource plugin #611

Merged
merged 1 commit into from
Aug 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
41 changes: 41 additions & 0 deletions grafanalib/azuredataexplorer.py
Original file line number Diff line number Diff line change
@@ -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
}
18 changes: 18 additions & 0 deletions grafanalib/tests/test_azuredataexplorer.py
Original file line number Diff line number Diff line change
@@ -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() != ''
Loading