Skip to content

Commit 8ce6cc0

Browse files
[Discover] Share profile provider services across Discover instances (elastic#240527)
## Summary This PR updates the Discover context awareness framework to share profile provider services across profiles manager instances. Previously `createProfileProviderServices` was called every time a `ProfilesManager` was instantiated, which happens for each Discover panel in a dashboard. We allow services to perform async work on init, such as hitting an API endpoint to fetch configs, so this could unnecessarily slow down each Discover panel. With these changes we only take the hit once. It also parallelizes some async calls on init to avoid waiting on them sequentially. Before: https://github.com/user-attachments/assets/c1f54c06-8ac5-4a59-99b7-7b91678adaa6 After: https://github.com/user-attachments/assets/3d08eaee-9767-41d4-ac93-3cba52fde471 ### Checklist - [ ] Any text added follows [EUI's writing guidelines](https://elastic.github.io/eui/#/guidelines/writing), uses sentence case text and includes [i18n support](https://github.com/elastic/kibana/blob/main/src/platform/packages/shared/kbn-i18n/README.md) - [ ] [Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html) was added for features that require explanation or tutorials - [x] [Unit or functional tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html) were updated or added to match the most common scenarios - [ ] If a plugin configuration key changed, check if it needs to be allowlisted in the cloud and added to the [docker list](https://github.com/elastic/kibana/blob/main/src/dev/build/tasks/os_packages/docker_generator/resources/base/bin/kibana-docker) - [x] This was checked for breaking HTTP API changes, and any breaking changes have been approved by the breaking-change committee. The `release_note:breaking` label should be applied in these situations. - [ ] [Flaky Test Runner](https://ci-stats.kibana.dev/trigger_flaky_test_runner/1) was used on any tests changed - [x] The PR description includes the appropriate Release Notes section, and the correct `release_note:*` label is applied per the [guidelines](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process) - [x] Review the [backport guidelines](https://docs.google.com/document/d/1VyN5k91e5OVumlc0Gb9RPa3h1ewuPE705nRtioPiTvY/edit?usp=sharing) and apply applicable `backport:*` labels. --------- Co-authored-by: kibanamachine <[email protected]>
1 parent 0a95dc1 commit 8ce6cc0

File tree

22 files changed

+156
-159
lines changed

22 files changed

+156
-159
lines changed

src/platform/plugins/shared/discover/public/__mocks__/services.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ export function createDiscoverServicesMock(): DiscoverServices {
266266
profilesManager: profilesManagerMock,
267267
ebtManager: new DiscoverEBTManager(),
268268
setHeaderActionMenu: jest.fn(),
269-
discoverShared: discoverSharedPluginMock.createStartContract().features,
269+
discoverShared: discoverSharedPluginMock.createStartContract(),
270270
discoverFeatureFlags: {
271271
getTabsEnabled: () => true,
272272
},

src/platform/plugins/shared/discover/public/build_services.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,8 @@ import type { AiopsPluginStart } from '@kbn/aiops-plugin/public';
6262
import type { DataVisualizerPluginStart } from '@kbn/data-visualizer-plugin/public';
6363
import type { FieldsMetadataPublicStart } from '@kbn/fields-metadata-plugin/public';
6464
import type { LogsDataAccessPluginStart } from '@kbn/logs-data-access-plugin/public';
65-
import type { ApmSourceAccessPluginStart } from '@kbn/apm-sources-access-plugin/public';
6665
import type { DiscoverSharedPublicStart } from '@kbn/discover-shared-plugin/public';
6766
import type { EmbeddableEnhancedPluginStart } from '@kbn/embeddable-enhanced-plugin/public';
68-
import type { MetricsExperiencePluginStart } from '@kbn/metrics-experience-plugin/public';
6967
import type { DiscoverStartPlugins } from './types';
7068
import type { DiscoverContextAppLocator } from './application/context/services/locator';
7169
import type { DiscoverSingleDocLocator } from './application/doc/locator';
@@ -152,8 +150,6 @@ export interface DiscoverServices {
152150
fieldsMetadata?: FieldsMetadataPublicStart;
153151
logsDataAccess?: LogsDataAccessPluginStart;
154152
embeddableEnhanced?: EmbeddableEnhancedPluginStart;
155-
apmSourcesAccess?: ApmSourceAccessPluginStart;
156-
metricsExperience?: MetricsExperiencePluginStart;
157153
}
158154

159155
export const buildServices = ({
@@ -251,7 +247,5 @@ export const buildServices = ({
251247
fieldsMetadata: plugins.fieldsMetadata,
252248
logsDataAccess: plugins.logsDataAccess,
253249
embeddableEnhanced: plugins.embeddableEnhanced,
254-
apmSourcesAccess: plugins.apmSourcesAccess,
255-
metricsExperience: plugins.metricsExperience,
256250
};
257251
};

src/platform/plugins/shared/discover/public/context_awareness/__mocks__/context_awareness.tsx

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,8 @@ import {
2323
RootProfileService,
2424
SolutionType,
2525
} from '../profiles';
26-
import type { ProfileProviderServices } from '../profile_providers/profile_provider_services';
2726
import { ProfilesManager } from '../profiles_manager';
2827
import { DiscoverEBTManager } from '../../ebt_manager';
29-
import {
30-
createApmContextServiceMock,
31-
createLogsContextServiceMock,
32-
createMetricsContextServiceMock,
33-
} from '@kbn/discover-utils/src/__mocks__';
34-
import { discoverSharedPluginMock } from '@kbn/discover-shared-plugin/public/mocks';
35-
import { pricingServiceMock } from '@kbn/core-pricing-browser-mocks';
3628

3729
export const FEATURE_ID_1 = 'discover:feature1';
3830
export const FEATURE_ID_2 = 'discover:feature2';
@@ -182,8 +174,6 @@ export const createContextAwarenessMocks = ({
182174
documentProfileServiceMock
183175
);
184176

185-
const profileProviderServices = createProfileProviderServicesMock();
186-
187177
return {
188178
rootProfileProviderMock,
189179
dataSourceProfileProviderMock,
@@ -194,24 +184,6 @@ export const createContextAwarenessMocks = ({
194184
contextRecordMock,
195185
contextRecordMock2,
196186
profilesManagerMock,
197-
profileProviderServices,
198187
scopedEbtManagerMock,
199188
};
200189
};
201-
202-
const createProfileProviderServicesMock = () => {
203-
return {
204-
logsContextService: createLogsContextServiceMock(),
205-
discoverShared: discoverSharedPluginMock.createStartContract(),
206-
apmContextService: createApmContextServiceMock(),
207-
metricsContextService: createMetricsContextServiceMock(),
208-
core: {
209-
pricing: pricingServiceMock.createStartContract() as ReturnType<
210-
typeof pricingServiceMock.createStartContract
211-
>,
212-
featureFlags: {
213-
getBooleanValue: jest.fn().mockReturnValue(true),
214-
},
215-
},
216-
} as unknown as ProfileProviderServices;
217-
};

src/platform/plugins/shared/discover/public/context_awareness/__mocks__/index.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,6 @@
88
*/
99

1010
export * from './context_awareness';
11+
export * from './profile_provider_services';
1112
export * from './data_table_record_with_context';
1213
export * from './profiles';
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the "Elastic License
4+
* 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side
5+
* Public License v 1"; you may not use this file except in compliance with, at
6+
* your election, the "Elastic License 2.0", the "GNU Affero General Public
7+
* License v3.0 only", or the "Server Side Public License, v 1".
8+
*/
9+
10+
import {
11+
createApmContextServiceMock,
12+
createLogsContextServiceMock,
13+
createMetricsContextServiceMock,
14+
} from '@kbn/discover-utils/src/__mocks__';
15+
import type { ProfileProviderServices } from '../profile_providers';
16+
import { createDiscoverServicesMock } from '../../__mocks__/services';
17+
18+
export const createProfileProviderSharedServicesMock = (
19+
discoverServices = createDiscoverServicesMock()
20+
): ProfileProviderServices => ({
21+
...discoverServices,
22+
logsContextService: createLogsContextServiceMock(),
23+
apmContextService: createApmContextServiceMock(),
24+
metricsContextService: createMetricsContextServiceMock(),
25+
});

src/platform/plugins/shared/discover/public/context_awareness/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ export {
1616
ContextualProfileLevel,
1717
type GetProfilesOptions,
1818
} from './profiles_manager';
19+
export { type ProfileProviderSharedServices } from './profile_providers';
1920
export {
2021
useProfileAccessor,
2122
useRootProfile,

src/platform/plugins/shared/discover/public/context_awareness/profile_providers/common/classic_nav_root_profile/profile.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@
88
*/
99

1010
import { SolutionType } from '../../../profiles';
11-
import { createContextAwarenessMocks } from '../../../__mocks__';
11+
import { createProfileProviderSharedServicesMock } from '../../../__mocks__';
1212
import { createClassicNavRootProfileProvider } from './profile';
1313

14-
const mockServices = createContextAwarenessMocks().profileProviderServices;
14+
const mockServices = createProfileProviderSharedServicesMock();
1515

1616
describe('classicNavRootProfileProvider', () => {
1717
const classicNavRootProfileProvider = createClassicNavRootProfileProvider(mockServices);

src/platform/plugins/shared/discover/public/context_awareness/profile_providers/common/metrics_data_source_profile/profile.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@
99
import { DataSourceType } from '../../../../../common/data_sources';
1010
import type { MetricsExperienceDataSourceProfileProvider } from './profile';
1111
import { METRICS_DATA_SOURCE_PROFILE_ID, createMetricsDataSourceProfileProvider } from './profile';
12-
import { createContextAwarenessMocks } from '../../../__mocks__';
12+
import { createProfileProviderSharedServicesMock } from '../../../__mocks__';
1313
import type { ContextWithProfileId } from '../../../profile_service';
1414
import type { MetricsExperienceClient } from '@kbn/metrics-experience-plugin/public';
1515
import type { DataSourceProfileProviderParams, RootContext } from '../../../profiles';
1616
import { DataSourceCategory, SolutionType } from '../../../profiles';
1717

18-
const mockServices = createContextAwarenessMocks().profileProviderServices;
18+
const mockServices = createProfileProviderSharedServicesMock();
1919

2020
const RESOLUTION_MATCH = {
2121
isMatch: true,

src/platform/plugins/shared/discover/public/context_awareness/profile_providers/index.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,9 @@
77
* License v3.0 only", or the "Server Side Public License, v 1".
88
*/
99

10+
export {
11+
type ProfileProviderSharedServices,
12+
type ProfileProviderServices,
13+
createProfileProviderSharedServices,
14+
} from './profile_provider_services';
1015
export { registerProfileProviders } from './register_profile_providers';

src/platform/plugins/shared/discover/public/context_awareness/profile_providers/observability/log_document_profile/profile.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@ import type {
1515
RootContext,
1616
} from '../../../profiles';
1717
import { DataSourceCategory, SolutionType } from '../../../profiles';
18-
import { createContextAwarenessMocks } from '../../../__mocks__';
18+
import { createProfileProviderSharedServicesMock } from '../../../__mocks__';
1919
import { createObservabilityLogDocumentProfileProvider } from './profile';
2020
import type { ContextWithProfileId } from '../../../profile_service';
2121
import { OBSERVABILITY_ROOT_PROFILE_ID } from '../consts';
2222
import { RESOLUTION_MATCH } from './__mocks__';
2323

24-
const mockServices = createContextAwarenessMocks().profileProviderServices;
24+
const mockServices = createProfileProviderSharedServicesMock();
2525

2626
describe('logDocumentProfileProvider', () => {
2727
const logDocumentProfileProvider = createObservabilityLogDocumentProfileProvider(mockServices);

0 commit comments

Comments
 (0)