Skip to content

Commit

Permalink
[Profiling,Infra,APM] Disable Profiling integration by default (#175201)
Browse files Browse the repository at this point in the history
Closes #175016

## Summary

This PR disables the Profiling integration in Infra and APM by default
on the plugin configuration level because this integration require users
to first configure the main `profiling` plugin. On-prem users will have
to manually enable both integrations once they enabled the Universal
Profiling for their hosts. Cloud users will have Infra and APM
integrations enabled by default because on Cloud instances Universal
Profiling is already configured. A PR for the default Cloud settings
will follow after this one is merged.

Changes I've made:
* Disabled the Infra integration be default
* Introduced a new APM feature flag for the Profiling integration
* Made sure all the places in APM that rely on Profiling integration
respect the new feature flag
* Fixed a bug in APM when Universal Profiling was shown even though the
integration was disabled in UI settings


https://github.com/elastic/kibana/assets/793851/65dfbb5b-1850-4d18-a92a-6ad59e0436a3

## How To Test

1. Checkout locally
2. Make sure you don't have `xpack.infra.featureFlags.profilingEnabled`
already enabled in `kibana.yml`
3. Open kibana and make sure you don't see "Universal Profiling" tab in
Host and Service details
4. Enabled both flags in `kibana.yml`:
`xpack.infra.featureFlags.profilingEnabled` and
`xpack.apm.featureFlags.profilingIntegrationAvailable: true`
5. Check that now you see "Universal Profiling" tab in the details
screens in both Infra and APM
6. Go to Infra settings view and disable the Profiling integration, make
sure the tab disappears
7. 6. Go to APM settings view and disable the Profiling integration,
make sure the tab disappears

---------

Co-authored-by: Kibana Machine <[email protected]>
  • Loading branch information
mykolaharmash and kibanamachine authored Jan 24, 2024
1 parent 6ca8cfb commit abd3515
Show file tree
Hide file tree
Showing 13 changed files with 103 additions and 28 deletions.
3 changes: 2 additions & 1 deletion test/plugin_functional/test_suites/core_plugins/rendering.ts
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@ export default function ({ getService }: PluginFunctionalProviderContext) {
'xpack.apm.featureFlags.migrationToFleetAvailable (any)',
'xpack.apm.featureFlags.sourcemapApiAvailable (any)',
'xpack.apm.featureFlags.storageExplorerAvailable (any)',
'xpack.apm.featureFlags.profilingIntegrationAvailable (boolean)',
'xpack.apm.serverless.enabled (any)', // It's a boolean (any because schema.conditional)
'xpack.assetManager.alphaEnabled (boolean)',
'xpack.observability_onboarding.serverless.enabled (any)', // It's a boolean (any because schema.conditional)
Expand Down Expand Up @@ -282,7 +283,7 @@ export default function ({ getService }: PluginFunctionalProviderContext) {
'xpack.infra.featureFlags.logThresholdAlertRuleEnabled (any)',
'xpack.infra.featureFlags.logsUIEnabled (any)',
'xpack.infra.featureFlags.alertsAndRulesDropdownEnabled (any)',
'xpack.infra.featureFlags.profilingEnabled (any)',
'xpack.infra.featureFlags.profilingEnabled (boolean)',

'xpack.license_management.ui.enabled (boolean)',
'xpack.maps.preserveDrawingBuffer (boolean)',
Expand Down
5 changes: 5 additions & 0 deletions x-pack/plugins/apm/common/apm_feature_flags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export enum ApmFeatureFlagName {
MigrationToFleetAvailable = 'migrationToFleetAvailable',
SourcemapApiAvailable = 'sourcemapApiAvailable',
StorageExplorerAvailable = 'storageExplorerAvailable',
ProfilingIntegrationAvailable = 'profilingIntegrationAvailable',
}

const apmFeatureFlagMap = {
Expand Down Expand Up @@ -47,6 +48,10 @@ const apmFeatureFlagMap = {
default: true,
type: t.boolean,
},
[ApmFeatureFlagName.ProfilingIntegrationAvailable]: {
default: false,
type: t.boolean,
},
};

type ApmFeatureFlagMap = typeof apmFeatureFlagMap;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ import {
} from '@kbn/observability-shared-plugin/public';
import { FieldRowProvider } from '@kbn/management-settings-components-field-row';
import { ValueValidation } from '@kbn/core-ui-settings-browser/src/types';
import { useApmFeatureFlag } from '../../../../hooks/use_apm_feature_flag';
import { ApmFeatureFlagName } from '../../../../../common/apm_feature_flags';
import { useApmPluginContext } from '../../../../context/apm_plugin/use_apm_plugin_context';

const LazyFieldRow = React.lazy(async () => ({
Expand All @@ -40,24 +42,35 @@ const LazyFieldRow = React.lazy(async () => ({

const FieldRow = withSuspense(LazyFieldRow);

const apmSettingsKeys = [
enableComparisonByDefault,
defaultApmServiceEnvironment,
apmServiceGroupMaxNumberOfServices,
enableInspectEsQueries,
apmLabsButton,
apmAWSLambdaPriceFactor,
apmAWSLambdaRequestCostPerMillion,
apmEnableServiceMetrics,
apmEnableContinuousRollups,
enableAgentExplorerView,
apmEnableTableSearchBar,
apmEnableProfilingIntegration,
];
function getApmSettingsKeys(isProfilingIntegrationEnabled: boolean) {
const keys = [
enableComparisonByDefault,
defaultApmServiceEnvironment,
apmServiceGroupMaxNumberOfServices,
enableInspectEsQueries,
apmLabsButton,
apmAWSLambdaPriceFactor,
apmAWSLambdaRequestCostPerMillion,
apmEnableServiceMetrics,
apmEnableContinuousRollups,
enableAgentExplorerView,
apmEnableTableSearchBar,
];

if (isProfilingIntegrationEnabled) {
keys.push(apmEnableProfilingIntegration);
}

return keys;
}

export function GeneralSettings() {
const trackApmEvent = useUiTracker({ app: 'apm' });
const { docLinks, notifications } = useApmPluginContext().core;
const isProfilingIntegrationEnabled = useApmFeatureFlag(
ApmFeatureFlagName.ProfilingIntegrationAvailable
);
const apmSettingsKeys = getApmSettingsKeys(isProfilingIntegrationEnabled);
const {
fields,
handleFieldChange,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,13 @@ import { fromQuery } from '../../../shared/links/url_helpers';

import { TransactionDistribution } from '.';

const coreMock = {
settings: { client: { get: () => {} } },
} as unknown as CoreStart;

function Wrapper({ children }: { children?: ReactNode }) {
const KibanaReactContext = createKibanaReactContext({
...coreMock,
usageCollection: { reportUiCounter: () => {} },
} as Partial<CoreStart>);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { enableAwsLambdaMetrics } from '@kbn/observability-plugin/common';
import { omit } from 'lodash';
import React from 'react';
import { useHistory, useLocation } from 'react-router-dom';
import { useProfilingIntegrationSetting } from '../../../../hooks/use_profiling_integration_setting';
import {
isAWSLambdaAgentName,
isAzureFunctionsAgentName,
Expand Down Expand Up @@ -224,6 +225,8 @@ function useTabs({ selectedTab }: { selectedTab: Tab['key'] }) {
ApmFeatureFlagName.InfrastructureTabAvailable
);

const isProfilingIntegrationEnabled = useProfilingIntegrationSetting();

const isAwsLambdaEnabled = core.uiSettings.get<boolean>(
enableAwsLambdaMetrics,
true
Expand Down Expand Up @@ -404,6 +407,7 @@ function useTabs({ selectedTab }: { selectedTab: Tab['key'] }) {
defaultMessage: 'Universal Profiling',
}),
hidden:
!isProfilingIntegrationEnabled ||
isRumOrMobileAgentName(agentName) ||
isAWSLambdaAgentName(serverlessType),
append: (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import { TransactionActionMenu } from './transaction_action_menu';
import * as Transactions from './__fixtures__/mock_data';
import { KibanaContextProvider } from '@kbn/kibana-react-plugin/public';
import * as useAdHocApmDataView from '../../../hooks/use_adhoc_apm_data_view';
import { useProfilingIntegrationSetting } from '../../../hooks/use_profiling_integration_setting';

const apmContextMock = {
...mockApmPluginContextValue,
Expand Down Expand Up @@ -60,6 +61,10 @@ const apmContextMock = {
},
} as unknown as ApmPluginContextValue;

jest.mock('../../../hooks/use_profiling_integration_setting', () => ({
useProfilingIntegrationSetting: jest.fn().mockReturnValue(false),
}));

const history = createMemoryHistory();
history.replace(
'/services/testbeans-go/transactions/view?rangeFrom=now-24h&rangeTo=now&transactionName=GET+%2Ftestbeans-go%2Fapi'
Expand Down Expand Up @@ -115,6 +120,10 @@ const expectLogsLocatorsToBeCalled = () => {
let useAdHocApmDataViewSpy: jest.SpyInstance;

describe('TransactionActionMenu ', () => {
beforeEach(() => {
jest.clearAllMocks();
});

jest.spyOn(hooks, 'useFetcher').mockReturnValue({
// return as Profiling had been initialized
data: {
Expand Down Expand Up @@ -308,6 +317,10 @@ describe('TransactionActionMenu ', () => {
});

describe('Profiling items', () => {
beforeEach(() => {
(useProfilingIntegrationSetting as jest.Mock).mockReturnValue(true);
});

it('renders flamegraph item', async () => {
const component = await renderTransaction(
Transactions.transactionWithHostData
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ const mockConfig: ConfigSchema = {
migrationToFleetAvailable: true,
sourcemapApiAvailable: true,
storageExplorerAvailable: true,
profilingIntegrationAvailable: false,
},
serverless: { enabled: false },
};
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
* 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 { useUiSetting } from '@kbn/kibana-react-plugin/public';
import { apmEnableProfilingIntegration } from '@kbn/observability-plugin/common';
import { ApmFeatureFlagName } from '../../common/apm_feature_flags';
import { useApmFeatureFlag } from './use_apm_feature_flag';

export function useProfilingIntegrationSetting() {
const isProfilingIntegrationFeatureFlagEnabled = useApmFeatureFlag(
ApmFeatureFlagName.ProfilingIntegrationAvailable
);
const isProfilingIntegrationUiSettingEnabled = useUiSetting<boolean>(
apmEnableProfilingIntegration
);

return (
isProfilingIntegrationFeatureFlagEnabled &&
isProfilingIntegrationUiSettingEnabled
);
}
9 changes: 3 additions & 6 deletions x-pack/plugins/apm/public/hooks/use_profiling_plugin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,13 @@
* 2.0.
*/

import { apmEnableProfilingIntegration } from '@kbn/observability-plugin/common';
import { useApmPluginContext } from '../context/apm_plugin/use_apm_plugin_context';
import { isPending, useFetcher } from './use_fetcher';
import { useProfilingIntegrationSetting } from './use_profiling_integration_setting';

export function useProfilingPlugin() {
const { plugins, core } = useApmPluginContext();
const isProfilingIntegrationEnabled = core.uiSettings.get<boolean>(
apmEnableProfilingIntegration,
true
);
const { plugins } = useApmPluginContext();
const isProfilingIntegrationEnabled = useProfilingIntegrationSetting();

const { data, status } = useFetcher((callApmApi) => {
return callApmApi('GET /internal/apm/profiling/status');
Expand Down
1 change: 1 addition & 0 deletions x-pack/plugins/apm/public/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export interface ConfigSchema {
migrationToFleetAvailable: boolean;
sourcemapApiAvailable: boolean;
storageExplorerAvailable: boolean;
profilingIntegrationAvailable: boolean;
};
serverless: {
enabled: boolean;
Expand Down
6 changes: 6 additions & 0 deletions x-pack/plugins/apm/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,12 @@ const configSchema = schema.object({
migrationToFleetAvailable: disabledOnServerless,
sourcemapApiAvailable: disabledOnServerless,
storageExplorerAvailable: disabledOnServerless,
/**
* Depends on optional "profilingDataAccess" and "profiling"
* plugins. Enable both with `xpack.profiling.enabled: true` before
* enabling this feature flag.
*/
profilingIntegrationAvailable: schema.boolean({ defaultValue: false }),
}),
serverless: schema.object({
enabled: offeringBasedSchema({
Expand Down
11 changes: 4 additions & 7 deletions x-pack/plugins/infra/server/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,14 +113,11 @@ export const config: PluginConfigDescriptor<InfraConfig> = {
serverless: schema.boolean({ defaultValue: true }),
}),
/**
* This flag depends on profilingDataAccess optional plugin,
* make sure to enable it with `xpack.profiling.enabled: true`
* before enabling this flag.
* Depends on optional "profilingDataAccess" and "profiling"
* plugins. Enable both with `xpack.profiling.enabled: true` before
* enabling this feature flag.
*/
profilingEnabled: offeringBasedSchema({
traditional: schema.boolean({ defaultValue: true }),
serverless: schema.boolean({ defaultValue: false }),
}),
profilingEnabled: schema.boolean({ defaultValue: false }),
}),
}),
exposeToBrowser: publicConfigKeys,
Expand Down
7 changes: 7 additions & 0 deletions x-pack/test/functional/apps/infra/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,12 @@ export default async function ({ readConfigFile }: FtrConfigProviderContext) {
return {
...functionalConfig.getAll(),
testFiles: [require.resolve('.')],
kbnTestServer: {
...functionalConfig.get('kbnTestServer'),
serverArgs: [
...functionalConfig.get('kbnTestServer.serverArgs'),
`--xpack.infra.featureFlags.profilingEnabled=true`,
],
},
};
}

0 comments on commit abd3515

Please sign in to comment.