Skip to content

Commit

Permalink
add util function, show 'warning' on monitoring table, fix e2e tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dhurley14 committed Mar 5, 2021
1 parent 5d7263d commit 2b4efd2
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
EntriesArray,
ExceptionListItemSchema,
} from '../shared_imports';
import { Type } from './schemas/common/schemas';
import { Type, JobStatus } from './schemas/common/schemas';

export const hasLargeValueItem = (
exceptionItems: Array<ExceptionListItemSchema | CreateExceptionListItemSchema>
Expand Down Expand Up @@ -54,3 +54,6 @@ export const normalizeThresholdField = (
? []
: [thresholdField!];
};

export const getRuleStatusText = (value: JobStatus | null | undefined): JobStatus | null =>
value === 'partial failure' ? 'warning' : value != null ? value : null;
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,6 @@ export interface RuleStatus {
}

export type RuleStatusType =
| 'executing'
| 'failed'
| 'going to run'
| 'succeeded'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import { LocalizedDateTooltip } from '../../../../../common/components/localized
import { LinkAnchor } from '../../../../../common/components/links';
import { getToolTipContent, canEditRuleWithActions } from '../../../../../common/utils/privileges';
import { TagsDisplay } from './tag_display';
import { getRuleStatusText } from '../../../../../../common/detection_engine/utils';

export const getActions = (
dispatch: React.Dispatch<RulesTableAction>,
Expand Down Expand Up @@ -201,7 +202,7 @@ export const getColumns = ({
return (
<>
<EuiHealth color={getStatusColor(value ?? null)}>
{value === 'partial failure' ? 'warning' : value != null ? value : getEmptyTagValue()}
{getRuleStatusText(value) ?? getEmptyTagValue()}
</EuiHealth>
</>
);
Expand Down Expand Up @@ -398,7 +399,7 @@ export const getMonitoringColumns = (
return (
<>
<EuiHealth color={getStatusColor(value ?? null)}>
{value ?? getEmptyTagValue()}
{getRuleStatusText(value) ?? getEmptyTagValue()}
</EuiHealth>
</>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ import * as statusI18n from '../../../../components/rules/rule_status/translatio
import * as i18n from './translations';
import { isTab } from '../../../../../common/components/accessibility/helpers';
import { NeedAdminForUpdateRulesCallOut } from '../../../../components/callouts/need_admin_for_update_callout';
import { getRuleStatusText } from '../../../../../../common/detection_engine/utils';

/**
* Need a 100% height here to account for the graph/analyze tool, which sets no explicit height parameters, but fills the available space.
Expand Down Expand Up @@ -329,7 +330,7 @@ const RuleDetailsPageComponent = () => {
) : (
<>
<RuleStatus
status={currentStatus?.status === 'partial failure' ? 'warning' : currentStatus?.status}
status={getRuleStatusText(currentStatus?.status)}
statusDate={currentStatus?.status_date}
>
<EuiButtonIcon
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ export default ({ getService }: FtrProviderContext) => {
await esArchiver.unload('security_solution/timestamp_override');
});

it('should create a single rule which has a timestamp override for an index pattern that does not exist and write a warning status', async () => {
it('should create a single rule which has a timestamp override for an index pattern that does not exist and write a partial failure status', async () => {
// defaults to event.ingested timestamp override.
// event.ingested is one of the timestamp fields set on the es archive data
// inside of x-pack/test/functional/es_archives/security_solution/timestamp_override/data.json.gz
Expand All @@ -303,23 +303,25 @@ export default ({ getService }: FtrProviderContext) => {
const bodyId = body.id;

await waitForAlertToComplete(supertest, bodyId);
await waitForRuleSuccessOrStatus(supertest, bodyId, 'warning');
await waitForRuleSuccessOrStatus(supertest, bodyId, 'partial failure');

const { body: statusBody } = await supertest
.post(DETECTION_ENGINE_RULES_STATUS_URL)
.set('kbn-xsrf', 'true')
.send({ ids: [bodyId] })
.expect(200);

expect((statusBody as RuleStatusResponse)[bodyId].current_status?.status).to.eql('warning');
expect((statusBody as RuleStatusResponse)[bodyId].current_status?.status).to.eql(
'partial failure'
);
expect(
(statusBody as RuleStatusResponse)[bodyId].current_status?.last_success_message
).to.eql(
'The following indices are missing the timestamp override field "event.ingested": ["myfakeindex-1"]'
);
});

it('should create a single rule which has a timestamp override and generates two signals with a "warning" status', async () => {
it('should create a single rule which has a timestamp override and generates two signals with a "partial failure" status', async () => {
// defaults to event.ingested timestamp override.
// event.ingested is one of the timestamp fields set on the es archive data
// inside of x-pack/test/functional/es_archives/security_solution/timestamp_override/data.json.gz
Expand All @@ -331,7 +333,7 @@ export default ({ getService }: FtrProviderContext) => {
.expect(200);
const bodyId = body.id;

await waitForRuleSuccessOrStatus(supertest, bodyId, 'warning');
await waitForRuleSuccessOrStatus(supertest, bodyId, 'partial failure');
await waitForSignalsToBePresent(supertest, 2, [bodyId]);

const { body: statusBody } = await supertest
Expand All @@ -340,7 +342,7 @@ export default ({ getService }: FtrProviderContext) => {
.send({ ids: [bodyId] })
.expect(200);

expect(statusBody[bodyId].current_status.status).to.eql('warning');
expect(statusBody[bodyId].current_status.status).to.eql('partial failure');
});
});
});
Expand Down

0 comments on commit 2b4efd2

Please sign in to comment.