diff --git a/packages/web-console/src/scenes/Editor/Metrics/queries.ts b/packages/web-console/src/scenes/Editor/Metrics/queries.ts index c29350ffa..09fff6d55 100644 --- a/packages/web-console/src/scenes/Editor/Metrics/queries.ts +++ b/packages/web-console/src/scenes/Editor/Metrics/queries.ts @@ -4,7 +4,7 @@ import { SampleBy, minutesToDays, minutesToHours, - mappedSampleBy, + defaultSampleByForDuration, durationInMinutes, } from "./utils" @@ -29,7 +29,7 @@ and created > date_trunc('minute', dateadd('${minutes >= 1440 ? "d" : "h"}', -${ minutes >= 1440 ? minutesToDays(minutes) : minutesToHours(minutes) }, now())) and created < date_trunc('minute', now()) -sample by ${sampleBy ?? mappedSampleBy[metricDuration]}` +sample by ${sampleBy ?? defaultSampleByForDuration[metricDuration]}` } export const rowsAppliedLastNotNull = (id: number) => ` @@ -61,7 +61,7 @@ and created > date_trunc('minute', dateadd('${minutes >= 1440 ? "d" : "h"}', -${ minutes >= 1440 ? minutesToDays(minutes) : minutesToHours(minutes) }, now())) and created < date_trunc('minute', now()) -sample by ${sampleBy ?? mappedSampleBy[metricDuration]} +sample by ${sampleBy ?? defaultSampleByForDuration[metricDuration]} ` } diff --git a/packages/web-console/src/scenes/Editor/Metrics/utils.ts b/packages/web-console/src/scenes/Editor/Metrics/utils.ts index 14e919c95..d18739cb2 100644 --- a/packages/web-console/src/scenes/Editor/Metrics/utils.ts +++ b/packages/web-console/src/scenes/Editor/Metrics/utils.ts @@ -53,7 +53,7 @@ export const durationInMinutes: Record = { [MetricDuration.SEVEN_DAYS]: 60 * 168, } -export const mappedSampleBy: Record = { +export const defaultSampleByForDuration: Record = { [MetricDuration.ONE_HOUR]: SampleBy.ONE_SECOND, [MetricDuration.THREE_HOURS]: SampleBy.ONE_SECOND, [MetricDuration.SIX_HOURS]: SampleBy.ONE_SECOND, @@ -83,9 +83,8 @@ export type RowsApplied = { } export type Latency = { - time: string - numOfWalApplies: string - avg_latency: string + created: string + latency: string } export type LastNotNull = { diff --git a/packages/web-console/src/scenes/Editor/Metrics/widgets/commitRate.ts b/packages/web-console/src/scenes/Editor/Metrics/widgets/commitRate.ts index 1604cfd78..d93d80b3d 100644 --- a/packages/web-console/src/scenes/Editor/Metrics/widgets/commitRate.ts +++ b/packages/web-console/src/scenes/Editor/Metrics/widgets/commitRate.ts @@ -31,7 +31,7 @@ export const commitRate: Widget = { from ${TelemetryTable.WAL} where ${tableId ? `tableId = ${tableId} and ` : ""} event = 103 - ${getTimeFilter(minutes)} + and ${getTimeFilter(minutes)} -- it is important this is 1s, should this value change -- the "commit_rate" value will have to be adjusted to rate/s sample by 1s diff --git a/packages/web-console/src/scenes/Editor/Metrics/widgets/latency.ts b/packages/web-console/src/scenes/Editor/Metrics/widgets/latency.ts index d721fae02..8c079ce91 100644 --- a/packages/web-console/src/scenes/Editor/Metrics/widgets/latency.ts +++ b/packages/web-console/src/scenes/Editor/Metrics/widgets/latency.ts @@ -1,6 +1,6 @@ import uPlot from "uplot" import { Latency, sqlValueToFixed } from "../utils" -import { Widget, mappedSampleBy, durationInMinutes } from "../utils" +import { Widget, defaultSampleByForDuration, durationInMinutes } from "../utils" import { getTimeFilter } from "./utils" import { TelemetryTable } from "../../../../consts" @@ -11,29 +11,29 @@ export const latency: Widget = { getQuery: ({ tableId, metricDuration, sampleBy }) => { const minutes = durationInMinutes[metricDuration] return ` -select - created time, - count(latency) / 2 numOfWalApplies, - avg(latency) * 2 avg_latency -from ${TelemetryTable.WAL} -where ${tableId ? `tableId = ${tableId} and ` : ""} -(event = 105 or event = 103) -${getTimeFilter(minutes)} -sample by ${sampleBy ?? mappedSampleBy[metricDuration]} -` +select created, approx_percentile(latency, 0.9, 3) latency + from + (select * from ${TelemetryTable.WAL} where ${getTimeFilter(minutes)}) + where + event = 105 -- event is fixed + and rowCount > 0 -- this is fixed clause, we have rows with - rowCount logged + ${tableId ? `and tableId = ${tableId}` : ""} + sample by ${sampleBy ?? defaultSampleByForDuration[metricDuration]} + fill(0) + ` }, getQueryLastNotNull: (tableId) => ` select created from ${TelemetryTable.WAL} where ${tableId ? `tableId = ${tableId} and ` : ""} -(event = 105 or event = 103) -and latency != null +event = 105 +and latency != null and rowCount > 0 limit -1 `, alignData: (latency: Latency[]): uPlot.AlignedData => [ - latency.map((l) => new Date(l.time).getTime()), - latency.map((l) => sqlValueToFixed(l.avg_latency)), + latency.map((l) => new Date(l.created).getTime()), + latency.map((l) => sqlValueToFixed(l.latency)), ], mapYValue: (rawValue: number) => { if (rawValue >= 1000) { diff --git a/packages/web-console/src/scenes/Editor/Metrics/widgets/utils.ts b/packages/web-console/src/scenes/Editor/Metrics/widgets/utils.ts index dd98319b4..0829f0b11 100644 --- a/packages/web-console/src/scenes/Editor/Metrics/widgets/utils.ts +++ b/packages/web-console/src/scenes/Editor/Metrics/widgets/utils.ts @@ -23,7 +23,7 @@ export const minutesToSeconds = (durationInMinutes: number) => export const getTimeFilter = ( minutes: number, -) => `and created > date_trunc('minute', dateadd('${ +) => `created > date_trunc('minute', dateadd('${ minutes >= 1440 ? "d" : "h" }', -${ minutes >= 1440 ? minutesToDays(minutes) : minutesToHours(minutes) diff --git a/packages/web-console/src/scenes/Editor/Metrics/widgets/writeAmplification.ts b/packages/web-console/src/scenes/Editor/Metrics/widgets/writeAmplification.ts index 11163b5c8..cfe05d153 100644 --- a/packages/web-console/src/scenes/Editor/Metrics/widgets/writeAmplification.ts +++ b/packages/web-console/src/scenes/Editor/Metrics/widgets/writeAmplification.ts @@ -1,6 +1,6 @@ import uPlot from "uplot" import { sqlValueToFixed, formatNumbers, WriteAmplification } from "../utils" -import { Widget, mappedSampleBy, durationInMinutes } from "../utils" +import { Widget, defaultSampleByForDuration, durationInMinutes } from "../utils" import { TelemetryTable } from "../../../../consts" import { getTimeFilter } from "./utils" @@ -29,8 +29,8 @@ from ( where ${tableId ? `tableId = ${tableId} and ` : ""} event = 105 and rowCount > 0 -- this is fixed clause, we have rows with - rowCount logged - ${getTimeFilter(minutes)} - sample by ${sampleBy ?? mappedSampleBy[metricDuration]} + and ${getTimeFilter(minutes)} + sample by ${sampleBy ?? defaultSampleByForDuration[metricDuration]} -- fill with null to avoid spurious values and division by 0 fill(null,null) ) diff --git a/packages/web-console/src/scenes/Editor/Metrics/widgets/writeThroughput.ts b/packages/web-console/src/scenes/Editor/Metrics/widgets/writeThroughput.ts index 9d20a8d9c..161b99513 100644 --- a/packages/web-console/src/scenes/Editor/Metrics/widgets/writeThroughput.ts +++ b/packages/web-console/src/scenes/Editor/Metrics/widgets/writeThroughput.ts @@ -1,6 +1,6 @@ import uPlot from "uplot" import { RowsApplied, sqlValueToFixed, formatNumbers } from "../utils" -import { Widget, mappedSampleBy, durationInMinutes } from "../utils" +import { Widget, defaultSampleByForDuration, durationInMinutes } from "../utils" import { TelemetryTable } from "../../../../consts" import { getTimeFilter } from "./utils" @@ -21,8 +21,8 @@ select from ${TelemetryTable.WAL} where ${tableId ? `tableId = ${tableId} and ` : ""} event = 105 -${getTimeFilter(minutes)} -sample by ${sampleBy ?? mappedSampleBy[metricDuration]}` +and ${getTimeFilter(minutes)} +sample by ${sampleBy ?? defaultSampleByForDuration[metricDuration]}` }, getQueryLastNotNull: (tableId) => ` select