Skip to content

Commit

Permalink
v5 (#320)
Browse files Browse the repository at this point in the history
  • Loading branch information
ludeknovy authored Sep 11, 2024
1 parent acafc92 commit f8e2e5c
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 97 deletions.
4 changes: 2 additions & 2 deletions src/db/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
FROM timescale/timescaledb:2.4.1-pg13
FROM timescale/timescaledb-ha:pg16.4-ts2.16.1-all
ENV POSTGRES_DB jtl_report
COPY schema.sql /docker-entrypoint-initdb.d/
COPY schema.sql /docker-entrypoint-initdb.d/
19 changes: 9 additions & 10 deletions src/server/controllers/item/shared/item-data-processing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,17 @@ import {
updateItemApdexSettings,
chartOverviewStatusCodesQuery,
responseTimePerLabelHistogram,
findRawData,
getBaselineItemWithStats,
findGroupedErrors,
findTop5ErrorsByLabel,
threadsPerThreadGroup,
threadsPerThreadGroup, getDownsampledRawData,
} from "../../../queries/items"
import { ReportStatus } from "../../../queries/items.model"
import { getScenarioSettings } from "../../../queries/scenario"
import { sendDegradationNotifications, sendReportNotifications } from "../../../utils/notifications/send-notification"
import { scenarioThresholdsCalc } from "../utils/scenario-thresholds-calc"
import { extraIntervalMilliseconds } from "./extra-intervals-mapping"
import { AnalyticsEvent } from "../../../utils/analytics/anyltics-event"
import { downsampleData } from "../../../utils/lttb"
import moment = require("moment");
import { DataProcessingException } from "../../../errors/data-processing-exceptions"

export const itemDataProcessing = async ({ projectName, scenarioName, itemId }) => {
Expand All @@ -46,6 +43,7 @@ export const itemDataProcessing = async ({ projectName, scenarioName, itemId })
let distributedThreads = null
let sutMetrics = []
let apdex = []
let rawDataArray = null

try {
const aggOverview = await db.one(aggOverviewQuery(itemId))
Expand All @@ -55,13 +53,12 @@ export const itemDataProcessing = async ({ projectName, scenarioName, itemId })
const responseFailures = await db.manyOrNone(responseMessageFailures(itemId))
const scenarioSettings = await db.one(getScenarioSettings(projectName, scenarioName))

let rawData = await db.manyOrNone(findRawData(itemId))
let rawDataArray = rawData?.map(row => [moment(row.timestamp).valueOf(), row.elapsed])
const rawDataDownSampled = downsampleData(rawDataArray, MAX_SCATTER_CHART_POINTS)
let rawDownsampledData = await db.manyOrNone(getDownsampledRawData(itemId, MAX_SCATTER_CHART_POINTS))
rawDataArray = rawDownsampledData?.map(row => [row.timestamp, row.value])
rawDownsampledData = null

const groupedErrors = await db.manyOrNone(findGroupedErrors(itemId))
const top5ErrorsByLabel = await db.manyOrNone(findTop5ErrorsByLabel(itemId))
rawData = null
rawDataArray = null

if (aggOverview.number_of_sut_hostnames > 1) {
sutMetrics = await db.many(sutOverviewQuery(itemId))
Expand Down Expand Up @@ -153,7 +150,7 @@ export const itemDataProcessing = async ({ projectName, scenarioName, itemId })
await t.none(saveItemStats(itemId, JSON.stringify(labelStats),
overview, JSON.stringify(sutOverview), JSON.stringify(errors)))
await t.none(savePlotData(itemId, JSON.stringify(chartData), JSON.stringify(extraChartData),
JSON.stringify(responseTimeHistogram), JSON.stringify(rawDataDownSampled)))
JSON.stringify(responseTimeHistogram), JSON.stringify(rawDataArray)))
await t.none(updateItem(itemId, ReportStatus.Ready, overview.startDate))
})

Expand All @@ -170,5 +167,7 @@ export const itemDataProcessing = async ({ projectName, scenarioName, itemId })
} catch(error) {
throw new DataProcessingException(
`Error while processing dataId: ${itemId} for item: ${itemId}, error: ${error}`)
} finally {
rawDataArray = []
}
}
10 changes: 6 additions & 4 deletions src/server/queries/items.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,13 @@ export const findItemStats = (testItem) => {
}
}

export const findRawData = (itemId) => {
export const getDownsampledRawData = (itemId: string, threshold: number) => {
return {
text: `SELECT timestamp, elapsed
FROM jtl.samples WHERE item_id = $1`,
values: [itemId],
text: `SELECT (EXTRACT(epoch FROM time) * 1000)::bigint as timestamp, value
FROM unnest((
SELECT lttb(timestamp, elapsed, $2)
FROM jtl.samples WHERE item_id = $1));`,
values: [itemId, threshold],
}
}

Expand Down
81 changes: 0 additions & 81 deletions src/server/utils/lttb.ts

This file was deleted.

0 comments on commit f8e2e5c

Please sign in to comment.