Skip to content

Health Check Api #159

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

Merged
merged 2 commits into from
Apr 20, 2018
Merged

Health Check Api #159

merged 2 commits into from
Apr 20, 2018

Conversation

lamdav
Copy link
Contributor

@lamdav lamdav commented Mar 18, 2018

@@ -46,6 +46,7 @@

private ClientConfig clientConfig;
private Client apiClient;
private String baseUrl;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added a field to keep track of the original url.

}
}

return (new URL(url.toString()));
return urlBuilder.toString();
Copy link
Contributor Author

Choose a reason for hiding this comment

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

factored out url building logic so that it can be applied with the baseUrl as well.

* @param token Health Status token
* @return LivenessHealthCheck instance
* @throws GitLabApiException if any exception occurs
* @deprecated
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Gitlab docs state these have been deprecated. I added them in any way so that it is at least backward compatible during the deprecation process.


@XmlAccessorType(XmlAccessType.FIELD)
public class HealthCheckStatus {
private String status;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ideally, these should be enums but I don't know all the possible values other than "ok". If you have any ideas, I would be happy to update this.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Check out the source for the health controller at:
https://gitlab.com/gitlab-org/gitlab-ce/blob/master/app/controllers/health_controller.rb

Valid status are: "ok", "failed"


@XmlAccessorType(XmlAccessType.FIELD)
public class HealthCheckStatusLabel {
private String shard;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The only extra label I had was "shard". If you have an idea of other labels, I am willing to add them.

Ideally, this should be an enum as well but I have not encountered other values while testing.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Looking at the source for the health check controller, I do not believe that the labels should be enums, they instead should be a dictionary of name/value pairs.

Making them a dictionary would also eliminate the need for this class.

Copy link
Contributor Author

@lamdav lamdav left a comment

Choose a reason for hiding this comment

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

I left some comments pointing out a few things. Let me know what you think.

@gmessner
Copy link
Collaborator

@lamdav
I have avoided adding functionality that is not part of the GitLab API, this health check API is part of the admin dashboard and requires an entirely different access token than the API does. This could possibly lead to confusion when the same access token doesn't work with the other API calls.

I guess what I'm saying is that I'm not sure this belongs here, though you might be able to convince me otherwise.

@lamdav
Copy link
Contributor Author

lamdav commented Mar 19, 2018

@gmessner
Thanks for taking a look.

If I remove the deprecated call, there would be no methods that take a new token. That is, there should be no confusion between api token and monitoring token as the preferred method of accessing this gitlab endpoint is through ip_whitelisting. This is further added in the javadoc upon 404 errors if the user is confused.

As for your question on whether this belongs here or not, I do not think I have a convincing argument. I will elaborate on my desired usage. I am working on a project that integrates heavily with gitlab and several other components. I would like to create a monitoring dashboard that monitors all components. Since I am already using a gitlab wrapper, I would rather use the wrapper's abstractions for gitlab to query their health endpoints. This will help keep all application communication through gitlab localize through the library. The alternative, and in my opinion, less elegant solution is to use barebone java to do so and parse the results. Other alternatives would include adding dependencies which I think is overkill for one kind of query.

If your main concern is possible confusion, then perhaps we can work with the GitlabApi class and have a method called getAdminApi() in which it constructs a class GitLabAdminApi which wraps things such as HealthCheckApi and other admin level apis. This way the intent is clear to the user that using this api requires elevated permissions.

Here is what it would look:

gitlabApi.getAdminApi().getHealthCheckApi().getLiveness();

Let me know what you think.

@gmessner
Copy link
Collaborator

I think you are on the right track with making the AdminApi separate, however I think that we should not make the AdminApi/HealthCheckApi part of the GitLabApi as it will require one to properly instantiate a GitLabApi instance to get to the AdminApi HealthCheckApi instance. I have an idea on how to make it separate, when I get home tonight I will provide more info on that or maybe even create it.

@lamdav
Copy link
Contributor Author

lamdav commented Apr 19, 2018

@gmessner Can I get a status update on this?

Copy link
Collaborator

@gmessner gmessner left a comment

Choose a reason for hiding this comment

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

After looking at the source for the health_controller at:
https://gitlab.com/gitlab-org/gitlab-ce/blob/master/app/controllers/health_controller.rb

I believe both readiness and liveliness should use the same class for results, so I would like to see just a single results class called: HealthCheckInfo

HealthCheckInfo should be comprised of HealthCheckItem (was HealthCheckStatus) which includes the status, labels (now a Map<String, String>), and message properties.

/**
* Get Health Checks from the liveness endpoint.
* Requires ip_whitelist
*
Copy link
Collaborator

Choose a reason for hiding this comment

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

Clarify "Requires ip_whitelist". This should provide clear instructions for the IP whitelist, you could provide the URL:
https://docs.gitlab.com/ee/administration/monitoring/ip_whitelist.html

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good idea. I put the url for all methods doc strings.


@XmlAccessorType(XmlAccessType.FIELD)
public class HealthCheckStatusLabel {
private String shard;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Looking at the source for the health check controller, I do not believe that the labels should be enums, they instead should be a dictionary of name/value pairs.

Making them a dictionary would also eliminate the need for this class.


@XmlAccessorType(XmlAccessType.FIELD)
public class HealthCheckStatus {
private String status;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Check out the source for the health controller at:
https://gitlab.com/gitlab-org/gitlab-ce/blob/master/app/controllers/health_controller.rb

Valid status are: "ok", "failed"

import javax.xml.bind.annotation.XmlAccessorType;

@XmlAccessorType(XmlAccessType.FIELD)
public class HealthCheckStatusDetail extends HealthCheckStatus {
Copy link
Collaborator

@gmessner gmessner Apr 20, 2018

Choose a reason for hiding this comment

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

No longer needed after refactoring LivenessHealthCheck.java to HealthCheckInfo.java

import javax.xml.bind.annotation.XmlAccessorType;

@XmlAccessorType(XmlAccessType.FIELD)
public class HealthCheckStatus {
Copy link
Collaborator

@gmessner gmessner Apr 20, 2018

Choose a reason for hiding this comment

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

Rename this HealthCheckItem and include the following properties

private HealthCheckStatus status;
private Map<String, String> labels;
private String message;


@XmlRootElement
@XmlAccessorType(XmlAccessType.FIELD)
public class LivenessHealthCheck {
Copy link
Collaborator

@gmessner gmessner Apr 20, 2018

Choose a reason for hiding this comment

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

Rename to HealthCheckInfo and use the newly refactored HealthCheckItem instead of HealthCheckStatus


@XmlRootElement
@XmlAccessorType(XmlAccessType.FIELD)
public class ReadinessHealthCheck {
Copy link
Collaborator

@gmessner gmessner Apr 20, 2018

Choose a reason for hiding this comment

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

No longer needed, use HealthCheckInfo as the class for both readiness and liveliness

@gmessner
Copy link
Collaborator

I have decided to go with your changes to GitLabApi and GitLabApiClient, however after reviewing the health_controller.rb source I believe your implementation can be greatly simplified. I have started a code review.

You'll find the source for the health_controller at: https://gitlab.com/gitlab-org/gitlab-ce/blob/master/app/controllers/health_controller.rb

@lamdav lamdav force-pushed the feature/health-check-api branch from f62ab0d to 743d1a7 Compare April 20, 2018 05:44
@lamdav
Copy link
Contributor Author

lamdav commented Apr 20, 2018

@gmessner Thanks for the feedback. I think I made the changes you suggested accordingly. Let me know if I misunderstood something or if you have any other changes you would like to make.

```java
// Get the liveness endpoint health check results.
// Assumes ip_whitelisted
LivenessHealthCheck healthCheck = gitLabApi.getHealthCheckApi().getLiveness();
Copy link
Collaborator

@gmessner gmessner Apr 20, 2018

Choose a reason for hiding this comment

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

LivenessHealthCheck should be HealthCheckInfo.

Nevermind, since I will be editing this file to bump the version when I release, I can make the edit then.

@gmessner
Copy link
Collaborator

gmessner commented Apr 20, 2018

@lamdav
Changes are spot on. Thanks for your contribution and my apologies for taking so long to get to it

@gmessner gmessner merged commit 900c1a9 into gitlab4j:master Apr 20, 2018
gmessner added a commit that referenced this pull request Apr 20, 2018
gmessner added a commit that referenced this pull request Apr 20, 2018
gmessner added a commit that referenced this pull request Apr 20, 2018
gmessner added a commit that referenced this pull request Apr 20, 2018
gmessner added a commit that referenced this pull request Apr 20, 2018
gmessner added a commit that referenced this pull request Apr 20, 2018
@gmessner
Copy link
Collaborator

@lamdav
I added unit tests, made a few minor changes, and released 4.8.12. Thanks again for your contribution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants