Skip to content

Commit f5fa6ae

Browse files
committed
Add initial Grafana tests
Adds one tests that checks some basic Grafana statistics. Mostly to check that we can access the API.
1 parent b81d910 commit f5fa6ae

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
grafana-client==4.1.*
12
opensearch-py==2.5.*
23
prometheus-api-client==0.5.*
34
pytest-testinfra==10.1.*
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# Copyright (c) 2024 StackHPC Ltd.
2+
3+
# Licensed under the Apache License, Version 2.0 (the "License"); you may
4+
# not use this file except in compliance with the License. You may obtain
5+
# a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12+
# License for the specific language governing permissions and limitations
13+
# under the License.
14+
15+
# TODO: Check if we can validate that dashboards load correctly.
16+
17+
from grafana_client import GrafanaApi
18+
import os
19+
import pytest
20+
21+
22+
@pytest.fixture
23+
def grafana() -> GrafanaApi:
24+
"""Pytest fixture that creates a Grafana API client."""
25+
# https://github.com/grafana-toolbox/grafana-client
26+
grafana_url = os.environ["GRAFANA_URL"]
27+
grafana_username = os.environ["GRAFANA_USERNAME"]
28+
grafana_password = os.environ["GRAFANA_PASSWORD"]
29+
return GrafanaApi.from_url(
30+
grafana_url,
31+
credential=(grafana_username, grafana_password),
32+
)
33+
34+
35+
def test_grafana_api_stats(grafana):
36+
"""Test that Grafana API stats are accessible."""
37+
# https://grafana.com/docs/grafana/latest/developers/http_api/admin/#grafana-stats
38+
result = grafana.admin.stats()
39+
assert result["dashboards"] > 0
40+
assert result["datasources"] > 0

0 commit comments

Comments
 (0)