Skip to content

Commit 6c8d037

Browse files
Merge branch 'master' into data-telemetry/add-async-search-test
2 parents 98446cd + 5a9fc21 commit 6c8d037

File tree

37 files changed

+311
-277
lines changed

37 files changed

+311
-277
lines changed

docs/development/plugins/data/public/kibana-plugin-plugins-data-public.isearchoptions.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ export interface ISearchOptions
1919
| [isRestore](./kibana-plugin-plugins-data-public.isearchoptions.isrestore.md) | <code>boolean</code> | Whether the session is restored (i.e. search requests should re-use the stored search IDs, rather than starting from scratch) |
2020
| [isStored](./kibana-plugin-plugins-data-public.isearchoptions.isstored.md) | <code>boolean</code> | Whether the session is already saved (i.e. sent to background) |
2121
| [legacyHitsTotal](./kibana-plugin-plugins-data-public.isearchoptions.legacyhitstotal.md) | <code>boolean</code> | Request the legacy format for the total number of hits. If sending <code>rest_total_hits_as_int</code> to something other than <code>true</code>, this should be set to <code>false</code>. |
22+
| [requestResponder](./kibana-plugin-plugins-data-public.isearchoptions.requestresponder.md) | <code>RequestResponder</code> | |
2223
| [sessionId](./kibana-plugin-plugins-data-public.isearchoptions.sessionid.md) | <code>string</code> | A session ID, grouping multiple search requests into a single session. |
2324
| [strategy](./kibana-plugin-plugins-data-public.isearchoptions.strategy.md) | <code>string</code> | Use this option to force using a specific server side search strategy. Leave empty to use the default strategy. |
2425

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
2+
3+
[Home](./index.md) &gt; [kibana-plugin-plugins-data-public](./kibana-plugin-plugins-data-public.md) &gt; [ISearchOptions](./kibana-plugin-plugins-data-public.isearchoptions.md) &gt; [requestResponder](./kibana-plugin-plugins-data-public.isearchoptions.requestresponder.md)
4+
5+
## ISearchOptions.requestResponder property
6+
7+
<b>Signature:</b>
8+
9+
```typescript
10+
requestResponder?: RequestResponder;
11+
```

docs/development/plugins/data/public/kibana-plugin-plugins-data-public.search.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ search: {
5353
timeRange: import("../common").TimeRange | undefined;
5454
} | undefined;
5555
};
56-
getRequestInspectorStats: typeof getRequestInspectorStats;
5756
getResponseInspectorStats: typeof getResponseInspectorStats;
5857
tabifyAggResponse: typeof tabifyAggResponse;
5958
tabifyGetColumns: typeof tabifyGetColumns;

docs/development/plugins/data/public/kibana-plugin-plugins-data-public.searchsource.getsearchrequestbody.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ Returns body contents of the search request, often referred as query DSL.
99
<b>Signature:</b>
1010

1111
```typescript
12-
getSearchRequestBody(): Promise<any>;
12+
getSearchRequestBody(): any;
1313
```
1414
<b>Returns:</b>
1515

16-
`Promise<any>`
16+
`any`
1717

docs/development/plugins/data/server/kibana-plugin-plugins-data-server.isearchoptions.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ export interface ISearchOptions
1919
| [isRestore](./kibana-plugin-plugins-data-server.isearchoptions.isrestore.md) | <code>boolean</code> | Whether the session is restored (i.e. search requests should re-use the stored search IDs, rather than starting from scratch) |
2020
| [isStored](./kibana-plugin-plugins-data-server.isearchoptions.isstored.md) | <code>boolean</code> | Whether the session is already saved (i.e. sent to background) |
2121
| [legacyHitsTotal](./kibana-plugin-plugins-data-server.isearchoptions.legacyhitstotal.md) | <code>boolean</code> | Request the legacy format for the total number of hits. If sending <code>rest_total_hits_as_int</code> to something other than <code>true</code>, this should be set to <code>false</code>. |
22+
| [requestResponder](./kibana-plugin-plugins-data-server.isearchoptions.requestresponder.md) | <code>RequestResponder</code> | |
2223
| [sessionId](./kibana-plugin-plugins-data-server.isearchoptions.sessionid.md) | <code>string</code> | A session ID, grouping multiple search requests into a single session. |
2324
| [strategy](./kibana-plugin-plugins-data-server.isearchoptions.strategy.md) | <code>string</code> | Use this option to force using a specific server side search strategy. Leave empty to use the default strategy. |
2425

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
2+
3+
[Home](./index.md) &gt; [kibana-plugin-plugins-data-server](./kibana-plugin-plugins-data-server.md) &gt; [ISearchOptions](./kibana-plugin-plugins-data-server.isearchoptions.md) &gt; [requestResponder](./kibana-plugin-plugins-data-server.isearchoptions.requestresponder.md)
4+
5+
## ISearchOptions.requestResponder property
6+
7+
<b>Signature:</b>
8+
9+
```typescript
10+
requestResponder?: RequestResponder;
11+
```

