-
Notifications
You must be signed in to change notification settings - Fork 8.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Search] Add telemetry for data plugin search service (#70677)
* [search] Refactor the way search strategies are registered/retrieved on the server * Fix types and tests and update docs * Fix failing test * Fix build of example plugin * Fix functional test * Make server strategies sync * Move strategy name into options * docs * Remove FE strategies * TypeScript of hell delete search explorer * Fix search interceptor OSS tests * typos * test cleanup * Update search interceptor tests and abort utils * [Search] Add telemetry for data plugin search service * Add tracking of average query time * Add tests and rename to collectors * Fix TS * Fixed interceptor jest tests * Add to kibana json * docs * Properly use observables rather than only during setup * Update or create * Swallow version conflict errors Co-authored-by: Liza K <liza.katz@elastic.co> Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
- Loading branch information
1 parent
240b46c
commit 364595f
Showing
31 changed files
with
668 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
...ublic/kibana-plugin-plugins-data-public.searchinterceptordeps.usagecollector.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<!-- Do not edit this file. It is automatically generated by API Documenter. --> | ||
|
||
[Home](./index.md) > [kibana-plugin-plugins-data-public](./kibana-plugin-plugins-data-public.md) > [SearchInterceptorDeps](./kibana-plugin-plugins-data-public.searchinterceptordeps.md) > [usageCollector](./kibana-plugin-plugins-data-public.searchinterceptordeps.usagecollector.md) | ||
|
||
## SearchInterceptorDeps.usageCollector property | ||
|
||
<b>Signature:</b> | ||
|
||
```typescript | ||
usageCollector?: SearchUsageCollector; | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
...ent/plugins/data/server/kibana-plugin-plugins-data-server.isearchsetup.usage.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<!-- Do not edit this file. It is automatically generated by API Documenter. --> | ||
|
||
[Home](./index.md) > [kibana-plugin-plugins-data-server](./kibana-plugin-plugins-data-server.md) > [ISearchSetup](./kibana-plugin-plugins-data-server.isearchsetup.md) > [usage](./kibana-plugin-plugins-data-server.isearchsetup.usage.md) | ||
|
||
## ISearchSetup.usage property | ||
|
||
Used internally for telemetry | ||
|
||
<b>Signature:</b> | ||
|
||
```typescript | ||
usage: SearchUsage; | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
107 changes: 107 additions & 0 deletions
107
src/plugins/data/public/search/collectors/create_usage_collector.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
/* | ||
* Licensed to Elasticsearch B.V. under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch B.V. licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
import { CoreSetup, CoreStart } from '../../../../../core/public'; | ||
import { coreMock } from '../../../../../core/public/mocks'; | ||
import { usageCollectionPluginMock, Setup } from '../../../../usage_collection/public/mocks'; | ||
import { createUsageCollector } from './create_usage_collector'; | ||
import { SEARCH_EVENT_TYPE, SearchUsageCollector } from './types'; | ||
import { METRIC_TYPE } from '@kbn/analytics'; | ||
import { from } from 'rxjs'; | ||
|
||
describe('Search Usage Collector', () => { | ||
let mockCoreSetup: MockedKeys<CoreSetup>; | ||
let mockUsageCollectionSetup: Setup; | ||
let usageCollector: SearchUsageCollector; | ||
|
||
beforeEach(() => { | ||
mockCoreSetup = coreMock.createSetup(); | ||
(mockCoreSetup as any).getStartServices.mockResolvedValue([ | ||
{ | ||
application: { | ||
currentAppId$: from(['foo/bar']), | ||
}, | ||
} as jest.Mocked<CoreStart>, | ||
{} as any, | ||
{} as any, | ||
]); | ||
mockUsageCollectionSetup = usageCollectionPluginMock.createSetupContract(); | ||
usageCollector = createUsageCollector(mockCoreSetup, mockUsageCollectionSetup); | ||
}); | ||
|
||
test('tracks query timeouts', async () => { | ||
await usageCollector.trackQueryTimedOut(); | ||
expect(mockUsageCollectionSetup.reportUiStats).toHaveBeenCalled(); | ||
expect(mockUsageCollectionSetup.reportUiStats.mock.calls[0][0]).toBe('foo/bar'); | ||
expect(mockUsageCollectionSetup.reportUiStats.mock.calls[0][1]).toBe(METRIC_TYPE.LOADED); | ||
expect(mockUsageCollectionSetup.reportUiStats.mock.calls[0][2]).toBe( | ||
SEARCH_EVENT_TYPE.QUERY_TIMED_OUT | ||
); | ||
}); | ||
|
||
test('tracks query cancellation', async () => { | ||
await usageCollector.trackQueriesCancelled(); | ||
expect(mockUsageCollectionSetup.reportUiStats).toHaveBeenCalled(); | ||
expect(mockUsageCollectionSetup.reportUiStats.mock.calls[0][1]).toBe(METRIC_TYPE.LOADED); | ||
expect(mockUsageCollectionSetup.reportUiStats.mock.calls[0][2]).toBe( | ||
SEARCH_EVENT_TYPE.QUERIES_CANCELLED | ||
); | ||
}); | ||
|
||
test('tracks long popups', async () => { | ||
await usageCollector.trackLongQueryPopupShown(); | ||
expect(mockUsageCollectionSetup.reportUiStats).toHaveBeenCalled(); | ||
expect(mockUsageCollectionSetup.reportUiStats.mock.calls[0][1]).toBe(METRIC_TYPE.LOADED); | ||
expect(mockUsageCollectionSetup.reportUiStats.mock.calls[0][2]).toBe( | ||
SEARCH_EVENT_TYPE.LONG_QUERY_POPUP_SHOWN | ||
); | ||
}); | ||
|
||
test('tracks long popups dismissed', async () => { | ||
await usageCollector.trackLongQueryDialogDismissed(); | ||
expect(mockUsageCollectionSetup.reportUiStats).toHaveBeenCalled(); | ||
expect(mockUsageCollectionSetup.reportUiStats.mock.calls[0][1]).toBe(METRIC_TYPE.CLICK); | ||
expect(mockUsageCollectionSetup.reportUiStats.mock.calls[0][2]).toBe( | ||
SEARCH_EVENT_TYPE.LONG_QUERY_DIALOG_DISMISSED | ||
); | ||
}); | ||
|
||
test('tracks run query beyond timeout', async () => { | ||
await usageCollector.trackLongQueryRunBeyondTimeout(); | ||
expect(mockUsageCollectionSetup.reportUiStats).toHaveBeenCalled(); | ||
expect(mockUsageCollectionSetup.reportUiStats.mock.calls[0][1]).toBe(METRIC_TYPE.CLICK); | ||
expect(mockUsageCollectionSetup.reportUiStats.mock.calls[0][2]).toBe( | ||
SEARCH_EVENT_TYPE.LONG_QUERY_RUN_BEYOND_TIMEOUT | ||
); | ||
}); | ||
|
||
test('tracks response errors', async () => { | ||
const duration = 10; | ||
await usageCollector.trackError(duration); | ||
expect(mockCoreSetup.http.post).toBeCalled(); | ||
expect(mockCoreSetup.http.post.mock.calls[0][0]).toBe('/api/search/usage'); | ||
}); | ||
|
||
test('tracks response duration', async () => { | ||
const duration = 5; | ||
await usageCollector.trackSuccess(duration); | ||
expect(mockCoreSetup.http.post).toBeCalled(); | ||
expect(mockCoreSetup.http.post.mock.calls[0][0]).toBe('/api/search/usage'); | ||
}); | ||
}); |
92 changes: 92 additions & 0 deletions
92
src/plugins/data/public/search/collectors/create_usage_collector.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
/* | ||
* Licensed to Elasticsearch B.V. under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch B.V. licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
import { first } from 'rxjs/operators'; | ||
import { CoreSetup } from '../../../../../core/public'; | ||
import { METRIC_TYPE, UsageCollectionSetup } from '../../../../usage_collection/public'; | ||
import { SEARCH_EVENT_TYPE, SearchUsageCollector } from './types'; | ||
|
||
export const createUsageCollector = ( | ||
core: CoreSetup, | ||
usageCollection?: UsageCollectionSetup | ||
): SearchUsageCollector => { | ||
const getCurrentApp = async () => { | ||
const [{ application }] = await core.getStartServices(); | ||
return application.currentAppId$.pipe(first()).toPromise(); | ||
}; | ||
|
||
return { | ||
trackQueryTimedOut: async () => { | ||
const currentApp = await getCurrentApp(); | ||
return usageCollection?.reportUiStats( | ||
currentApp!, | ||
METRIC_TYPE.LOADED, | ||
SEARCH_EVENT_TYPE.QUERY_TIMED_OUT | ||
); | ||
}, | ||
trackQueriesCancelled: async () => { | ||
const currentApp = await getCurrentApp(); | ||
return usageCollection?.reportUiStats( | ||
currentApp!, | ||
METRIC_TYPE.LOADED, | ||
SEARCH_EVENT_TYPE.QUERIES_CANCELLED | ||
); | ||
}, | ||
trackLongQueryPopupShown: async () => { | ||
const currentApp = await getCurrentApp(); | ||
return usageCollection?.reportUiStats( | ||
currentApp!, | ||
METRIC_TYPE.LOADED, | ||
SEARCH_EVENT_TYPE.LONG_QUERY_POPUP_SHOWN | ||
); | ||
}, | ||
trackLongQueryDialogDismissed: async () => { | ||
const currentApp = await getCurrentApp(); | ||
return usageCollection?.reportUiStats( | ||
currentApp!, | ||
METRIC_TYPE.CLICK, | ||
SEARCH_EVENT_TYPE.LONG_QUERY_DIALOG_DISMISSED | ||
); | ||
}, | ||
trackLongQueryRunBeyondTimeout: async () => { | ||
const currentApp = await getCurrentApp(); | ||
return usageCollection?.reportUiStats( | ||
currentApp!, | ||
METRIC_TYPE.CLICK, | ||
SEARCH_EVENT_TYPE.LONG_QUERY_RUN_BEYOND_TIMEOUT | ||
); | ||
}, | ||
trackError: async (duration: number) => { | ||
return core.http.post('/api/search/usage', { | ||
body: JSON.stringify({ | ||
eventType: 'error', | ||
duration, | ||
}), | ||
}); | ||
}, | ||
trackSuccess: async (duration: number) => { | ||
return core.http.post('/api/search/usage', { | ||
body: JSON.stringify({ | ||
eventType: 'success', | ||
duration, | ||
}), | ||
}); | ||
}, | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
/* | ||
* Licensed to Elasticsearch B.V. under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch B.V. licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
export { createUsageCollector } from './create_usage_collector'; | ||
export { SEARCH_EVENT_TYPE, SearchUsageCollector } from './types'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* | ||
* Licensed to Elasticsearch B.V. under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch B.V. licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
export enum SEARCH_EVENT_TYPE { | ||
QUERY_TIMED_OUT = 'queryTimedOut', | ||
QUERIES_CANCELLED = 'queriesCancelled', | ||
LONG_QUERY_POPUP_SHOWN = 'longQueryPopupShown', | ||
LONG_QUERY_DIALOG_DISMISSED = 'longQueryDialogDismissed', | ||
LONG_QUERY_RUN_BEYOND_TIMEOUT = 'longQueryRunBeyondTimeout', | ||
} | ||
|
||
export interface SearchUsageCollector { | ||
trackQueryTimedOut: () => Promise<void>; | ||
trackQueriesCancelled: () => Promise<void>; | ||
trackLongQueryPopupShown: () => Promise<void>; | ||
trackLongQueryDialogDismissed: () => Promise<void>; | ||
trackLongQueryRunBeyondTimeout: () => Promise<void>; | ||
trackError: (duration: number) => Promise<void>; | ||
trackSuccess: (duration: number) => Promise<void>; | ||
} |
Oops, something went wrong.