Skip to content

Commit

Permalink
Merge branch 'main' into feat/tsdb
Browse files Browse the repository at this point in the history
  • Loading branch information
kibanamachine authored Nov 16, 2022
2 parents 12801bb + ee5b361 commit d764486
Show file tree
Hide file tree
Showing 4 changed files with 89 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ import {
getRuleStatusMessage,
} from '../../../../common/lib/rule_status_helpers';
import RuleStatusPanelWithApi from './rule_status_panel';
import {
ALERT_STATUS_LICENSE_ERROR,
rulesLastRunOutcomeTranslationMapping,
rulesStatusesTranslationsMapping,
} from '../../rules_list/translations';

const RuleEventLogList = lazy(() => import('./rule_event_log_list'));
const RuleAlertList = lazy(() => import('./rule_alert_list'));
Expand Down Expand Up @@ -74,7 +79,12 @@ export function RuleComponent({
};

const healthColor = getRuleHealthColor(rule);
const statusMessage = getRuleStatusMessage(rule);
const statusMessage = getRuleStatusMessage({
rule,
licenseErrorText: ALERT_STATUS_LICENSE_ERROR,
lastOutcomeTranslations: rulesLastRunOutcomeTranslationMapping,
executionStatusTranslations: rulesStatusesTranslationsMapping,
});

const renderRuleAlertList = () => {
return suspendedComponentWithProps(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ import {
getIsLicenseError,
getRuleStatusMessage,
} from '../../../../common/lib/rule_status_helpers';
import {
ALERT_STATUS_LICENSE_ERROR,
rulesLastRunOutcomeTranslationMapping,
rulesStatusesTranslationsMapping,
} from '../translations';

export interface RulesListTableStatusCellProps {
rule: RuleTableItem;
Expand All @@ -33,7 +38,12 @@ export const RulesListTableStatusCell = (props: RulesListTableStatusCellProps) =

const isLicenseError = getIsLicenseError(rule);
const healthColor = getRuleHealthColor(rule);
const statusMessage = getRuleStatusMessage(rule);
const statusMessage = getRuleStatusMessage({
rule,
licenseErrorText: ALERT_STATUS_LICENSE_ERROR,
lastOutcomeTranslations: rulesLastRunOutcomeTranslationMapping,
executionStatusTranslations: rulesStatusesTranslationsMapping,
});
const tooltipMessage = lastRun?.outcome === 'failed' ? `Error: ${lastRun?.outcomeMsg}` : null;

if (!statusMessage) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ import { getRuleHealthColor, getRuleStatusMessage } from './rule_status_helpers'
import { RuleTableItem } from '../../types';

import { getIsExperimentalFeatureEnabled } from '../get_experimental_features';
import {
ALERT_STATUS_LICENSE_ERROR,
rulesLastRunOutcomeTranslationMapping,
rulesStatusesTranslationsMapping,
} from '../../application/sections/rules_list/translations';

jest.mock('../get_experimental_features', () => ({
getIsExperimentalFeatureEnabled: jest.fn(),
Expand Down Expand Up @@ -97,38 +102,78 @@ describe('getRuleHealthColor', () => {

describe('getRuleStatusMessage', () => {
it('should get the status message for a successful rule', () => {
let statusMessage = getRuleStatusMessage(mockRule);
let statusMessage = getRuleStatusMessage({
rule: mockRule,
licenseErrorText: ALERT_STATUS_LICENSE_ERROR,
lastOutcomeTranslations: rulesLastRunOutcomeTranslationMapping,
executionStatusTranslations: rulesStatusesTranslationsMapping,
});
expect(statusMessage).toEqual('Succeeded');

(getIsExperimentalFeatureEnabled as jest.Mock<any, any>).mockImplementation(() => false);
statusMessage = getRuleStatusMessage(mockRule);
statusMessage = getRuleStatusMessage({
rule: mockRule,
licenseErrorText: ALERT_STATUS_LICENSE_ERROR,
lastOutcomeTranslations: rulesLastRunOutcomeTranslationMapping,
executionStatusTranslations: rulesStatusesTranslationsMapping,
});
expect(statusMessage).toEqual('Active');
});

it('should get the status message for a warning rule', () => {
let statusMessage = getRuleStatusMessage(warningRule);
let statusMessage = getRuleStatusMessage({
rule: warningRule,
licenseErrorText: ALERT_STATUS_LICENSE_ERROR,
lastOutcomeTranslations: rulesLastRunOutcomeTranslationMapping,
executionStatusTranslations: rulesStatusesTranslationsMapping,
});
expect(statusMessage).toEqual('Warning');

(getIsExperimentalFeatureEnabled as jest.Mock<any, any>).mockImplementation(() => false);
statusMessage = getRuleStatusMessage(warningRule);
statusMessage = getRuleStatusMessage({
rule: warningRule,
licenseErrorText: ALERT_STATUS_LICENSE_ERROR,
lastOutcomeTranslations: rulesLastRunOutcomeTranslationMapping,
executionStatusTranslations: rulesStatusesTranslationsMapping,
});
expect(statusMessage).toEqual('Warning');
});

it('should get the status message for a failed rule', () => {
let statusMessage = getRuleStatusMessage(failedRule);
let statusMessage = getRuleStatusMessage({
rule: failedRule,
licenseErrorText: ALERT_STATUS_LICENSE_ERROR,
lastOutcomeTranslations: rulesLastRunOutcomeTranslationMapping,
executionStatusTranslations: rulesStatusesTranslationsMapping,
});
expect(statusMessage).toEqual('Failed');

(getIsExperimentalFeatureEnabled as jest.Mock<any, any>).mockImplementation(() => false);
statusMessage = getRuleStatusMessage(failedRule);
statusMessage = getRuleStatusMessage({
rule: failedRule,
licenseErrorText: ALERT_STATUS_LICENSE_ERROR,
lastOutcomeTranslations: rulesLastRunOutcomeTranslationMapping,
executionStatusTranslations: rulesStatusesTranslationsMapping,
});
expect(statusMessage).toEqual('Error');
});

it('should get the status message for a license error rule', () => {
let statusMessage = getRuleStatusMessage(licenseErrorRule);
let statusMessage = getRuleStatusMessage({
rule: licenseErrorRule,
licenseErrorText: ALERT_STATUS_LICENSE_ERROR,
lastOutcomeTranslations: rulesLastRunOutcomeTranslationMapping,
executionStatusTranslations: rulesStatusesTranslationsMapping,
});
expect(statusMessage).toEqual('License Error');

(getIsExperimentalFeatureEnabled as jest.Mock<any, any>).mockImplementation(() => false);
statusMessage = getRuleStatusMessage(licenseErrorRule);
statusMessage = getRuleStatusMessage({
rule: licenseErrorRule,
licenseErrorText: ALERT_STATUS_LICENSE_ERROR,
lastOutcomeTranslations: rulesLastRunOutcomeTranslationMapping,
executionStatusTranslations: rulesStatusesTranslationsMapping,
});
expect(statusMessage).toEqual('License Error');
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,6 @@ import {
} from '@kbn/alerting-plugin/common';
import { getIsExperimentalFeatureEnabled } from '../get_experimental_features';
import { Rule } from '../../types';
import {
rulesLastRunOutcomeTranslationMapping,
rulesStatusesTranslationsMapping,
ALERT_STATUS_LICENSE_ERROR,
} from '../../application/sections/rules_list/translations';

export const getOutcomeHealthColor = (status: RuleLastRunOutcomes) => {
switch (status) {
Expand Down Expand Up @@ -62,15 +57,25 @@ export const getIsLicenseError = (rule: Rule) => {
);
};

export const getRuleStatusMessage = (rule: Rule) => {
export const getRuleStatusMessage = ({
rule,
licenseErrorText,
lastOutcomeTranslations,
executionStatusTranslations,
}: {
rule: Rule;
licenseErrorText: string;
lastOutcomeTranslations: Record<string, string>;
executionStatusTranslations: Record<string, string>;
}) => {
const isLicenseError = getIsLicenseError(rule);
const isRuleLastRunOutcomeEnabled = getIsExperimentalFeatureEnabled('ruleLastRunOutcome');

if (isLicenseError) {
return ALERT_STATUS_LICENSE_ERROR;
return licenseErrorText;
}
if (isRuleLastRunOutcomeEnabled) {
return rule.lastRun && rulesLastRunOutcomeTranslationMapping[rule.lastRun.outcome];
return rule.lastRun && lastOutcomeTranslations[rule.lastRun.outcome];
}
return rulesStatusesTranslationsMapping[rule.executionStatus.status];
return executionStatusTranslations[rule.executionStatus.status];
};

0 comments on commit d764486

Please sign in to comment.