Skip to content

Commit

Permalink
[Infra UI] Disable Osquery in serverless (elastic#167233)
Browse files Browse the repository at this point in the history
closes elastic#163280

## Summary

Disables OSquery in serverless. 


<img width="1670" alt="image"
src="https://github.com/elastic/kibana/assets/2767137/0ece0503-a5f3-46a1-a99b-29285088526c">

<img width="1670" alt="image"
src="https://github.com/elastic/kibana/assets/2767137/5d20aaa4-7bdc-47e5-b9c2-469ecf62ab1f">


<img width="1670" alt="image"
src="https://github.com/elastic/kibana/assets/2767137/97874aee-be98-4f0a-984a-562abbd4187d">

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 <[email protected]>
  • Loading branch information
crespocarlos and kibanamachine authored Oct 4, 2023
1 parent 5fb9a38 commit ede81cf
Show file tree
Hide file tree
Showing 8 changed files with 49 additions and 6 deletions.
5 changes: 5 additions & 0 deletions test/plugin_functional/test_suites/core_plugins/rendering.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)',
Expand Down
1 change: 1 addition & 0 deletions x-pack/plugins/infra/common/plugin_config_types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export interface InfraConfig {
};
featureFlags: {
metricsExplorerEnabled: boolean;
osqueryEnabled: boolean;
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -107,10 +108,32 @@ const useRightSideItems = (links?: LinkOptions[]) => {
return { rightSideItems };
};

const useFeatureFlagTabs = () => {
const { featureFlags } = usePluginConfig();
const featureFlagControlledTabs: Partial<Record<ContentTabIds, boolean>> = 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) => {
Expand Down Expand Up @@ -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);
}
Expand All @@ -161,7 +184,7 @@ const useTabs = (tabs: Tab[]) => {
label: name,
};
}),
[activeTabId, getTabToApmTraces, onTabClick, tabs]
[activeTabId, isTabEnabled, getTabToApmTraces, onTabClick, tabs]
);

return { tabEntries };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 <EuiSkeletonText lines={10} />;
}

return <OsqueryAction agentId={metadata?.info?.agent?.id} hideAgentsField formType="simple" />;
}, [OsqueryAction, metadataLoading, metadata]);
}, [featureFlags.osqueryEnabled, metadataLoading, OsqueryAction, metadata?.info?.agent?.id]);

return content;
};
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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<InfraConfig> = {
featureFlags: { metricsExplorerEnabled: false, osqueryEnabled: false },
};
const { result } = renderHook(() => usePluginConfig(), {
wrapper: ({ children }) => {
return <PluginConfigProvider value={config}>{children}</PluginConfigProvider>;
return (
<PluginConfigProvider value={config as InfraConfig}>{children}</PluginConfigProvider>
);
},
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1900,6 +1900,7 @@ const createMockStaticConfiguration = (sources: any): InfraConfig => ({
},
featureFlags: {
metricsExplorerEnabled: true,
osqueryEnabled: true,
},
enabled: true,
sources,
Expand Down
1 change: 1 addition & 0 deletions x-pack/plugins/infra/server/lib/sources/sources.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ const createMockStaticConfiguration = (sources: any): InfraConfig => ({
},
featureFlags: {
metricsExplorerEnabled: true,
osqueryEnabled: true,
},
sources,
enabled: true,
Expand Down
4 changes: 4 additions & 0 deletions x-pack/plugins/infra/server/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,10 @@ export const config: PluginConfigDescriptor<InfraConfig> = {
traditional: schema.boolean({ defaultValue: true }),
serverless: schema.boolean({ defaultValue: false }),
}),
osqueryEnabled: offeringBasedSchema({
traditional: schema.boolean({ defaultValue: true }),
serverless: schema.boolean({ defaultValue: false }),
}),
}),
}),
deprecations: configDeprecations,
Expand Down

0 comments on commit ede81cf

Please sign in to comment.