Skip to content

Commit

Permalink
[Security Solution][Hosts] Update the host search strategy API respon…
Browse files Browse the repository at this point in the history
…se and remove redundant endpoint data (#156709)

## Summary

- Removes several pieces of data from the Host Details search strategy
response that is now available via the `hostInfo` property of the data
returned.

This PR is a follow up from
#154961 (comment)
  • Loading branch information
paul-tavares authored May 8, 2023
1 parent 3b789e3 commit 7f6e047
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 54 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import type { CloudEcs, HostEcs, OsEcs } from '@kbn/securitysolution-ecs';
import type { Hit, Hits, Maybe, SearchHit, StringOrNumber, TotalValue } from '../../../common';
import type { EndpointPendingActions, HostInfo, HostStatus } from '../../../../endpoint/types';
import type { EndpointPendingActions, HostInfo } from '../../../../endpoint/types';
import type { CommonFields } from '../..';

export enum HostPolicyResponseActionStatus {
Expand All @@ -23,15 +23,8 @@ export enum HostsFields {
}

export interface EndpointFields {
endpointPolicy?: Maybe<string>;
sensorVersion?: Maybe<string>;
policyStatus?: Maybe<HostPolicyResponseActionStatus>;
/** if the host is currently isolated */
isolation?: Maybe<boolean>;
/** A count of pending endpoint actions against the host */
pendingActions?: Maybe<EndpointPendingActions['pending_actions']>;
elasticAgentStatus?: Maybe<HostStatus>;
fleetAgentId?: Maybe<string>;
id?: Maybe<string>;
/** The complete Endpoint Host Details information (which also includes some of the fields above */
hostInfo?: HostInfo;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,8 +190,10 @@ const HostDetailsComponent: React.FC<HostDetailsProps> = ({ detailName, hostDeta
}
title={detailName}
rightSideItems={[
hostOverview.endpoint?.fleetAgentId && (
<ResponderActionButton endpointId={hostOverview.endpoint?.fleetAgentId} />
hostOverview.endpoint?.hostInfo?.metadata.elastic.agent.id && (
<ResponderActionButton
endpointId={hostOverview.endpoint?.hostInfo?.metadata.elastic.agent.id}
/>
),
]}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,8 @@ import { TestProviders } from '../../../../common/mock';

import { EndpointOverview } from '.';
import type { EndpointFields } from '../../../../../common/search_strategy/security_solution/hosts';
import { HostPolicyResponseActionStatus } from '../../../../../common/search_strategy/security_solution/hosts';
import { HostStatus } from '../../../../../common/endpoint/types';
import { EndpointMetadataGenerator } from '../../../../../common/endpoint/data_generators/endpoint_metadata_generator';
import { set } from 'lodash';

jest.mock('../../../../common/lib/kibana');

Expand All @@ -39,11 +38,6 @@ describe('EndpointOverview Component', () => {

beforeEach(() => {
endpointData = {
endpointPolicy: 'demo',
policyStatus: HostPolicyResponseActionStatus.success,
sensorVersion: '7.9.0-SNAPSHOT',
isolation: false,
elasticAgentStatus: HostStatus.HEALTHY,
pendingActions: {},
hostInfo: new EndpointMetadataGenerator('seed').generateHostInfo({
metadata: {
Expand All @@ -59,9 +53,13 @@ describe('EndpointOverview Component', () => {

test('it renders with endpoint data', () => {
render();
expect(findData.at(0).text()).toEqual(endpointData.endpointPolicy);
expect(findData.at(1).text()).toEqual(endpointData.policyStatus);
expect(findData.at(2).text()).toContain(endpointData.sensorVersion); // contain because drag adds a space
expect(findData.at(0).text()).toEqual(
endpointData?.hostInfo?.metadata.Endpoint.policy.applied.name
);
expect(findData.at(1).text()).toEqual(
endpointData?.hostInfo?.metadata.Endpoint.policy.applied.status
);
expect(findData.at(2).text()).toContain(endpointData?.hostInfo?.metadata.agent.version); // contain because drag adds a space
expect(findData.at(3).text()).toEqual('HealthyIsolated');
});

Expand All @@ -74,7 +72,7 @@ describe('EndpointOverview Component', () => {
});

test('it shows isolation status', () => {
endpointData.isolation = true;
set(endpointData.hostInfo ?? {}, 'metadata.Endpoint.state.isolation', true);
render();
expect(findData.at(3).text()).toEqual('HealthyIsolated');
});
Expand All @@ -84,7 +82,7 @@ describe('EndpointOverview Component', () => {
['isolate', 'Isolating'],
['unisolate', 'Releasing'],
])('it shows pending %s status', (action, expectedLabel) => {
endpointData.isolation = true;
set(endpointData.hostInfo ?? {}, 'metadata.Endpoint.state.isolation', true);
endpointData.pendingActions![action] = 1;
render();
expect(findData.at(3).text()).toEqual(`Healthy${expectedLabel}`);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,42 +34,41 @@ export const EndpointOverview = React.memo<Props>(({ contextID, data }) => {
),
[contextID]
);
const descriptionLists: Readonly<DescriptionList[][]> = useMemo(
() => [
const descriptionLists: Readonly<DescriptionList[][]> = useMemo(() => {
const appliedPolicy = data?.hostInfo?.metadata.Endpoint.policy.applied;

return [
[
{
title: i18n.ENDPOINT_POLICY,
description:
data != null && data.endpointPolicy != null ? data.endpointPolicy : getEmptyTagValue(),
description: appliedPolicy?.name ?? getEmptyTagValue(),
},
],
[
{
title: i18n.POLICY_STATUS,
description:
data != null && data.policyStatus != null ? (
<EuiHealth
aria-label={data.policyStatus}
color={
data.policyStatus === HostPolicyResponseActionStatus.failure
? 'danger'
: data.policyStatus
}
>
{data.policyStatus}
</EuiHealth>
) : (
getEmptyTagValue()
),
description: appliedPolicy?.status ? (
<EuiHealth
aria-label={appliedPolicy?.status}
color={
appliedPolicy?.status === HostPolicyResponseActionStatus.failure
? 'danger'
: appliedPolicy?.status
}
>
{appliedPolicy?.status}
</EuiHealth>
) : (
getEmptyTagValue()
),
},
],
[
{
title: i18n.SENSORVERSION,
description:
data != null && data.sensorVersion != null
? getDefaultRenderer('sensorVersion', data, 'agent.version')
: getEmptyTagValue(),
description: data?.hostInfo?.metadata.agent.version
? getDefaultRenderer('hostInfo.metadata.agent.version', data, 'agent.version')
: getEmptyTagValue(),
},
],
[
Expand All @@ -86,9 +85,8 @@ export const EndpointOverview = React.memo<Props>(({ contextID, data }) => {
),
},
],
],
[data, getDefaultRenderer]
);
];
}, [data, getDefaultRenderer]);

return (
<>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,12 +202,6 @@ export const getHostEndpoint = async (

return {
hostInfo: endpointData,
endpointPolicy: endpointData.metadata.Endpoint.policy.applied.name,
policyStatus: endpointData.metadata.Endpoint.policy.applied.status,
sensorVersion: endpointData.metadata.agent.version,
elasticAgentStatus: endpointData.host_status,
isolation: endpointData.metadata.Endpoint.state?.isolation ?? false,
fleetAgentId: endpointData.metadata.elastic.agent.id,
pendingActions,
};
} catch (err) {
Expand Down

0 comments on commit 7f6e047

Please sign in to comment.