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

feat: support configurable chunk size #944

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
34 changes: 33 additions & 1 deletion __tests__/push/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -200,8 +200,8 @@ heartbeat.monitors:
`
);
const output = await runPush();
expect(output).toContain(`Aborted: Duplicate monitors found`);
await rm(heartbeatYml, { force: true });
expect(output).toContain(`Aborted: Duplicate monitors found`);
});

it('format duplicate monitors', () => {
Expand All @@ -218,6 +218,38 @@ heartbeat.monitors:
expect(formatDuplicateError(duplicates as Set<Monitor>)).toMatchSnapshot();
});

it('error on invalid CHUNK SIZE', async () => {
await fakeProjectSetup(
{ id: 'test-project', space: 'dummy', url: server.PREFIX },
{ locations: ['test-loc'], schedule: 3 }
);
const output = await runPush(undefined, { CHUNK_SIZE: '251' });
expect(output).toContain(
'Invalid CHUNK_SIZE. CHUNK_SIZE must be less than or equal to 250'
);
});

it('respects valid CHUNK SIZE', async () => {
await fakeProjectSetup(
{ id: 'test-project', space: 'dummy', url: server.PREFIX },
{ locations: ['test-loc'], schedule: 3 }
);
const testJourney = join(PROJECT_DIR, 'chunk.journey.ts');
await writeFile(
testJourney,
`import {journey, monitor} from '../../../';
journey('a', () => monitor.use({ tags: ['chunk'] }));
journey('b', () => monitor.use({ tags: ['chunk'] }));`
);
const output = await runPush([...DEFAULT_ARGS, '--tags', 'chunk'], {
CHUNK_SIZE: '1',
});
await rm(testJourney, { force: true });
expect(output).toContain('Added(2)');
expect(output).toContain('creating or updating 1 monitors');
expect(output).toContain('✓ Pushed:');
});

['8.5.0', '8.6.0'].forEach(version => {
describe('API: ' + version, () => {
let server: Server;
Expand Down
5 changes: 5 additions & 0 deletions src/push/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,11 @@ import {
import { log } from '../core/logger';

export async function push(monitors: Monitor[], options: PushOptions) {
if (parseInt(process.env.CHUNK_SIZE) > 250) {
throw error(
'Invalid CHUNK_SIZE. CHUNK_SIZE must be less than or equal to 250'
);
}
const duplicates = trackDuplicates(monitors);
if (duplicates.size > 0) {
throw error(formatDuplicateError(duplicates));
Expand Down
2 changes: 1 addition & 1 deletion src/push/kibana_api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ import {
import { generateURL } from './utils';

// Default chunk size for bulk put / delete
export const CHUNK_SIZE = 100;
export const CHUNK_SIZE = parseInt(process.env.CHUNK_SIZE) || 100;
vigneshshanmugam marked this conversation as resolved.
Show resolved Hide resolved

export type PutResponse = {
createdMonitors: string[];
Expand Down
Loading