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

Add recordSize option to Webhooks #107

Merged
merged 1 commit into from
Sep 20, 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
4 changes: 2 additions & 2 deletions src/kafkaDataGenerator.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import alert from 'cli-alerts';
import cryptoRandomString from 'crypto-random-string';
import recordSize from './utils/recordSize.js';
import { KafkaProducer } from './kafka/producer.js';
import { generateMegaRecord } from './schemas/generateMegaRecord.js';
import { OutputFormat } from './formats/outputFormat.js';
Expand All @@ -22,7 +22,7 @@ export default async function kafkaDataGenerator({

let payload: string;
if (global.recordSize) {
payload = cryptoRandomString({ length: global.recordSize, type: 'base64' });
payload = await recordSize();
}

let producer: KafkaProducer | null = null;
Expand Down
15 changes: 15 additions & 0 deletions src/utils/recordSize.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import cryptoRandomString from 'crypto-random-string';

export default async function recordSize(): Promise<string> {
let payload: string;
if (global.recordSize) {
if (global.recordSize <= 0) {
global.recordSize = 1;
}
payload = cryptoRandomString({
length: global.recordSize,
type: 'base64'
});
}
return payload;
}
10 changes: 8 additions & 2 deletions src/webhookDataGenerator.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import alert from 'cli-alerts';
import crypto from 'crypto';
import * as pg from 'pg';
import { generateMegaRecord } from './schemas/generateMegaRecord.js';
import { OutputFormat } from './formats/outputFormat.js';
import sleep from './utils/sleep.js';
import recordSize from './utils/recordSize.js';
import asyncGenerator from './utils/asyncGenerator.js';
import webhookConfig from './webhook/webhookConfig.js';

Expand Down Expand Up @@ -38,6 +37,9 @@ export default async function webhookDataGenerator({
}

let payload: string;
if (global.recordSize) {
payload = await recordSize();
}

for await (const iteration of asyncGenerator(iterations)) {
global.iterationIndex = iteration;
Expand All @@ -56,6 +58,10 @@ export default async function webhookDataGenerator({
const handler = async (megaRecord: any, iteration: number) => {
for (const endpoint in megaRecord) {
for await (const record of megaRecord[endpoint].records) {
if (global.recordSize) {
record.recordSizePayload = payload;
}

if (global.dryRun) {
alert({
type: `success`,
Expand Down