add filter to queries to make use of index
@@ -219,13 +219,23 @@ class ActiveJobClusterGauge:
def __init__(self, name):
self._gauge = Gauge(name, "A gauge of current ammount of active jobs per cluster",
['state', 'cluster'])
- self._request_per_cluster = "SELECT cluster_name, count(id) filter(WHERE state = 'running'), " \
- "count(id) filter(WHERE state = 'queued'),count(id) filter(WHERE state = 'scheduled') " \
- "FROM job GROUP BY cluster_name"
+ self._request_per_cluster = """
+ SELECT cluster_name,
+ count(id) filter(WHERE state = 'running'),
+ count(id) filter(WHERE state = 'queued'),
+ count(id) filter(WHERE state = 'scheduled')
+ FROM job
+ WHERE state in ('running', 'queued', 'scheduled')
+ GROUP BY cluster_name
+ """
- self._request_total = "SELECT count(id) filter(WHERE state = 'running'), " \
- "count(id) filter(WHERE state = 'queued'), " \
- "count(id) filter(WHERE state = 'scheduled') FROM job"
+ self._request_total = """
+ SELECT count(id) filter(WHERE state = 'running'),
+ count(id) filter(WHERE state = 'queued'),
+ count(id) filter(WHERE state = 'scheduled')
+ WHERE state in ('running', 'queued', 'scheduled')
+ FROM job
+ """
def update(self, conn):
per_cluster = execute_sql(conn, self._request_per_cluster, None)
