From b1b9a0bec52c3ee327a4f944dd94867bb919dfda Mon Sep 17 00:00:00 2001 From: shahzad31 Date: Tue, 18 Jul 2023 12:19:01 +0200 Subject: [PATCH 1/4] update files --- .gitignore | 2 ++ src/push/index.ts | 9 +++++---- src/push/monitor.ts | 17 ++++++++++------- 3 files changed, 17 insertions(+), 11 deletions(-) diff --git a/.gitignore b/.gitignore index d83fc53d..69fb1f20 100644 --- a/.gitignore +++ b/.gitignore @@ -121,3 +121,5 @@ __tests__/e2e/junit.xml seccomp/build test-projects/ + +.DS_Store diff --git a/src/push/index.ts b/src/push/index.ts index 92344963..f4eeab58 100644 --- a/src/push/index.ts +++ b/src/push/index.ts @@ -73,8 +73,12 @@ export async function push(monitors: Monitor[], options: PushOptions) { return await pushLegacy(monitors, options); } - const local = getLocalMonitors(monitors); const { monitors: remote } = await bulkGetMonitors(options); + + progress(`bundling ${monitors.length} monitors`); + const schemas = await buildMonitorSchema(monitors, true); + const local = getLocalMonitors(schemas); + const { newIDs, changedIDs, removedIDs, unchangedIDs } = diffMonitorHashIDs( local, remote @@ -83,9 +87,6 @@ export async function push(monitors: Monitor[], options: PushOptions) { const updatedMonitors = new Set([...changedIDs, ...newIDs]); if (updatedMonitors.size > 0) { - const toBundle = monitors.filter(m => updatedMonitors.has(m.config.id)); - progress(`bundling ${toBundle.length} monitors`); - const schemas = await buildMonitorSchema(toBundle, true); const chunks = getChunks(schemas, CHUNK_SIZE); for (const chunk of chunks) { await liveProgress( diff --git a/src/push/monitor.ts b/src/push/monitor.ts index cd186544..02e95f90 100644 --- a/src/push/monitor.ts +++ b/src/push/monitor.ts @@ -110,12 +110,12 @@ export function diffMonitors( return result; } -export function getLocalMonitors(monitors: Monitor[]) { +export function getLocalMonitors(monitorSchemas: MonitorSchema[]) { const data: MonitorHashID[] = []; - for (const monitor of monitors) { + for (const monitor of monitorSchemas) { data.push({ - journey_id: monitor.config.id, - hash: monitor.hash(), + journey_id: monitor.id, + hash: monitor.hash, }); } return data; @@ -137,14 +137,17 @@ export async function buildMonitorSchema(monitors: Monitor[], isV2: boolean) { ...config, locations: translateLocation(config.locations), }; - if (isV2) { - schema.hash = monitor.hash(); - } + if (type === 'browser') { const outPath = join(bundlePath, config.name + '.zip'); const content = await bundler.build(source.file, outPath); + monitor.content = content; Object.assign(schema, { content, filter }); } + if (isV2) { + schema.hash = monitor.hash(); + console.log(schema.hash); + } schemas.push(schema); } From 8642d9019471359526a38be8a3389519a27fe51f Mon Sep 17 00:00:00 2001 From: shahzad31 Date: Tue, 18 Jul 2023 12:23:19 +0200 Subject: [PATCH 2/4] remove console --- src/push/monitor.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/push/monitor.ts b/src/push/monitor.ts index 02e95f90..6aec3198 100644 --- a/src/push/monitor.ts +++ b/src/push/monitor.ts @@ -146,7 +146,6 @@ export async function buildMonitorSchema(monitors: Monitor[], isV2: boolean) { } if (isV2) { schema.hash = monitor.hash(); - console.log(schema.hash); } schemas.push(schema); } From 5e921c78f96eba9a85b5a12a1564281974d762b3 Mon Sep 17 00:00:00 2001 From: shahzad31 Date: Tue, 18 Jul 2023 12:31:37 +0200 Subject: [PATCH 3/4] update test --- __tests__/push/monitor.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/__tests__/push/monitor.test.ts b/__tests__/push/monitor.test.ts index 25a86bfb..6cb684e2 100644 --- a/__tests__/push/monitor.test.ts +++ b/__tests__/push/monitor.test.ts @@ -105,7 +105,7 @@ describe('Monitors', () => { }); monitor.setContent('foo'); const schema1 = await buildMonitorSchema([monitor], true); - expect(schema1[0].hash).not.toEqual(schema[0].hash); + expect(schema1[0].hash).toEqual(schema[0].hash); }); it('parse @every schedule format', async () => { From 5bccdc86fb1cdf3a39c50a6d6cf6b20dbe686c62 Mon Sep 17 00:00:00 2001 From: vigneshshanmugam Date: Wed, 26 Jul 2023 08:19:05 -0700 Subject: [PATCH 4/4] improve test and api --- __tests__/push/monitor.test.ts | 4 ++-- src/dsl/journey.ts | 1 - src/dsl/monitor.ts | 1 + src/push/monitor.ts | 14 +++++++++----- 4 files changed, 12 insertions(+), 8 deletions(-) diff --git a/__tests__/push/monitor.test.ts b/__tests__/push/monitor.test.ts index 6cb684e2..cd0b62ec 100644 --- a/__tests__/push/monitor.test.ts +++ b/__tests__/push/monitor.test.ts @@ -103,9 +103,9 @@ describe('Monitors', () => { match: 'test', }, }); - monitor.setContent('foo'); + monitor.update({ locations: ['brazil'] }); const schema1 = await buildMonitorSchema([monitor], true); - expect(schema1[0].hash).toEqual(schema[0].hash); + expect(schema1[0].hash).not.toEqual(schema[0].hash); }); it('parse @every schedule format', async () => { diff --git a/src/dsl/journey.ts b/src/dsl/journey.ts index 9a748903..ae917ee1 100644 --- a/src/dsl/journey.ts +++ b/src/dsl/journey.ts @@ -97,7 +97,6 @@ export class Journey { ...config, }); this.monitor.setSource(this.location); - this.monitor.setContent(this.callback.toString()); this.monitor.setFilter({ match: this.name }); } diff --git a/src/dsl/monitor.ts b/src/dsl/monitor.ts index f5c488b1..eb943377 100644 --- a/src/dsl/monitor.ts +++ b/src/dsl/monitor.ts @@ -109,6 +109,7 @@ export class Monitor { /** * The underlying journey code of the monitor + * along with its dependencies */ setContent(content = '') { this.content = content; diff --git a/src/push/monitor.ts b/src/push/monitor.ts index 6aec3198..a920de61 100644 --- a/src/push/monitor.ts +++ b/src/push/monitor.ts @@ -110,12 +110,12 @@ export function diffMonitors( return result; } -export function getLocalMonitors(monitorSchemas: MonitorSchema[]) { +export function getLocalMonitors(schemas: MonitorSchema[]) { const data: MonitorHashID[] = []; - for (const monitor of monitorSchemas) { + for (const schema of schemas) { data.push({ - journey_id: monitor.id, - hash: monitor.hash, + journey_id: schema.id, + hash: schema.hash, }); } return data; @@ -141,9 +141,13 @@ export async function buildMonitorSchema(monitors: Monitor[], isV2: boolean) { if (type === 'browser') { const outPath = join(bundlePath, config.name + '.zip'); const content = await bundler.build(source.file, outPath); - monitor.content = content; + monitor.setContent(content); Object.assign(schema, { content, filter }); } + /** + * Generate hash only after the bundled content is created + * to capture code changes in imported files + */ if (isV2) { schema.hash = monitor.hash(); }