diff --git a/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.isearchsetup.usage.md b/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.isearchsetup.usage.md
index 85abd9d9dba980..1a94a709cc214a 100644
--- a/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.isearchsetup.usage.md
+++ b/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.isearchsetup.usage.md
@@ -9,5 +9,5 @@ Used internally for telemetry
Signature:
```typescript
-usage: SearchUsage;
+usage?: SearchUsage;
```
diff --git a/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.md b/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.md
index 6bf481841f3347..1bcd575803f880 100644
--- a/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.md
+++ b/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.md
@@ -27,6 +27,7 @@
| [parseInterval(interval)](./kibana-plugin-plugins-data-server.parseinterval.md) | |
| [plugin(initializerContext)](./kibana-plugin-plugins-data-server.plugin.md) | Static code to be shared externally |
| [shouldReadFieldFromDocValues(aggregatable, esType)](./kibana-plugin-plugins-data-server.shouldreadfieldfromdocvalues.md) | |
+| [usageProvider(core)](./kibana-plugin-plugins-data-server.usageprovider.md) | |
## Interfaces
@@ -49,6 +50,7 @@
| [PluginStart](./kibana-plugin-plugins-data-server.pluginstart.md) | |
| [Query](./kibana-plugin-plugins-data-server.query.md) | |
| [RefreshInterval](./kibana-plugin-plugins-data-server.refreshinterval.md) | |
+| [SearchUsage](./kibana-plugin-plugins-data-server.searchusage.md) | |
| [TimeRange](./kibana-plugin-plugins-data-server.timerange.md) | |
## Variables
diff --git a/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.searchusage.md b/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.searchusage.md
new file mode 100644
index 00000000000000..d867509e915b6a
--- /dev/null
+++ b/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.searchusage.md
@@ -0,0 +1,19 @@
+
+
+[Home](./index.md) > [kibana-plugin-plugins-data-server](./kibana-plugin-plugins-data-server.md) > [SearchUsage](./kibana-plugin-plugins-data-server.searchusage.md)
+
+## SearchUsage interface
+
+Signature:
+
+```typescript
+export interface SearchUsage
+```
+
+## Methods
+
+| Method | Description |
+| --- | --- |
+| [trackError()](./kibana-plugin-plugins-data-server.searchusage.trackerror.md) | |
+| [trackSuccess(duration)](./kibana-plugin-plugins-data-server.searchusage.tracksuccess.md) | |
+
diff --git a/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.searchusage.trackerror.md b/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.searchusage.trackerror.md
new file mode 100644
index 00000000000000..212133588f62d5
--- /dev/null
+++ b/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.searchusage.trackerror.md
@@ -0,0 +1,15 @@
+
+
+[Home](./index.md) > [kibana-plugin-plugins-data-server](./kibana-plugin-plugins-data-server.md) > [SearchUsage](./kibana-plugin-plugins-data-server.searchusage.md) > [trackError](./kibana-plugin-plugins-data-server.searchusage.trackerror.md)
+
+## SearchUsage.trackError() method
+
+Signature:
+
+```typescript
+trackError(): Promise;
+```
+Returns:
+
+`Promise`
+
diff --git a/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.searchusage.tracksuccess.md b/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.searchusage.tracksuccess.md
new file mode 100644
index 00000000000000..b58f440c7dccf6
--- /dev/null
+++ b/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.searchusage.tracksuccess.md
@@ -0,0 +1,22 @@
+
+
+[Home](./index.md) > [kibana-plugin-plugins-data-server](./kibana-plugin-plugins-data-server.md) > [SearchUsage](./kibana-plugin-plugins-data-server.searchusage.md) > [trackSuccess](./kibana-plugin-plugins-data-server.searchusage.tracksuccess.md)
+
+## SearchUsage.trackSuccess() method
+
+Signature:
+
+```typescript
+trackSuccess(duration: number): Promise;
+```
+
+## Parameters
+
+| Parameter | Type | Description |
+| --- | --- | --- |
+| duration | number
| |
+
+Returns:
+
+`Promise`
+
diff --git a/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.usageprovider.md b/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.usageprovider.md
new file mode 100644
index 00000000000000..ad5c61b5c85a1c
--- /dev/null
+++ b/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.usageprovider.md
@@ -0,0 +1,22 @@
+
+
+[Home](./index.md) > [kibana-plugin-plugins-data-server](./kibana-plugin-plugins-data-server.md) > [usageProvider](./kibana-plugin-plugins-data-server.usageprovider.md)
+
+## usageProvider() function
+
+Signature:
+
+```typescript
+export declare function usageProvider(core: CoreSetup): SearchUsage;
+```
+
+## Parameters
+
+| Parameter | Type | Description |
+| --- | --- | --- |
+| core | CoreSetup
| |
+
+Returns:
+
+`SearchUsage`
+
diff --git a/src/plugins/data/public/search/collectors/create_usage_collector.test.ts b/src/plugins/data/public/search/collectors/create_usage_collector.test.ts
index a9ca9efb8b7e1a..aaaac5ae6ff7c4 100644
--- a/src/plugins/data/public/search/collectors/create_usage_collector.test.ts
+++ b/src/plugins/data/public/search/collectors/create_usage_collector.test.ts
@@ -90,18 +90,4 @@ describe('Search Usage Collector', () => {
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');
- });
});
diff --git a/src/plugins/data/public/search/collectors/create_usage_collector.ts b/src/plugins/data/public/search/collectors/create_usage_collector.ts
index cb1b2b65c17c84..7adb0c3caa6759 100644
--- a/src/plugins/data/public/search/collectors/create_usage_collector.ts
+++ b/src/plugins/data/public/search/collectors/create_usage_collector.ts
@@ -72,21 +72,5 @@ export const createUsageCollector = (
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,
- }),
- });
- },
};
};
diff --git a/src/plugins/data/public/search/collectors/types.ts b/src/plugins/data/public/search/collectors/types.ts
index bb85532fd3ab59..3e98f901eb0c39 100644
--- a/src/plugins/data/public/search/collectors/types.ts
+++ b/src/plugins/data/public/search/collectors/types.ts
@@ -31,6 +31,4 @@ export interface SearchUsageCollector {
trackLongQueryPopupShown: () => Promise;
trackLongQueryDialogDismissed: () => Promise;
trackLongQueryRunBeyondTimeout: () => Promise;
- trackError: (duration: number) => Promise;
- trackSuccess: (duration: number) => Promise;
}
diff --git a/src/plugins/data/public/search/search_interceptor.ts b/src/plugins/data/public/search/search_interceptor.ts
index 84e24114a9e6c4..21586374d1e512 100644
--- a/src/plugins/data/public/search/search_interceptor.ts
+++ b/src/plugins/data/public/search/search_interceptor.ts
@@ -18,7 +18,7 @@
*/
import { BehaviorSubject, throwError, timer, Subscription, defer, from, Observable } from 'rxjs';
-import { finalize, filter, tap } from 'rxjs/operators';
+import { finalize, filter } from 'rxjs/operators';
import { ApplicationStart, Toast, ToastsStart, CoreStart } from 'kibana/public';
import { getCombinedSignal, AbortError } from '../../common/utils';
import { IEsSearchRequest, IEsSearchResponse } from '../../common/search';
@@ -123,13 +123,6 @@ export class SearchInterceptor {
this.pendingCount$.next(++this.pendingCount);
return this.runSearch(request, combinedSignal).pipe(
- tap({
- next: (e) => {
- if (this.deps.usageCollector) {
- this.deps.usageCollector.trackSuccess(e.rawResponse.took);
- }
- },
- }),
finalize(() => {
this.pendingCount$.next(--this.pendingCount);
cleanup();
diff --git a/src/plugins/data/server/index.ts b/src/plugins/data/server/index.ts
index 461b21e1cc980c..1f3d7fbcb9f0f0 100644
--- a/src/plugins/data/server/index.ts
+++ b/src/plugins/data/server/index.ts
@@ -170,6 +170,8 @@ export {
ISearchStart,
getDefaultSearchParams,
getTotalLoaded,
+ usageProvider,
+ SearchUsage,
} from './search';
// Search namespace
diff --git a/src/plugins/data/server/search/collectors/index.ts b/src/plugins/data/server/search/collectors/index.ts
new file mode 100644
index 00000000000000..417dc1c2012d37
--- /dev/null
+++ b/src/plugins/data/server/search/collectors/index.ts
@@ -0,0 +1,20 @@
+/*
+ * 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 { usageProvider, SearchUsage } from './usage';
diff --git a/src/plugins/data/server/search/collectors/routes.ts b/src/plugins/data/server/search/collectors/routes.ts
deleted file mode 100644
index 38fb517e3c3f66..00000000000000
--- a/src/plugins/data/server/search/collectors/routes.ts
+++ /dev/null
@@ -1,50 +0,0 @@
-/*
- * 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 { schema } from '@kbn/config-schema';
-import { CoreSetup } from '../../../../../core/server';
-import { DataPluginStart } from '../../plugin';
-import { SearchUsage } from './usage';
-
-export function registerSearchUsageRoute(
- core: CoreSetup