-
Notifications
You must be signed in to change notification settings - Fork 82
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
Get cluster health from v1/info #264
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
gateway-ha/src/main/java/io/trino/gateway/ha/clustermonitor/ClusterStatsInfoApiMonitor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package io.trino.gateway.ha.clustermonitor; | ||
|
||
import io.airlift.http.client.HttpClient; | ||
import io.airlift.http.client.HttpClientConfig; | ||
import io.airlift.http.client.JsonResponseHandler; | ||
import io.airlift.http.client.Request; | ||
import io.airlift.http.client.jetty.JettyHttpClient; | ||
import io.trino.gateway.ha.config.ProxyBackendConfiguration; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import java.net.URI; | ||
|
||
import static io.airlift.http.client.HttpUriBuilder.uriBuilderFrom; | ||
import static io.airlift.http.client.JsonResponseHandler.createJsonResponseHandler; | ||
import static io.airlift.http.client.Request.Builder.prepareGet; | ||
import static io.airlift.json.JsonCodec.jsonCodec; | ||
|
||
public class ClusterStatsInfoApiMonitor | ||
implements ClusterStatsMonitor | ||
{ | ||
//TODO: make client options configurable | ||
willmostly marked this conversation as resolved.
Show resolved
Hide resolved
|
||
private static final HttpClient client = new JettyHttpClient(new HttpClientConfig()); | ||
private static final Logger log = LoggerFactory.getLogger(ClusterStatsInfoApiMonitor.class); | ||
private static final JsonResponseHandler<ServerInfo> SERVER_INFO_JSON_RESPONSE_HANDLER = createJsonResponseHandler(jsonCodec(ServerInfo.class)); | ||
|
||
@Override | ||
public ClusterStats monitor(ProxyBackendConfiguration backend) | ||
{ | ||
return ClusterStats.builder(backend.getName()).healthy(isReadyStatus(backend.getProxyTo())) | ||
.proxyTo(backend.getProxyTo()) | ||
.externalUrl(backend.getExternalUrl()) | ||
.routingGroup(backend.getRoutingGroup()).build(); | ||
} | ||
|
||
private boolean isReadyStatus(String baseUrl) | ||
{ | ||
Request request = prepareGet() | ||
.setUri(uriBuilderFrom(URI.create(baseUrl)).appendPath("/v1/info").build()) | ||
.build(); | ||
|
||
try { | ||
ServerInfo serverInfo = client.execute(request, SERVER_INFO_JSON_RESPONSE_HANDLER); | ||
return !serverInfo.isStarting(); | ||
} | ||
catch (Exception e) { | ||
log.error("Exception checking {} for health: {} ", request.getUri(), e.getMessage()); | ||
} | ||
return false; | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
gateway-ha/src/main/java/io/trino/gateway/ha/clustermonitor/ServerInfo.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package io.trino.gateway.ha.clustermonitor; | ||
|
||
import com.fasterxml.jackson.annotation.JsonCreator; | ||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
|
||
import static java.util.Objects.requireNonNull; | ||
|
||
// based on https://github.com/trinodb/trino/blob/439/client/trino-client/src/main/java/io/trino/client/ServerInfo.java | ||
// without unused fields | ||
public class ServerInfo | ||
{ | ||
private final Boolean starting; | ||
|
||
@JsonCreator | ||
public ServerInfo( | ||
@JsonProperty("starting") Boolean starting) | ||
{ | ||
this.starting = requireNonNull(starting, "starting is null"); | ||
} | ||
|
||
public boolean isStarting() | ||
{ | ||
return starting; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
gateway-ha/src/main/java/io/trino/gateway/ha/config/ClusterStatsMonitorType.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package io.trino.gateway.ha.config; | ||
|
||
public enum ClusterStatsMonitorType | ||
{ | ||
NOOP, | ||
INFO_API, | ||
UI_API, | ||
JDBC | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
are we potentially removing OkHttp to use this in the future? Or we will keep both in the repo?
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 think we should be able to eliminate the runtime dependency on
OkHttp
. It is used in several tests, but the gateway itself only uses it inClusterStatsApiMonitor
. We can probably switch over for tests too, just a bit more work.