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] Substitute MissingVersion symbol in the ThreeWayDiff object with a boolean #188277

Closed
Tracked by #174168
nikitaindik opened this issue Jul 13, 2024 · 3 comments · Fixed by #187770
Closed
Tracked by #174168
Assignees
Labels
8.16 candidate Feature:Prebuilt Detection Rules Security Solution Prebuilt Detection Rules area refactoring Team:Detection Rule Management Security Detection Rule Management Team Team:Detections and Resp Security Detection Response Team Team: SecuritySolution Security Solutions Team working on SIEM, Endpoint, Timeline, Resolver, etc.

Comments

@nikitaindik
Copy link
Contributor

nikitaindik commented Jul 13, 2024

Epics: https://github.com/elastic/security-team/issues/1974 (internal), #174168

Summary

TL;DR: We can't use the MissingVersion symbol in UI code because it's getting cut away from backend responses.

When calculating a three-way diff for a rule field, we take the value of this field from each of the three rule versions: base, current, and target. In case the base version of a rule is missing, we set the field's value to a MissingVersion symbol.

Thus, we pass an object of this shape to a diffing algorithm function, like simpleDiffAlgorithm:

// Diffing algorithm input - 3 versions of a field value
{
     base_version: field value | MissingVersion,
     current_version: field value,
     target_version: field value
}

Each diffing algorithm function returns a ThreeWayDiff object that is later sent to the front end.

// Diffing algorithm output (ThreeWayDiff)
{
     base_version, // field value or MissingVersion
     current_version, // field value
     target_version, // field value
     merged_version, // field value
     diff_outcome,
     merge_outcome,
     has_update,
     has_conflict
}

Before being sent to the FE the ThreeWayDiff gets converted into a JSON. And so base_version: MissingVersion symbol becomes base_version: undefined since JS symbols don't exist in JSON.

This makes using the ThreeWayDiff TS type unsafe on the FE because the received object can now have base_version equal to undefined, while the TS type "guarantees" base_version to be either a symbol or an actual field value.

One way to solve this would be to not use the MissingVersion symbol in ThreeWayDiff but to add a boolean property like has_base_version.

// Updated diffing algorithm output (ThreeWayDiff)
{
     has_base_version, // boolean
     base_version, // field value or undefined
     current_version, // field value
     target_version, // field value
     merged_version, // field value
     diff_outcome,
     merge_outcome,
     has_update,
     has_conflict
}
@nikitaindik nikitaindik added technical debt Improvement of the software architecture and operational architecture Team:Detections and Resp Security Detection Response Team Team: SecuritySolution Security Solutions Team working on SIEM, Endpoint, Timeline, Resolver, etc. Team:Detection Rule Management Security Detection Rule Management Team Feature:Prebuilt Detection Rules Security Solution Prebuilt Detection Rules area Feature:Rule Details Security Solution Detection Rule Details page v8.16.0 8.17 candidate labels Jul 13, 2024
@elasticmachine
Copy link
Contributor

Pinging @elastic/security-detections-response (Team:Detections and Resp)

@elasticmachine
Copy link
Contributor

Pinging @elastic/security-detection-rule-management (Team:Detection Rule Management)

@elasticmachine
Copy link
Contributor

Pinging @elastic/security-solution (Team: SecuritySolution)

@nikitaindik nikitaindik changed the title [Security Solution] Get rid of the MissingVersion symbol in the ThreeWayDiff object [Security Solution] Substitute MissingVersion symbol in the ThreeWayDiff object with a boolean Jul 15, 2024
@banderror banderror added triage_needed refactoring 8.16 candidate and removed v8.16.0 8.17 candidate triage_needed technical debt Improvement of the software architecture and operational architecture Feature:Rule Details Security Solution Detection Rule Details page labels Jul 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
8.16 candidate Feature:Prebuilt Detection Rules Security Solution Prebuilt Detection Rules area refactoring Team:Detection Rule Management Security Detection Rule Management Team Team:Detections and Resp Security Detection Response Team Team: SecuritySolution Security Solutions Team working on SIEM, Endpoint, Timeline, Resolver, etc.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants