-
Notifications
You must be signed in to change notification settings - Fork 479
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
Health Check Api #159
Conversation
@@ -46,6 +46,7 @@ | |||
|
|||
private ClientConfig clientConfig; | |||
private Client apiClient; | |||
private String baseUrl; |
There was a problem hiding this comment.
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(); |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this 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.
@lamdav I guess what I'm saying is that I'm not sure this belongs here, though you might be able to convince me otherwise. |
@gmessner 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 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 Here is what it would look: gitlabApi.getAdminApi().getHealthCheckApi().getLiveness(); Let me know what you think. |
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. |
@gmessner Can I get a status update on this? |
There was a problem hiding this 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 | ||
* |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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
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 |
f62ab0d
to
743d1a7
Compare
@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(); |
There was a problem hiding this comment.
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.
@lamdav |
@lamdav |
https://docs.gitlab.com/ce/user/admin_area/monitoring/health_check.html
This is a mostly admin endpoint.