Skip to content

Commit

Permalink
fix: tests fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
aashishmalik committed Mar 20, 2024
1 parent 30eb066 commit d10e813
Show file tree
Hide file tree
Showing 12 changed files with 76 additions and 69 deletions.
18 changes: 9 additions & 9 deletions src/controllers/bulkUpload.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* eslint-disable global-require, import/no-dynamic-require, @typescript-eslint/no-unused-vars */
import customLogger from "@rudderstack/integrations-lib/build/structured-logger";
import logger from "@rudderstack/integrations-lib/build/structured-logger";
import { client as errNotificationClient } from '../util/errorNotifier';
import { CatchErr, ContextBodySimple } from '../util/types';
// TODO: To be refactored and redisgned
Expand Down Expand Up @@ -31,7 +31,7 @@ const getReqMetadata = (ctx) => {
};

export const fileUpload = async (ctx) => {
customLogger.debug(
logger.debug(
'Native(Bulk-Upload): Request to transformer:: /fileUpload route',
JSON.stringify(ctx.request.body),
);
Expand Down Expand Up @@ -69,15 +69,15 @@ export const fileUpload = async (ctx) => {
});
}
ctx.body = response;
customLogger.debug(
logger.debug(
'Native(Bulk-Upload): Response from transformer:: /fileUpload route',
JSON.stringify(ctx.body),
);
return ctx.body;
};

export const pollStatus = async (ctx) => {
customLogger.debug(
logger.debug(
'Native(Bulk-Upload): Request to transformer:: /pollStatus route',
JSON.stringify(ctx.request.body),
);
Expand All @@ -104,15 +104,15 @@ export const pollStatus = async (ctx) => {
});
}
ctx.body = response;
customLogger.debug(
logger.debug(
'Native(Bulk-Upload): Request from transformer:: /pollStatus route',
JSON.stringify(ctx.body),
);
return ctx.body;
};

export const getWarnJobStatus = async (ctx) => {
customLogger.debug(
logger.debug(
'Native(Bulk-Upload): Request to transformer:: /getWarningJobs route',
JSON.stringify(ctx.request.body),
);
Expand Down Expand Up @@ -140,15 +140,15 @@ export const getWarnJobStatus = async (ctx) => {
});
}
ctx.body = response;
customLogger.debug(
logger.debug(
'Native(Bulk-Upload): Request from transformer:: /getWarningJobs route',
JSON.stringify(ctx.body),
);
return ctx.body;
};

