Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add health check api #68

Merged
merged 4 commits into from
Mar 13, 2020
Merged

Conversation

masudur-rahman
Copy link
Contributor

No description provided.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.3%) to 35.365% when pulling 7f54780 on searchlight:health-check-api into dcbbf97 on grafana-tools:master.

Copy link
Collaborator

@GiedriusS GiedriusS left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, a few suggestions. Could these files also be renamed to rest-healthcheck.go and rest-healthcheck_integration_test.go accordingly?

"fmt"
)

// Checks health of the grafana base url
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comments should be of the form // CheckHealth .... We should add this check to the CI, to be honest.


// Checks health of the grafana base url
// Reflects GET BaseURL API call.
func (r *Client) CheckHealth() error {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The pattern in Go is typically to return (bool, error) in such cases because we want to differentiate between an error while trying to actually check this and the (non-)healthiness of Grafana. Actually, Grafana even returns such a response:

{
  "commit": "21bf8b71bc",
  "database": "ok",
  "version": "6.6.1"
}

So I'd suggest creating a new struct which has this information and then change the return type to (HealthResponse, error). What do you think about this?

code int
err error
)
if raw, code, err = r.get("", nil); err != nil {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not /api/health? If we are just checking the root URI then I'm not sure if this should even be a part of this library. This could be achieved by other means then after all, right? We should be checking Grafana-specific things.


// Checks health of the grafana base url
// Reflects GET BaseURL API call.
func (r *Client) CheckHealth() error {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, please change this to GetHealth because it would reflect what kind of verb we are sending better.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your quick response. I'll try to do as your suggestions.

Signed-off-by: Masudur Rahman <masud@appscode.com>
Signed-off-by: Masudur Rahman <masud@appscode.com>
Signed-off-by: Masudur Rahman <masud@appscode.com>
@masudur-rahman
Copy link
Contributor Author

@GiedriusS, Sorry for being late. Could you please review the changes again ?

Copy link
Collaborator

@GiedriusS GiedriusS left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No problem! Thanks for your work on this. Almost looks good to me. One suggestion in line.


// HealthResponse represents the health of grafana server
type HealthResponse struct {
Alive bool `json:"alive"`
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you point me to documentation where the response of that end-point could return a JSON which has a key called alive?

if err := json.Unmarshal(raw, &health); err != nil {
return HealthResponse{}, err
}
health.Alive = health.Database == "ok"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unless I am mistaken, this doesn't come from the api end-point and we should remove this field and this line. Let the caller decide what is "alive". WDYT?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've removed Alive field from HealthResponse structure. Let me know if anything's out of order.

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

@GiedriusS GiedriusS left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Thanks for working through my comments 😄 Let's wait a few days to see if there are any other comments. If not then I will merge it.

@masudur-rahman
Copy link
Contributor Author

Yeah, sure.

@GiedriusS
Copy link
Collaborator

Actually, this has been up for quite some time and no one else has commented on it besides me so I will merge it now so make the process a bit faster 😄 thanks a lot for your PR!

@GiedriusS GiedriusS merged commit 81c32c2 into grafana-tools:master Mar 13, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants