Skip to content

Commit

Permalink
using db with timescale toolkit pre-installed, lttb module removed an…
Browse files Browse the repository at this point in the history
…d replaced by db function to avoid high memory usage
  • Loading branch information
ludeknovy committed Apr 17, 2024
1 parent c9f100d commit 1f26470
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 96 deletions.
3 changes: 3 additions & 0 deletions migrations/1713374194350_toolkit.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
exports.up = (pgm) => {
pgm.createExtension("timescaledb_toolkit")
}
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 novyl/jtl-reporter-db:latest
ENV POSTGRES_DB jtl_report
COPY schema.sql /docker-entrypoint-initdb.d/
COPY schema.sql /docker-entrypoint-initdb.d/
18 changes: 9 additions & 9 deletions src/server/controllers/item/shared/item-data-processing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +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");

Check failure on line 38 in src/server/controllers/item/shared/item-data-processing.ts

View workflow job for this annotation

GitHub Actions / build

'moment' is defined but never used
import { DataProcessingException } from "../../../errors/data-processing-exceptions"

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

Check warning on line 47 in src/server/controllers/item/shared/item-data-processing.ts

View check run for this annotation

Codecov / codecov/patch

src/server/controllers/item/shared/item-data-processing.ts#L47

Added line #L47 was not covered by tests

try {
const aggOverview = await db.one(aggOverviewQuery(itemId))
Expand All @@ -55,13 +54,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))

Check warning on line 57 in src/server/controllers/item/shared/item-data-processing.ts

View check run for this annotation

Codecov / codecov/patch

src/server/controllers/item/shared/item-data-processing.ts#L57

Added line #L57 was not covered by tests
rawDataArray = rawDownsampledData?.map(row => [row.timestamp, row.value])
rawDownsampledData = null

Check warning on line 59 in src/server/controllers/item/shared/item-data-processing.ts

View check run for this annotation

Codecov / codecov/patch

src/server/controllers/item/shared/item-data-processing.ts#L59

Added line #L59 was not covered by tests

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 +151,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 +168,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 = []

Check warning on line 172 in src/server/controllers/item/shared/item-data-processing.ts

View check run for this annotation

Codecov / codecov/patch

src/server/controllers/item/shared/item-data-processing.ts#L172

Added line #L172 was not covered by tests
}
}
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 1f26470

Please sign in to comment.