-
Notifications
You must be signed in to change notification settings - Fork 82
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e2aaa0e
commit 836fec5
Showing
9 changed files
with
139 additions
and
26 deletions.
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
74 changes: 74 additions & 0 deletions
74
.../src/main/java/io/trino/gateway/ha/clustermonitor/ClusterStatsCoordinatorInfoMonitor.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,74 @@ | ||
/* | ||
* 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.databind.ObjectMapper; | ||
import io.trino.client.ServerInfo; | ||
import io.trino.gateway.ha.config.ProxyBackendConfiguration; | ||
import okhttp3.Call; | ||
import okhttp3.HttpUrl; | ||
import okhttp3.OkHttpClient; | ||
import okhttp3.Request; | ||
import okhttp3.Response; | ||
import org.eclipse.jetty.http.HttpStatus; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import java.io.IOException; | ||
|
||
public class ClusterStatsCoordinatorInfoMonitor | ||
implements ClusterStatsMonitor | ||
{ | ||
private static OkHttpClient client = new OkHttpClient(); | ||
private static final ObjectMapper objectMapper = new ObjectMapper(); | ||
private static final Logger log = LoggerFactory.getLogger(ClusterStatsCoordinatorInfoMonitor.class); | ||
|
||
@Override | ||
public ClusterStats monitor(ProxyBackendConfiguration backend) | ||
{ | ||
ClusterStats.Builder clusterStats = ClusterStats.builder(backend.getName()); | ||
|
||
clusterStats.healthy(isReadyStatus(backend.getProxyTo())) | ||
.proxyTo(backend.getProxyTo()) | ||
.externalUrl(backend.getExternalUrl()) | ||
.routingGroup(backend.getRoutingGroup()); | ||
|
||
return clusterStats.build(); | ||
} | ||
|
||
private boolean isReadyStatus(String baseUrl) | ||
{ | ||
String statusUrl = baseUrl + "/v1/status"; | ||
|
||
Request request = new Request.Builder() | ||
.url(HttpUrl.parse(statusUrl)) | ||
.get() | ||
.build(); | ||
|
||
Call call = client.newCall(request); | ||
|
||
try (Response res = call.execute()) { | ||
if (res.code() != HttpStatus.OK_200) { | ||
return false; | ||
} | ||
ServerInfo info = objectMapper.readValue(res.body().string(), ServerInfo.class); | ||
return !info.isStarting(); | ||
} | ||
catch (IOException e) { | ||
log.warn("Error checking health of backend {}. Error: {}", baseUrl, e.getMessage()); | ||
} | ||
return false; | ||
} | ||
} |
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, | ||
COORDINATOR_INFO, | ||
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