Skip to content

Commit

Permalink
Merge branch 'master' into snyk-upgrade-65739b77637fa00b9a0b7e7a6ffcc4c1
Browse files Browse the repository at this point in the history
  • Loading branch information
ludeknovy authored Dec 12, 2024
2 parents 5a2f9b5 + 6a1fed6 commit 934e1ba
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 24 deletions.
37 changes: 21 additions & 16 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@
"license": "ISC",
"dependencies": {
"@breejs/ts-worker": "^2.0.0",
"axios": "^1.7.5",
"axios": "^1.7.8",
"bcrypt": "^5.1.1",
"body-parser": "^1.20.3",
"boom": "^7.2.0",
"bree": "^9.2.4",
"compression": "^1.7.4",
"dotenv": "^16.4.5",
"express": "^4.21.0",
"express": "^4.21.2",
"express-winston": "^4.2.0",
"fast-csv": "^4.3.6",
"helmet": "^6.2.0",
Expand Down
30 changes: 28 additions & 2 deletions src/logger.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,32 @@
import * as winston from "winston"

const LOG_LEVELS = winston.config.syslog.levels
const DEFAULT_LOG_LEVEL = "debug"

const getLogLevel = (): string => {
const logLevelEnvVar = process.env.LOG_LEVEL
if (logLevelEnvVar) {
const isAllowedLogLevel = Object.keys(LOG_LEVELS)
.find(level => logLevelEnvVar.toLowerCase() === level.toLowerCase())
if (!isAllowedLogLevel) {
console.log("Unsupported log level: ", logLevelEnvVar)
} else {
return isAllowedLogLevel
}
}
return DEFAULT_LOG_LEVEL


}

export const logger = winston.createLogger({
levels: winston.config.syslog.levels,
transports: [ new winston.transports.Console() ],
format: winston.format.combine(
winston.format.timestamp({ format: "YYYY-MM-DD HH:mm:ss" }),
winston.format.json()
),
level: getLogLevel(),
levels: LOG_LEVELS,
transports: [new winston.transports.Console()],
})


18 changes: 17 additions & 1 deletion src/server/controllers/item/shared/item-data-processing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,29 +46,40 @@ export const itemDataProcessing = async ({ projectName, scenarioName, itemId })
let rawDataArray = null

try {
logger.debug("Loading overview aggregation")
const aggOverview = await db.one(aggOverviewQuery(itemId))
logger.debug("Loading label aggregation")
const aggLabel = await db.many(aggLabelQuery(itemId))
logger.debug("Loading status code distribution")
const statusCodeDistribution = await db.manyOrNone(responseCodeDistribution(itemId))
logger.debug("Loading response time per label distribution")
const responseTimePerLabelDistribution = await db.manyOrNone(responseTimePerLabelHistogram(itemId))
logger.debug("Loading response failures")
const responseFailures = await db.manyOrNone(responseMessageFailures(itemId))
logger.debug("Loading scenario settings")
const scenarioSettings = await db.one(getScenarioSettings(projectName, scenarioName))

logger.debug("Loading raw downsampled data")
let rawDownsampledData = await db.manyOrNone(getDownsampledRawData(itemId, MAX_SCATTER_CHART_POINTS))
rawDataArray = rawDownsampledData?.map(row => [row.timestamp, row.value])
rawDownsampledData = null

logger.debug("Loading grouped errors")
const groupedErrors = await db.manyOrNone(findGroupedErrors(itemId))
logger.debug("Loading top 5 errors by label")
const top5ErrorsByLabel = await db.manyOrNone(findTop5ErrorsByLabel(itemId))

if (aggOverview.number_of_sut_hostnames > 1) {
logger.debug("Loading SUT overview")
sutMetrics = await db.many(sutOverviewQuery(itemId))
}

if (scenarioSettings.apdexSettings.enabled) {
const { satisfyingThreshold, toleratingThreshold } = scenarioSettings.apdexSettings
logger.debug("Calculating apdex")
apdex = await db.many(calculateApdexValues(itemId,
satisfyingThreshold,
toleratingThreshold))
logger.debug("Updating apdex settings")
await db.none(updateItemApdexSettings(itemId, {
satisfyingThreshold,
toleratingThreshold,
Expand All @@ -92,13 +103,18 @@ export const itemDataProcessing = async ({ projectName, scenarioName, itemId })

// distributed mode
if (aggOverview?.number_of_hostnames > 1) {
logger.debug("Loading distributed threads")
distributedThreads = await db.manyOrNone(distributedThreadsQuery(interval, itemId))
}


logger.debug("Loading label chart")
const labelChart = await db.many(charLabelQuery(interval, itemId))
logger.debug("Loading overview chart")
const overviewChart = await db.many(chartOverviewQuery(interval, itemId))
logger.debug("Loading status code chart")
const statusCodeChart = await db.many(chartOverviewStatusCodesQuery(interval, itemId))
logger.debug("Loading threads per group")
const threadsPerGroup = await db.manyOrNone(threadsPerThreadGroup(interval, itemId))
if (parseInt(index, 10) === 0) { // default interval
chartData = prepareChartDataForSaving(
Expand Down
6 changes: 3 additions & 3 deletions src/server/middleware/authorization-middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ import { isUserAuthorizedForProject } from "../queries/user-project-access"
export const authorizationMiddleware = (allowedRoles: AllowedRoles[]) => {
return async (request, response, next) => {
const user = request.user
logger.info(`User ${user.userId} with role ${user.role} accessing a resource with allowed roles: ${allowedRoles}`)
logger.debug(`User ${user.userId} with role ${user.role} accessing a resource with allowed roles: ${allowedRoles}`)
// check project authorization
const { projectName } = request.params
if (projectName && user?.userId && user?.role !== AllowedRoles.Admin) {
logger.info(`User ${user.userId} with role ${user.role} accessing a resource within ${projectName} project`)
logger.debug(`User ${user.userId} with role ${user.role} accessing a resource within ${projectName} project`)
const userAuthorizedForProject = await db.oneOrNone(isUserAuthorizedForProject(projectName, user.userId))
if (!userAuthorizedForProject && user.role) {
logger.info(`User ${user.userId} has no access to project ${projectName}`)
logger.debug(`User ${user.userId} has no access to project ${projectName}`)
return next(boom.forbidden(`You dont have permission to access`))
}
// user is authorized, we can proceed
Expand Down

0 comments on commit 934e1ba

Please sign in to comment.