-
Notifications
You must be signed in to change notification settings - Fork 185
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* 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
1 parent
ebfd6e2
commit 81c32c2
Showing
2 changed files
with
67 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} |