Skip to content

Commit 7d437a5

Browse files
committed
add some docs for Grafana client
1 parent e05e656 commit 7d437a5

File tree

2 files changed

+81
-1
lines changed

2 files changed

+81
-1
lines changed

book/src/SUMMARY.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@
9393
- [Anvil]()
9494
- [AWS Secrets Manager](./libv2/client/aws_secrets_manager.md)
9595
- [Github](./libv2/client/github.md)
96-
- [Grafana]()
96+
- [Grafana](./libv2/client/grafana.md)
9797
- [Kafka](./libv2/client/kafka.md)
9898
- [Loki](./libv2/client/loki.md)
9999
- [MockServer](./libv2/client/mockserver.md)

book/src/libv2/client/grafana.md

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
# Grafana
2+
3+
> [!NOTE]
4+
> Contrary to other clients, you will find Grafana client in a [separate package & go module](https://github.com/smartcontractkit/chainlink-testing-framework/tree/main/lib/grafana).
5+
6+
Grafana client encapsulate following functionalities:
7+
* Dashboard creation
8+
* Managing dashboard annotations (CRUD)
9+
* Checking alerts
10+
11+
# New instance
12+
In order to create a new instance you will need:
13+
* URL
14+
* API token
15+
16+
For example:
17+
```go
18+
url := "http://grafana.io"
19+
apiToken := "such-a-secret-1&11n"
20+
gc := NewGrafanaClient(url, apiToken)
21+
```
22+
23+
# Dashboard creation
24+
You can create a new dashboard defined in JSON with:
25+
```go
26+
27+
//define your dashboard here
28+
dashboardJson := ``
29+
30+
request := PostDashboardRequest {
31+
Dashboard: dashboardJson,
32+
FolderId: 5 // change to your folder id
33+
}
34+
35+
dr, rawResponse, err := gc.PostDashboard(request)
36+
if err != nil {
37+
panic(err)
38+
}
39+
40+
if rawResponse.StatusCode() != 200 {
41+
panic("response code wasn't 200, but " + rawResponse.StatusCode())
42+
}
43+
44+
fmt.Println("Dashboard slug is is " + *dr.Slug)
45+
```
46+
47+
# Posting annotations
48+
You can post annotations in a following way:
49+
```go
50+
annDetails := PostAnnotation {
51+
DashboardUID: "some-uid",
52+
Time: time.Now(),
53+
TimeEnd: time.Now().Add(1 * time.Second)
54+
Text: "my test annotation"
55+
}
56+
57+
r, rawResponse, err := gc.PostAnnotation(annDetails)
58+
if rawResponse.StatusCode() != 200 {
59+
panic("response code wasn't 200, but " + rawResponse.StatusCode())
60+
}
61+
62+
fmt.Println("Created annotation with id: " + r.Id)
63+
64+
```
65+
66+
# Checking alerts
67+
You can check alerts firing for a dashboard with UID:
68+
```go
69+
alerts, rawResponse, err := gc.AlertRulerClient.GetAlertsForDashboard("some-uid")
70+
if rawResponse.StatusCode() != 200 {
71+
panic("response code wasn't 200, but " + rawResponse.StatusCode())
72+
}
73+
74+
for name, value := range alerts {
75+
fmt.Println("Alert named " + name + "was triggered. Details: " + string(value))
76+
}
77+
```
78+
79+
# Troubleshooting
80+
To enable debug mode for the underlaying HTTP client set `RESTY_DEBUG` environment variable to `true`.

0 commit comments

Comments
 (0)