Skip to content

Commit e9b4112

Browse files
committed
feat(correlation-rules): add rule_group_by_def to support grouping in correlation rules
1 parent 86d6d7f commit e9b4112

File tree

5 files changed

+54
-0
lines changed

5 files changed

+54
-0
lines changed

backend/src/main/java/com/park/utmstack/domain/correlation/rules/UtmCorrelationRules.java

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,10 @@ public class UtmCorrelationRules implements Serializable {
110110
@Setter(AccessLevel.NONE)
111111
private List<SearchRequest> afterEvents;
112112

113+
@JsonIgnore
114+
@Column(name = "rule_group_by_def")
115+
private String ruleGroupByDef;
116+
113117
@JsonIgnore
114118
@Column(name = "rule_deduplicate_by_def")
115119
private String deduplicateByDef;
@@ -136,6 +140,28 @@ public void setDeduplicateBy(List<String> deduplicateBy) throws UtmSerialization
136140
this.deduplicateBy = deduplicateBy;
137141
}
138142

143+
@Transient
144+
@JsonSerialize
145+
@JsonDeserialize
146+
@Getter(AccessLevel.NONE)
147+
@Setter(AccessLevel.NONE)
148+
private List<String> groupBy;
149+
150+
public List<String> getGroupBy() throws UtmSerializationException {
151+
if (StringUtils.hasText(deduplicateByDef))
152+
groupBy = UtilSerializer.jsonDeserializeList(String.class, ruleGroupByDef);
153+
return groupBy == null ? new ArrayList<>() : groupBy;
154+
}
155+
156+
public void setGroupBy(List<String> groupBy) throws UtmSerializationException {
157+
if (CollectionUtils.isEmpty(groupBy))
158+
this.ruleGroupByDef = null;
159+
else
160+
this.ruleGroupByDef = UtilSerializer.jsonSerialize(groupBy);
161+
162+
this.groupBy = groupBy;
163+
}
164+
139165
@ManyToMany(fetch = FetchType.EAGER)
140166
@JoinTable(name = "utm_group_rules_data_type",
141167
joinColumns = @JoinColumn(name = "rule_id"),

backend/src/main/java/com/park/utmstack/service/dto/correlation/UtmCorrelationRulesDTO.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,5 +62,7 @@ public class UtmCorrelationRulesDTO implements Serializable {
6262

6363
private List<String> deduplicateBy;
6464

65+
private List<String> groupBy;
66+
6567
}
6668

backend/src/main/java/com/park/utmstack/service/dto/correlation/UtmCorrelationRulesMapper.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ public UtmCorrelationRulesDTO toDto(UtmCorrelationRules entity) {
3535
dto.setRuleActive(entity.getRuleActive());
3636
dto.setAfterEvents(entity.getAfterEvents());
3737
dto.setDeduplicateBy(entity.getDeduplicateBy());
38+
dto.setGroupBy(entity.getGroupBy());
3839
return dto;
3940
} catch (UtmSerializationException e) {
4041
logger.error("Error serializing rule references", e);
@@ -62,6 +63,7 @@ public UtmCorrelationRules toEntity(UtmCorrelationRulesDTO dto) {
6263
entity.setRuleLastUpdate(Instant.now(Clock.systemUTC()));
6364
entity.setAfterEvents(dto.getAfterEvents());
6465
entity.setDeduplicateBy(dto.getDeduplicateBy());
66+
entity.setGroupBy(dto.getGroupBy());
6567

6668
return entity;
6769
} catch (UtmSerializationException e) {
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<databaseChangeLog
3+
xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
4+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5+
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.5.xsd">
6+
7+
<changeSet id="20260119001" author="manuel">
8+
9+
<addColumn tableName="utm_correlation_rules">
10+
<column name="rule_group_by_def" type="text"/>
11+
</addColumn>
12+
13+
<update tableName="utm_correlation_rules">
14+
<column name="rule_group_by_def" valueComputed="rule_deduplicate_by_def"/>
15+
</update>
16+
17+
<update tableName="utm_correlation_rules">
18+
<column name="rule_deduplicate_by_def" value=""/>
19+
</update>
20+
21+
</changeSet>
22+
</databaseChangeLog>

backend/src/main/resources/config/liquibase/master.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,8 @@
307307

308308
<include file="/config/liquibase/changelog/20260119001_update_menu_url_for_soc_ai.xml" relativeToChangelogFile="false"/>
309309

310+
<include file="/config/liquibase/changelog/20260120001_add_rule_group_by_to_correlation_rules.xml" relativeToChangelogFile="false"/>
311+
310312

311313

312314

0 commit comments

Comments
 (0)