-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Added `antelope_token_api` prefix - More descriptive names and description for all metrics - Added configurable large queries counter monitoring
- Loading branch information
Showing
6 changed files
with
54 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,40 @@ | ||
import * as crypto from 'node:crypto' | ||
import client from "./client.js"; | ||
|
||
import { logger } from "../logger.js"; | ||
import * as prometheus from "../prometheus.js"; | ||
|
||
import type { ResponseJSON } from "@clickhouse/client-web"; | ||
import type { ValidQueryParams } from "../types/api.js"; | ||
import { config } from "../config.js"; | ||
|
||
export async function makeQuery<T = unknown>(query: string, query_params: ValidQueryParams) { | ||
logger.trace({ query, query_params }); | ||
const query_id = crypto.randomUUID(); | ||
logger.trace({ query_id, query, query_params }); | ||
|
||
const response = await client.query({ query, query_params, format: "JSON" }); | ||
const response = await client.query({ query, query_params, format: "JSON", query_id }); | ||
const data: ResponseJSON<T> = await response.json(); | ||
prometheus.queries.inc(); | ||
|
||
prometheus.query.inc(); | ||
if ( data.statistics ) { | ||
if (response.query_id !== query_id) throw new Error(`Wrong query ID for query: sent ${query_id} / received ${response.query_id}`); | ||
|
||
if (data.statistics) { | ||
prometheus.bytes_read.observe(data.statistics.bytes_read); | ||
prometheus.rows_read.observe(data.statistics.rows_read); | ||
prometheus.elapsed.observe(data.statistics.elapsed); | ||
prometheus.elapsed_seconds.observe(data.statistics.elapsed); | ||
|
||
if (data.statistics.rows_read > config.maxRowsTrigger || data.statistics.bytes_read > config.maxBytesTrigger) | ||
prometheus.large_queries.inc({ | ||
query_id, | ||
query, | ||
query_params: JSON.stringify(query_params), | ||
bytes_read: data.statistics.bytes_read, | ||
rows_read: data.statistics.rows_read, | ||
elapsed_seconds: data.statistics.elapsed | ||
}); | ||
} | ||
|
||
logger.trace({ statistics: data.statistics, rows: data.rows, rows_before_limit_at_least: data.rows_before_limit_at_least }); | ||
logger.trace({ query_id: response.query_id, statistics: data.statistics, rows: data.rows, rows_before_limit_at_least: data.rows_before_limit_at_least }); | ||
|
||
return data; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters