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

chore: add execution stats header to the ut response #3882

Closed
wants to merge 2 commits into from
Closed
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: 15 additions & 0 deletions src/middlewares/stats.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { Context, Next } from 'koa';

export class StatsMiddleware {
private static instanceID: string = process.env.INSTANCE_ID || 'default';

private static workerID: string = process.env.WORKER_ID || 'master';

public static async executionStats(ctx: Context, next: Next) {
const start = Date.now();
await next();
const ms = Date.now() - start;
ctx.set('X-Response-Time', `${ms}ms`);
ctx.set('X-Instance-ID', `${StatsMiddleware.instanceID}/${StatsMiddleware.workerID}`);
}
}
7 changes: 5 additions & 2 deletions src/routes/userTransform.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import Router from '@koa/router';
import { RouteActivationMiddleware } from '../middlewares/routeActivation';
import { FeatureFlagMiddleware } from '../middlewares/featureFlag';
import { Context } from 'koa';

Check failure on line 2 in src/routes/userTransform.ts

View workflow job for this annotation

GitHub Actions / Check for formatting & lint errors

'Context' is defined but never used

Check failure on line 2 in src/routes/userTransform.ts

View workflow job for this annotation

GitHub Actions / Code Coverage

'Context' is defined but never used
import { UserTransformController } from '../controllers/userTransform';
import { FeatureFlagMiddleware } from '../middlewares/featureFlag';
import { RouteActivationMiddleware } from '../middlewares/routeActivation';
import { StatsMiddleware } from '../middlewares/stats';

const router = new Router();

Expand All @@ -15,6 +17,7 @@
'/customTransform',
RouteActivationMiddleware.isUserTransformRouteActive,
FeatureFlagMiddleware.handle,
StatsMiddleware.executionStats,
UserTransformController.transform,
);
router.post(
Expand Down
6 changes: 5 additions & 1 deletion src/util/cluster.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
}

function start(port, app, metricsApp) {
console.log(numWorkers);

Check warning on line 31 in src/util/cluster.js

View workflow job for this annotation

GitHub Actions / Check for formatting & lint errors

Unexpected console statement

Check warning on line 31 in src/util/cluster.js

View workflow job for this annotation

GitHub Actions / Code Coverage

Unexpected console statement
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
console.log(numWorkers);


if (cluster.isMaster) {
logger.info(`Master (pid: ${process.pid}) has started`);

Expand All @@ -44,7 +46,9 @@

// Fork workers.
for (let i = 0; i < numWorkers; i += 1) {
cluster.fork();
cluster.fork({
WORKER_ID: `worker-${i + 1}`,
});
}

cluster.on('online', (worker) => {
Expand Down
Loading