Skip to content

Commit 686f95a

Browse files
fix: push only newly created/updated monitors (#939)
* fix: push only newly created/updated monitors * fix test
1 parent 2d26404 commit 686f95a

File tree

3 files changed

+12
-12
lines changed

3 files changed

+12
-12
lines changed

__tests__/push/index.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ heartbeat.monitors:
267267
expect(output).toContain(
268268
"Pushing monitors for 'test-project' project in kibana 'dummy' space"
269269
);
270-
expect(output).toContain('bundling 2 monitors');
270+
expect(output).toContain('preparing 2 monitors');
271271
expect(output).toContain('creating or updating 2 monitors');
272272
expect(output).toContain(deleteProgress);
273273
expect(output).toContain('✓ Pushed:');

src/push/index.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ export async function push(monitors: Monitor[], options: PushOptions) {
7878

7979
const { monitors: remote } = await bulkGetMonitors(options);
8080

81-
progress(`bundling ${monitors.length} monitors`);
81+
progress(`preparing ${monitors.length} monitors`);
8282
const schemas = await buildMonitorSchema(monitors, true);
8383
const local = getLocalMonitors(schemas);
8484

@@ -90,7 +90,8 @@ export async function push(monitors: Monitor[], options: PushOptions) {
9090

9191
const updatedMonitors = new Set<string>([...changedIDs, ...newIDs]);
9292
if (updatedMonitors.size > 0) {
93-
const chunks = getChunks(schemas, CHUNK_SIZE);
93+
const updatedMonSchemas = schemas.filter(s => updatedMonitors.has(s.id));
94+
const chunks = getChunks(updatedMonSchemas, CHUNK_SIZE);
9495
for (const chunk of chunks) {
9596
await liveProgress(
9697
bulkPutMonitors(options, chunk),
@@ -217,9 +218,8 @@ export function validateSettings(opts: PushOptions) {
217218
- CLI '--schedule <mins>'
218219
- Config file 'monitors.schedule' field`;
219220
} else if (opts.schedule && !ALLOWED_SCHEDULES.includes(opts.schedule)) {
220-
reason = `Set default schedule(${
221-
opts.schedule
222-
}) to one of the allowed values - ${ALLOWED_SCHEDULES.join(',')}`;
221+
reason = `Set default schedule(${opts.schedule
222+
}) to one of the allowed values - ${ALLOWED_SCHEDULES.join(',')}`;
223223
}
224224

225225
if (!reason) return;
@@ -288,7 +288,7 @@ export async function pushLegacy(monitors: Monitor[], options: PushOptions) {
288288

289289
let schemas: MonitorSchema[] = [];
290290
if (monitors.length > 0) {
291-
progress(`bundling ${monitors.length} monitors`);
291+
progress(`preparing ${monitors.length} monitors`);
292292
schemas = await buildMonitorSchema(monitors, false);
293293
const chunks = getChunks(schemas, 10);
294294
for (const chunk of chunks) {

src/push/utils.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,14 @@ export function logDiff<T extends Set<string>>(
3737
) {
3838
progress(
3939
'Monitor Diff: ' +
40-
green(`Added(${newIDs.size}) `) +
41-
yellow(`Updated(${changedIDs.size}) `) +
42-
red(`Removed(${removedIDs.size}) `) +
43-
grey(`Unchanged(${unchangedIDs.size})`)
40+
green(`Added(${newIDs.size}) `) +
41+
yellow(`Updated(${changedIDs.size}) `) +
42+
red(`Removed(${removedIDs.size}) `) +
43+
grey(`Unchanged(${unchangedIDs.size})`)
4444
);
4545
}
4646

47-
export function getChunks(arr: any[], size: number) {
47+
export function getChunks<T>(arr: Array<T>, size: number): Array<T[]> {
4848
const chunks = [];
4949
for (let i = 0; i < arr.length; i += size) {
5050
chunks.push(arr.slice(i, i + size));

0 commit comments

Comments
 (0)