Skip to content

Commit ec13d4e

Browse files
prakhar10ebyhr
authored andcommitted
Show cluster healthy/unhealthy status on dashboard
1 parent b4f7158 commit ec13d4e

File tree

5 files changed

+44
-0
lines changed

5 files changed

+44
-0
lines changed

gateway-ha/src/main/java/io/trino/gateway/ha/domain/response/DistributionResponse.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ public class DistributionResponse
2323
private Integer totalBackendCount;
2424
private Integer offlineBackendCount;
2525
private Integer onlineBackendCount;
26+
private Integer healthyBackendCount;
27+
private Integer unhealthyBackendCount;
2628

2729
/**
2830
* Total number of queries.
@@ -55,6 +57,28 @@ public class DistributionResponse
5557
private Map<String, List<LineChart>> lineChart;
5658
private String startTime;
5759

60+
@JsonProperty
61+
public Integer getHealthyBackendCount()
62+
{
63+
return healthyBackendCount;
64+
}
65+
66+
public void setHealthyBackendCount(Integer healthyBackendCount)
67+
{
68+
this.healthyBackendCount = healthyBackendCount;
69+
}
70+
71+
@JsonProperty
72+
public Integer getUnhealthyBackendCount()
73+
{
74+
return unhealthyBackendCount;
75+
}
76+
77+
public void setUnhealthyBackendCount(Integer unhealthyBackendCount)
78+
{
79+
this.unhealthyBackendCount = unhealthyBackendCount;
80+
}
81+
5882
@JsonProperty
5983
public String getStartTime()
6084
{

gateway-ha/src/main/java/io/trino/gateway/ha/resource/GatewayWebAppResource.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import com.google.common.base.Strings;
1717
import com.google.inject.Inject;
1818
import io.trino.gateway.ha.clustermonitor.ClusterStats;
19+
import io.trino.gateway.ha.clustermonitor.TrinoStatus;
1920
import io.trino.gateway.ha.config.HaGatewayConfiguration;
2021
import io.trino.gateway.ha.config.ProxyBackendConfiguration;
2122
import io.trino.gateway.ha.config.RoutingRulesConfiguration;
@@ -160,6 +161,11 @@ public Response getDistribution(QueryDistributionRequest query)
160161
Map<String, String> urlToNameMap = allBackends
161162
.stream().collect(Collectors.toMap(ProxyBackendConfiguration::getProxyTo, ProxyBackendConfiguration::getName, (o, n) -> n));
162163
Map<Boolean, List<ProxyBackendConfiguration>> activeMap = allBackends.stream().collect(Collectors.groupingBy(ProxyBackendConfiguration::isActive));
164+
Map<Boolean, Integer> statusCounts = allBackends.stream()
165+
.map(backendStateManager::getBackendState)
166+
.collect(Collectors.partitioningBy(
167+
state -> state.trinoStatus() == TrinoStatus.HEALTHY,
168+
Collectors.collectingAndThen(Collectors.counting(), Long::intValue)));
163169
Integer latestHour = query.latestHour();
164170
Long ts = System.currentTimeMillis() - (latestHour * 60 * 60 * 1000);
165171
List<DistributionResponse.LineChart> lineChart = queryHistoryManager.findDistribution(ts);
@@ -179,6 +185,8 @@ public Response getDistribution(QueryDistributionRequest query)
179185
distributionResponse.setTotalBackendCount(allBackends.size());
180186
distributionResponse.setOfflineBackendCount(requireNonNullElse(activeMap.get(false), Collections.emptyList()).size());
181187
distributionResponse.setOnlineBackendCount(requireNonNullElse(activeMap.get(true), Collections.emptyList()).size());
188+
distributionResponse.setHealthyBackendCount(statusCounts.getOrDefault(true, 0));
189+
distributionResponse.setUnhealthyBackendCount(statusCounts.getOrDefault(false, 0));
182190
distributionResponse.setLineChart(lineChartMap);
183191
distributionResponse.setDistributionChart(distributionChart);
184192
distributionResponse.setTotalQueryCount(totalQueryCount);

webapp/src/components/dashboard.tsx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,14 @@ export function Dashboard() {
4949
key: Locale.Dashboard.BackendsOffline,
5050
value: distributionDetail?.offlineBackendCount
5151
},
52+
{
53+
key: Locale.Dashboard.BackendsHealthy,
54+
value: distributionDetail?.healthyBackendCount,
55+
},
56+
{
57+
key: Locale.Dashboard.BackendsUnhealthy,
58+
value: distributionDetail?.unhealthyBackendCount
59+
},
5260
{
5361
key: (
5462
<div className={styles.tip}>

webapp/src/locales/en_US.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ const en_US = {
1212
Backends: "Backends",
1313
BackendsOffline: "Backends offline",
1414
BackendsOnline: "Backends online",
15+
BackendsHealthy: "Backends healthy",
16+
BackendsUnhealthy: "Backends unhealthy",
1517
StartTime: "Started at",
1618
Summary: "Summary",
1719
QueryDistribution: "Query distribution in last hour",

webapp/src/types/dashboard.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ export interface DistributionDetail {
22
totalBackendCount: number;
33
offlineBackendCount: number;
44
onlineBackendCount: number;
5+
healthyBackendCount: number;
6+
unhealthyBackendCount: number;
57
totalQueryCount: number;
68
averageQueryCountMinute: number;
79
averageQueryCountSecond: number;

0 commit comments

Comments
 (0)