kibana/x-pack/plugins/observability_shared/public/plugin.ts
Cauê Marcondes 98d2766de8
[Profiling-APM] Removing Profiling dependency from APM (#166253)
This PR removes the Profiling dependency from APM, introduced on `8.10`.

- Exposes a new service in profiling-data-access plugin
- Create a new APM API that calls the new service and checks if
Profiling is initialized
- Move Locators from the Profiling plugin to the Observability-shared
plugin
- Move logic to check Profiling status (has_setup/has_data...) from
Profiling server to profiling-data-access plugin
- Create API tests, testing the status services based on different
scenarios:
  - When profiling hasn't been initialized and there's no data
  - When profiling is initialized but has no data
  - When collector integration is not installed
  - When symbolized integration is not installed
  - When APM server integration is not found

---------

Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
2023-09-22 09:16:48 +01:00

91 lines
3.5 KiB
TypeScript

/*
* 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; you may not use this file except in compliance with the Elastic License
* 2.0.
*/
import { BehaviorSubject } from 'rxjs';
import type { CoreStart, Plugin, CoreSetup } from '@kbn/core/public';
import type { GuidedOnboardingPluginStart } from '@kbn/guided-onboarding-plugin/public';
import { CasesUiStart } from '@kbn/cases-plugin/public';
import { SpacesPluginStart } from '@kbn/spaces-plugin/public';
import type { EmbeddableStart } from '@kbn/embeddable-plugin/public';
import type { SharePluginSetup, SharePluginStart } from '@kbn/share-plugin/public';
import { createNavigationRegistry } from './components/page_template/helpers/navigation_registry';
import { createLazyObservabilityPageTemplate } from './components/page_template';
import { updateGlobalNavigation } from './services/update_global_navigation';
import { FlamegraphLocatorDefinition } from './locators/profiling/flamegraph_locator';
import { TopNFunctionsLocatorDefinition } from './locators/profiling/topn_functions_locator';
import { StacktracesLocatorDefinition } from './locators/profiling/stacktraces_locator';
export interface ObservabilitySharedSetup {
share: SharePluginSetup;
}
export interface ObservabilitySharedStart {
spaces?: SpacesPluginStart;
cases: CasesUiStart;
guidedOnboarding: GuidedOnboardingPluginStart;
setIsSidebarEnabled: (isEnabled: boolean) => void;
embeddable: EmbeddableStart;
share: SharePluginStart;
}
export type ObservabilitySharedPluginSetup = ReturnType<ObservabilitySharedPlugin['setup']>;
export type ObservabilitySharedPluginStart = ReturnType<ObservabilitySharedPlugin['start']>;
export class ObservabilitySharedPlugin implements Plugin {
private readonly navigationRegistry = createNavigationRegistry();
private isSidebarEnabled$: BehaviorSubject<boolean>;
constructor() {
this.isSidebarEnabled$ = new BehaviorSubject<boolean>(true);
}
public setup(coreSetup: CoreSetup, pluginsSetup: ObservabilitySharedSetup) {
return {
locators: {
profiling: {
flamegraphLocator: pluginsSetup.share.url.locators.create(
new FlamegraphLocatorDefinition()
),
topNFunctionsLocator: pluginsSetup.share.url.locators.create(
new TopNFunctionsLocatorDefinition()
),
stacktracesLocator: pluginsSetup.share.url.locators.create(
new StacktracesLocatorDefinition()
),
},
},
navigation: {
registerSections: this.navigationRegistry.registerSections,
},
};
}
public start(core: CoreStart, plugins: ObservabilitySharedStart) {
const { application } = core;
const PageTemplate = createLazyObservabilityPageTemplate({
currentAppId$: application.currentAppId$,
getUrlForApp: application.getUrlForApp,
navigateToApp: application.navigateToApp,
navigationSections$: this.navigationRegistry.sections$,
guidedOnboardingApi: plugins.guidedOnboarding.guidedOnboardingApi,
getPageTemplateServices: () => ({ coreStart: core }),
isSidebarEnabled$: this.isSidebarEnabled$,
});
return {
navigation: {
PageTemplate,
registerSections: this.navigationRegistry.registerSections,
},
updateGlobalNavigation,
setIsSidebarEnabled: (isEnabled: boolean) => this.isSidebarEnabled$.next(isEnabled),
};
}
public stop() {}
}