Skip to content

Commit

Permalink
[Reporting] Add max concurrent shards setting to schema (#170344)
Browse files Browse the repository at this point in the history
## Summary

Closes #161561
This PR exposes the `max_concurrent_shards` setting in the schema for
customers for point in time CSV report generation.

### Checklist

- [x] [Unit or functional
tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)
were updated or added to match the most common scenarios

---------

Co-authored-by: Tim Sullivan <tsullivan@users.noreply.github.com>
  • Loading branch information
rshen91 and tsullivan committed Dec 5, 2023
1 parent 39caf94 commit 7508ee1
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 9 deletions.
12 changes: 8 additions & 4 deletions packages/kbn-generate-csv/src/generate_csv.test.ts
Expand Up @@ -118,6 +118,7 @@ describe('CsvGenerator', () => {
useByteOrderMarkEncoding: false,
scroll: { size: 500, duration: '30s' },
enablePanelActionDownload: true,
maxConcurrentShardRequests: 5,
};

searchSourceMock.getField = jest.fn((key: string) => {
Expand Down Expand Up @@ -245,6 +246,7 @@ describe('CsvGenerator', () => {
useByteOrderMarkEncoding: false,
scroll: { size: 500, duration: '30s' },
enablePanelActionDownload: true,
maxConcurrentShardRequests: 5,
};

mockDataClient.search = jest.fn().mockImplementation(() =>
Expand Down Expand Up @@ -345,7 +347,7 @@ describe('CsvGenerator', () => {

expect(mockDataClient.search).toHaveBeenCalledTimes(10);
expect(mockDataClient.search).toBeCalledWith(
{ params: { body: {}, ignore_throttled: undefined } },
{ params: { body: {}, ignore_throttled: undefined, max_concurrent_shard_requests: 5 } },
{ strategy: 'es', transport: { maxRetries: 0, requestTimeout: '30s' } }
);

Expand All @@ -356,7 +358,7 @@ describe('CsvGenerator', () => {
index: 'logstash-*',
keep_alive: '30s',
},
{ maxRetries: 0, requestTimeout: '30s' }
{ maxConcurrentShardRequests: 5, maxRetries: 0, requestTimeout: '30s' }
);

expect(mockEsClient.asCurrentUser.closePointInTime).toHaveBeenCalledTimes(1);
Expand Down Expand Up @@ -763,6 +765,7 @@ describe('CsvGenerator', () => {
useByteOrderMarkEncoding: false,
scroll: { size: 500, duration: '30s' },
enablePanelActionDownload: true,
maxConcurrentShardRequests: 5,
};
mockDataClient.search = jest.fn().mockImplementation(() =>
Rx.of({
Expand Down Expand Up @@ -833,7 +836,7 @@ describe('CsvGenerator', () => {
index: 'logstash-*',
keep_alive: '30s',
},
{ maxRetries: 0, requestTimeout: '30s' }
{ maxConcurrentShardRequests: 5, maxRetries: 0, requestTimeout: '30s' }
);

expect(mockEsClient.asCurrentUser.openPointInTime).toHaveBeenCalledWith(
Expand All @@ -843,13 +846,14 @@ describe('CsvGenerator', () => {
index: 'logstash-*',
keep_alive: '30s',
},
{ maxRetries: 0, requestTimeout: '30s' }
{ maxConcurrentShardRequests: 5, maxRetries: 0, requestTimeout: '30s' }
);

expect(mockDataClient.search).toBeCalledWith(
{
params: {
body: {},
max_concurrent_shard_requests: 5,
},
},
{ strategy: 'es', transport: { maxRetries: 0, requestTimeout: '30s' } }
Expand Down
22 changes: 17 additions & 5 deletions packages/kbn-generate-csv/src/generate_csv.ts
Expand Up @@ -12,6 +12,7 @@ import type { Writable } from 'stream';
import { errors as esErrors, estypes } from '@elastic/elasticsearch';
import type { IScopedClusterClient, IUiSettingsClient, Logger } from '@kbn/core/server';
import type {
IEsSearchRequest,
IKibanaSearchResponse,
ISearchSource,
ISearchStartSearchSource,
Expand Down Expand Up @@ -66,7 +67,11 @@ export class CsvGenerator {
) {}

private async openPointInTime(indexPatternTitle: string, settings: CsvExportSettings) {
const { duration } = settings.scroll;
const {
includeFrozen,
maxConcurrentShardRequests,
scroll: { duration },
} = settings;
let pitId: string | undefined;
this.logger.debug(`Requesting PIT for: [${indexPatternTitle}]...`);
try {
Expand All @@ -77,11 +82,12 @@ export class CsvGenerator {
keep_alive: duration,
ignore_unavailable: true,
// @ts-expect-error ignore_throttled is not in the type definition, but it is accepted by es
ignore_throttled: settings.includeFrozen ? false : undefined, // "true" will cause deprecation warnings logged in ES
ignore_throttled: includeFrozen ? false : undefined, // "true" will cause deprecation warnings logged in ES
},
{
requestTimeout: duration,
maxRetries: 0,
maxConcurrentShardRequests,
}
);
pitId = response.id;
Expand Down Expand Up @@ -135,7 +141,7 @@ export class CsvGenerator {
settings: CsvExportSettings,
searchAfter?: estypes.SortResults
) {
const { scroll: scrollSettings } = settings;
const { scroll: scrollSettings, maxConcurrentShardRequests } = settings;
searchSource.setField('size', scrollSettings.size);

if (searchAfter) {
Expand All @@ -153,8 +159,14 @@ export class CsvGenerator {
throw new Error('Could not retrieve the search body!');
}

const searchParams = { params: { body: searchBody } };
let results: estypes.SearchResponse<unknown>;
const searchParams: IEsSearchRequest = {
params: {
body: searchBody,
max_concurrent_shard_requests: maxConcurrentShardRequests,
},
};

let results: estypes.SearchResponse<unknown> | undefined;
try {
const { rawResponse, ...rawDetails } = await lastValueFrom(
this.clients.data.search(searchParams, {
Expand Down
2 changes: 2 additions & 0 deletions packages/kbn-generate-csv/src/get_export_settings.test.ts
Expand Up @@ -30,6 +30,7 @@ describe('getExportSettings', () => {
maxSizeBytes: 180000,
scroll: { size: 500, duration: '30s' },
useByteOrderMarkEncoding: false,
maxConcurrentShardRequests: 5,
enablePanelActionDownload: true,
};
const logger = loggingSystemMock.createLogger();
Expand Down Expand Up @@ -62,6 +63,7 @@ describe('getExportSettings', () => {
"escapeFormulaValues": false,
"escapeValue": [Function],
"includeFrozen": false,
"maxConcurrentShardRequests": 5,
"maxSizeBytes": 180000,
"scroll": Object {
"duration": "30s",
Expand Down
2 changes: 2 additions & 0 deletions packages/kbn-generate-csv/src/get_export_settings.ts
Expand Up @@ -31,6 +31,7 @@ export interface CsvExportSettings {
escapeFormulaValues: boolean;
escapeValue: (value: string) => string;
includeFrozen: boolean;
maxConcurrentShardRequests: number;
}

export const getExportSettings = async (
Expand Down Expand Up @@ -82,5 +83,6 @@ export const getExportSettings = async (
checkForFormulas: config.checkForFormulas,
escapeFormulaValues,
escapeValue,
maxConcurrentShardRequests: config.maxConcurrentShardRequests,
};
};

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions packages/kbn-reporting/server/config_schema.ts
Expand Up @@ -75,6 +75,7 @@ const CsvSchema = schema.object({
}),
size: schema.number({ defaultValue: 500 }),
}),
maxConcurrentShardRequests: schema.number({ defaultValue: 5 }),
});

const EncryptionKeySchema = schema.conditional(
Expand Down

0 comments on commit 7508ee1

Please sign in to comment.