Skip to content

Commit 81c32c2

Browse files
Add health check api (#68)
* Add health check api Signed-off-by: Masudur Rahman <[email protected]> * Add test for health check api Signed-off-by: Masudur Rahman <[email protected]> * Update health check api Signed-off-by: Masudur Rahman <[email protected]> * Update HealthResponse struct and test Signed-off-by: Masudur Rahman <[email protected]>
1 parent ebfd6e2 commit 81c32c2

File tree

2 files changed

+67
-0
lines changed

2 files changed

+67
-0
lines changed

rest-get_health.go

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
package sdk
2+
3+
/*
4+
Copyright 2016 Alexander I.Grafov <[email protected]>
5+
Copyright 2016-2019 The Grafana SDK authors
6+
7+
Licensed under the Apache License, Version 2.0 (the "License");
8+
you may not use this file except in compliance with the License.
9+
You may obtain a copy of the License at
10+
11+
http://www.apache.org/licenses/LICENSE-2.0
12+
13+
Unless required by applicable law or agreed to in writing, software
14+
distributed under the License is distributed on an "AS IS" BASIS,
15+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
See the License for the specific language governing permissions and
17+
limitations under the License.
18+
19+
ॐ तारे तुत्तारे तुरे स्व
20+
*/
21+
22+
import (
23+
"encoding/json"
24+
)
25+
26+
// HealthResponse represents the health of grafana server
27+
type HealthResponse struct {
28+
Commit string `json:"commit"`
29+
Database string `json:"database"`
30+
Version string `json:"version"`
31+
}
32+
33+
// GetHealth retrieves the health of the grafana server
34+
// Reflects GET BaseURL API call.
35+
func (r *Client) GetHealth() (HealthResponse, error) {
36+
var (
37+
raw []byte
38+
err error
39+
)
40+
if raw, _, err = r.get("/api/health", nil); err != nil {
41+
return HealthResponse{}, err
42+
}
43+
44+
health := HealthResponse{}
45+
if err := json.Unmarshal(raw, &health); err != nil {
46+
return HealthResponse{}, err
47+
}
48+
return health, nil
49+
}

rest-get_health_integration_test.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package sdk_test
2+
3+
import (
4+
"testing"
5+
)
6+
7+
func TestClient_GetHealth(t *testing.T) {
8+
shouldSkip(t)
9+
client := getClient(t)
10+
11+
health, err := client.GetHealth()
12+
if err != nil {
13+
t.Fatal(err)
14+
}
15+
if health.Database != "ok" {
16+
t.Fatalf("expected `Database` to be %v, got %v.", "ok", health.Database)
17+
}
18+
}

0 commit comments

Comments
 (0)