Skip to content

Commit

Permalink
ref(async-inserts): Add system queries (#5998)
Browse files Browse the repository at this point in the history
  • Loading branch information
MeredithAnya authored Jun 4, 2024
1 parent 12b6455 commit 448f010
Showing 1 changed file with 89 additions and 0 deletions.
89 changes: 89 additions & 0 deletions snuba/admin/clickhouse/predefined_system_queries.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,3 +132,92 @@ class ColumnSizeOnDisk(SystemQuery):
column
ORDER BY size DESC;
"""


class PartCreations(SystemQuery):
"""
New parts created in the last 10 minutes. Replicas have event_type 'DownloadPart',
therefore we'll only see the new parts on the node that got the insert
"""

sql = """
SELECT
hostName() AS node_name,
event_time,
part_name,
rows,
size_in_bytes AS bytes_on_disk,
partition_id,
part_type
FROM
system.part_log
WHERE
database = 'default'
AND table = '{{table}}'
AND event_time > now() - toIntervalMinute(10)
and event_type = 'NewPart'
"""


class AsyncInsertPendingFlushes(SystemQuery):
"""
Current number of aysnc insert queries that are waiting to be flushed
"""

# Insert is a keyword that isn't allowed, hence using 'like'
sql = """
SELECT
value as queries
FROM system.metrics
WHERE metric like 'PendingAsyncInser%'
"""


class AsyncInsertFlushes(SystemQuery):
"""
Async insert queries (flushes) that happened in the last 10 minutes,
with a successful status
"""

sql = """
SELECT
table,
query,
format,
query_id,
bytes,
flush_time,
flush_query_id
FROM
system.asynchronous_insert_log
WHERE
status = 'Ok'
AND database = 'default'
AND flush_time > now() - toIntervalMinute(10)
ORDER BY table, flush_time
"""


class AsyncInsertFlushErrors(SystemQuery):
"""
Async insert queries that failed within the last 10 minutes
"""

sql = """
SELECT
max(event_time) AS flush,
status,
exception,
any(query_id) AS query_id
FROM
system.asynchronous_insert_log
WHERE
database = 'default'
AND status <> 'Ok'
AND table = '{{table}}'
AND flush_time > now() - toIntervalMinute(10)
GROUP BY status, exception
ORDER BY
flush DESC
"""

0 comments on commit 448f010

Please sign in to comment.