Skip to content

Commit ebb0203

Browse files
committed
Merge remote-tracking branch 'origin/ML-52618-search-partition-value' into ML-52618-search-partition-value
2 parents 5af3846 + 29a3d34 commit ebb0203

File tree

19 files changed

+186
-47
lines changed

19 files changed

+186
-47
lines changed

src/legacy/core_plugins/console/public/kibana.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,6 @@
33
"version": "kibana",
44
"server": true,
55
"ui": true,
6-
"requiredPlugins": ["home"]
6+
"requiredPlugins": ["home"],
7+
"optionalPlugins": ["usageCollection"]
78
}

src/legacy/core_plugins/console/public/legacy.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,13 @@ import { I18nContext } from 'ui/i18n';
2222
import chrome from 'ui/chrome';
2323
import { FeatureCatalogueCategory } from 'ui/registry/feature_catalogue';
2424

25+
import { plugin } from './np_ready';
26+
import { DevToolsSetup } from '../../../../plugins/dev_tools/public';
27+
import { HomePublicPluginSetup } from '../../../../plugins/home/public';
28+
import { UsageCollectionSetup } from '../../../../plugins/usage_collection/public';
29+
2530
export interface XPluginSet {
31+
usageCollection: UsageCollectionSetup;
2632
dev_tools: DevToolsSetup;
2733
home: HomePublicPluginSetup;
2834
__LEGACY: {
@@ -32,10 +38,6 @@ export interface XPluginSet {
3238
};
3339
}
3440

35-
import { plugin } from './np_ready';
36-
import { DevToolsSetup } from '../../../../plugins/dev_tools/public';
37-
import { HomePublicPluginSetup } from '../../../../plugins/home/public';
38-
3941
const pluginInstance = plugin({} as any);
4042

4143
(async () => {

src/legacy/core_plugins/console/public/np_ready/application/containers/editor/legacy/console_editor/editor.test.mock.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ jest.mock('../../../../contexts/editor_context/editor_registry.ts', () => ({
2222
setInputEditor: () => {},
2323
getInputEditor: () => ({
2424
getRequestsInRange: async () => [{ test: 'test' }],
25+
getCoreEditor: () => ({ getCurrentPosition: jest.fn() }),
2526
}),
2627
},
2728
}));
@@ -52,3 +53,6 @@ jest.mock('../../../../models/sense_editor', () => {
5253
jest.mock('../../../../hooks/use_send_current_request_to_es/send_request_to_es', () => ({
5354
sendRequestToES: jest.fn(),
5455
}));
56+
jest.mock('../../../../../lib/autocomplete/get_endpoint_from_position', () => ({
57+
getEndpointFromPosition: jest.fn(),
58+
}));

src/legacy/core_plugins/console/public/np_ready/application/containers/editor/legacy/console_editor/editor.test.tsx

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,18 @@ import {
3232
ServicesContextProvider,
3333
EditorContextProvider,
3434
RequestContextProvider,
35+
ContextValue,
3536
} from '../../../../contexts';
3637

38+
// Mocked functions
3739
import { sendRequestToES } from '../../../../hooks/use_send_current_request_to_es/send_request_to_es';
40+
import { getEndpointFromPosition } from '../../../../../lib/autocomplete/get_endpoint_from_position';
41+
3842
import * as consoleMenuActions from '../console_menu_actions';
3943
import { Editor } from './editor';
4044

4145
describe('Legacy (Ace) Console Editor Component Smoke Test', () => {
42-
let mockedAppContextValue: any;
46+
let mockedAppContextValue: ContextValue;
4347
const sandbox = sinon.createSandbox();
4448

4549
const doMount = () =>
@@ -58,22 +62,28 @@ describe('Legacy (Ace) Console Editor Component Smoke Test', () => {
5862
beforeEach(() => {
5963
document.queryCommandSupported = sinon.fake(() => true);
6064
mockedAppContextValue = {
65+
elasticsearchUrl: 'test',
6166
services: {
67+
trackUiMetric: { count: () => {}, load: () => {} },
68+
settings: {} as any,
69+
storage: {} as any,
6270
history: {
63-
getSavedEditorState: () => null,
71+
getSavedEditorState: () => ({} as any),
6472
updateCurrentState: jest.fn(),
65-
},
73+
} as any,
6674
notifications: notificationServiceMock.createSetupContract(),
6775
},
6876
docLinkVersion: 'NA',
6977
};
7078
});
7179

7280
afterEach(() => {
81+
jest.clearAllMocks();
7382
sandbox.restore();
7483
});
7584

7685
it('calls send current request to ES', async () => {
86+
(getEndpointFromPosition as jest.Mock).mockReturnValue({ patterns: [] });
7787
(sendRequestToES as jest.Mock).mockRejectedValue({});
7888
const editor = doMount();
7989
act(() => {

src/legacy/core_plugins/console/public/np_ready/application/containers/editor/legacy/console_menu_actions.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@
1717
* under the License.
1818
*/
1919

20-
// @ts-ignore
21-
import { getEndpointFromPosition } from '../../../../lib/autocomplete/autocomplete';
20+
import { getEndpointFromPosition } from '../../../../lib/autocomplete/get_endpoint_from_position';
2221
import { SenseEditor } from '../../../models/sense_editor';
2322

2423
export async function autoIndent(editor: SenseEditor, event: Event) {
@@ -40,7 +39,7 @@ export function getDocumentation(
4039
}
4140
const position = requests[0].range.end;
4241
position.column = position.column - 1;
43-
const endpoint = getEndpointFromPosition(editor, position, editor.parser);
42+
const endpoint = getEndpointFromPosition(editor.getCoreEditor(), position, editor.parser);
4443
if (endpoint && endpoint.documentation && endpoint.documentation.indexOf('http') !== -1) {
4544
return endpoint.documentation
4645
.replace('/master/', `/${docLinkVersion}/`)

src/legacy/core_plugins/console/public/np_ready/application/contexts/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
* under the License.
1818
*/
1919

20-
export { useServicesContext, ServicesContextProvider } from './services_context';
20+
export { useServicesContext, ServicesContextProvider, ContextValue } from './services_context';
2121

2222
export {
2323
useRequestActionContext,

src/legacy/core_plugins/console/public/np_ready/application/contexts/services_context.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,15 @@
2020
import React, { createContext, useContext } from 'react';
2121
import { NotificationsSetup } from 'kibana/public';
2222
import { History, Storage, Settings } from '../../services';
23+
import { MetricsTracker } from '../../types';
2324

24-
interface ContextValue {
25+
export interface ContextValue {
2526
services: {
2627
history: History;
2728
storage: Storage;
2829
settings: Settings;
2930
notifications: NotificationsSetup;
31+
trackUiMetric: MetricsTracker;
3032
};
3133
elasticsearchUrl: string;
3234
docLinkVersion: string;

src/legacy/core_plugins/console/public/np_ready/application/hooks/use_send_current_request_to_es/send_request_to_es.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ export interface ESRequestResult {
3939
}
4040

4141
let CURRENT_REQ_ID = 0;
42-
export function sendRequestToES({ requests }: EsRequestArgs): Promise<ESRequestResult[]> {
42+
export function sendRequestToES(args: EsRequestArgs): Promise<ESRequestResult[]> {
43+
const requests = args.requests.slice();
4344
return new Promise((resolve, reject) => {
4445
const reqId = ++CURRENT_REQ_ID;
4546
const results: ESRequestResult[] = [];
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/*
2+
* Licensed to Elasticsearch B.V. under one or more contributor
3+
* license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright
5+
* ownership. Elasticsearch B.V. licenses this file to you under
6+
* the Apache License, Version 2.0 (the "License"); you may
7+
* not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
import { SenseEditor } from '../../models/sense_editor';
21+
import { getEndpointFromPosition } from '../../../lib/autocomplete/get_endpoint_from_position';
22+
import { MetricsTracker } from '../../../types';
23+
24+
export const track = (requests: any[], editor: SenseEditor, trackUiMetric: MetricsTracker) => {
25+
const coreEditor = editor.getCoreEditor();
26+
// `getEndpointFromPosition` gets values from the server-side generated JSON files which
27+
// are a combination of JS, automatically generated JSON and manual overrides. That means
28+
// the metrics reported from here will be tied to the definitions in those files.
29+
// See src/legacy/core_plugins/console/server/api_server/spec
30+
const endpointDescription = getEndpointFromPosition(
31+
coreEditor,
32+
coreEditor.getCurrentPosition(),
33+
editor.parser
34+
);
35+
36+
if (requests[0] && endpointDescription) {
37+
const eventName = `${requests[0].method}_${endpointDescription.id ?? 'unknown'}`;
38+
trackUiMetric.count(eventName);
39+
}
40+
};

src/legacy/core_plugins/console/public/np_ready/application/hooks/use_send_current_request_to_es/use_send_current_request_to_es.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,16 @@
1919
import { i18n } from '@kbn/i18n';
2020
import { useCallback } from 'react';
2121
import { instance as registry } from '../../contexts/editor_context/editor_registry';
22-
import { useServicesContext } from '../../contexts';
22+
import { useRequestActionContext, useServicesContext } from '../../contexts';
2323
import { sendRequestToES } from './send_request_to_es';
24-
import { useRequestActionContext } from '../../contexts';
24+
import { track } from './track';
25+
2526
// @ts-ignore
2627
import mappings from '../../../lib/mappings/mappings';
2728

2829
export const useSendCurrentRequestToES = () => {
2930
const {
30-
services: { history, settings, notifications },
31+
services: { history, settings, notifications, trackUiMetric },
3132
} = useServicesContext();
3233

3334
const dispatch = useRequestActionContext();
@@ -45,9 +46,10 @@ export const useSendCurrentRequestToES = () => {
4546
return;
4647
}
4748

48-
const results = await sendRequestToES({
49-
requests,
50-
});
49+
// Fire and forget
50+
setTimeout(() => track(requests, editor, trackUiMetric), 0);
51+
52+
const results = await sendRequestToES({ requests });
5153

5254
results.forEach(({ request: { path, method, data } }) => {
5355
history.addToHistory(path, method, data);
@@ -82,5 +84,5 @@ export const useSendCurrentRequestToES = () => {
8284
});
8385
}
8486
}
85-
}, [dispatch, settings, history, notifications]);
87+
}, [dispatch, settings, history, notifications, trackUiMetric]);
8688
};

0 commit comments

Comments
 (0)