Skip to content

Commit 834725f

Browse files
[FEAT] Add HTTP/2 support (#34)
* feat: Add HTTP/2 support *fix: Update the Python version inside the GH Action *fix: Update the GH lint Action *fix: Remove the unused import *feat: Adjust the API implementation and add new integration tests *docs: Add the documentation *feat: Adjust the GH Actions --------- Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
1 parent 6802785 commit 834725f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+1155
-294
lines changed

.github/workflows/integrationtest.yml

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,27 +5,48 @@ on:
55
- cron: '0 22 * * 1'
66
push:
77
branches: [ main ]
8-
pull_request:
9-
branches: [ main ]
108
workflow_dispatch:
9+
workflow_call:
1110

1211
jobs:
1312

14-
test:
13+
grafana-api-sdk-test:
1514
runs-on: ubuntu-latest
15+
strategy:
16+
matrix:
17+
python-version: [ '3.10' ]
1618

1719
steps:
1820
- uses: actions/checkout@v3
1921

22+
- name: Set up Python
23+
uses: actions/setup-python@v4
24+
with:
25+
python-version: ${{ matrix.python-version }}
26+
architecture: x64
27+
cache: 'pip'
28+
2029
- name: Install the requirements
2130
run: pip install -r requirements.txt
2231

23-
- name: Execute the integrationtests
24-
run: python3 --version && python3 -m unittest discover tests/integrationtest
32+
- name: Execute the integrationtests (http1.1)
33+
run: python3 -m unittest discover tests/integrationtest
34+
env:
35+
GRAFANA_HOST: ${{ secrets.GRAFANA_HOST }}
36+
GRAFANA_TOKEN: ${{ secrets.GRAFANA_TOKEN }}
37+
GRAFANA_DASHBOARD_PATH: ${{ secrets.GRAFANA_DASHBOARD_PATH }}
38+
GRAFANA_DASHBOARD_NAME: ${{ secrets.GRAFANA_DASHBOARD_NAME }}
39+
GRAFANA_USERNAME: ${{ secrets.GRAFANA_USERNAME }}
40+
GRAFANA_PASSWORD: ${{ secrets.GRAFANA_PASSWORD }}
41+
HTTP2: "False"
42+
43+
- name: Execute the integrationtests (http2)
44+
run: python3 -m unittest discover tests/integrationtest
2545
env:
2646
GRAFANA_HOST: ${{ secrets.GRAFANA_HOST }}
2747
GRAFANA_TOKEN: ${{ secrets.GRAFANA_TOKEN }}
2848
GRAFANA_DASHBOARD_PATH: ${{ secrets.GRAFANA_DASHBOARD_PATH }}
2949
GRAFANA_DASHBOARD_NAME: ${{ secrets.GRAFANA_DASHBOARD_NAME }}
3050
GRAFANA_USERNAME: ${{ secrets.GRAFANA_USERNAME }}
3151
GRAFANA_PASSWORD: ${{ secrets.GRAFANA_PASSWORD }}
52+
HTTP2: "True"

.github/workflows/publish-to-pypi.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ jobs:
2424
cache: 'pip'
2525

2626
- name: Install the requirements
27-
run: pip install -r requirements.txt
27+
run: pip install -r requirements.txt && pip install setuptools~=65.5.1
2828

2929
- name: Install pypa/build
3030
run: >-

.github/workflows/pull-request-checks.yml

Lines changed: 60 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ on:
66

77
jobs:
88

9-
test:
9+
pr-test:
1010
runs-on: ubuntu-latest
1111
strategy:
1212
matrix:
13-
python-version: [ '3.x' ]
13+
python-version: [ '3.10' ]
1414

1515
steps:
1616
- uses: actions/checkout@v3
@@ -28,11 +28,11 @@ jobs:
2828
- name: Execute the unittests
2929
run: python3 -m unittest discover tests/unittests
3030

31-
lint:
31+
pr-lint:
3232
runs-on: ubuntu-latest
3333
strategy:
3434
matrix:
35-
python-version: [ '3.x' ]
35+
python-version: [ '3.10' ]
3636

3737
steps:
3838
- uses: actions/checkout@v3
@@ -44,20 +44,18 @@ jobs:
4444
architecture: x64
4545
cache: 'pip'
4646

47-
- name: Install the requirements
48-
run: pip install -r requirements.txt
49-
5047
- name: Execute the linting checks
51-
uses: reviewdog/action-flake8@v3.7.0
48+
uses: reviewdog/action-flake8@v3
5249
with:
5350
github_token: ${{ secrets.GITHUB_TOKEN }}
5451
flake8_args: --config=.flake8
52+
fail_on_error: true
5553

56-
coverage:
54+
pr-coverage:
5755
runs-on: ubuntu-latest
5856
strategy:
5957
matrix:
60-
python-version: [ '3.x' ]
58+
python-version: [ '3.10' ]
6159

6260
steps:
6361
- uses: actions/checkout@v3
@@ -81,15 +79,59 @@ jobs:
8179
- name: Execute the coverage checks
8280
uses: MishaKav/[email protected]
8381
with:
84-
github_token: ${{ secrets.GITHUB_TOKEN }}
82+
github-token: ${{ secrets.GITHUB_TOKEN }}
8583
pytest-coverage-path: ./pytest-coverage.txt
8684
junitxml-path: ./pytest.xml
8785
hide-badge: true
88-
create-new-commit: true
86+
create-new-comment: false
8987

9088
- name: Generate coverage badge
9189
run: coverage-badge -f -o docs/coverage.svg
9290

91+
- name: Check changed files
92+
uses: tj-actions/verify-changed-files@v16
93+
id: verify-changed-files
94+
with:
95+
files: |
96+
docs
97+
98+
- name: Commit files
99+
if: steps.verify-changed-files.outputs.files_changed == 'true'
100+
run: |
101+
git config --local user.email "github-actions[bot]@users.noreply.github.com"
102+
git config --local user.name "github-actions[bot]"
103+
git add --force docs
104+
git commit -m "docs: Add coverage badge"
105+
106+
- name: Push changes
107+
uses: ad-m/github-push-action@master
108+
if: steps.verify-changed-files.outputs.files_changed == 'true'
109+
with:
110+
github_token: ${{ secrets.GITHUB_TOKEN }}
111+
branch: ${{ github.head_ref }}
112+
113+
pr-documentation:
114+
runs-on: ubuntu-latest
115+
strategy:
116+
matrix:
117+
python-version: [ '3.9' ]
118+
119+
steps:
120+
- uses: actions/checkout@v3
121+
with:
122+
persist-credentials: false
123+
fetch-depth: 0
124+
125+
- name: Set up Python
126+
uses: actions/setup-python@v4
127+
with:
128+
python-version: ${{ matrix.python-version }}
129+
architecture: x64
130+
cache: 'pip'
131+
132+
- name: Install the requirements
133+
run: pip install pydoc-markdown==4.6.3 mkdocs mkdocs-material
134+
93135
- name: Generate documentation
94136
run: pydoc-markdown --render-toc && rm -rf docs/content && mv build/docs/* docs
95137

@@ -106,11 +148,15 @@ jobs:
106148
git config --local user.email "github-actions[bot]@users.noreply.github.com"
107149
git config --local user.name "github-actions[bot]"
108150
git add --force docs
109-
git commit -m "docs: Add coverage badge and documentation"
151+
git commit -m "docs: Add the documentation"
110152
111153
- name: Push changes
112154
uses: ad-m/github-push-action@master
113155
if: steps.verify-changed-files.outputs.files_changed == 'true'
114156
with:
115157
github_token: ${{ secrets.GITHUB_TOKEN }}
116-
branch: ${{ github.head_ref }}
158+
branch: ${{ github.head_ref }}
159+
160+
pr-integrationtest:
161+
uses: ./.github/workflows/integrationtest.yml
162+
secrets: inherit

README.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
# Grafana API SDK ![Coverage report](https://github.com/ZPascal/grafana_api_sdk/blob/main/docs/coverage.svg)
2-
The repository includes a Python SDK for the Grafana API. It's possible to communicate with the Grafana API endpoints. Another feature of the SDK is the possibility to specify the used folder for the dashboard.
2+
The repository includes an SDK for the Grafana API. It's possible to interact with all public available Grafana HTTP API endpoints.
33

44
## Differences between [grafana-client](https://github.com/panodata/grafana-client), [grafana_api](https://github.com/m0nhawk/grafana_api/) and the [grafana_api_sdk](https://github.com/ZPascal/grafana_api_sdk)
55
The grafana-client is only a fork of the non-maintained grafana_api repository. In general, the grafana-client project started at the same time, as I started this project. The corresponding SDK is a completely new project and based on non-other project and include a few features that are currently not implemented inside the grafana-client.
66

7-
The main feature that is implemented inside this library:
7+
The core features that are implemented inside this library:
88

9-
- Grafana V8 Alerting API support (possibility to communicate (currently read only) with the attached Prometheus and Alertmanager)
9+
- All public Grafana API (HTTP) endpoints are supported
10+
- Full API support for Grafana legacy alerting, current alerting, alerting channels and alert provisioning
11+
- Possibility to specify custom and self-signed certificates
12+
- HTTP/2 support
1013

1114
In general my focus inside this project is to implement and deliver old and new features from the Grafana API, to document all features and functionality clear and to increase the overall test coverage of the project.
1215

@@ -230,6 +233,7 @@ In general my focus inside this project is to implement and deliver old and new
230233
- Renew login session
231234
- Get health status
232235
- Get metrics
236+
- Get Plugin metrics
233237

234238
### Licensing
235239
- Check license availability

docs/content/grafana_api/api.md

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
* [api](#api)
44
* [Api](#api.Api)
55
* [call\_the\_api](#api.Api.call_the_api)
6+
* [prepare\_api\_string](#api.Api.prepare_api_string)
7+
* [create\_the\_http\_api\_client](#api.Api.create_the_http_api_client)
68

79
<a id="api"></a>
810

@@ -61,3 +63,43 @@ The method execute a defined API call against the Grafana endpoints
6163

6264
- `api_call` _any_ - Returns the value of the api call
6365

66+
<a id="api.Api.prepare_api_string"></a>
67+
68+
#### prepare\_api\_string
69+
70+
```python
71+
@staticmethod
72+
def prepare_api_string(query_string: str) -> str
73+
```
74+
75+
The method includes a functionality to prepare the api string for the queries
76+
77+
**Arguments**:
78+
79+
- `query_string` _str_ - Specify the corresponding query string
80+
81+
82+
**Returns**:
83+
84+
- `query_string` _str_ - Returns the adjusted query string
85+
86+
<a id="api.Api.create_the_http_api_client"></a>
87+
88+
#### create\_the\_http\_api\_client
89+
90+
```python
91+
def create_the_http_api_client(
92+
headers: dict = None) -> Union[httpx.Client, httpx.AsyncClient]
93+
```
94+
95+
The method includes a functionality to create the corresponding HTTP client
96+
97+
**Arguments**:
98+
99+
- `headers` _dict_ - Specify the optional inserted headers (Default None)
100+
101+
102+
**Returns**:
103+
104+
- `client` _Union[httpx.Client, httpx.AsyncClient]_ - Returns the corresponding client
105+

docs/content/grafana_api/model.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ The class includes all necessary variables to establish a connection to the Graf
7979
- `username` _str_ - Specify the username of the Grafana system
8080
- `password` _str_ - Specify the password of the Grafana system
8181
- `timeout` _float_ - Specify the timeout of the Grafana system
82+
- `http2_support` _bool_ - Specify if you want to use HTTP/2
8283
- `ssl_context` _ssl.SSLContext_ - Specify the custom ssl context of the Grafana system
8384
- `num_pools` _int_ - Specify the number of the connection pool
8485
- `retries` _any_ - Specify the number of the retries. Please use False as parameter to disable the retries

docs/content/grafana_api/other-http.md

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
* [renew\_login\_session\_based\_on\_remember\_cookie](#other_http.OtherHTTP.renew_login_session_based_on_remember_cookie)
77
* [get\_health\_status](#other_http.OtherHTTP.get_health_status)
88
* [get\_metrics](#other_http.OtherHTTP.get_metrics)
9+
* [get\_plugin\_metrics](#other_http.OtherHTTP.get_plugin_metrics)
910

1011
<a id="other_http"></a>
1112

@@ -92,13 +93,49 @@ The method includes a functionality to get the health information
9293
#### get\_metrics
9394

9495
```python
95-
def get_metrics() -> str
96+
def get_metrics(basic_auth_username: str = None,
97+
basic_auth_password: str = None) -> str
9698
```
9799

98100
The method includes a functionality to get the Grafana metrics information
99101

102+
**Arguments**:
103+
104+
- `basic_auth_username` _str_ - Specify the optional basic auth username
105+
- `basic_auth_password` _str_ - Specify the optional basic auth password
106+
107+
108+
**Raises**:
109+
110+
- `Exception` - Unspecified error by executing the API call
111+
112+
113+
**Returns**:
114+
115+
- `api_call` _str_ - Returns the metrics information
116+
117+
<a id="other_http.OtherHTTP.get_plugin_metrics"></a>
118+
119+
#### get\_plugin\_metrics
120+
121+
```python
122+
def get_plugin_metrics(plugin_id: str,
123+
basic_auth_username: str = None,
124+
basic_auth_password: str = None) -> str
125+
```
126+
127+
The method includes a functionality to get the Grafana plugin metrics information
128+
129+
**Arguments**:
130+
131+
- `plugin_id` _str_ - Specify the plugin id
132+
- `basic_auth_username` _str_ - Specify the optional basic auth username
133+
- `basic_auth_password` _str_ - Specify the optional basic auth password
134+
135+
100136
**Raises**:
101137

138+
- `ValueError` - Missed specifying a necessary value
102139
- `Exception` - Unspecified error by executing the API call
103140

104141

0 commit comments

Comments
 (0)