mirror of
https://github.com/apache/druid.git
synced 2025-02-17 07:25:02 +00:00
Web console: better management proxy detection (#15453)
* better management proxy detection * fix checkstyle issue * add test * test should read the body also * use ObjectMapper * assert read ammount
This commit is contained in:
parent
74ab6024e1
commit
31fa63e789
@ -63,6 +63,9 @@ public class AsyncManagementForwardingServlet extends AsyncProxyServlet
|
||||
private static final String ARBITRARY_COORDINATOR_BASE_PATH = "/proxy/coordinator";
|
||||
private static final String ARBITRARY_OVERLORD_BASE_PATH = "/proxy/overlord";
|
||||
|
||||
// This path is used to check if the managment proxy is enabled, it simply returns {"enabled":true}
|
||||
private static final String ENABLED_PATH = "/proxy/enabled";
|
||||
|
||||
private final ObjectMapper jsonMapper;
|
||||
private final Provider<HttpClient> httpClientProvider;
|
||||
private final DruidHttpClientConfig httpClientConfig;
|
||||
@ -106,6 +109,9 @@ public class AsyncManagementForwardingServlet extends AsyncProxyServlet
|
||||
MODIFIED_PATH_ATTRIBUTE,
|
||||
request.getRequestURI().substring(ARBITRARY_OVERLORD_BASE_PATH.length())
|
||||
);
|
||||
} else if (ENABLED_PATH.equals(requestURI)) {
|
||||
handleEnabledRequest(response);
|
||||
return;
|
||||
} else {
|
||||
handleBadRequest(response, StringUtils.format("Unsupported proxy destination [%s]", request.getRequestURI()));
|
||||
return;
|
||||
@ -188,4 +194,14 @@ public class AsyncManagementForwardingServlet extends AsyncProxyServlet
|
||||
}
|
||||
response.flushBuffer();
|
||||
}
|
||||
|
||||
private void handleEnabledRequest(HttpServletResponse response) throws IOException
|
||||
{
|
||||
if (!response.isCommitted()) {
|
||||
response.resetBuffer();
|
||||
response.setStatus(HttpServletResponse.SC_OK);
|
||||
jsonMapper.writeValue(response.getOutputStream(), ImmutableMap.of("enabled", true));
|
||||
}
|
||||
response.flushBuffer();
|
||||
}
|
||||
}
|
||||
|
@ -317,6 +317,21 @@ public class AsyncManagementForwardingServletTest extends BaseJettyTest
|
||||
Assert.assertTrue("overlord called", OVERLORD_EXPECTED_REQUEST.called);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testProxyEnebledCheck() throws Exception
|
||||
{
|
||||
HttpURLConnection connection = ((HttpURLConnection)
|
||||
new URL(StringUtils.format("http://localhost:%d/proxy/enabled", port)).openConnection());
|
||||
connection.setRequestMethod("GET");
|
||||
|
||||
Assert.assertEquals(200, connection.getResponseCode());
|
||||
byte[] bytes = new byte[connection.getContentLength()];
|
||||
Assert.assertEquals(connection.getInputStream().read(bytes), connection.getContentLength());
|
||||
Assert.assertEquals(ImmutableMap.of("enabled", true), new ObjectMapper().readValue(bytes, Map.class));
|
||||
Assert.assertFalse("coordinator called", COORDINATOR_EXPECTED_REQUEST.called);
|
||||
Assert.assertFalse("overlord called", OVERLORD_EXPECTED_REQUEST.called);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBadProxyDestination() throws Exception
|
||||
{
|
||||
|
@ -102,11 +102,13 @@ export class Capabilities {
|
||||
|
||||
static async detectManagementProxy(): Promise<boolean> {
|
||||
try {
|
||||
await Api.instance.get(`/proxy/coordinator/status?capabilities`, {
|
||||
await Api.instance.get(`/proxy/enabled?capabilities`, {
|
||||
timeout: Capabilities.STATUS_TIMEOUT,
|
||||
});
|
||||
} catch (e) {
|
||||
return false;
|
||||
const { response } = e;
|
||||
// If we detect error code 400 the management proxy is enabled but just does not know about the recently added /proxy/enabled route so treat this as a win.
|
||||
return response.status === 400;
|
||||
}
|
||||
|
||||
return true;
|
||||
|
Loading…
x
Reference in New Issue
Block a user