From be14769c4980d818696db4398715a4a4fb1af3de Mon Sep 17 00:00:00 2001 From: Alexey Antonov Date: Fri, 30 Apr 2021 16:16:54 +0300 Subject: [PATCH 1/7] [TSVB] Expensive queries are causing unnecessary load and delays on Elasticsearch Part of: #93770 --- .../get_usage_collector.test.ts | 32 ++---- .../usage_collector/get_usage_collector.ts | 102 +++++++++--------- .../register_timeseries_collector.test.ts | 19 +--- .../register_timeseries_collector.ts | 13 +-- 4 files changed, 69 insertions(+), 97 deletions(-) diff --git a/src/plugins/vis_type_timeseries/server/usage_collector/get_usage_collector.test.ts b/src/plugins/vis_type_timeseries/server/usage_collector/get_usage_collector.test.ts index 8ecc02072905f..6769b76e84941 100644 --- a/src/plugins/vis_type_timeseries/server/usage_collector/get_usage_collector.test.ts +++ b/src/plugins/vis_type_timeseries/server/usage_collector/get_usage_collector.test.ts @@ -9,6 +9,7 @@ import { getStats } from './get_usage_collector'; import { createCollectorFetchContextMock } from 'src/plugins/usage_collection/server/mocks'; import { TIME_RANGE_DATA_MODES } from '../../common/timerange_data_modes'; +import { SavedObjectsClientContract } from 'kibana/server'; const mockedSavedObjects = [ { @@ -94,23 +95,20 @@ const mockedSavedObjectsByValue = [ const getMockCollectorFetchContext = (hits?: unknown[], savedObjectsByValue: unknown[] = []) => { const fetchParamsMock = createCollectorFetchContextMock(); - fetchParamsMock.esClient.search = jest.fn().mockResolvedValue({ body: { hits: { hits } } }); - fetchParamsMock.soClient.find = jest.fn().mockResolvedValue({ - saved_objects: savedObjectsByValue, - }); + fetchParamsMock.soClient = ({ + createPointInTimeFinder: jest.fn().mockResolvedValue({ + find: function* asyncGenerator() { + yield savedObjectsByValue; + }, + }), + } as unknown) as SavedObjectsClientContract; return fetchParamsMock; }; describe('Timeseries visualization usage collector', () => { - const mockIndex = 'mock_index'; - test('Returns undefined when no results found (undefined)', async () => { const mockCollectorFetchContext = getMockCollectorFetchContext([], []); - const result = await getStats( - mockCollectorFetchContext.esClient, - mockCollectorFetchContext.soClient, - mockIndex - ); + const result = await getStats(mockCollectorFetchContext.soClient); expect(result).toBeUndefined(); }); @@ -141,11 +139,7 @@ describe('Timeseries visualization usage collector', () => { }, ] ); - const result = await getStats( - mockCollectorFetchContext.esClient, - mockCollectorFetchContext.soClient, - mockIndex - ); + const result = await getStats(mockCollectorFetchContext.soClient); expect(result).toBeUndefined(); }); @@ -155,11 +149,7 @@ describe('Timeseries visualization usage collector', () => { mockedSavedObjects, mockedSavedObjectsByValue ); - const result = await getStats( - mockCollectorFetchContext.esClient, - mockCollectorFetchContext.soClient, - mockIndex - ); + const result = await getStats(mockCollectorFetchContext.soClient); expect(result).toMatchObject({ timeseries_use_last_value_mode_total: 3, diff --git a/src/plugins/vis_type_timeseries/server/usage_collector/get_usage_collector.ts b/src/plugins/vis_type_timeseries/server/usage_collector/get_usage_collector.ts index c1a8715f72227..12470f1a9a6cb 100644 --- a/src/plugins/vis_type_timeseries/server/usage_collector/get_usage_collector.ts +++ b/src/plugins/vis_type_timeseries/server/usage_collector/get_usage_collector.ts @@ -6,49 +6,69 @@ * Side Public License, v 1. */ -import { ElasticsearchClient } from 'src/core/server'; -import { SavedObjectsClientContract, ISavedObjectsRepository } from 'kibana/server'; +import { + SavedObjectsClientContract, + ISavedObjectsRepository, + SavedObjectsFindResult, +} from 'kibana/server'; import { TIME_RANGE_DATA_MODES } from '../../common/timerange_data_modes'; import { findByValueEmbeddables } from '../../../dashboard/server'; +import { SavedVisState } from '../../../visualizations/common'; + +// elasticsearch index.max_result_window default value +const ES_MAX_RESULT_WINDOW_DEFAULT_VALUE = 1000; export interface TimeseriesUsage { timeseries_use_last_value_mode_total: number; } -interface VisState { - type?: string; - params?: any; -} +const doTelemetryFoVisualizations = async ( + soClient: SavedObjectsClientContract | ISavedObjectsRepository, + telemetryUseLastValueMode: (savedVis: SavedVisState) => void +) => { + const finder = await soClient.createPointInTimeFinder({ + type: 'visualization', + perPage: ES_MAX_RESULT_WINDOW_DEFAULT_VALUE, + }); -export const getStats = async ( - esClient: ElasticsearchClient, + for await (const response of finder.find()) { + (response.saved_objects || []).forEach(({ attributes }: SavedObjectsFindResult) => { + if (attributes?.visState) { + try { + const visState: SavedVisState = JSON.parse(attributes.visState); + + telemetryUseLastValueMode(visState); + } catch { + // nothing to be here, "so" not valid + } + } + }); + + if (!response.saved_objects.length) { + await finder.close(); + } + } +}; + +const doTelemetryForByValueVisualizations = async ( soClient: SavedObjectsClientContract | ISavedObjectsRepository, - index: string + telemetryUseLastValueMode: (savedVis: SavedVisState) => void +) => { + const byValueVisualizations = await findByValueEmbeddables(soClient, 'visualization'); + + for (const item of byValueVisualizations) { + telemetryUseLastValueMode(item.savedVis as SavedVisState); + } +}; + +export const getStats = async ( + soClient: SavedObjectsClientContract | ISavedObjectsRepository ): Promise => { const timeseriesUsage = { timeseries_use_last_value_mode_total: 0, }; - const searchParams = { - size: 10000, - index, - ignoreUnavailable: true, - filterPath: ['hits.hits._id', 'hits.hits._source.visualization'], - body: { - query: { - bool: { - filter: { term: { type: 'visualization' } }, - }, - }, - }, - }; - - const { body: esResponse } = await esClient.search<{ - visualization: { visState: string }; - updated_at: string; - }>(searchParams); - - function telemetryUseLastValueMode(visState: VisState) { + function telemetryUseLastValueMode(visState: SavedVisState) { if ( visState.type === 'metrics' && visState.params.type !== 'timeseries' && @@ -59,28 +79,8 @@ export const getStats = async ( } } - if (esResponse?.hits?.hits?.length) { - for (const hit of esResponse.hits.hits) { - if (hit._source && 'visualization' in hit._source) { - const { visualization } = hit._source!; - - let visState: VisState = {}; - try { - visState = JSON.parse(visualization?.visState ?? '{}'); - } catch (e) { - // invalid visState - } - - telemetryUseLastValueMode(visState); - } - } - } - - const byValueVisualizations = await findByValueEmbeddables(soClient, 'visualization'); - - for (const item of byValueVisualizations) { - telemetryUseLastValueMode(item.savedVis as VisState); - } + await doTelemetryFoVisualizations(soClient, telemetryUseLastValueMode); + await doTelemetryForByValueVisualizations(soClient, telemetryUseLastValueMode); return timeseriesUsage.timeseries_use_last_value_mode_total ? timeseriesUsage : undefined; }; diff --git a/src/plugins/vis_type_timeseries/server/usage_collector/register_timeseries_collector.test.ts b/src/plugins/vis_type_timeseries/server/usage_collector/register_timeseries_collector.test.ts index 726ad972ab8d1..881aa260b2bb7 100644 --- a/src/plugins/vis_type_timeseries/server/usage_collector/register_timeseries_collector.test.ts +++ b/src/plugins/vis_type_timeseries/server/usage_collector/register_timeseries_collector.test.ts @@ -6,27 +6,22 @@ * Side Public License, v 1. */ -import { of } from 'rxjs'; import { mockStats, mockGetStats } from './get_usage_collector.mock'; import { createUsageCollectionSetupMock } from 'src/plugins/usage_collection/server/mocks'; import { createCollectorFetchContextMock } from 'src/plugins/usage_collection/server/mocks'; import { registerTimeseriesUsageCollector } from './register_timeseries_collector'; -import { ConfigObservable } from '../types'; describe('registerTimeseriesUsageCollector', () => { - const mockIndex = 'mock_index'; - const mockConfig = of({ kibana: { index: mockIndex } }) as ConfigObservable; - it('makes a usage collector and registers it`', () => { const mockCollectorSet = createUsageCollectionSetupMock(); - registerTimeseriesUsageCollector(mockCollectorSet, mockConfig); + registerTimeseriesUsageCollector(mockCollectorSet); expect(mockCollectorSet.makeUsageCollector).toBeCalledTimes(1); expect(mockCollectorSet.registerCollector).toBeCalledTimes(1); }); it('makeUsageCollector configs fit the shape', () => { const mockCollectorSet = createUsageCollectionSetupMock(); - registerTimeseriesUsageCollector(mockCollectorSet, mockConfig); + registerTimeseriesUsageCollector(mockCollectorSet); expect(mockCollectorSet.makeUsageCollector).toHaveBeenCalledWith({ type: 'vis_type_timeseries', isReady: expect.any(Function), @@ -39,23 +34,19 @@ describe('registerTimeseriesUsageCollector', () => { it('makeUsageCollector config.isReady returns true', () => { const mockCollectorSet = createUsageCollectionSetupMock(); - registerTimeseriesUsageCollector(mockCollectorSet, mockConfig); + registerTimeseriesUsageCollector(mockCollectorSet); const usageCollectorConfig = mockCollectorSet.makeUsageCollector.mock.calls[0][0]; expect(usageCollectorConfig.isReady()).toBe(true); }); it('makeUsageCollector config.fetch calls getStats', async () => { const mockCollectorSet = createUsageCollectionSetupMock(); - registerTimeseriesUsageCollector(mockCollectorSet, mockConfig); + registerTimeseriesUsageCollector(mockCollectorSet); const usageCollector = mockCollectorSet.makeUsageCollector.mock.results[0].value; const mockedCollectorFetchContext = createCollectorFetchContextMock(); const fetchResult = await usageCollector.fetch(mockedCollectorFetchContext); expect(mockGetStats).toBeCalledTimes(1); - expect(mockGetStats).toBeCalledWith( - mockedCollectorFetchContext.esClient, - mockedCollectorFetchContext.soClient, - mockIndex - ); + expect(mockGetStats).toBeCalledWith(mockedCollectorFetchContext.soClient); expect(fetchResult).toBe(mockStats); }); }); diff --git a/src/plugins/vis_type_timeseries/server/usage_collector/register_timeseries_collector.ts b/src/plugins/vis_type_timeseries/server/usage_collector/register_timeseries_collector.ts index 5edeb6654020e..1094d0d2969bc 100644 --- a/src/plugins/vis_type_timeseries/server/usage_collector/register_timeseries_collector.ts +++ b/src/plugins/vis_type_timeseries/server/usage_collector/register_timeseries_collector.ts @@ -7,14 +7,9 @@ */ import { UsageCollectionSetup } from 'src/plugins/usage_collection/server'; -import { first } from 'rxjs/operators'; import { getStats, TimeseriesUsage } from './get_usage_collector'; -import { ConfigObservable } from '../types'; -export function registerTimeseriesUsageCollector( - collectorSet: UsageCollectionSetup, - config: ConfigObservable -) { +export function registerTimeseriesUsageCollector(collectorSet: UsageCollectionSetup) { const collector = collectorSet.makeUsageCollector({ type: 'vis_type_timeseries', isReady: () => true, @@ -24,11 +19,7 @@ export function registerTimeseriesUsageCollector( _meta: { description: 'Number of TSVB visualizations using "last value" as a time range' }, }, }, - fetch: async ({ esClient, soClient }) => { - const { index } = (await config.pipe(first()).toPromise()).kibana; - - return await getStats(esClient, soClient, index); - }, + fetch: async ({ soClient }) => await getStats(soClient), }); collectorSet.registerCollector(collector); From f4476aadcce77fe4343322f5aded0a7e68d9155b Mon Sep 17 00:00:00 2001 From: Alexey Antonov Date: Fri, 30 Apr 2021 17:11:29 +0300 Subject: [PATCH 2/7] remove globalConfig --- src/plugins/vis_type_timeseries/server/plugin.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/plugins/vis_type_timeseries/server/plugin.ts b/src/plugins/vis_type_timeseries/server/plugin.ts index 93fd39528e70e..4f3897698029e 100644 --- a/src/plugins/vis_type_timeseries/server/plugin.ts +++ b/src/plugins/vis_type_timeseries/server/plugin.ts @@ -120,7 +120,7 @@ export class VisTypeTimeseriesPlugin implements Plugin { fieldsRoutes(router, framework); if (plugins.usageCollection) { - registerTimeseriesUsageCollector(plugins.usageCollection, globalConfig$); + registerTimeseriesUsageCollector(plugins.usageCollection); } return { From 4a73c1c43dd02e1c7817ef679105c7dcd8044ecb Mon Sep 17 00:00:00 2001 From: Alexey Antonov Date: Fri, 30 Apr 2021 18:58:12 +0300 Subject: [PATCH 3/7] fix tests --- .../get_usage_collector.test.ts | 67 +++++++++---------- .../usage_collector/get_usage_collector.ts | 7 +- 2 files changed, 33 insertions(+), 41 deletions(-) diff --git a/src/plugins/vis_type_timeseries/server/usage_collector/get_usage_collector.test.ts b/src/plugins/vis_type_timeseries/server/usage_collector/get_usage_collector.test.ts index 6769b76e84941..c5c1dc75ba528 100644 --- a/src/plugins/vis_type_timeseries/server/usage_collector/get_usage_collector.test.ts +++ b/src/plugins/vis_type_timeseries/server/usage_collector/get_usage_collector.test.ts @@ -9,14 +9,12 @@ import { getStats } from './get_usage_collector'; import { createCollectorFetchContextMock } from 'src/plugins/usage_collection/server/mocks'; import { TIME_RANGE_DATA_MODES } from '../../common/timerange_data_modes'; -import { SavedObjectsClientContract } from 'kibana/server'; +import { SavedObjectsClientContract, SavedObjectsFindResponse } from 'kibana/server'; -const mockedSavedObjects = [ - { - _id: 'visualization:timeseries-123', - _source: { - type: 'visualization', - visualization: { +const mockedSavedObject = { + saved_objects: [ + { + attributes: { visState: JSON.stringify({ type: 'metrics', title: 'TSVB visualization 1', @@ -26,12 +24,8 @@ const mockedSavedObjects = [ }), }, }, - }, - { - _id: 'visualization:timeseries-321', - _source: { - type: 'visualization', - visualization: { + { + attributes: { visState: JSON.stringify({ type: 'metrics', title: 'TSVB visualization 2', @@ -41,12 +35,8 @@ const mockedSavedObjects = [ }), }, }, - }, - { - _id: 'visualization:timeseries-456', - _source: { - type: 'visualization', - visualization: { + { + attributes: { visState: JSON.stringify({ type: 'metrics', title: 'TSVB visualization 3', @@ -56,8 +46,8 @@ const mockedSavedObjects = [ }), }, }, - }, -]; + ], +} as SavedObjectsFindResponse; const mockedSavedObjectsByValue = [ { @@ -92,13 +82,20 @@ const mockedSavedObjectsByValue = [ }, ]; -const getMockCollectorFetchContext = (hits?: unknown[], savedObjectsByValue: unknown[] = []) => { +const getMockCollectorFetchContext = ( + savedObjects: SavedObjectsFindResponse, + savedObjectsByValue: unknown[] = [] +) => { const fetchParamsMock = createCollectorFetchContextMock(); fetchParamsMock.soClient = ({ + find: jest.fn().mockResolvedValue({ + saved_objects: savedObjectsByValue, + }), createPointInTimeFinder: jest.fn().mockResolvedValue({ + close: jest.fn(), find: function* asyncGenerator() { - yield savedObjectsByValue; + yield savedObjects; }, }), } as unknown) as SavedObjectsClientContract; @@ -107,24 +104,21 @@ const getMockCollectorFetchContext = (hits?: unknown[], savedObjectsByValue: unk describe('Timeseries visualization usage collector', () => { test('Returns undefined when no results found (undefined)', async () => { - const mockCollectorFetchContext = getMockCollectorFetchContext([], []); + const mockCollectorFetchContext = getMockCollectorFetchContext( + ({ saved_objects: [] } as unknown) as SavedObjectsFindResponse, + [] + ); const result = await getStats(mockCollectorFetchContext.soClient); expect(result).toBeUndefined(); }); test('Returns undefined when no timeseries saved objects found', async () => { - const mockCollectorFetchContext = getMockCollectorFetchContext( - [ + const mockCollectorFetchContext = getMockCollectorFetchContext({ + saved_objects: [ { - _id: 'visualization:myvis-123', - _source: { - type: 'visualization', - visualization: { visState: '{"type": "area"}' }, - }, + attributes: { visState: '{"type": "area"}' }, }, - ], - [ { attributes: { panelsJSON: JSON.stringify({ @@ -137,8 +131,9 @@ describe('Timeseries visualization usage collector', () => { }), }, }, - ] - ); + ], + } as SavedObjectsFindResponse); + const result = await getStats(mockCollectorFetchContext.soClient); expect(result).toBeUndefined(); @@ -146,7 +141,7 @@ describe('Timeseries visualization usage collector', () => { test('Summarizes visualizations response data', async () => { const mockCollectorFetchContext = getMockCollectorFetchContext( - mockedSavedObjects, + mockedSavedObject, mockedSavedObjectsByValue ); const result = await getStats(mockCollectorFetchContext.soClient); diff --git a/src/plugins/vis_type_timeseries/server/usage_collector/get_usage_collector.ts b/src/plugins/vis_type_timeseries/server/usage_collector/get_usage_collector.ts index 12470f1a9a6cb..4296111951612 100644 --- a/src/plugins/vis_type_timeseries/server/usage_collector/get_usage_collector.ts +++ b/src/plugins/vis_type_timeseries/server/usage_collector/get_usage_collector.ts @@ -15,9 +15,6 @@ import { TIME_RANGE_DATA_MODES } from '../../common/timerange_data_modes'; import { findByValueEmbeddables } from '../../../dashboard/server'; import { SavedVisState } from '../../../visualizations/common'; -// elasticsearch index.max_result_window default value -const ES_MAX_RESULT_WINDOW_DEFAULT_VALUE = 1000; - export interface TimeseriesUsage { timeseries_use_last_value_mode_total: number; } @@ -28,7 +25,7 @@ const doTelemetryFoVisualizations = async ( ) => { const finder = await soClient.createPointInTimeFinder({ type: 'visualization', - perPage: ES_MAX_RESULT_WINDOW_DEFAULT_VALUE, + perPage: 1000, }); for await (const response of finder.find()) { @@ -44,7 +41,7 @@ const doTelemetryFoVisualizations = async ( } }); - if (!response.saved_objects.length) { + if (!response.saved_objects.length || response.total === response.saved_objects.length) { await finder.close(); } } From 7dae80b04571ce65df46a99dd14d7023881d20e8 Mon Sep 17 00:00:00 2001 From: Alexey Antonov Date: Mon, 3 May 2021 10:55:15 +0300 Subject: [PATCH 4/7] fix finder.close --- .../server/usage_collector/get_usage_collector.ts | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/plugins/vis_type_timeseries/server/usage_collector/get_usage_collector.ts b/src/plugins/vis_type_timeseries/server/usage_collector/get_usage_collector.ts index 4296111951612..0a489cfc49c2f 100644 --- a/src/plugins/vis_type_timeseries/server/usage_collector/get_usage_collector.ts +++ b/src/plugins/vis_type_timeseries/server/usage_collector/get_usage_collector.ts @@ -40,11 +40,8 @@ const doTelemetryFoVisualizations = async ( } } }); - - if (!response.saved_objects.length || response.total === response.saved_objects.length) { - await finder.close(); - } } + await finder.close(); }; const doTelemetryForByValueVisualizations = async ( From bf17be898447834486e0ecb0cb853dab6df2c1f6 Mon Sep 17 00:00:00 2001 From: Alexey Antonov Date: Mon, 3 May 2021 12:31:59 +0300 Subject: [PATCH 5/7] cleanup code --- .../usage_collector/get_usage_collector.test.ts | 4 ++-- .../server/usage_collector/get_usage_collector.ts | 11 ++++++----- .../register_timeseries_collector.test.ts | 4 ++-- .../usage_collector/register_timeseries_collector.ts | 2 +- 4 files changed, 11 insertions(+), 10 deletions(-) diff --git a/src/plugins/vis_type_timeseries/server/usage_collector/get_usage_collector.test.ts b/src/plugins/vis_type_timeseries/server/usage_collector/get_usage_collector.test.ts index c5c1dc75ba528..8c2a22e1cd9f4 100644 --- a/src/plugins/vis_type_timeseries/server/usage_collector/get_usage_collector.test.ts +++ b/src/plugins/vis_type_timeseries/server/usage_collector/get_usage_collector.test.ts @@ -7,9 +7,9 @@ */ import { getStats } from './get_usage_collector'; -import { createCollectorFetchContextMock } from 'src/plugins/usage_collection/server/mocks'; +import { createCollectorFetchContextMock } from '../../../usage_collection/server/mocks'; import { TIME_RANGE_DATA_MODES } from '../../common/timerange_data_modes'; -import { SavedObjectsClientContract, SavedObjectsFindResponse } from 'kibana/server'; +import type { SavedObjectsClientContract, SavedObjectsFindResponse } from '../../../../core/server'; const mockedSavedObject = { saved_objects: [ diff --git a/src/plugins/vis_type_timeseries/server/usage_collector/get_usage_collector.ts b/src/plugins/vis_type_timeseries/server/usage_collector/get_usage_collector.ts index 0a489cfc49c2f..9c8ba583c3542 100644 --- a/src/plugins/vis_type_timeseries/server/usage_collector/get_usage_collector.ts +++ b/src/plugins/vis_type_timeseries/server/usage_collector/get_usage_collector.ts @@ -6,14 +6,15 @@ * Side Public License, v 1. */ -import { +import { TIME_RANGE_DATA_MODES } from '../../common/timerange_data_modes'; +import { findByValueEmbeddables } from '../../../dashboard/server'; + +import type { SavedObjectsClientContract, ISavedObjectsRepository, SavedObjectsFindResult, -} from 'kibana/server'; -import { TIME_RANGE_DATA_MODES } from '../../common/timerange_data_modes'; -import { findByValueEmbeddables } from '../../../dashboard/server'; -import { SavedVisState } from '../../../visualizations/common'; +} from '../../../../core/server'; +import type { SavedVisState } from '../../../visualizations/common'; export interface TimeseriesUsage { timeseries_use_last_value_mode_total: number; diff --git a/src/plugins/vis_type_timeseries/server/usage_collector/register_timeseries_collector.test.ts b/src/plugins/vis_type_timeseries/server/usage_collector/register_timeseries_collector.test.ts index 881aa260b2bb7..0dfe5ae5f9351 100644 --- a/src/plugins/vis_type_timeseries/server/usage_collector/register_timeseries_collector.test.ts +++ b/src/plugins/vis_type_timeseries/server/usage_collector/register_timeseries_collector.test.ts @@ -7,8 +7,8 @@ */ import { mockStats, mockGetStats } from './get_usage_collector.mock'; -import { createUsageCollectionSetupMock } from 'src/plugins/usage_collection/server/mocks'; -import { createCollectorFetchContextMock } from 'src/plugins/usage_collection/server/mocks'; +import { createUsageCollectionSetupMock } from '../../../usage_collection/server/mocks'; +import { createCollectorFetchContextMock } from '../../../usage_collection/server/mocks'; import { registerTimeseriesUsageCollector } from './register_timeseries_collector'; describe('registerTimeseriesUsageCollector', () => { diff --git a/src/plugins/vis_type_timeseries/server/usage_collector/register_timeseries_collector.ts b/src/plugins/vis_type_timeseries/server/usage_collector/register_timeseries_collector.ts index 1094d0d2969bc..7e9294f03ba1c 100644 --- a/src/plugins/vis_type_timeseries/server/usage_collector/register_timeseries_collector.ts +++ b/src/plugins/vis_type_timeseries/server/usage_collector/register_timeseries_collector.ts @@ -6,8 +6,8 @@ * Side Public License, v 1. */ -import { UsageCollectionSetup } from 'src/plugins/usage_collection/server'; import { getStats, TimeseriesUsage } from './get_usage_collector'; +import type { UsageCollectionSetup } from '../../../usage_collection/server'; export function registerTimeseriesUsageCollector(collectorSet: UsageCollectionSetup) { const collector = collectorSet.makeUsageCollector({ From 6fe3164ee7efafecf7fb7d9bcf05c7798d875b30 Mon Sep 17 00:00:00 2001 From: Alexey Antonov Date: Tue, 4 May 2021 11:30:50 +0300 Subject: [PATCH 6/7] run queries concurrently --- .../server/usage_collector/get_usage_collector.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/plugins/vis_type_timeseries/server/usage_collector/get_usage_collector.ts b/src/plugins/vis_type_timeseries/server/usage_collector/get_usage_collector.ts index 9c8ba583c3542..6dbf1df91f511 100644 --- a/src/plugins/vis_type_timeseries/server/usage_collector/get_usage_collector.ts +++ b/src/plugins/vis_type_timeseries/server/usage_collector/get_usage_collector.ts @@ -74,8 +74,10 @@ export const getStats = async ( } } - await doTelemetryFoVisualizations(soClient, telemetryUseLastValueMode); - await doTelemetryForByValueVisualizations(soClient, telemetryUseLastValueMode); + await Promise.all([ + doTelemetryFoVisualizations(soClient, telemetryUseLastValueMode), + doTelemetryForByValueVisualizations(soClient, telemetryUseLastValueMode), + ]); return timeseriesUsage.timeseries_use_last_value_mode_total ? timeseriesUsage : undefined; }; From 412f767719940a076dee62523620af03b76f418f Mon Sep 17 00:00:00 2001 From: Alexey Antonov Date: Fri, 27 Aug 2021 16:04:11 +0300 Subject: [PATCH 7/7] add namespaces: ['*'], --- .../server/usage_collector/get_usage_collector.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/plugins/vis_type_timeseries/server/usage_collector/get_usage_collector.ts b/src/plugins/vis_type_timeseries/server/usage_collector/get_usage_collector.ts index 054421c4c616a..b5b22e06b51c9 100644 --- a/src/plugins/vis_type_timeseries/server/usage_collector/get_usage_collector.ts +++ b/src/plugins/vis_type_timeseries/server/usage_collector/get_usage_collector.ts @@ -27,6 +27,7 @@ const doTelemetryFoVisualizations = async ( const finder = await soClient.createPointInTimeFinder({ type: 'visualization', perPage: 1000, + namespaces: ['*'], }); for await (const response of finder.find()) { @@ -52,7 +53,7 @@ const doTelemetryForByValueVisualizations = async ( const byValueVisualizations = await findByValueEmbeddables(soClient, 'visualization'); for (const item of byValueVisualizations) { - telemetryUseLastValueMode(item.savedVis as SavedVisState); + telemetryUseLastValueMode((item.savedVis as unknown) as SavedVisState); } };