From ede81cfdb0585a44536755213c6f7931d5dd4cb0 Mon Sep 17 00:00:00 2001 From: Carlos Crespo Date: Wed, 4 Oct 2023 12:48:30 +0200 Subject: [PATCH] [Infra UI] Disable Osquery in serverless (#167233) closes https://github.com/elastic/kibana/issues/163280 ## Summary Disables OSquery in serverless. image image image Osquery is now only used in the Asset Details flyout/full-page view. The header component in the Asset Details now checks the feature flag object to show/hide the OSquery tab. ### How to test - Start a local es instance: `yarn es serverless --kill --clean --license trial --ssl` - Enable `infra` in the `serverless.oblt.dev.yml` file: - `xpack.infra.enabled: true` - Start a local kibana instance: `yarn serverless-oblt --ssl` and see if the side nav contains the Infrastructure item - Navigate to `https://0.0.0.0:5601/ftw/app/metrics` and open the Asset Details flyout from Inventory and Hosts View. Navigate to the details view and check that Osquery tab isn't present. - Confirm if OSquery tab is present in stateful. --------- Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com> --- .../test_suites/core_plugins/rendering.ts | 5 ++++ .../infra/common/plugin_config_types.ts | 1 + .../asset_details/hooks/use_page_header.tsx | 27 +++++++++++++++++-- .../asset_details/tabs/osquery/osquery.tsx | 7 ++++- .../containers/plugin_config_context.test.tsx | 9 ++++--- .../metric_threshold_executor.test.ts | 1 + .../infra/server/lib/sources/sources.test.ts | 1 + x-pack/plugins/infra/server/plugin.ts | 4 +++ 8 files changed, 49 insertions(+), 6 deletions(-) diff --git a/test/plugin_functional/test_suites/core_plugins/rendering.ts b/test/plugin_functional/test_suites/core_plugins/rendering.ts index e01822be1d6c0..87e3b2077bcb5 100644 --- a/test/plugin_functional/test_suites/core_plugins/rendering.ts +++ b/test/plugin_functional/test_suites/core_plugins/rendering.ts @@ -256,6 +256,11 @@ export default function ({ getService }: PluginFunctionalProviderContext) { * and will resolve to (boolean) */ 'xpack.infra.featureFlags.metricsExplorerEnabled (any)', + /** + * xpack.infra.featureFlags.osqueryEnabled is conditional based on traditional/serverless offering + * and will resolve to (boolean) + */ + 'xpack.infra.featureFlags.osqueryEnabled (any)', 'xpack.license_management.ui.enabled (boolean)', 'xpack.maps.preserveDrawingBuffer (boolean)', 'xpack.maps.showMapsInspectorAdapter (boolean)', diff --git a/x-pack/plugins/infra/common/plugin_config_types.ts b/x-pack/plugins/infra/common/plugin_config_types.ts index 89bbd1dbe4e5b..f3d3a04f3b4c4 100644 --- a/x-pack/plugins/infra/common/plugin_config_types.ts +++ b/x-pack/plugins/infra/common/plugin_config_types.ts @@ -27,6 +27,7 @@ export interface InfraConfig { }; featureFlags: { metricsExplorerEnabled: boolean; + osqueryEnabled: boolean; }; } diff --git a/x-pack/plugins/infra/public/components/asset_details/hooks/use_page_header.tsx b/x-pack/plugins/infra/public/components/asset_details/hooks/use_page_header.tsx index 987adf78c33dd..bff9cc1ea17e2 100644 --- a/x-pack/plugins/infra/public/components/asset_details/hooks/use_page_header.tsx +++ b/x-pack/plugins/infra/public/components/asset_details/hooks/use_page_header.tsx @@ -18,6 +18,7 @@ import React, { useCallback, useMemo } from 'react'; import { capitalize } from 'lodash'; import { useHistory, useLocation } from 'react-router-dom'; import { FormattedMessage } from '@kbn/i18n-react'; +import { usePluginConfig } from '../../../containers/plugin_config_context'; import { useKibanaContextForPlugin } from '../../../hooks/use_kibana'; import { APM_HOST_FILTER_FIELD } from '../constants'; import { LinkToAlertsRule, LinkToApmServices, LinkToNodeDetails } from '../links'; @@ -107,10 +108,32 @@ const useRightSideItems = (links?: LinkOptions[]) => { return { rightSideItems }; }; +const useFeatureFlagTabs = () => { + const { featureFlags } = usePluginConfig(); + const featureFlagControlledTabs: Partial> = useMemo( + () => ({ + [ContentTabIds.OSQUERY]: featureFlags.osqueryEnabled, + }), + [featureFlags.osqueryEnabled] + ); + + const isTabEnabled = useCallback( + (tabItem: Tab) => { + return featureFlagControlledTabs[tabItem.id] ?? true; + }, + [featureFlagControlledTabs] + ); + + return { + isTabEnabled, + }; +}; + const useTabs = (tabs: Tab[]) => { const { showTab, activeTabId } = useTabSwitcherContext(); const { asset } = useAssetDetailsRenderPropsContext(); const { euiTheme } = useEuiTheme(); + const { isTabEnabled } = useFeatureFlagTabs(); const onTabClick = useCallback( (tabId: TabIds) => { @@ -148,7 +171,7 @@ const useTabs = (tabs: Tab[]) => { const tabEntries: TabItem[] = useMemo( () => - tabs.map(({ name, ...tab }) => { + tabs.filter(isTabEnabled).map(({ name, ...tab }) => { if (tab.id === ContentTabIds.LINK_TO_APM) { return getTabToApmTraces(name); } @@ -161,7 +184,7 @@ const useTabs = (tabs: Tab[]) => { label: name, }; }), - [activeTabId, getTabToApmTraces, onTabClick, tabs] + [activeTabId, isTabEnabled, getTabToApmTraces, onTabClick, tabs] ); return { tabEntries }; diff --git a/x-pack/plugins/infra/public/components/asset_details/tabs/osquery/osquery.tsx b/x-pack/plugins/infra/public/components/asset_details/tabs/osquery/osquery.tsx index a71778cb98d19..b7ff3da85a077 100644 --- a/x-pack/plugins/infra/public/components/asset_details/tabs/osquery/osquery.tsx +++ b/x-pack/plugins/infra/public/components/asset_details/tabs/osquery/osquery.tsx @@ -7,10 +7,12 @@ import { EuiSkeletonText } from '@elastic/eui'; import React, { useMemo } from 'react'; +import { usePluginConfig } from '../../../../containers/plugin_config_context'; import { useKibanaContextForPlugin } from '../../../../hooks/use_kibana'; import { useMetadataStateProviderContext } from '../../hooks/use_metadata_state'; export const Osquery = () => { + const { featureFlags } = usePluginConfig(); const { metadata, loading: metadataLoading } = useMetadataStateProviderContext(); const { @@ -22,13 +24,16 @@ export const Osquery = () => { // avoids component rerender when resizing the popover const content = useMemo(() => { + if (!featureFlags.osqueryEnabled) { + return null; + } // TODO: Add info when Osquery plugin is not available if (metadataLoading || !OsqueryAction) { return ; } return ; - }, [OsqueryAction, metadataLoading, metadata]); + }, [featureFlags.osqueryEnabled, metadataLoading, OsqueryAction, metadata?.info?.agent?.id]); return content; }; diff --git a/x-pack/plugins/infra/public/containers/plugin_config_context.test.tsx b/x-pack/plugins/infra/public/containers/plugin_config_context.test.tsx index 2b89e4b996da2..e37e1b57a962a 100644 --- a/x-pack/plugins/infra/public/containers/plugin_config_context.test.tsx +++ b/x-pack/plugins/infra/public/containers/plugin_config_context.test.tsx @@ -5,6 +5,7 @@ * 2.0. */ +import type { InfraConfig } from '../../common/plugin_config_types'; import { renderHook } from '@testing-library/react-hooks'; import React from 'react'; import { PluginConfigProvider, usePluginConfig } from './plugin_config_context'; @@ -17,12 +18,14 @@ describe('usePluginConfig()', () => { }); it('returns the plugin config what was set through the provider', () => { - const config = { - featureFlags: { metricsExplorerEnabled: false }, + const config: Partial = { + featureFlags: { metricsExplorerEnabled: false, osqueryEnabled: false }, }; const { result } = renderHook(() => usePluginConfig(), { wrapper: ({ children }) => { - return {children}; + return ( + {children} + ); }, }); diff --git a/x-pack/plugins/infra/server/lib/alerting/metric_threshold/metric_threshold_executor.test.ts b/x-pack/plugins/infra/server/lib/alerting/metric_threshold/metric_threshold_executor.test.ts index c28245ececfef..517f4defeb52a 100644 --- a/x-pack/plugins/infra/server/lib/alerting/metric_threshold/metric_threshold_executor.test.ts +++ b/x-pack/plugins/infra/server/lib/alerting/metric_threshold/metric_threshold_executor.test.ts @@ -1900,6 +1900,7 @@ const createMockStaticConfiguration = (sources: any): InfraConfig => ({ }, featureFlags: { metricsExplorerEnabled: true, + osqueryEnabled: true, }, enabled: true, sources, diff --git a/x-pack/plugins/infra/server/lib/sources/sources.test.ts b/x-pack/plugins/infra/server/lib/sources/sources.test.ts index b149838c82b32..d730dde016b98 100644 --- a/x-pack/plugins/infra/server/lib/sources/sources.test.ts +++ b/x-pack/plugins/infra/server/lib/sources/sources.test.ts @@ -127,6 +127,7 @@ const createMockStaticConfiguration = (sources: any): InfraConfig => ({ }, featureFlags: { metricsExplorerEnabled: true, + osqueryEnabled: true, }, sources, enabled: true, diff --git a/x-pack/plugins/infra/server/plugin.ts b/x-pack/plugins/infra/server/plugin.ts index 50e0779928ecd..0a5f9a6982cbd 100644 --- a/x-pack/plugins/infra/server/plugin.ts +++ b/x-pack/plugins/infra/server/plugin.ts @@ -85,6 +85,10 @@ export const config: PluginConfigDescriptor = { traditional: schema.boolean({ defaultValue: true }), serverless: schema.boolean({ defaultValue: false }), }), + osqueryEnabled: offeringBasedSchema({ + traditional: schema.boolean({ defaultValue: true }), + serverless: schema.boolean({ defaultValue: false }), + }), }), }), deprecations: configDeprecations,