Skip to content

Commit 396369c

Browse files
Allow custom metrics for the metrics monitor health check
* Update METRICS monitor to configure custom metrics for running and queued queries
1 parent 51c8461 commit 396369c

File tree

3 files changed

+49
-5
lines changed

3 files changed

+49
-5
lines changed

docs/installation.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,24 @@ It retrieves the number of running and queued queries for use with
394394
the `QueryCountBasedRouter` (either `METRICS` or `JDBC` must be enabled if
395395
`QueryCountBasedRouter` is used).
396396

397+
By default, it uses the `trino_execution_name_QueryManager_RunningQueries` and
398+
`trino_execution_name_QueryManager_QueuedQueries` to track the number of running
399+
and queued queries respectively, however these metrics can be configured as follows:
400+
401+
```yaml
402+
monitor:
403+
runningQueriesMetricName: io_starburst_galaxy_name_GalaxyMetrics_RunningQueries
404+
queuedQueriesMetricName: io_starburst_galaxy_name_GalaxyMetrics_QueuedQueries
405+
```
406+
407+
Similarly, by default the monitor pulls the metrics using the `/metrics` endpoint, but it
408+
can be updated to use another one:
409+
410+
```yaml
411+
monitor:
412+
metricsEndpoint: /v1/metrics
413+
```
414+
397415
This monitor allows customizing health definitions by comparing metrics to fixed
398416
values. This is configured through two maps: `metricMinimumValues` and
399417
`metricMaximumValues`. The keys of these maps are the metric names, and the values

gateway-ha/src/main/java/io/trino/gateway/ha/clustermonitor/ClusterStatsMetricsMonitor.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,15 +46,15 @@
4646
public class ClusterStatsMetricsMonitor
4747
implements ClusterStatsMonitor
4848
{
49-
public static final String RUNNING_QUERIES_METRIC = "trino_execution_name_QueryManager_RunningQueries";
50-
public static final String QUEUED_QUERIES_METRIC = "trino_execution_name_QueryManager_QueuedQueries";
5149
private static final Logger log = Logger.get(ClusterStatsMetricsMonitor.class);
5250

5351
private final HttpClient httpClient;
5452
private final int retries;
5553
private final MetricsResponseHandler metricsResponseHandler;
5654
private final Header identityHeader;
5755
private final String metricsEndpoint;
56+
private final String runningQueriesMetricName;
57+
private final String queuedQueriesMetricName;
5858
private final ImmutableSet<String> metricNames;
5959
private final Map<String, Float> metricMinimumValues;
6060
private final Map<String, Float> metricMaximumValues;
@@ -71,10 +71,12 @@ public ClusterStatsMetricsMonitor(HttpClient httpClient, BackendStateConfigurati
7171
identityHeader = new Header("X-Trino-User", backendStateConfiguration.getUsername());
7272
}
7373
metricsEndpoint = monitorConfiguration.getMetricsEndpoint();
74+
runningQueriesMetricName = monitorConfiguration.getRunningQueriesMetricName();
75+
queuedQueriesMetricName = monitorConfiguration.getQueuedQueriesMetricName();
7476
metricMinimumValues = ImmutableMap.copyOf(monitorConfiguration.getMetricMinimumValues());
7577
metricMaximumValues = ImmutableMap.copyOf(monitorConfiguration.getMetricMaximumValues());
7678
metricNames = ImmutableSet.<String>builder()
77-
.add(RUNNING_QUERIES_METRIC, QUEUED_QUERIES_METRIC)
79+
.add(runningQueriesMetricName, queuedQueriesMetricName)
7880
.addAll(metricMinimumValues.keySet())
7981
.addAll(metricMaximumValues.keySet())
8082
.build();
@@ -117,8 +119,8 @@ public ClusterStats monitor(ProxyBackendConfiguration backend)
117119
}
118120
return ClusterStats.builder(backend.getName())
119121
.trinoStatus(TrinoStatus.HEALTHY)
120-
.runningQueryCount((int) Float.parseFloat(metrics.get(RUNNING_QUERIES_METRIC)))
121-
.queuedQueryCount((int) Float.parseFloat(metrics.get(QUEUED_QUERIES_METRIC)))
122+
.runningQueryCount((int) Float.parseFloat(metrics.get(runningQueriesMetricName)))
123+
.queuedQueryCount((int) Float.parseFloat(metrics.get(queuedQueriesMetricName)))
122124
.proxyTo(backend.getProxyTo())
123125
.externalUrl(backend.getExternalUrl())
124126
.routingGroup(backend.getRoutingGroup())

gateway-ha/src/main/java/io/trino/gateway/ha/config/MonitorConfiguration.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ public class MonitorConfiguration
3333

3434
private String metricsEndpoint = "/metrics";
3535

36+
private String runningQueriesMetricName = "trino_execution_name_QueryManager_RunningQueries";
37+
38+
private String queuedQueriesMetricName = "trino_execution_name_QueryManager_QueuedQueries";
39+
3640
// Require 1 node for health by default. This configuration only applies to the ClusterStatsMetricsMonitor
3741
private Map<String, Float> metricMinimumValues = ImmutableMap.of("trino_metadata_name_DiscoveryNodeManager_ActiveNodeCount", 1f);
3842

@@ -90,6 +94,26 @@ public void setMetricsEndpoint(String metricsEndpoint)
9094
this.metricsEndpoint = metricsEndpoint;
9195
}
9296

97+
public String getRunningQueriesMetricName()
98+
{
99+
return runningQueriesMetricName;
100+
}
101+
102+
public void setRunningQueriesMetricName(String runningQueriesMetricName)
103+
{
104+
this.runningQueriesMetricName = runningQueriesMetricName;
105+
}
106+
107+
public String getQueuedQueriesMetricName()
108+
{
109+
return queuedQueriesMetricName;
110+
}
111+
112+
public void setQueuedQueriesMetricName(String queuedQueriesMetricName)
113+
{
114+
this.queuedQueriesMetricName = queuedQueriesMetricName;
115+
}
116+
93117
public Map<String, Float> getMetricMinimumValues()
94118
{
95119
return metricMinimumValues;

0 commit comments

Comments
 (0)