Skip to content

Commit

Permalink
Merge branch 'chore.update-workflow-engine' of github.com:rudderlabs/…
Browse files Browse the repository at this point in the history
…rudder-transformer into chore.update-workflow-engine
  • Loading branch information
koladilip committed Sep 14, 2023
2 parents 0309abb + ed4ff50 commit 363678b
Show file tree
Hide file tree
Showing 22 changed files with 142 additions and 139 deletions.
18 changes: 18 additions & 0 deletions src/controllers/misc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,22 @@ export default class MiscController {
ctx.status = 200;
return ctx;
}

public static async getCPUProfile(ctx: Context) {
const { seconds } = ctx.query;
let secondsData = 10;
// if seconds is not null and is not array then parseInt
if (seconds && !Array.isArray(seconds)) {
secondsData = parseInt(seconds, 10);
}
ctx.body = await MiscService.getCPUProfile(secondsData);
ctx.status = 200;
return ctx;
}

public static async getHeapProfile(ctx: Context) {
ctx.body = await MiscService.getHeapProfile();
ctx.status = 200;
return ctx;
}
}
7 changes: 4 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,19 @@ import cluster from './util/cluster';
import { router } from './legacy/router';
import { testRouter } from './testRouter';
import { metricsRouter } from './routes/metricsRouter';
import { addStatMiddleware, addRequestSizeMiddleware, addPyroscopeMiddleware } from './middleware';
import { addStatMiddleware, addRequestSizeMiddleware, initPyroscope } from './middleware';
import { logProcessInfo } from './util/utils';
import { applicationRoutes, addSwaggerRoutes } from './routes';
import { RedisDB } from './util/redis/redisConnector';

dotenv.config();
const clusterEnabled = process.env.CLUSTER_ENABLED !== 'false';
const useUpdatedRoutes = process.env.ENABLE_NEW_ROUTES !== 'false';
const port = parseInt(process.env.PORT || '9090', 10);
const port = parseInt(process.env.PORT ?? '9090', 10);
const metricsPort = parseInt(process.env.METRICS_PORT || '9091', 10);

initPyroscope();

const app = new Koa();
addStatMiddleware(app);

Expand All @@ -30,7 +32,6 @@ app.use(
jsonLimit: '200mb',
}),
);
addPyroscopeMiddleware(app);
addRequestSizeMiddleware(app);
addSwaggerRoutes(app);

Expand Down
51 changes: 12 additions & 39 deletions src/middleware.js
Original file line number Diff line number Diff line change
@@ -1,48 +1,19 @@
const Pyroscope = require('@pyroscope/nodejs');
const stats = require('./util/stats');
const logger = require('./logger');

Pyroscope.init({
appName: 'rudder-transformer',
});

async function handlerCpu(ctx) {
try {
const p = await Pyroscope.collectCpu(Number(ctx.query.seconds));
ctx.body = p;
ctx.status = 200;
} catch (e) {
logger.error(e);
ctx.status = 500;
}
}

