Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -112,3 +112,5 @@ venv.bak/
# mypy
.mypy_cache/

# visual code launch...
.vscode/launch.json
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ This table outlines which parts of Grafana's HTTP API are covered by
| Folder | + |
| Folder Permissions | + |
| Folder/Dashboard Search | +- |
| Health | + |
| Organisation | + |
| Other | + |
| Preferences | + |
Expand Down
2 changes: 2 additions & 0 deletions grafana_client/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
Dashboard,
Datasource,
Folder,
Health,
Notifications,
Organization,
Organizations,
Expand Down Expand Up @@ -40,6 +41,7 @@ def __init__(
self.dashboard = Dashboard(self.client)
self.datasource = Datasource(self.client)
self.folder = Folder(self.client)
self.health = Health(self.client)
self.organization = Organization(self.client)
self.organizations = Organizations(self.client)
self.search = Search(self.client)
Expand Down
1 change: 1 addition & 0 deletions grafana_client/elements/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from .base import Base
from .dashboard import Dashboard
from .datasource import Datasource
from .health import Health
from .folder import Folder
from .notifications import Notifications
from .organization import Organization, Organizations
Expand Down
28 changes: 28 additions & 0 deletions grafana_client/elements/datasource.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,3 +95,31 @@ def delete_datasource_by_name(self, datasource_name):
delete_datasource = "/datasources/name/%s" % datasource_name
r = self.client.DELETE(delete_datasource)
return r

def get_datasource_proxy_data(self, datasource_id
Copy link
Contributor

@amotl amotl Feb 6, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If there are problems with this PR, just tell me. Particularly concerning code coverage, because I'm not really familiar with this concept.

I can't see where get_datasource_proxy_data() will be called from any code, including test cases. This is probably why Codecov reported about a 0.52% decline in code coverage at #5 (comment).

In order to learn something about the general concept, I would like to refer you to 1. Maybe you can add a corresponding test case for this function? Please let me know if you need further assistance or clarification on this detail.

Footnotes

  1. https://en.wikipedia.org/wiki/Code_coverage

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see that the documentation section 1 does not contain any example about how to use the datasource element. Feel free to add a short example there about its baseline usage, and in particular about its usage with get_datasource_proxy_data. Do you think this is a good idea?

Footnotes

  1. https://github.com/panodata/grafana-client#getting-started

, query_type='query'
, version='v1'
, expr=None
, time=None
, start=None
, end=None
, step=None
):
"""

:param datasource_id:
:param version: api_version currently v1
:param query_type: query_range |query
:param expr: expr to query

:return: r (dict)
"""
get_datasource_path = "/datasources/proxy/{}" \
'/api/{}/{}?query={}'.format( datasource_id, version, query_type, expr)
if query_type == 'query_range':
get_datasource_path = get_datasource_path + '&start={}&end={}&step={}'.format(
start, end, step)
else:
get_datasource_path = get_datasource_path + '&time={}'.format(time)
r = self.api.GET(get_datasource_path)
return r
16 changes: 16 additions & 0 deletions grafana_client/elements/health.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
from .base import Base


class Health(Base):
def __init__(self, client):
super(Health, self).__init__(client)
self.client = client

def check(self):
"""

:return:
"""
path = "/health"
r = self.client.GET(path)
return r
33 changes: 33 additions & 0 deletions test/elements/test_health.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import unittest

import requests_mock

from grafana_client import GrafanaApi
from grafana_client.client import (
GrafanaBadInputError,
GrafanaClientError,
GrafanaServerError,
GrafanaUnauthorizedError,
)


class HealthTestCase(unittest.TestCase):
def setUp(self):
self.grafana = GrafanaApi(("admin", "admin"), host="localhost", url_path_prefix="", protocol="http")

@requests_mock.Mocker()
def test_search_dashboards(self, m):
m.get(
"http://localhost/api/health",
json=[
{
"commit": "6f8c1d9fe4",
"database": "ok",
"version": "7.5.11"
}
],
)

result = self.grafana.health.check()
self.assertEqual(result[0]["database"], 'ok')
self.assertEqual(len(result), 1)