MCPcopy
hub / github.com/OneUptime/oneuptime / getClickhouseTelemetryIngestion

Function getClickhouseTelemetryIngestion

App/API/AdminHealth.ts:2036–2144  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

2034 * Edition + master-admin gated at the route.
2035 */
2036async function getClickhouseTelemetryIngestion(): Promise<JSONObject> {
2037 const result: JSONObject = {
2038 connected: false,
2039 tables: [],
2040 };
2041
2042 try {
2043 const client: ReturnType<typeof ClickhouseAppInstance.getDataSource> =
2044 ClickhouseAppInstance.getDataSource();
2045
2046 if (!client) {
2047 return result;
2048 }
2049
2050 result["connected"] = true;
2051
2052 /*
2053 * Total ACTUAL (uncompressed) data volume per telemetry table, read from
2054 * system.parts metadata — this is the real data size, not the compressed
2055 * bytes_on_disk. It is a metadata aggregate (no data scan), so it stays cheap
2056 * regardless of table size. Guarded independently so a failure here never
2057 * drops the ingestion counts below.
2058 */
2059 const uncompressedBytesByTable: Map<string, number | null> = new Map();
2060 try {
2061 const databaseLiteral: string = ClickhouseDatabaseName.replace(
2062 /'/g,
2063 "''",
2064 );
2065 const tableListLiteral: string = TELEMETRY_INGESTION_TABLES.map(
2066 (spec: { table: AnalyticsTableName }): string => {
2067 return `'${String(spec.table).replace(/'/g, "''")}'`;
2068 },
2069 ).join(", ");
2070
2071 const sizesResult: ClickhouseJsonResult = (await (
2072 await client.query({
2073 query:
2074 "SELECT table, sum(data_uncompressed_bytes) AS uncompressed_bytes " +
2075 "FROM system.parts " +
2076 `WHERE active AND database = '${databaseLiteral}' AND table IN (${tableListLiteral}) ` +
2077 "GROUP BY table" +
2078 CH_DIAG_QUERY_SETTINGS,
2079 format: "JSON",
2080 })
2081 ).json()) as ClickhouseJsonResult;
2082
2083 for (const row of sizesResult.data || []) {
2084 uncompressedBytesByTable.set(
2085 String(row["table"]),
2086 toNumberOrNull(row["uncompressed_bytes"]),
2087 );
2088 }
2089 } catch (err) {
2090 logger.debug("AdminHealth: telemetry uncompressed-size query failed");
2091 logger.debug(err);
2092 }
2093

Callers 1

AdminHealth.tsFile · 0.85

Calls 10

toNumberOrNullFunction · 0.70
getDataSourceMethod · 0.45
replaceMethod · 0.45
mapMethod · 0.45
queryMethod · 0.45
setMethod · 0.45
debugMethod · 0.45
getMethod · 0.45
pushMethod · 0.45
errorMethod · 0.45

Tested by

no test coverage detected