Skip to content

Commit

Permalink
[Fleet] Add featureFlag to support standalone fleet server (#151865)
Browse files Browse the repository at this point in the history
  • Loading branch information
nchaulet authored Feb 22, 2023
1 parent 81a4b39 commit 629b876
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 9 deletions.
1 change: 1 addition & 0 deletions x-pack/plugins/fleet/common/experimental_features.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export const allowedExperimentalValues = Object.freeze({
showIntegrationsSubcategories: false,
agentFqdnMode: true,
showExperimentalShipperOptions: false,
fleetServerStandalone: false,
});

type ExperimentalConfigKeys = Array<keyof ExperimentalFeatures>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import {
useStartServices,
useFlyoutContext,
sendGetAgentTags,
useFleetServerStandalone,
} from '../../../hooks';
import { AgentEnrollmentFlyout } from '../../../components';
import {
Expand Down Expand Up @@ -433,6 +434,9 @@ export const AgentListPage: React.FunctionComponent<{}> = () => {

// Fleet server unhealthy status
const { isUnhealthy: isFleetServerUnhealthy } = useFleetServerUnhealthy();
const { isFleetServerStandalone } = useFleetServerStandalone();
const showUnhealthyCallout = isFleetServerUnhealthy && !isFleetServerStandalone;

const onClickAddFleetServer = useCallback(() => {
flyoutContext.openFleetServerFlyout();
}, [flyoutContext]);
Expand Down Expand Up @@ -558,7 +562,7 @@ export const AgentListPage: React.FunctionComponent<{}> = () => {
}}
/>
)}
{isFleetServerUnhealthy && (
{showUnhealthyCallout && (
<>
{cloud?.deploymentUrl ? (
<FleetServerCloudUnhealthyCallout deploymentUrl={cloud.deploymentUrl} />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ jest.mock('../../hooks', () => {
return {
...jest.requireActual('../../hooks'),
useFleetStatus: jest.fn(),
useFleetServerStandalone: jest.fn(),
useAgentEnrollmentFlyoutData: jest.fn(),
};
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import {
useAgentEnrollmentFlyoutData,
KibanaVersionContext,
useFleetStatus,
useFleetServerStandalone,
} from '../../hooks';

import { useAdvancedForm } from '../../applications/fleet/components/fleet_server_instructions/hooks';
Expand Down Expand Up @@ -92,6 +93,7 @@ describe('<AgentEnrollmentFlyout />', () => {
],
},
});
jest.mocked(useFleetServerStandalone).mockReturnValue({ isFleetServerStandalone: false });

(useFleetStatus as jest.Mock).mockReturnValue({ isReady: true });
(useFleetServerUnhealthy as jest.Mock).mockReturnValue({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,15 @@ import React, { useMemo, useEffect } from 'react';
import { EuiText, EuiSpacer } from '@elastic/eui';
import { FormattedMessage } from '@kbn/i18n-react';

import { useFleetStatus, useGetAgents } from '../../hooks';

import { useFleetStatus, useGetAgents, useFleetServerStandalone } from '../../hooks';
import { FleetServerRequirementPage } from '../../applications/fleet/sections/agents/agent_requirements_page';

import { AGENTS_PREFIX, FLEET_SERVER_PACKAGE, SO_SEARCH_LIMIT } from '../../constants';

import { useFleetServerUnhealthy } from '../../applications/fleet/sections/agents/hooks/use_fleet_server_unhealthy';

import { Loading } from '..';

import { policyHasFleetServer } from '../../services';

import { AdvancedTab } from '../../applications/fleet/components/fleet_server_instructions/advanced_tab';

import type { InstructionProps } from './types';

import { ManagedSteps, StandaloneSteps } from './steps';
import { DefaultMissingRequirements } from './default_missing_requirements';

Expand All @@ -45,6 +38,8 @@ export const Instructions = (props: InstructionProps) => {
const { isUnhealthy: isFleetServerUnhealthy, isLoading: isLoadingFleetServerHealth } =
useFleetServerUnhealthy();

const { isFleetServerStandalone } = useFleetServerStandalone();

useEffect(() => {
refreshAgentPolicies();
}, [refreshAgentPolicies]);
Expand Down Expand Up @@ -74,12 +69,14 @@ export const Instructions = (props: InstructionProps) => {

const showAgentEnrollment =
isFleetServerPolicySelected ||
isFleetServerStandalone ||
(fleetStatus.isReady &&
!isFleetServerUnhealthy &&
fleetServers.length > 0 &&
(fleetServerHosts?.length ?? 0) > 0);

const showFleetServerEnrollment =
!isFleetServerStandalone &&
!isFleetServerPolicySelected &&
(fleetServers.length === 0 ||
isFleetServerUnhealthy ||
Expand Down
1 change: 1 addition & 0 deletions x-pack/plugins/fleet/public/hooks/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,4 @@ export * from './use_agent_enrollment_flyout_data';
export * from './use_flyout_context';
export * from './use_is_guided_onboarding_active';
export * from './use_fleet_server_hosts_for_policy';
export * from './use_fleet_server_standalone';
14 changes: 14 additions & 0 deletions x-pack/plugins/fleet/public/hooks/use_fleet_server_standalone.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/*
* 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 { ExperimentalFeaturesService } from '../applications/fleet/services';

export function useFleetServerStandalone() {
const isFleetServerStandalone = ExperimentalFeaturesService.get().fleetServerStandalone;

return { isFleetServerStandalone };
}

0 comments on commit 629b876

Please sign in to comment.