-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Liza K
committed
Feb 16, 2021
1 parent
320e723
commit 69cdc32
Showing
6 changed files
with
139 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
57 changes: 57 additions & 0 deletions
57
src/plugins/data/public/autocomplete/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,57 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
import { first } from 'rxjs/operators'; | ||
import { StartServicesAccessor } from '../../../../../core/public'; | ||
import { METRIC_TYPE, UsageCollectionSetup } from '../../../../usage_collection/public'; | ||
import { AUTOCOMPLETE_EVENT_TYPE, AutocompleteUsageCollector } from './types'; | ||
|
||
export const createUsageCollector = ( | ||
getStartServices: StartServicesAccessor, | ||
usageCollection?: UsageCollectionSetup | ||
): AutocompleteUsageCollector => { | ||
const getCurrentApp = async () => { | ||
const [{ application }] = await getStartServices(); | ||
return application.currentAppId$.pipe(first()).toPromise(); | ||
}; | ||
|
||
return { | ||
trackCall: async () => { | ||
const currentApp = await getCurrentApp(); | ||
return usageCollection?.reportUiCounter( | ||
currentApp!, | ||
METRIC_TYPE.LOADED, | ||
AUTOCOMPLETE_EVENT_TYPE.CALL | ||
); | ||
}, | ||
trackRequest: async () => { | ||
const currentApp = await getCurrentApp(); | ||
return usageCollection?.reportUiCounter( | ||
currentApp!, | ||
METRIC_TYPE.LOADED, | ||
AUTOCOMPLETE_EVENT_TYPE.REQUEST | ||
); | ||
}, | ||
trackResult: async () => { | ||
const currentApp = await getCurrentApp(); | ||
return usageCollection?.reportUiCounter( | ||
currentApp!, | ||
METRIC_TYPE.LOADED, | ||
AUTOCOMPLETE_EVENT_TYPE.RESULT | ||
); | ||
}, | ||
trackError: async () => { | ||
const currentApp = await getCurrentApp(); | ||
return usageCollection?.reportUiCounter( | ||
currentApp!, | ||
METRIC_TYPE.LOADED, | ||
AUTOCOMPLETE_EVENT_TYPE.ERROR | ||
); | ||
}, | ||
}; | ||
}; |
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,10 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
export { createUsageCollector } from './create_usage_collector'; | ||
export { AUTOCOMPLETE_EVENT_TYPE, AutocompleteUsageCollector } 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,21 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
export enum AUTOCOMPLETE_EVENT_TYPE { | ||
CALL = 'call', | ||
REQUEST = 'req', | ||
RESULT = 'res', | ||
ERROR = 'err', | ||
} | ||
|
||
export interface AutocompleteUsageCollector { | ||
trackCall: () => Promise<void>; | ||
trackRequest: () => Promise<void>; | ||
trackResult: () => Promise<void>; | ||
trackError: () => Promise<void>; | ||
} |
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