This repository has been archived by the owner on Nov 4, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* transpile code via babel-standalone * move vm.ts into vm/ * add TASK_TIMEOUT config * add babel transform to timeout while loops * update refactored rename * vm while timeout test * add more unimplemented timeout tests * add transforms for while/for/do-while loops * fix loop timeout ms * remove extra ; * fix import * fix more imports * fix even more imports * fix error messages * simplify errors * small refactor * fix import * add async guard and protect against long promises * async guard around setupPlugin() * add column * slightly safer variables * less noise in vm bench * can not override async guard for the main functions (e.g. processEvent, etc) * reduce how much we do in a benchmark * add types to loop timeout * types for promise timeout * fix line/column numbers * explain some decisions * verify that the process event timeout applies e2e. * managed to get equal, so changing * update message that it's just a warning * add e2e kafka test for bad delay * shorter test in github action * increase test timeout to see if that makes a difference (locally it takes 3min for both tests) * skip the "slow on GH action" test for now * process kafka events in parallel by default * add more metrics to kafka queue * some debug to help fix the test * add debug log in the delayUntilEventIngested function * add "single_event_batch" timing to the event processing steps * fix timer * Improve timeoutGuard default timeout * revert benchmark to the last one that worked * skip bad delay * add back a 1:1 copy of the e2e.kafka test, but with the timeout code. see if GH actions run * remove broken tests, improve logging of working tests * Clan up vm.ts * Improve clarity of loopTimeout * Refactor transforms slightly * Refactor transform call to secureCode func * Add secureCode tests Co-authored-by: Michael Matloka <dev@twixes.com>
- Loading branch information
1 parent
e91d131
commit b235de3
Showing
33 changed files
with
995 additions
and
183 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
import { performance } from 'perf_hooks' | ||
|
||
import { KAFKA_EVENTS_PLUGIN_INGESTION } from '../../src/ingestion/topics' | ||
import { startPluginsServer } from '../../src/server' | ||
import { ClickHouseEvent, LogLevel, PluginsServerConfig, Queue } from '../../src/types' | ||
import { PluginsServer } from '../../src/types' | ||
import { delay, UUIDT } from '../../src/utils' | ||
import { createPosthog, DummyPostHog } from '../../src/vm/extensions/posthog' | ||
import { makePiscina } from '../../src/worker/piscina' | ||
import { resetTestDatabaseClickhouse } from '../../tests/helpers/clickhouse' | ||
import { resetKafka } from '../../tests/helpers/kafka' | ||
import { pluginConfig39 } from '../../tests/helpers/plugins' | ||
import { resetTestDatabase } from '../../tests/helpers/sql' | ||
import { delayUntilEventIngested } from '../../tests/shared/process-event' | ||
|
||
jest.setTimeout(600000) // 10min timeout | ||
|
||
const extraServerConfig: Partial<PluginsServerConfig> = { | ||
KAFKA_ENABLED: true, | ||
KAFKA_HOSTS: process.env.KAFKA_HOSTS || 'kafka:9092', | ||
WORKER_CONCURRENCY: 4, | ||
TASK_TIMEOUT: 5, | ||
PLUGIN_SERVER_INGESTION: true, | ||
KAFKA_CONSUMPTION_TOPIC: KAFKA_EVENTS_PLUGIN_INGESTION, | ||
KAFKA_BATCH_PARALELL_PROCESSING: true, | ||
LOG_LEVEL: LogLevel.Log, | ||
} | ||
|
||
describe('e2e kafka processing timeout benchmark', () => { | ||
let queue: Queue | ||
let server: PluginsServer | ||
let stopServer: () => Promise<void> | ||
let posthog: DummyPostHog | ||
|
||
beforeEach(async () => { | ||
await resetTestDatabase(` | ||
async function processEvent (event) { | ||
await new Promise(resolve => __jestSetTimeout(() => resolve(), 15000 * Math.random())) | ||
event.properties.timeout = 'no timeout' | ||
return event | ||
} | ||
`) | ||
await resetKafka(extraServerConfig) | ||
await resetTestDatabaseClickhouse(extraServerConfig) | ||
|
||
const startResponse = await startPluginsServer(extraServerConfig, makePiscina) | ||
server = startResponse.server | ||
stopServer = startResponse.stop | ||
queue = startResponse.queue | ||
|
||
posthog = createPosthog(server, pluginConfig39) | ||
}) | ||
|
||
afterEach(async () => { | ||
await stopServer() | ||
}) | ||
|
||
test('measure performance', async () => { | ||
console.debug = () => null | ||
|
||
const count = 3000 | ||
|
||
// fill in the queue | ||
function createEvent() { | ||
const uuid = new UUIDT().toString() | ||
posthog.capture('custom event', { name: 'haha', uuid, randomProperty: 'lololo' }) | ||
} | ||
await queue.pause() | ||
for (let i = 0; i < count; i++) { | ||
createEvent() | ||
} | ||
|
||
// hope that 5sec is enough to load kafka with all the events (posthog.capture can't be awaited) | ||
await delay(5000) | ||
await queue.resume() | ||
|
||
console.log('Starting timer') | ||
const startTime = performance.now() | ||
await delayUntilEventIngested(() => server.db.fetchEvents(), count, 500, count) | ||
const timeMs = performance.now() - startTime | ||
console.log('Finished!') | ||
|
||
const n = (n: number) => `${Math.round(n * 100) / 100}` | ||
console.log( | ||
`ℹ️️ [Kafka & ClickHouse] Ingested ${count} events in ${n(timeMs / 1000)}s (${n( | ||
1000 / (timeMs / count) | ||
)} events/sec, ${n(timeMs / count)}ms per event)` | ||
) | ||
const events = (await server.db.fetchEvents()) as ClickHouseEvent[] | ||
const passedEvents = events.filter((e) => e.properties.timeout).length | ||
console.log( | ||
`ℹ️ Out of 3000 events: ${passedEvents} took under 5sec, ${ | ||
3000 - passedEvents | ||
} timed out. This should be a 1:2 ratio.` | ||
) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.