docs/development/plugins/data/server/kibana-plugin-plugins-data-server.search.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,6 @@ search: {
3636
toAbsoluteDates: typeof toAbsoluteDates;
3737
calcAutoIntervalLessThan: typeof calcAutoIntervalLessThan;
3838
};
39-
getRequestInspectorStats: typeof getRequestInspectorStats;
40-
getResponseInspectorStats: typeof getResponseInspectorStats;
4139
tabifyAggResponse: typeof tabifyAggResponse;
4240
tabifyGetColumns: typeof tabifyGetColumns;
4341
}

examples/search_examples/public/search/app.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -204,8 +204,8 @@ export const SearchExamplesApp = ({
204204
});
205205
}
206206

207-
setRequest(await searchSource.getSearchRequestBody());
208-
const res = await searchSource.fetch();
207+
setRequest(searchSource.getSearchRequestBody());
208+
const res = await searchSource.fetch$().toPromise();
209209
setResponse(res);
210210

211211
const message = <EuiText>Searched {res.hits.total} documents.</EuiText>;

src/core/server/config/ensure_valid_configuration.test.ts

Lines changed: 43 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,40 @@ describe('ensureValidConfiguration', () => {
1616
beforeEach(() => {
1717
jest.clearAllMocks();
1818
configService = configServiceMock.create();
19-
configService.getUsedPaths.mockReturnValue(Promise.resolve(['core', 'elastic']));
19+
20+
configService.validate.mockResolvedValue();
21+
configService.getUsedPaths.mockReturnValue(Promise.resolve([]));
2022
});
2123

22-
it('returns normally when there is no unused keys', async () => {
23-
configService.getUnusedPaths.mockResolvedValue([]);
24+
it('returns normally when there is no unused keys and when the config validates', async () => {
2425
await expect(ensureValidConfiguration(configService as any)).resolves.toBeUndefined();
2526
});
2627

28+
it('throws when config validation fails', async () => {
29+
configService.validate.mockImplementation(() => {
30+
throw new Error('some message');
31+
});
32+
33+
await expect(ensureValidConfiguration(configService as any)).rejects.toMatchInlineSnapshot(
34+
`[Error: some message]`
35+
);
36+
});
37+
38+
it('throws a `CriticalError` with the correct processExitCode value when config validation fails', async () => {
39+
expect.assertions(2);
40+
41+
configService.validate.mockImplementation(() => {
42+
throw new Error('some message');
43+
});
44+
45+
try {
46+
await ensureValidConfiguration(configService as any);
47+
} catch (e) {
48+
expect(e).toBeInstanceOf(CriticalError);
49+
expect(e.processExitCode).toEqual(78);
50+
}
51+
});
52+
2753
it('throws when there are some unused keys', async () => {
2854
configService.getUnusedPaths.mockResolvedValue(['some.key', 'some.other.key']);
2955

@@ -44,4 +70,18 @@ describe('ensureValidConfiguration', () => {
4470
expect(e.processExitCode).toEqual(64);
4571
}
4672
});
73+
74+
it('does not throw when all unused keys are included in the ignored paths', async () => {
75+
configService.getUnusedPaths.mockResolvedValue(['dev.someDevKey', 'elastic.apm.enabled']);
76+
77+
await expect(ensureValidConfiguration(configService as any)).resolves.toBeUndefined();
78+
});
79+
80+
it('throws when only some keys are included in the ignored paths', async () => {
81+
configService.getUnusedPaths.mockResolvedValue(['dev.someDevKey', 'some.key']);
82+
83+
await expect(ensureValidConfiguration(configService as any)).rejects.toMatchInlineSnapshot(
84+
`[Error: Unknown configuration key(s): "some.key". Check for spelling errors and ensure that expected plugins are installed.]`
85+
);
86+
});
4787
});

src/core/server/config/ensure_valid_configuration.ts

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,27 @@
99
import { ConfigService } from '@kbn/config';
1010
import { CriticalError } from '../errors';
1111

12+
const ignoredPaths = ['dev.', 'elastic.apm.'];
13+
14+
const invalidConfigExitCode = 78;
15+
const legacyInvalidConfigExitCode = 64;
16+
1217
export async function ensureValidConfiguration(configService: ConfigService) {
13-
await configService.validate();
18+
try {
19+
await configService.validate();
20+
} catch (e) {
21+
throw new CriticalError(e.message, 'InvalidConfig', invalidConfigExitCode, e);
22+
}
1423

15-
const unusedConfigKeys = await configService.getUnusedPaths();
24+
const unusedPaths = await configService.getUnusedPaths();
25+
const unusedConfigKeys = unusedPaths.filter((unusedPath) => {
26+
return !ignoredPaths.some((ignoredPath) => unusedPath.startsWith(ignoredPath));
27+
});
1628

1729
if (unusedConfigKeys.length > 0) {
1830
const message = `Unknown configuration key(s): ${unusedConfigKeys
1931
.map((key) => `"${key}"`)
2032
.join(', ')}. Check for spelling errors and ensure that expected plugins are installed.`;
21-
throw new InvalidConfigurationError(message);
22-
}
23-
}
24-
25-
class InvalidConfigurationError extends CriticalError {
26-
constructor(message: string) {
27-
super(message, 'InvalidConfig', 64);
28-
Object.setPrototypeOf(this, InvalidConfigurationError.prototype);
33+
throw new CriticalError(message, 'InvalidConfig', legacyInvalidConfigExitCode);
2934
}
3035
}

0 commit comments

Comments
 (0)