|
1 | 1 | import type { NextApiRequest, NextApiResponse } from "next"; |
2 | | -import { getLog, namedParameters, SqlQueryParameters, unrollParams } from "juava"; |
| 2 | +import { namedParameters, SqlQueryParameters, unrollParams } from "juava"; |
3 | 3 | import { withErrorHandler } from "../../../lib/error-handler"; |
4 | 4 | import { auth } from "../../../lib/auth"; |
5 | 5 | import { clickhouse, pg } from "../../../lib/services"; |
@@ -39,28 +39,6 @@ function isoDateTOClickhouse(date: ISODate): string { |
39 | 39 | return date.replace("T", " ").replace("Z", "").split(".")[0]; |
40 | 40 | } |
41 | 41 |
|
42 | | -async function getPostgresPart({ granularity, start, end, workspaceId }: ReportParams): Promise<WorkspaceReportRow[]> { |
43 | | - const sql = `select |
44 | | - obj."workspaceId" as "workspaceId", |
45 | | - date_trunc(:granularity, (m.timestamp::TIMESTAMPTZ)) as period, |
46 | | - sum(m.value) as events |
47 | | - from newjitsuee.bulker_metrics m |
48 | | - left join newjitsu."ConfigurationObjectLink" obj |
49 | | - on obj."id" = m."destinationId" |
50 | | - where m.metric_name = 'bulkerapp_ingest_messages' and m.status = 'success' and m.timestamp <= '2023-07-28T00:00:00Z' and ${ |
51 | | - workspaceId ? 'obj."workspaceId" = :workspaceId and' : "" |
52 | | - } date_trunc(:granularity, "timestamp") >= date_trunc(:granularity, :start::timestamp) and |
53 | | - date_trunc(:granularity, "timestamp") <= date_trunc(:granularity, :end::timestamp) |
54 | | - group by period, "workspaceId" |
55 | | - order by period, "workspaceId" desc;; |
56 | | - `; |
57 | | - const params = removeUndefined({ start, end, granularity, workspaceId }); |
58 | | - const { query, values } = namedParameters(sql, params); |
59 | | - return await pg.query({ text: query, values }).then(res => { |
60 | | - return res.rows; |
61 | | - }); |
62 | | -} |
63 | | - |
64 | 42 | async function getClickhousePart({ |
65 | 43 | granularity, |
66 | 44 | start, |
@@ -136,11 +114,7 @@ export async function buildWorkspaceReport( |
136 | 114 | granularity: "day", |
137 | 115 | workspaceId: string | undefined |
138 | 116 | ): Promise<WorkspaceReportRow[]> { |
139 | | - const [pgRes, chRes] = await Promise.all([ |
140 | | - getPostgresPart({ start, end, granularity, workspaceId }), |
141 | | - getClickhousePart({ start, end, granularity, workspaceId }), |
142 | | - ]); |
143 | | - return [...pgRes.map(s => ({ ...s, src: "pg" })), ...chRes.map(s => ({ ...s, src: "ch" }))]; |
| 117 | + return (await getClickhousePart({ start, end, granularity, workspaceId })).map(s => ({ ...s, src: "ch" })); |
144 | 118 | } |
145 | 119 |
|
146 | 120 | async function extend(reportResult: WorkspaceReportRow[]): Promise<ExtendedWorkspaceReportRow[]> { |
|
0 commit comments