Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

thresholds reworked #213

Merged
merged 5 commits into from
Apr 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions src/server/controllers/item/shared/item-data-processing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ import {
calculateApdexValues,
updateItemApdexSettings,
chartOverviewStatusCodesQuery,
responseTimePerLabelHistogram, findRawData,
responseTimePerLabelHistogram, findRawData, getBaselineItemWithStats,
} from "../../../queries/items"
import { ReportStatus } from "../../../queries/items.model"
import { getScenarioSettings, currentScenarioMetrics } from "../../../queries/scenario"
import { getScenarioSettings } from "../../../queries/scenario"
import { sendNotifications } from "../../../utils/notifications/send-notification"
import { scenarioThresholdsCalc } from "../utils/scenario-thresholds-calc"
import { extraIntervalMilliseconds } from "./extra-intervals-mapping"
Expand Down Expand Up @@ -122,10 +122,13 @@ export const itemDataProcessing = async ({ projectName, scenarioName, itemId })
overview.maxVu = Math.max(...chartData.threads.map(([, vu]) => vu))

if (scenarioSettings.thresholdEnabled) {
const scenarioMetrics = await db.one(currentScenarioMetrics(projectName, scenarioName, overview.maxVu))
const thresholdResult = scenarioThresholdsCalc(overview, scenarioMetrics, scenarioSettings)
if (thresholdResult) {
await db.none(saveThresholdsResult(projectName, scenarioName, itemId, thresholdResult))
logger.info("threshold comparison enabled, fetching baseline report")
const baselineReport = await db.oneOrNone(getBaselineItemWithStats(projectName, scenarioName))
if (baselineReport) {
const thresholdResult = scenarioThresholdsCalc(labelStats, baselineReport.stats, scenarioSettings)
if (thresholdResult) {
await db.none(saveThresholdsResult(projectName, scenarioName, itemId, thresholdResult))
}
}
}

Expand Down
68 changes: 53 additions & 15 deletions src/server/controllers/item/update-item-controller.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,61 @@
import { Request, Response, NextFunction } from "express"
import { updateTestItemInfo, removeCurrentBaseFlag, setBaseFlag } from "../../queries/items"
import {
updateTestItemInfo,
removeCurrentBaseFlag,
setBaseFlag,
findItemStats, saveThresholdsResult, findItemsWithThresholds,
} from "../../queries/items"
import { db } from "../../../db/db"
import { StatusCode } from "../../utils/status-code"
import { scenarioThresholdsCalc } from "./utils/scenario-thresholds-calc"
import { getScenarioSettings } from "../../queries/scenario"
import { logger } from "../../../logger"


export const updateItemController = async (req: Request, res: Response, next: NextFunction) => {
const { projectName, scenarioName, itemId } = req.params
const { note, environment, hostname, base, name } = req.body
try {
await db.query("BEGIN")
await db.none(updateTestItemInfo(itemId, scenarioName, projectName, note, environment, hostname, name))
if (base) {
await db.none(removeCurrentBaseFlag(scenarioName, projectName))
await db.none(setBaseFlag(itemId, scenarioName, projectName))
const { projectName, scenarioName, itemId } = req.params
const { note, environment, hostname, base, name } = req.body
try {
await db.query("BEGIN")
await db.none(updateTestItemInfo(itemId, scenarioName, projectName, note, environment, hostname, name))
if (base) {
await db.none(removeCurrentBaseFlag(scenarioName, projectName))
await db.none(setBaseFlag(itemId, scenarioName, projectName))
const scenarioSettings = await db.one(getScenarioSettings(projectName, scenarioName))
if (scenarioSettings.thresholdEnabled) {
logger.info("Thresholds enabled, searching for any connected reports")
// items
const itemsWithThresholds = await db.manyOrNone(findItemsWithThresholds(projectName, scenarioName))

if (itemsWithThresholds && itemsWithThresholds.length > 0) {
logger.info("Items with thresholds that need to be updated found")
const { stats: newBaseLineReport } = await db.one(findItemStats(itemId))

// eslint-disable-next-line max-depth
for (const itemIdToBeRecalculated of itemsWithThresholds) {
logger.info(`About to re-calculate threshold for item: ${itemIdToBeRecalculated.id}`)

const { stats: statsToBeRecalculatedItem } = await db.one(
findItemStats(itemIdToBeRecalculated.id))

const updatedThreshold = scenarioThresholdsCalc(statsToBeRecalculatedItem,
newBaseLineReport, scenarioSettings)
// eslint-disable-next-line max-depth
if (updatedThreshold) {
// eslint-disable-next-line max-len
logger.info(`About to save re-calculated threshold values for item: ${itemIdToBeRecalculated.id}`)
await db.none(saveThresholdsResult(projectName, scenarioName,
itemIdToBeRecalculated.id, updatedThreshold))
}
}
}
}

}
await db.query("COMMIT")
res.status(StatusCode.NoContent).send()
} catch(error) {
await db.query("ROLLBACK")
return next(error)
}
await db.query("COMMIT")
res.status(StatusCode.NoContent).send()
} catch(error) {
await db.query("ROLLBACK")
return next(error)
}
}
Loading