export const getFailedJobStatus = async (ctx) => {
customLogger.debug(
logger.debug(
'Native(Bulk-Upload): Request to transformer:: /getFailedJobs route',
JSON.stringify(ctx.request.body),
);
Expand Down Expand Up @@ -176,7 +176,7 @@ export const getFailedJobStatus = async (ctx) => {
});
}
ctx.body = response;
customLogger.debug(
logger.debug(
'Native(Bulk-Upload): Request from transformer:: /getFailedJobs route',
JSON.stringify(ctx.body),
);
Expand Down
14 changes: 7 additions & 7 deletions src/controllers/delivery.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint-disable prefer-destructuring */
/* eslint-disable sonarjs/no-duplicate-string */
import { Context } from 'koa';
import customLogger from "@rudderstack/integrations-lib/build/structured-logger";
import logger from "@rudderstack/integrations-lib/build/structured-logger";
import { MiscService } from '../services/misc';
import {
DeliveriesResponse,
Expand All @@ -21,7 +21,7 @@ const NON_DETERMINABLE = 'Non-determinable';

export class DeliveryController {
public static async deliverToDestination(ctx: Context) {
customLogger.debug('Native(Delivery):: Request to transformer::', JSON.stringify(ctx.request.body));
logger.debug('Native(Delivery):: Request to transformer::', JSON.stringify(ctx.request.body));
let deliveryResponse: DeliveryResponse;
const requestMetadata = MiscService.getRequestMetadata(ctx);
const deliveryRequest = ctx.request.body as ProxyDeliveryRequest;
Expand Down Expand Up @@ -51,12 +51,12 @@ export class DeliveryController {
ctx.body = { output: deliveryResponse };
ControllerUtility.deliveryPostProcess(ctx, deliveryResponse.status);

customLogger.debug('Native(Delivery):: Response from transformer::', JSON.stringify(ctx.body));
logger.debug('Native(Delivery):: Response from transformer::', JSON.stringify(ctx.body));
return ctx;
}

public static async deliverToDestinationV1(ctx: Context) {
customLogger.debug('Native(Delivery):: Request to transformer::', JSON.stringify(ctx.request.body));
logger.debug('Native(Delivery):: Request to transformer::', JSON.stringify(ctx.request.body));
let deliveryResponse: DeliveriesResponse;
const requestMetadata = MiscService.getRequestMetadata(ctx);
const deliveryRequest = ctx.request.body as ProxyDeliveriesRequest;
Expand Down Expand Up @@ -86,12 +86,12 @@ export class DeliveryController {
ctx.body = { output: deliveryResponse };
ControllerUtility.deliveryPostProcess(ctx, deliveryResponse.status);

customLogger.debug('Native(Delivery):: Response from transformer::', JSON.stringify(ctx.body));
logger.debug('Native(Delivery):: Response from transformer::', JSON.stringify(ctx.body));
return ctx;
}

public static async testDestinationDelivery(ctx: Context) {
customLogger.debug(
logger.debug(
'Native(Delivery-Test):: Request to transformer::',
JSON.stringify(ctx.request.body),
);
Expand All @@ -112,7 +112,7 @@ export class DeliveryController {
);
ctx.body = { output: response };
ControllerUtility.postProcess(ctx);
customLogger.debug('Native(Delivery-Test):: Response from transformer::', JSON.stringify(ctx.body));
logger.debug('Native(Delivery-Test):: Response from transformer::', JSON.stringify(ctx.body));
return ctx;
}
}
16 changes: 8 additions & 8 deletions src/controllers/destination.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Context } from 'koa';
import customLogger from "@rudderstack/integrations-lib/build/structured-logger";
import logger from "@rudderstack/integrations-lib/build/structured-logger";
import { MiscService } from '../services/misc';
import { DestinationPreTransformationService } from '../services/destination/preTransformation';
import { DestinationPostTransformationService } from '../services/destination/postTransformation';
Expand All @@ -19,7 +19,7 @@ import { DynamicConfigParser } from '../util/dynamicConfigParser';
export class DestinationController {
public static async destinationTransformAtProcessor(ctx: Context) {
const startTime = new Date();
customLogger.debug(
logger.info(
'Native(Process-Transform):: Requst to transformer::',
JSON.stringify(ctx.request.body),
);
Expand Down Expand Up @@ -68,7 +68,7 @@ export class DestinationController {
}
ctx.body = resplist;
ControllerUtility.postProcess(ctx);
customLogger.debug(
logger.info(
'Native(Process-Transform):: Response from transformer::',
JSON.stringify(ctx.body),
);
Expand All @@ -93,9 +93,9 @@ export class DestinationController {

public static async destinationTransformAtRouter(ctx: Context) {
const startTime = new Date();
customLogger.debug(
logger.info(
'Native(Router-Transform):: Requst to transformer::',
JSON.stringify(ctx.request.body),
ctx.request.body,
);
const requestMetadata = MiscService.getRequestMetadata(ctx);
const routerRequest = ctx.request.body as RouterTransformationRequest;
Expand Down Expand Up @@ -140,7 +140,7 @@ export class DestinationController {
version: 'v0',
...metaTags,
});
customLogger.debug(
logger.info(
'Native(Router-Transform):: Response from transformer::',
JSON.stringify(ctx.body),
);
Expand All @@ -154,7 +154,7 @@ export class DestinationController {
}

public static batchProcess(ctx: Context) {
customLogger.debug(
logger.info(
'Native(Process-Transform-Batch):: Requst to transformer::',
JSON.stringify(ctx.request.body),
);
Expand Down Expand Up @@ -189,7 +189,7 @@ export class DestinationController {
ctx.body = [errResp];
}
ControllerUtility.postProcess(ctx);
customLogger.debug(
logger.info(
'Native(Process-Transform-Batch):: Response from transformer::',
JSON.stringify(ctx.body),
);
Expand Down
6 changes: 3 additions & 3 deletions src/controllers/regulation.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Context } from 'koa';
import customLogger from "@rudderstack/integrations-lib/build/structured-logger";
import logger from "@rudderstack/integrations-lib/build/structured-logger";
import { UserDeletionRequest, UserDeletionResponse } from '../types';
import { ServiceSelector } from '../helpers/serviceSelector';
import tags from '../v0/util/tags';
Expand All @@ -10,7 +10,7 @@ import { CatchErr } from '../util/types';

export class RegulationController {
public static async deleteUsers(ctx: Context) {
customLogger.debug(
logger.debug(
'Native(Process-Transform):: Requst to transformer::',
JSON.stringify(ctx.request.body),
);
Expand All @@ -23,7 +23,7 @@ export class RegulationController {
rudderDestInfo = destInfoHeader;
}
} catch (error) {
customLogger.error(`Error while getting rudderDestInfo header value: ${error}`);
logger.error(`Error while getting rudderDestInfo header value: ${error}`);
}

const userDeletionRequests = ctx.request.body as UserDeletionRequest[];
Expand Down
6 changes: 3 additions & 3 deletions src/controllers/source.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { Context } from 'koa';
import customLogger from "@rudderstack/integrations-lib/build/structured-logger";
import logger from "@rudderstack/integrations-lib/build/structured-logger";
import { MiscService } from '../services/misc';
import { ServiceSelector } from '../helpers/serviceSelector';
import { ControllerUtility } from './util';
import { SourcePostTransformationService } from '../services/source/postTransformation';

export class SourceController {
public static async sourceTransform(ctx: Context) {
customLogger.debug(
logger.debug(
'Native(Source-Transform):: Request to transformer::',
JSON.stringify(ctx.request.body),
);
Expand All @@ -34,7 +34,7 @@ export class SourceController {
ctx.body = [resp];
}
ControllerUtility.postProcess(ctx);
customLogger.debug(
logger.debug(
'Native(Source-Transform):: Response from transformer::',
JSON.stringify(ctx.body),
);
Expand Down
16 changes: 8 additions & 8 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import Koa from 'koa';
import bodyParser from 'koa-bodyparser';
import gracefulShutdown from 'http-graceful-shutdown';
import dotenv from 'dotenv';
import customLogger from "@rudderstack/integrations-lib/build/structured-logger";
import logger from "@rudderstack/integrations-lib/build/structured-logger";
import cluster from './util/cluster';
import { metricsRouter } from './routes/metricsRouter';
import { addStatMiddleware, addRequestSizeMiddleware, initPyroscope } from './middleware';
Expand Down Expand Up @@ -32,13 +32,13 @@ app.use(
addRequestSizeMiddleware(app);
addSwaggerRoutes(app);

customLogger.info('Using new routes');
logger.info('Using new routes');
applicationRoutes(app);

function finalFunction() {
RedisDB.disconnect();
customLogger.info('Redis client disconnected');
customLogger.error(`Process (pid: ${process.pid}) was gracefully shutdown`);
logger.info('Redis client disconnected');
logger.error(`Process (pid: ${process.pid}) was gracefully shutdown`);
logProcessInfo();
}

Expand All @@ -59,15 +59,15 @@ if (clusterEnabled) {
const server = app.listen(port);

process.on('SIGTERM', () => {
customLogger.error(`SIGTERM signal received`);
logger.error(`SIGTERM signal received`);
});

process.on('SIGINT', () => {
customLogger.error(`SIGINT signal received`);
logger.error(`SIGINT signal received`);
});

process.on('SIGSEGV', () => {
customLogger.error(`SIGSEGV - JavaScript memory error occurred`);
logger.error(`SIGSEGV - JavaScript memory error occurred`);
});

gracefulShutdown(server, {
Expand All @@ -77,7 +77,7 @@ if (clusterEnabled) {
finally: finalFunction,
});

customLogger.info(`App started. Listening on port: ${port}`);
logger.info(`App started. Listening on port: ${port}`);
}

export default app;
19 changes: 16 additions & 3 deletions src/services/misc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@
import fs from 'fs';
import path from 'path';
import { Context } from 'koa';
import customLogger from '@rudderstack/integrations-lib';
import { LoggableExtraData } from '@rudderstack/integrations-lib';
import logger from "@rudderstack/integrations-lib/build/structured-logger";
import { DestHandlerMap } from '../constants/destinationCanonicalNames';
import { ErrorDetailer, LoggableExtraData, Metadata } from '../types';
import { ErrorDetailer, Metadata } from '../types';
import { getCPUProfile, getHeapProfile } from '../middleware';

export class MiscService {
Expand Down Expand Up @@ -85,11 +86,23 @@ export class MiscService {
...(errorDetailer?.destType && { destType: errorDetailer.destType }),
module: errorDetailer.module,
implementation: errorDetailer.implementation,
feature: errorDetailer.feature,
};
}

public static logError(errorMessage: string, errorDetailer: ErrorDetailer) {
const loggableExtraData: Partial<LoggableExtraData> = this.getLoggableData(errorDetailer);
customLogger.errorw(errorMessage || '', loggableExtraData);
logger.errorw(errorMessage || '', loggableExtraData);
}

public static logInfo(message: string, loggingDetails: ErrorDetailer) {
const loggableExtraData: Partial<LoggableExtraData> = this.getLoggableData(loggingDetails);
logger.infow(message || '', loggableExtraData);
}

public static logDebug(errorMessage: string, errorDetailer: ErrorDetailer) {
const loggableExtraData: Partial<LoggableExtraData> = this.getLoggableData(errorDetailer);
logger.debugw(errorMessage || '', loggableExtraData);
}

}
Loading

0 comments on commit d10e813

Please sign in to comment.