Skip to content

Commit

Permalink
Add health check api (#68)
Browse files Browse the repository at this point in the history
* Add health check api

Signed-off-by: Masudur Rahman <masud@appscode.com>

* Add test for health check api

Signed-off-by: Masudur Rahman <masud@appscode.com>

* Update health check api

Signed-off-by: Masudur Rahman <masud@appscode.com>

* Update HealthResponse struct and test

Signed-off-by: Masudur Rahman <masud@appscode.com>
  • Loading branch information
masudur-rahman committed Mar 13, 2020
1 parent ebfd6e2 commit 81c32c2
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 0 deletions.
49 changes: 49 additions & 0 deletions rest-get_health.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package sdk

/*
Copyright 2016 Alexander I.Grafov <grafov@gmail.com>
Copyright 2016-2019 The Grafana SDK authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
ॐ तारे तुत्तारे तुरे स्व
*/

import (
"encoding/json"
)

// HealthResponse represents the health of grafana server
type HealthResponse struct {
Commit string `json:"commit"`
Database string `json:"database"`
Version string `json:"version"`
}

// GetHealth retrieves the health of the grafana server
// Reflects GET BaseURL API call.
func (r *Client) GetHealth() (HealthResponse, error) {
var (
raw []byte
err error
)
if raw, _, err = r.get("/api/health", nil); err != nil {
return HealthResponse{}, err
}

health := HealthResponse{}
if err := json.Unmarshal(raw, &health); err != nil {
return HealthResponse{}, err
}
return health, nil
}
18 changes: 18 additions & 0 deletions rest-get_health_integration_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package sdk_test

import (
"testing"
)

func TestClient_GetHealth(t *testing.T) {
shouldSkip(t)
client := getClient(t)

health, err := client.GetHealth()
if err != nil {
t.Fatal(err)
}
if health.Database != "ok" {
t.Fatalf("expected `Database` to be %v, got %v.", "ok", health.Database)
}
}

0 comments on commit 81c32c2

Please sign in to comment.