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

[Security Solution] Rule Diff Phase 2 components #174564

Merged
merged 27 commits into from
Feb 12, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
95e1e59
working poc
dplumlee Jan 10, 2024
d6b55b3
adds feature flag
dplumlee Jan 10, 2024
78a7911
adds inline per field display
dplumlee Jan 10, 2024
3992626
adds field sort
dplumlee Jan 17, 2024
58803ca
updates ui
dplumlee Jan 18, 2024
e1ce9f3
updates ui
dplumlee Jan 23, 2024
3e01b6b
addresses comments and changes some types
dplumlee Jan 26, 2024
9405654
Merge remote-tracking branch 'upstream/main' into rule-upgrade-diff-p…
dplumlee Jan 26, 2024
c4fba65
fixes bugs and removes console logs
dplumlee Feb 1, 2024
35e99bd
changes header language
dplumlee Feb 5, 2024
57a92a6
Refactored getFormattedFieldDiff
jpdjere Feb 2, 2024
7bc88ff
Refactored per group util
jpdjere Feb 2, 2024
c0240f3
Renamed props
jpdjere Feb 2, 2024
da1375b
Fixed typing
jpdjere Feb 2, 2024
05070e6
Replace N/A with empty string for non existing fields
jpdjere Feb 2, 2024
1feb961
Merge remote-tracking branch 'upstream/main' into rule-upgrade-diff-p…
dplumlee Feb 5, 2024
0e34460
updates field name render dictionary
dplumlee Feb 5, 2024
2687192
fixes small bugs and adds code comments
dplumlee Feb 7, 2024
c92da27
turns off feature flag
dplumlee Feb 7, 2024
977eae3
typo
dplumlee Feb 7, 2024
18e0db2
turns off feature flag
dplumlee Feb 7, 2024
bc20d45
Merge remote-tracking branch 'upstream/main' into rule-upgrade-diff-p…
dplumlee Feb 7, 2024
95e5155
Merge remote-tracking branch 'upstream/main' into rule-upgrade-diff-p…
dplumlee Feb 8, 2024
4f7171e
adds remaining field groupings
dplumlee Feb 8, 2024
94b4cd8
addresses comments
dplumlee Feb 12, 2024
773501e
Merge remote-tracking branch 'upstream/main' into rule-upgrade-diff-p…
dplumlee Feb 12, 2024
faaec7f
addresses comments
dplumlee Feb 12, 2024
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
Prev Previous commit
Next Next commit
updates field name render dictionary
  • Loading branch information
dplumlee committed Feb 5, 2024
commit 0e3446014b843cba507e87b1cf5a2ea155dbf27d
Original file line number Diff line number Diff line change
Expand Up @@ -90,3 +90,5 @@ export type RuleFieldsDiffWithKqlQuery =
| NewTermsFieldsDiff;

export type RuleFieldsDiffWithEqlQuery = EqlFieldsDiff;

export type RuleFieldsDiffWithThreshold = ThresholdFieldsDiff;
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,23 @@
*/

import { i18n } from '@kbn/i18n';
import {
REFERENCES_FIELD_LABEL,
RISK_SCORE_MAPPING_FIELD_LABEL,
SEVERITY_MAPPING_FIELD_LABEL,
THREAT_INDICATOR_PATH_LABEL,
INDEX_FIELD_LABEL,
DATA_VIEW_ID_FIELD_LABEL,
THREAT_FIELD_LABEL,
ANOMALY_THRESHOLD_FIELD_LABEL,
MACHINE_LEARNING_JOB_ID_FIELD_LABEL,
THREAT_INDEX_FIELD_LABEL,
THREAT_MAPPING_FIELD_LABEL,
HISTORY_WINDOW_SIZE_FIELD_LABEL,
} from '../translations';

