Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make all risk score decimal places consistent #198450

Merged
merged 20 commits into from
Nov 8, 2024
Merged
Changes from 11 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -30,6 +30,7 @@ import {
SecurityCellActionType,
} from '../../../common/components/cell_actions';
import { FormattedRelativePreferenceDate } from '../../../common/components/formatted_date';
import { formatRiskScore } from '../../common';

type HostRiskScoreColumns = Array<EuiBasicTableColumn<HostRiskScore & UserRiskScore>>;

@@ -128,7 +129,7 @@ export const getRiskScoreColumns = (
if (riskScore != null) {
return (
<span data-test-subj="risk-score-truncate" title={`${riskScore}`}>
{Math.round(riskScore)}
{formatRiskScore(riskScore)}
</span>
);
}
Original file line number Diff line number Diff line change
@@ -21,6 +21,7 @@ import { type CriticalityLevels } from '../../../../../common/constants';
import { ENTITIES_LIST_TABLE_ID } from '../constants';
import { isUserEntity, sourceFieldToText } from '../helpers';
import { CRITICALITY_LEVEL_TITLE } from '../../asset_criticality/translations';
import { formatRiskScore } from '../../../common';

export type EntitiesListColumns = [
Columns<Entity>,
@@ -149,7 +150,7 @@ export const useEntitiesListColumns = (): EntitiesListColumns => {
if (riskScore != null) {
return (
<span data-test-subj="risk-score-truncate" title={`${riskScore}`}>
{Math.round(riskScore)}
{formatRiskScore(riskScore)}
</span>
);
}
Original file line number Diff line number Diff line change
@@ -23,6 +23,7 @@ import { RiskScoreLevel } from '../severity/common';
import { ENTITY_RISK_LEVEL } from '../risk_score/translations';
import { CELL_ACTIONS_TELEMETRY } from '../risk_score/constants';
import { FormattedRelativePreferenceDate } from '../../../common/components/formatted_date';
import { formatRiskScore } from '../../common';

export const getHostRiskScoreColumns = ({
dispatchSeverityUpdate,
@@ -82,7 +83,7 @@ export const getHostRiskScoreColumns = ({
if (riskScore != null) {
return (
<span data-test-subj="risk-score-truncate" title={`${riskScore}`}>
{Math.round(riskScore)}
{formatRiskScore(riskScore)}
</span>
);
}
Original file line number Diff line number Diff line change
@@ -24,6 +24,7 @@ import { UsersTableType } from '../../../explore/users/store/model';
import { ENTITY_RISK_LEVEL } from '../risk_score/translations';
import { CELL_ACTIONS_TELEMETRY } from '../risk_score/constants';
import { FormattedRelativePreferenceDate } from '../../../common/components/formatted_date';
import { formatRiskScore } from '../../common';

export const getUserRiskScoreColumns = ({
dispatchSeverityUpdate,
@@ -85,7 +86,7 @@ export const getUserRiskScoreColumns = ({
if (riskScore != null) {
return (
<span data-test-subj="risk-score-truncate" title={`${riskScore}`}>
{Math.round(riskScore)}
{formatRiskScore(riskScore)}
</span>
);
}
Original file line number Diff line number Diff line change
@@ -8,6 +8,7 @@
import React, { memo } from 'react';
import { ALERT_RISK_SCORE } from '@kbn/rule-data-utils';
import { FormattedMessage } from '@kbn/i18n-react';
import { formatRiskScore } from '../../../../entity_analytics/common';
import { AlertHeaderBlock } from './alert_header_block';
import { RISK_SCORE_TITLE_TEST_ID, RISK_SCORE_VALUE_TEST_ID } from './test_ids';
import { useDocumentDetailsContext } from '../../shared/context';
@@ -25,9 +26,9 @@ export const RiskScore = memo(() => {

let alertRiskScore: string;
if (typeof fieldsData === 'string') {
alertRiskScore = fieldsData;
alertRiskScore = formatRiskScore(Number(fieldsData));
CAWilson94 marked this conversation as resolved.
Show resolved Hide resolved
} else if (Array.isArray(fieldsData) && fieldsData.length > 0) {
alertRiskScore = fieldsData[0];
alertRiskScore = formatRiskScore(Number(fieldsData[0]));
} else {
return null;
}
Original file line number Diff line number Diff line change
@@ -21,4 +21,5 @@ export const SIGNAL_STATUS_FIELD_NAME = 'kibana.alert.workflow_status';
export const AGENT_STATUS_FIELD_NAME = 'agent.status';
export const QUARANTINED_PATH_FIELD_NAME = 'quarantined.path';
export const REASON_FIELD_NAME = 'kibana.alert.reason';
export const RISK_SCORE = 'kibana.alert.risk_score';
export const EVENT_SUMMARY_FIELD_NAME = 'eventSummary';
Original file line number Diff line number Diff line change
@@ -15,6 +15,7 @@ import { useMountAppended } from '../../../../../common/utils/use_mount_appended

import { FormattedFieldValue } from './formatted_field';
import { HOST_NAME_FIELD_NAME } from './constants';
import { formatRiskScore } from '../../../../../entity_analytics/common';

jest.mock('@elastic/eui', () => {
const original = jest.requireActual('@elastic/eui');
@@ -285,4 +286,39 @@ describe('Events', () => {
);
expect(wrapper.text()).toEqual(getEmptyValue());
});

test('it renders the formatted risk score when fieldName is RISK_SCORE and value is provided', () => {
const riskScoreValue = 85;
const wrapper = mount(
<TestProviders>
<FormattedFieldValue
contextId="test"
eventId={mockTimelineData[0].ecs._id}
fieldName="kibana.alert.risk_score"
value={riskScoreValue}
/>
</TestProviders>
);

expect(
wrapper.find(`[data-test-subj="formatted-field-kibana.alert.risk_score"]`).text()
).toEqual(formatRiskScore(riskScoreValue));
});

test('it does not render anything when fieldName is RISK_SCORE and value is not provided', () => {
const wrapper = mount(
<TestProviders>
<FormattedFieldValue
contextId="test"
eventId={mockTimelineData[0].ecs._id}
fieldName="kibana.alert.risk_score"
value={null}
/>
</TestProviders>
);

expect(
wrapper.find(`[data-test-subj="formatted-field-kibana.alert.risk_score"]`).exists()
).toEqual(false);
});
});
Original file line number Diff line number Diff line change
@@ -13,6 +13,7 @@ import { isEmpty, isNumber } from 'lodash/fp';
import React from 'react';
import { css } from '@emotion/css';
import type { FieldSpec } from '@kbn/data-plugin/common';
import { formatRiskScore } from '../../../../../entity_analytics/common';
import { getAgentTypeForAgentIdField } from '../../../../../common/lib/endpoint/utils/get_agent_type_for_agent_id_field';
import {
ALERT_HOST_CRITICALITY,
@@ -39,6 +40,7 @@ import {
IP_FIELD_TYPE,
MESSAGE_FIELD_NAME,
REFERENCE_URL_FIELD_NAME,
RISK_SCORE,
RULE_REFERENCE_FIELD_NAME,
SIGNAL_RULE_NAME_FIELD_NAME,
SIGNAL_STATUS_FIELD_NAME,
@@ -239,6 +241,10 @@ const FormattedFieldValueComponent: React.FC<{
value={value}
/>
);
} else if (fieldName === RISK_SCORE) {
return value ? (
<span data-test-subj={`formatted-field-${fieldName}`}>{formatRiskScore(Number(value))}</span>
) : null;
} else if (fieldName === EVENT_MODULE_FIELD_NAME) {
return renderEventModule({
contextId,