Skip to content

Commit 633da62

Browse files
committed
Switch to the grafana-client library fork
1 parent 699fc79 commit 633da62

File tree

5 files changed

+20
-16
lines changed

5 files changed

+20
-16
lines changed

CHANGES.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ grafana-wtf changelog
66
in progress
77
===========
88

9+
2022-02-03 0.13.1
10+
=================
11+
- Switch to the ``grafana-client`` library fork
12+
913
2022-01-22 0.13.0
1014
=================
1115
- CI: Use most recent Grafana 8.3.3

grafana_wtf/core.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
import colored
1313
import requests
1414
import requests_cache
15-
from munch import Munch, munchify, unmunchify
15+
from munch import Munch, munchify
1616
from tqdm import tqdm
1717

1818
from grafana_wtf.model import (
@@ -22,14 +22,14 @@
2222
DatasourceItem,
2323
GrafanaDataModel,
2424
)
25-
from grafana_wtf.monkey import monkeypatch_grafana_api
25+
from grafana_wtf.monkey import monkeypatch_grafana_client
2626

27-
# Apply monkeypatch to grafana-api
27+
# Apply monkeypatch to `grafana-client`.
2828
# https://github.com/m0nhawk/grafana_api/pull/85/files
29-
monkeypatch_grafana_api()
29+
monkeypatch_grafana_client()
3030

31-
from grafana_api.grafana_api import GrafanaClientError, GrafanaUnauthorizedError
32-
from grafana_api.grafana_face import GrafanaFace
31+
from grafana_client.api import GrafanaApi
32+
from grafana_client.client import GrafanaClientError, GrafanaUnauthorizedError
3333

3434
from grafana_wtf.util import JsonPathFinder
3535

@@ -84,7 +84,7 @@ def grafana_client_factory(grafana_url, grafana_token=None):
8484
password = url.password or "admin"
8585
auth = (username, password)
8686

87-
grafana = GrafanaFace(
87+
grafana = GrafanaApi(
8888
auth, protocol=url.scheme, host=url.hostname, port=url.port, url_path_prefix=url.path.lstrip("/")
8989
)
9090

@@ -99,8 +99,8 @@ def setup(self):
9999
# https://urllib3.readthedocs.io/en/latest/advanced-usage.html#customizing-pool-behavior
100100
# https://laike9m.com/blog/requests-secret-pool_connections-and-pool_maxsize,89/
101101
adapter = requests.adapters.HTTPAdapter(pool_connections=100, pool_maxsize=100, max_retries=5, pool_block=True)
102-
self.grafana.api.s.mount("http://", adapter)
103-
self.grafana.api.s.mount("https://", adapter)
102+
self.grafana.client.s.mount("http://", adapter)
103+
self.grafana.client.s.mount("https://", adapter)
104104

105105
return self
106106

@@ -251,7 +251,7 @@ class GrafanaWtf(GrafanaEngine):
251251
def info(self):
252252

253253
try:
254-
health = self.grafana.api.GET("/health")
254+
health = self.grafana.client.GET("/health")
255255
except Exception as ex:
256256
log.error(f"Request to /health endpoint failed: {ex}")
257257
health = {}
@@ -380,7 +380,7 @@ def get_red_message(message):
380380
def get_dashboard_versions(self, dashboard_id):
381381
# https://grafana.com/docs/http_api/dashboard_versions/
382382
get_dashboard_versions_path = "/dashboards/id/%s/versions" % dashboard_id
383-
r = self.grafana.dashboard.api.GET(get_dashboard_versions_path)
383+
r = self.grafana.dashboard.client.GET(get_dashboard_versions_path)
384384
return r
385385

386386
def explore_datasources(self):

grafana_wtf/monkey.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@ def update_dashboard(self, dashboard):
1515
dashboard["folderId"] = dashboard["meta"]["folderId"]
1616

1717
put_dashboard_path = "/dashboards/db"
18-
r = self.api.POST(put_dashboard_path, json=dashboard)
18+
r = self.client.POST(put_dashboard_path, json=dashboard)
1919
return r
2020

2121

22-
def monkeypatch_grafana_api():
23-
import grafana_api.api.dashboard as dashboard
22+
def monkeypatch_grafana_client():
23+
import grafana_client.elements.dashboard as dashboard
2424

2525
dashboard.Dashboard.update_dashboard = update_dashboard

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"tqdm>=4.37.0,<5",
1616
# Grafana
1717
"requests>=2.23.0,<3",
18-
"grafana-api>=1.0.3,<2",
18+
"grafana-client>=2,<3",
1919
"jsonpath-rw>=1.4.0,<2",
2020
# Caching
2121
"requests-cache>=0.5.2,<1",

tests/conftest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from pathlib import Path
44

55
import pytest
6-
from grafana_api.grafana_api import GrafanaClientError
6+
from grafana_client.client import GrafanaClientError
77

88
from grafana_wtf.core import GrafanaWtf
99

0 commit comments

Comments
 (0)