// Used when fields have different display names or formats than their corresponding rule object fields
export const fieldToDisplayNameMap: Record<string, string> = {
name: i18n.translate('xpack.securitySolution.detectionEngine.rules.upgradeRuleFields.nameLabel', {
defaultMessage: 'Name',
}),
data_source: i18n.translate(
'xpack.securitySolution.detectionEngine.rules.upgradeRuleFields.dataSourceLabel',
{
Expand All @@ -20,5 +32,40 @@ export const fieldToDisplayNameMap: Record<string, string> = {
note: i18n.translate('xpack.securitySolution.detectionEngine.rules.upgradeRuleFields.noteLabel', {
defaultMessage: 'Investigation guide',
}),
// TODO: fill the rest of this out
severity_mapping: SEVERITY_MAPPING_FIELD_LABEL,
risk_score_mapping: RISK_SCORE_MAPPING_FIELD_LABEL,
references: REFERENCES_FIELD_LABEL,
threat_indicator_path: THREAT_INDICATOR_PATH_LABEL,
index_patterns: INDEX_FIELD_LABEL,
data_view_id: DATA_VIEW_ID_FIELD_LABEL,
threat: THREAT_FIELD_LABEL,
eql_query: i18n.translate(
'xpack.securitySolution.detectionEngine.rules.upgradeRuleFields.eqlQueryLabel',
{
defaultMessage: 'EQL query',
}
),
kql_query: i18n.translate(
'xpack.securitySolution.detectionEngine.rules.upgradeRuleFields.kqlQueryLabel',
{
defaultMessage: 'KQL query',
}
),
threat_query: i18n.translate(
'xpack.securitySolution.detectionEngine.rules.upgradeRuleFields.threatQueryLabel',
{
defaultMessage: 'Indicator index query',
}
),
esql_query: i18n.translate(
'xpack.securitySolution.detectionEngine.rules.upgradeRuleFields.esqlQueryLabel',
{
defaultMessage: 'ESQL query',
}
),
anomaly_threshold: ANOMALY_THRESHOLD_FIELD_LABEL,
machine_learning_job_id: MACHINE_LEARNING_JOB_ID_FIELD_LABEL,
threat_index: THREAT_INDEX_FIELD_LABEL,
threat_mapping: THREAT_MAPPING_FIELD_LABEL,
history_window_start: HISTORY_WINDOW_SIZE_FIELD_LABEL,
};
Original file line number Diff line number Diff line change
Expand Up @@ -345,3 +345,46 @@ export const getFieldDiffsForBuildingBlock = (
: []),
];
};

export const getFieldDiffsForThreshold = (
thresholdThreeWayDiff: AllFieldsDiff['threshold']
): FieldDiff[] => {
const currentField = sortAndStringifyJson(thresholdThreeWayDiff.current_version?.field);
const targetField = sortAndStringifyJson(thresholdThreeWayDiff.target_version?.field);
const currentValue = sortAndStringifyJson(thresholdThreeWayDiff.current_version?.value);
const targetValue = sortAndStringifyJson(thresholdThreeWayDiff.target_version?.value);
const currentCardinality = sortAndStringifyJson(
thresholdThreeWayDiff.current_version?.cardinality
);
const targetCardinality = sortAndStringifyJson(thresholdThreeWayDiff.target_version?.cardinality);

return [
...(currentField !== targetField
? [
{
fieldName: 'field',
currentVersion: currentField,
targetVersion: targetField,
},
]
: []),
...(currentValue !== targetValue
? [
{
fieldName: 'value',
currentVersion: currentValue,
targetVersion: targetValue,
},
]
: []),
...(currentCardinality !== targetCardinality
? [
{
fieldName: 'cardiinality',
currentVersion: currentCardinality,
dplumlee marked this conversation as resolved.
Show resolved Hide resolved
targetVersion: targetCardinality,
},
]
: []),
];
};
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import type {
RuleFieldsDiffWithDataSource,
RuleFieldsDiffWithKqlQuery,
RuleFieldsDiffWithEqlQuery,
RuleFieldsDiffWithThreshold,
} from '../../../../../../common/api/detection_engine';
import type { FormattedFieldDiff } from '../../../model/rule_details/rule_field_diff';
import {
Expand All @@ -23,6 +24,7 @@ import {
getFieldDiffsForTimelineTemplate,
getFieldDiffsForBuildingBlock,
sortAndStringifyJson,
getFieldDiffsForThreshold,
} from './get_field_diffs_for_grouped_fields';

export const getFormattedFieldDiffGroups = (
Expand Down Expand Up @@ -80,6 +82,14 @@ export const getFormattedFieldDiffGroups = (
shouldShowSubtitles: true,
fieldDiffs: getFieldDiffsForBuildingBlock(buildingBlockThreeWayDiff),
};
case 'threshold':
const thresholdThreeWayDiff = (fields as RuleFieldsDiffWithThreshold)[
fieldName
] as AllFieldsDiff['threshold'];
return {
shouldShowSubtitles: true,
fieldDiffs: getFieldDiffsForThreshold(thresholdThreeWayDiff),
};
default:
const fieldThreeWayDiff = (fields as AllFieldsDiff)[fieldName];
const currentVersionField = sortAndStringifyJson(fieldThreeWayDiff.current_version);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ export const UpgradePrebuiltRulesTableContextProvider = ({

const extraTabs = useMemo<EuiTabbedContentTab[]>(() => {
const activeRule =
isJsonPrebuiltRulesDiffingEnabled &&
(isJsonPrebuiltRulesDiffingEnabled || isPerFieldPrebuiltRulesDiffingEnabled) &&
dplumlee marked this conversation as resolved.
Show resolved Hide resolved
previewedRule &&
filteredRules.find(({ id }) => id === previewedRule.id);

Expand Down