Normalize response payload returned by replicas
Change [1] introduced the ability for replicas to expose a healthcheck
endpoint, however it introduced a bug whereby the response payload was
wrapped with the http status and its value, rather than the value
itself.
The following payload was returned:
```
{
"status_code": 200,
"value": {
"elapsed": 82,
"auth": {...},
"querychanges": {...},
"jgit": {...},
...
}
}
```
rather than:
```
{
"elapsed": 82,
"auth": {...},
"querychanges": {...},
"jgit": {...},
...
}
```
Make replicas return the same payload response as the non-replicas.
Bug: Issue 13550
[1] I6ab4524dcaa96d8571c3fad2eb03624f00902943
Change-Id: Ia741d7fedc23a29299046cb5224d36d0b36c7d70
diff --git a/src/main/java/com/googlesource/gerrit/plugins/healthcheck/filter/HealthCheckStatusFilter.java b/src/main/java/com/googlesource/gerrit/plugins/healthcheck/filter/HealthCheckStatusFilter.java
index 3b7773c..b2e91b1 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/healthcheck/filter/HealthCheckStatusFilter.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/healthcheck/filter/HealthCheckStatusFilter.java
@@ -68,7 +68,7 @@
try {
Response<Map<String, Object>> healthStatus =
(Response<Map<String, Object>>) statusEndpoint.apply(new ConfigResource());
- String healthStatusJson = gson.toJson(healthStatus);
+ String healthStatusJson = gson.toJson(healthStatus.value());
if (healthStatus.statusCode() == HttpServletResponse.SC_OK) {
PrintWriter writer = httpResponse.getWriter();
writer.print(new String(RestApiServlet.JSON_MAGIC));
diff --git a/src/test/java/com/googlesource/gerrit/plugins/healthcheck/HealthCheckIT.java b/src/test/java/com/googlesource/gerrit/plugins/healthcheck/HealthCheckIT.java
index bccc626..186693e 100644
--- a/src/test/java/com/googlesource/gerrit/plugins/healthcheck/HealthCheckIT.java
+++ b/src/test/java/com/googlesource/gerrit/plugins/healthcheck/HealthCheckIT.java
@@ -85,16 +85,18 @@
@Test
@GerritConfig(name = "container.slave", value = "true")
- public void shouldHitHealthCheckStatusForReplicaWhenAuthenticated() throws Exception {
+ public void shouldReturnJGitCheckForReplicaWhenAuthenticated() throws Exception {
RestResponse resp = getHealthCheckStatus();
resp.assertOK();
+ assertCheckResult(getResponseJson(resp), JGIT, "passed");
}
@Test
@GerritConfig(name = "container.slave", value = "true")
- public void shouldHitHealthCheckStatusForReplicaAnonymously() throws Exception {
+ public void shouldReturnJGitCheckForReplicaAnonymously() throws Exception {
RestResponse resp = getHealthCheckStatusAnonymously();
resp.assertOK();
+ assertCheckResult(getResponseJson(resp), JGIT, "passed");
}
@Test