async function handlerHeap(ctx) {
try {
const p = await Pyroscope.collectHeap();
ctx.body = p;
ctx.status = 200;
} catch (e) {
logger.error(e);
ctx.status = 500;
}
function initPyroscope() {
Pyroscope.init({
appName: 'rudder-transformer',
});
Pyroscope.startHeapCollecting();
}

function pyroscopeMiddleware() {
Pyroscope.startHeapCollecting();
return (ctx, next) => {
if (ctx.method === 'GET' && ctx.path === '/debug/pprof/profile') {
return handlerCpu(ctx).then(() => next());
}
if (ctx.method === 'GET' && ctx.path === '/debug/pprof/heap') {
return handlerHeap(ctx).then(() => next());
}
return next();
};
function getCPUProfile(seconds) {
return Pyroscope.collectCpu(seconds);
}

function addPyroscopeMiddleware(app) {
app.use(pyroscopeMiddleware());
function getHeapProfile() {
return Pyroscope.collectHeap();
}

function durationMiddleware() {
Expand Down Expand Up @@ -90,5 +61,7 @@ function addRequestSizeMiddleware(app) {
module.exports = {
addStatMiddleware,
addRequestSizeMiddleware,
addPyroscopeMiddleware,
getHeapProfile,
getCPUProfile,
initPyroscope,
};
2 changes: 2 additions & 0 deletions src/routes/misc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,7 @@ router.get('/transformerBuildVersion', MiscController.buildVersion); // depricia
router.get('/buildVersion', MiscController.buildVersion);
router.get('/version', MiscController.version);
router.get('/features', MiscController.features);
router.get('/debug/pprof/profile', MiscController.getCPUProfile);
router.get('/debug/pprof/heap', MiscController.getHeapProfile);

export const miscRoutes = router.routes();
11 changes: 10 additions & 1 deletion src/services/misc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import path from 'path';
import { Context } from 'koa';
import { DestHandlerMap } from '../constants/destinationCanonicalNames';
import { Metadata } from '../types';
import { getCPUProfile, getHeapProfile, } from '../middleware';

export default class MiscService {
public static getDestHandler(dest: string, version: string) {
Expand Down Expand Up @@ -32,7 +33,7 @@ export default class MiscService {

public static getMetaTags(metadata: Metadata) {
if (!metadata) {
return {}
return {};
}
return {
sourceType: metadata.sourceType,
Expand Down Expand Up @@ -62,4 +63,12 @@ export default class MiscService {
const obj = JSON.parse(fs.readFileSync(path.resolve(__dirname, '../features.json'), 'utf8'));
return JSON.stringify(obj);
}

public static async getCPUProfile(seconds: number) {
return getCPUProfile(seconds);
}

public static async getHeapProfile() {
return getHeapProfile()
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const { getMappingConfig } = require('../../util');

const BASE_ENDPOINT = 'https://googleads.googleapis.com/v13/customers';
const BASE_ENDPOINT = 'https://googleads.googleapis.com/v14/customers';

const CONFIG_CATEGORIES = {
TRACK_CONFIG: { type: 'track', name: 'trackConfig' },
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const { getMappingConfig } = require('../../util');

const API_VERSION = 'v13';
const API_VERSION = 'v14';

const BASE_ENDPOINT = `https://googleads.googleapis.com/${API_VERSION}/customers/:customerId`;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ describe('getExisitingUserIdentifier util tests', () => {
describe('getClickConversionPayloadAndEndpoint util tests', () => {
it('getClickConversionPayloadAndEndpoint flow check when default field identifier is present', () => {
let expectedOutput = {
endpoint: 'https://googleads.googleapis.com/v13/customers/9625812972:uploadClickConversions',
endpoint: 'https://googleads.googleapis.com/v14/customers/9625812972:uploadClickConversions',
payload: {
conversions: [
{
Expand All @@ -187,7 +187,7 @@ describe('getClickConversionPayloadAndEndpoint util tests', () => {
delete fittingPayload.traits.email;
delete fittingPayload.properties.email;
let expectedOutput = {
endpoint: 'https://googleads.googleapis.com/v13/customers/9625812972:uploadClickConversions',
endpoint: 'https://googleads.googleapis.com/v14/customers/9625812972:uploadClickConversions',
payload: {
conversions: [
{
Expand Down Expand Up @@ -215,7 +215,7 @@ describe('getClickConversionPayloadAndEndpoint util tests', () => {
delete fittingPayload.traits.phone;
delete fittingPayload.properties.email;
let expectedOutput = {
endpoint: 'https://googleads.googleapis.com/v13/customers/9625812972:uploadClickConversions',
endpoint: 'https://googleads.googleapis.com/v14/customers/9625812972:uploadClickConversions',
payload: {
conversions: [
{
Expand Down Expand Up @@ -251,7 +251,7 @@ describe('getClickConversionPayloadAndEndpoint util tests', () => {
},
];
let expectedOutput = {
endpoint: 'https://googleads.googleapis.com/v13/customers/9625812972:uploadClickConversions',
endpoint: 'https://googleads.googleapis.com/v14/customers/9625812972:uploadClickConversions',
payload: {
conversions: [
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const { getMappingConfig } = require('../../util');

const BASE_ENDPOINT = 'https://googleads.googleapis.com/v13/customers';
const BASE_ENDPOINT = 'https://googleads.googleapis.com/v14/customers';
const CONFIG_CATEGORIES = {
AUDIENCE_LIST: { type: 'audienceList', name: 'offlineDataJobs' },
ADDRESSINFO: { type: 'addressInfo', name: 'addressInfo' },
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
{
"https://googleads.googleapis.com/v13/customers/11122233331/offlineUserDataJobs:create": {
"https://googleads.googleapis.com/v14/customers/11122233331/offlineUserDataJobs:create": {
"data": {
"resourceName": "customers/111-222-3333/offlineUserDataJobs/OFFLINE_USER_DATA_JOB_ID_FOR_ADD_FAILURE"
},
"status": 200
},
"https://googleads.googleapis.com/v13/customers/1112223333/offlineUserDataJobs:create": {
"https://googleads.googleapis.com/v14/customers/1112223333/offlineUserDataJobs:create": {
"data": {
"resourceName": "customers/111-222-3333/offlineUserDataJobs/OFFLINE_USER_DATA_JOB_ID"
},
"status": 200
},
"https://googleads.googleapis.com/v13/customers/customerid/offlineUserDataJobs:create": {
"https://googleads.googleapis.com/v14/customers/customerid/offlineUserDataJobs:create": {
"status": 401,
"data": {
"error": {
Expand All @@ -21,11 +21,11 @@
}
}
},
"https://googleads.googleapis.com/v13/customers/1112223333/offlineUserDataJobs/OFFLINE_USER_DATA_JOB_ID:addOperations": {
"https://googleads.googleapis.com/v14/customers/1112223333/offlineUserDataJobs/OFFLINE_USER_DATA_JOB_ID:addOperations": {
"status": 200,
"data": {}
},
"https://googleads.googleapis.com/v13/customers/11122233331/offlineUserDataJobs/OFFLINE_USER_DATA_JOB_ID_FOR_ADD_FAILURE:addOperations": {
"https://googleads.googleapis.com/v14/customers/11122233331/offlineUserDataJobs/OFFLINE_USER_DATA_JOB_ID_FOR_ADD_FAILURE:addOperations": {
"status": 400,
"data": {
"error": {
Expand All @@ -34,7 +34,7 @@
"status": "INVALID_ARGUMENT",
"details": [
{
"@type": "type.googleapis.com/google.ads.googleads.v13.errors.GoogleAdsFailure",
"@type": "type.googleapis.com/google.ads.googleads.v14.errors.GoogleAdsFailure",
"errors": [
{
"errorCode": {
Expand Down Expand Up @@ -67,13 +67,13 @@
}
}
},
"https://googleads.googleapis.com/v13/customers/1112223333/offlineUserDataJobs/OFFLINE_USER_DATA_JOB_ID:run": {
"https://googleads.googleapis.com/v14/customers/1112223333/offlineUserDataJobs/OFFLINE_USER_DATA_JOB_ID:run": {
"status": 200,
"data": {
"name": "customers/111-222-3333/operations/abcd="
}
},
"https://googleads.googleapis.com/v13/customers/customerid/offlineUserDataJobs/OFFLINE_USER_DATA_JOB_ID_ADD_FAILURE:addOperations": {
"https://googleads.googleapis.com/v14/customers/customerid/offlineUserDataJobs/OFFLINE_USER_DATA_JOB_ID_ADD_FAILURE:addOperations": {
"status": 400,
"data": {
"error": {
Expand All @@ -82,7 +82,7 @@
"status": "INVALID_ARGUMENT",
"details": [
{
"@type": "type.googleapis.com/google.ads.googleads.v13.errors.GoogleAdsFailure",
"@type": "type.googleapis.com/google.ads.googleads.v14.errors.GoogleAdsFailure",
"errors": [
{
"errorCode": {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
{
"https://googleads.googleapis.com/v13/customers/7693729833/offlineUserDataJobs:create": {
"https://googleads.googleapis.com/v14/customers/7693729833/offlineUserDataJobs:create": {
"status": 200,
"data": {
"resourceName": "customers/9249589672/offlineUserDataJobs/18025019461"
}
},
"https://googleads.googleapis.com/v13/customers/7693729833/offlineUserDataJobs/18025019461:addOperations": {
"https://googleads.googleapis.com/v14/customers/7693729833/offlineUserDataJobs/18025019461:addOperations": {
"status": 200
},
"https://googleads.googleapis.com/v13/customers/7693729833/offlineUserDataJobs/18025019461:run": {
"https://googleads.googleapis.com/v14/customers/7693729833/offlineUserDataJobs/18025019461:run": {
"status": 200
},
"https://googleads.googleapis.com/v13/customers/7693729834/offlineUserDataJobs:create": {
"https://googleads.googleapis.com/v14/customers/7693729834/offlineUserDataJobs:create": {
"status": 200,
"data": {
"resourceName": "customers/9249589672/offlineUserDataJobs/18025019462"
}
},
"https://googleads.googleapis.com/v13/customers/7693729834/offlineUserDataJobs/18025019462:addOperations": {
"https://googleads.googleapis.com/v14/customers/7693729834/offlineUserDataJobs/18025019462:addOperations": {
"response": {
"data": {
"error": {
Expand Down Expand Up @@ -60,7 +60,7 @@
"status": 400
}
},
"https://googleads.googleapis.com/v13/customers/1234567890/googleAds:searchStream": {
"https://googleads.googleapis.com/v14/customers/1234567890/googleAds:searchStream": {
"response": {
"data": [
{
Expand All @@ -74,11 +74,11 @@
"status": 401
}
},
"https://googleads.googleapis.com/v13/customers/1234567899/googleAds:searchStream": {
"https://googleads.googleapis.com/v14/customers/1234567899/googleAds:searchStream": {
"response": "",
"code": "ECONNREFUSED"
},
"https://googleads.googleapis.com/v13/customers/1234567891/googleAds:searchStream": {
"https://googleads.googleapis.com/v14/customers/1234567891/googleAds:searchStream": {
"data": [
{
"results": [
Expand All @@ -95,7 +95,7 @@
],
"status": 200
},
"https://googleads.googleapis.com/v13/customers/1234567891:uploadConversionAdjustments": {
"https://googleads.googleapis.com/v14/customers/1234567891:uploadConversionAdjustments": {
"data": [
{
"adjustmentType": "ENHANCEMENT",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"version": "1",
"type": "REST",
"method": "POST",
"endpoint": "https://googleads.googleapis.com/v13/customers/1234567890:uploadConversionAdjustments",
"endpoint": "https://googleads.googleapis.com/v14/customers/1234567890:uploadConversionAdjustments",
"headers": {
"Authorization": "Bearer abcd1234",
"Content-Type": "application/json",
Expand Down Expand Up @@ -91,7 +91,7 @@
"version": "1",
"type": "REST",
"method": "POST",
"endpoint": "https://googleads.googleapis.com/v13/customers/1234567890:uploadConversionAdjustments",
"endpoint": "https://googleads.googleapis.com/v14/customers/1234567890:uploadConversionAdjustments",
"headers": {
"Authorization": "Bearer abcd1234",
"Content-Type": "application/json",
Expand Down Expand Up @@ -204,7 +204,7 @@
"version": "1",
"type": "REST",
"method": "POST",
"endpoint": "https://googleads.googleapis.com/v13/customers/1234567890:uploadConversionAdjustments",
"endpoint": "https://googleads.googleapis.com/v14/customers/1234567890:uploadConversionAdjustments",
"headers": {
"Authorization": "Bearer abcd1234",
"Content-Type": "application/json",
Expand Down Expand Up @@ -260,7 +260,7 @@
"version": "1",
"type": "REST",
"method": "POST",
"endpoint": "https://googleads.googleapis.com/v13/customers/1234567890:uploadConversionAdjustments",
"endpoint": "https://googleads.googleapis.com/v14/customers/1234567890:uploadConversionAdjustments",
"headers": {
"Authorization": "Bearer abcd1234",
"Content-Type": "application/json",
Expand Down
Loading

0 comments on commit 363678b

Please sign in to comment.