Skip to content

Commit

Permalink
New latency query, update time filter
Browse files Browse the repository at this point in the history
  • Loading branch information
insmac committed Dec 4, 2024
1 parent ea281ba commit 3d3d44d
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 30 deletions.
6 changes: 3 additions & 3 deletions packages/web-console/src/scenes/Editor/Metrics/queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
SampleBy,
minutesToDays,
minutesToHours,
mappedSampleBy,
defaultSampleByForDuration,
durationInMinutes,
} from "./utils"

Expand All @@ -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) => `
Expand Down Expand Up @@ -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]}
`
}

Expand Down
7 changes: 3 additions & 4 deletions packages/web-console/src/scenes/Editor/Metrics/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export const durationInMinutes: Record<MetricDuration, number> = {
[MetricDuration.SEVEN_DAYS]: 60 * 168,
}

export const mappedSampleBy: Record<MetricDuration, SampleBy> = {
export const defaultSampleByForDuration: Record<MetricDuration, SampleBy> = {
[MetricDuration.ONE_HOUR]: SampleBy.ONE_SECOND,
[MetricDuration.THREE_HOURS]: SampleBy.ONE_SECOND,
[MetricDuration.SIX_HOURS]: SampleBy.ONE_SECOND,
Expand Down Expand Up @@ -83,9 +83,8 @@ export type RowsApplied = {
}

export type Latency = {
time: string
numOfWalApplies: string
avg_latency: string
created: string
latency: string
}

export type LastNotNull = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
30 changes: 15 additions & 15 deletions packages/web-console/src/scenes/Editor/Metrics/widgets/latency.ts
Original file line number Diff line number Diff line change
@@ -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"

Expand All @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
@@ -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"

Expand Down Expand Up @@ -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)
)
Expand Down
Original file line number Diff line number Diff line change
@@ -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"

Expand All @@ -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
Expand Down

0 comments on commit 3d3d44d

Please sign in to comment.