From 16d8b5d80bd58f681eccd0540c2dc271ed8324b8 Mon Sep 17 00:00:00 2001 From: Jan Heise Date: Tue, 14 Jan 2025 14:34:10 +0100 Subject: [PATCH 01/10] fixes missing query parameters in content packs --- .../AggregationEventProcessorConfigEntity.java | 10 ++++++++++ .../aggregation/AggregationEventProcessorConfig.java | 1 + 2 files changed, 11 insertions(+) diff --git a/graylog2-server/src/main/java/org/graylog/events/contentpack/entities/AggregationEventProcessorConfigEntity.java b/graylog2-server/src/main/java/org/graylog/events/contentpack/entities/AggregationEventProcessorConfigEntity.java index 9b212439194d..f7f9d435ea90 100644 --- a/graylog2-server/src/main/java/org/graylog/events/contentpack/entities/AggregationEventProcessorConfigEntity.java +++ b/graylog2-server/src/main/java/org/graylog/events/contentpack/entities/AggregationEventProcessorConfigEntity.java @@ -26,6 +26,7 @@ import org.graylog.events.processor.EventProcessorConfig; import org.graylog.events.processor.aggregation.AggregationConditions; import org.graylog.events.processor.aggregation.AggregationEventProcessorConfig; +import org.graylog.plugins.views.search.Parameter; import org.graylog.plugins.views.search.searchfilters.model.UsedSearchFilter; import org.graylog2.contentpacks.exceptions.ContentPackException; import org.graylog2.contentpacks.model.entities.Entity; @@ -40,6 +41,7 @@ import java.util.Map; import java.util.Objects; import java.util.Optional; +import java.util.Set; import java.util.stream.Collectors; import static org.graylog2.contentpacks.facades.StreamReferenceFacade.resolveStreamEntity; @@ -52,6 +54,7 @@ public abstract class AggregationEventProcessorConfigEntity implements EventProc public static final String TYPE_NAME = "aggregation-v1"; private static final String FIELD_QUERY = "query"; + private static final String FIELD_QUERY_PARAMETERS = "query_parameters"; private static final String FIELD_FILTERS = "filters"; private static final String FIELD_STREAMS = "streams"; private static final String FIELD_STREAM_CATEGORIES = "stream_categories"; @@ -68,6 +71,9 @@ public abstract class AggregationEventProcessorConfigEntity implements EventProc @JsonProperty(FIELD_QUERY) public abstract ValueReference query(); + @JsonProperty(FIELD_QUERY_PARAMETERS) + public abstract ImmutableSet queryParameters(); + @JsonProperty(FIELD_FILTERS) public abstract List filters(); @@ -126,6 +132,9 @@ public static Builder create() { @JsonProperty(FIELD_QUERY) public abstract Builder query(ValueReference query); + @JsonProperty(FIELD_QUERY_PARAMETERS) + public abstract Builder queryParameters(Set queryParameters); + @JsonProperty public abstract Builder filters(List filters); @@ -186,6 +195,7 @@ public EventProcessorConfig toNativeEntity(Map parameter return AggregationEventProcessorConfig.builder() .type(type()) .query(query().asString(parameters)) + .queryParameters(queryParameters()) .streams(streamSet) .filters(filters().stream().map(filter -> filter.toNativeEntity(parameters, nativeEntities)).toList()) .groupBy(groupBy()) diff --git a/graylog2-server/src/main/java/org/graylog/events/processor/aggregation/AggregationEventProcessorConfig.java b/graylog2-server/src/main/java/org/graylog/events/processor/aggregation/AggregationEventProcessorConfig.java index d497e7377b3d..7cd534a0c59c 100644 --- a/graylog2-server/src/main/java/org/graylog/events/processor/aggregation/AggregationEventProcessorConfig.java +++ b/graylog2-server/src/main/java/org/graylog/events/processor/aggregation/AggregationEventProcessorConfig.java @@ -332,6 +332,7 @@ public EventProcessorConfigEntity toContentPackEntity(EntityDescriptorIds entity return AggregationEventProcessorConfigEntity.builder() .type(type()) .query(ValueReference.of(query())) + .queryParameters(queryParameters()) .filters(filters().stream().map(filter -> filter.toContentPackEntity(entityDescriptorIds)).toList()) .streams(streamRefs) .streamCategories(streamCategories()) From aeb7996aec093f23878d8f67ebcc1e0c1db7f4f0 Mon Sep 17 00:00:00 2001 From: Jan Heise Date: Wed, 15 Jan 2025 11:34:02 +0100 Subject: [PATCH 02/10] add Nullable --- .../processor/aggregation/AggregationEventProcessorConfig.java | 1 + 1 file changed, 1 insertion(+) diff --git a/graylog2-server/src/main/java/org/graylog/events/processor/aggregation/AggregationEventProcessorConfig.java b/graylog2-server/src/main/java/org/graylog/events/processor/aggregation/AggregationEventProcessorConfig.java index 7cd534a0c59c..d5580b18c31e 100644 --- a/graylog2-server/src/main/java/org/graylog/events/processor/aggregation/AggregationEventProcessorConfig.java +++ b/graylog2-server/src/main/java/org/graylog/events/processor/aggregation/AggregationEventProcessorConfig.java @@ -86,6 +86,7 @@ public abstract class AggregationEventProcessorConfig implements EventProcessorC @JsonProperty(FIELD_QUERY) public abstract String query(); + @Nullable @JsonProperty(FIELD_QUERY_PARAMETERS) public abstract ImmutableSet queryParameters(); From b4b4026704d1c58412c1212214fc1daa00bf88b3 Mon Sep 17 00:00:00 2001 From: Jan Heise Date: Wed, 15 Jan 2025 13:19:31 +0100 Subject: [PATCH 03/10] add Nullable --- .../entities/AggregationEventProcessorConfigEntity.java | 1 + 1 file changed, 1 insertion(+) diff --git a/graylog2-server/src/main/java/org/graylog/events/contentpack/entities/AggregationEventProcessorConfigEntity.java b/graylog2-server/src/main/java/org/graylog/events/contentpack/entities/AggregationEventProcessorConfigEntity.java index f7f9d435ea90..c22990d11cb1 100644 --- a/graylog2-server/src/main/java/org/graylog/events/contentpack/entities/AggregationEventProcessorConfigEntity.java +++ b/graylog2-server/src/main/java/org/graylog/events/contentpack/entities/AggregationEventProcessorConfigEntity.java @@ -71,6 +71,7 @@ public abstract class AggregationEventProcessorConfigEntity implements EventProc @JsonProperty(FIELD_QUERY) public abstract ValueReference query(); + @Nullable @JsonProperty(FIELD_QUERY_PARAMETERS) public abstract ImmutableSet queryParameters(); From 0aa44fb789cbbdeb4e164db6e8a6031ccf58d630 Mon Sep 17 00:00:00 2001 From: Jan Heise Date: Mon, 20 Jan 2025 15:58:42 +0100 Subject: [PATCH 04/10] adding changelog --- changelog/unreleased/pr-21349.toml | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 changelog/unreleased/pr-21349.toml diff --git a/changelog/unreleased/pr-21349.toml b/changelog/unreleased/pr-21349.toml new file mode 100644 index 000000000000..16590eb2c792 --- /dev/null +++ b/changelog/unreleased/pr-21349.toml @@ -0,0 +1,4 @@ +type = "fixed" +message = "Fix missing Query Parameters in Event Definitions in Content Packs." + +pulls = ["21349"] From c633b46a37ac5262a7b6d1163372f4a653417e00 Mon Sep 17 00:00:00 2001 From: Jan Heise Date: Thu, 30 Jan 2025 16:44:00 +0100 Subject: [PATCH 05/10] adding dependency to lookup table --- .../aggregation/AggregationEventProcessorConfig.java | 1 + .../org/graylog/plugins/views/search/Parameter.java | 10 +++++++++- .../contentpacks/facades/LookupTableFacade.java | 3 ++- 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/graylog2-server/src/main/java/org/graylog/events/processor/aggregation/AggregationEventProcessorConfig.java b/graylog2-server/src/main/java/org/graylog/events/processor/aggregation/AggregationEventProcessorConfig.java index d5580b18c31e..a8d8266de84c 100644 --- a/graylog2-server/src/main/java/org/graylog/events/processor/aggregation/AggregationEventProcessorConfig.java +++ b/graylog2-server/src/main/java/org/graylog/events/processor/aggregation/AggregationEventProcessorConfig.java @@ -358,6 +358,7 @@ public void resolveNativeEntity(EntityDescriptor entityDescriptor, MutableGraph< .build(); mutableGraph.putEdge(entityDescriptor, depStream); }); + queryParameters().forEach(parameter -> parameter.resolveNativeEntity(entityDescriptor, mutableGraph)); filters().forEach(filter -> filter.resolveNativeEntity(entityDescriptor, mutableGraph)); } diff --git a/graylog2-server/src/main/java/org/graylog/plugins/views/search/Parameter.java b/graylog2-server/src/main/java/org/graylog/plugins/views/search/Parameter.java index a847b6bcc5a8..17d486f43336 100644 --- a/graylog2-server/src/main/java/org/graylog/plugins/views/search/Parameter.java +++ b/graylog2-server/src/main/java/org/graylog/plugins/views/search/Parameter.java @@ -21,6 +21,10 @@ import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonTypeInfo; import com.google.common.collect.Maps; +import com.google.common.graph.MutableGraph; +import org.graylog2.contentpacks.ContentPackable; +import org.graylog2.contentpacks.EntityDescriptorIds; +import org.graylog2.contentpacks.model.entities.EntityDescriptor; import javax.annotation.Nullable; import java.util.Map; @@ -41,7 +45,7 @@ property = Parameter.TYPE_FIELD, visible = true, defaultImpl = ValueParameter.class) -public interface Parameter { +public interface Parameter extends ContentPackable { String TYPE_FIELD = "type"; @JsonProperty(TYPE_FIELD) @@ -74,6 +78,10 @@ public interface Parameter { Parameter applyBindings(Map bindings); + default Parameter toContentPackEntity(EntityDescriptorIds entityDescriptorIds) { + return this; + } + interface Builder { @JsonProperty(TYPE_FIELD) SELF type(String type); diff --git a/graylog2-server/src/main/java/org/graylog2/contentpacks/facades/LookupTableFacade.java b/graylog2-server/src/main/java/org/graylog2/contentpacks/facades/LookupTableFacade.java index b600bf655a26..84fc81dc516d 100644 --- a/graylog2-server/src/main/java/org/graylog2/contentpacks/facades/LookupTableFacade.java +++ b/graylog2-server/src/main/java/org/graylog2/contentpacks/facades/LookupTableFacade.java @@ -76,7 +76,8 @@ private EntityDescriptor cacheDescriptor(String cacheId) { @VisibleForTesting Entity exportNativeEntity(LookupTableDto lookupTableDto, EntityDescriptorIds entityDescriptorIds) { final String tableId = entityDescriptorIds.get(EntityDescriptor.create(lookupTableDto.id(), ModelTypes.LOOKUP_TABLE_V1)) - .orElseThrow(() -> new ContentPackException("Couldn't find lookup table entity " + lookupTableDto.id())); + .orElseGet(() -> entityDescriptorIds.get(EntityDescriptor.create(lookupTableDto.name(), ModelTypes.LOOKUP_TABLE_V1)) + .orElseThrow(() -> new ContentPackException("Couldn't find lookup table entity " + lookupTableDto.id()))); final String cacheId = entityDescriptorIds.get(cacheDescriptor(lookupTableDto.cacheId())) .orElseThrow(() -> new ContentPackException("Couldn't find lookup cache entity " + lookupTableDto.cacheId())); final String adapterId = entityDescriptorIds.get(adapterDescriptor(lookupTableDto.dataAdapterId())) From d0fda64b408fc1376e84dca73c4450ffb275cad9 Mon Sep 17 00:00:00 2001 From: Jan Heise Date: Thu, 30 Jan 2025 16:47:50 +0100 Subject: [PATCH 06/10] adding dependency to lookup table, removing obsolete imports --- .../main/java/org/graylog/plugins/views/search/Parameter.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/graylog2-server/src/main/java/org/graylog/plugins/views/search/Parameter.java b/graylog2-server/src/main/java/org/graylog/plugins/views/search/Parameter.java index 17d486f43336..9fc859da9e0c 100644 --- a/graylog2-server/src/main/java/org/graylog/plugins/views/search/Parameter.java +++ b/graylog2-server/src/main/java/org/graylog/plugins/views/search/Parameter.java @@ -21,10 +21,8 @@ import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonTypeInfo; import com.google.common.collect.Maps; -import com.google.common.graph.MutableGraph; import org.graylog2.contentpacks.ContentPackable; import org.graylog2.contentpacks.EntityDescriptorIds; -import org.graylog2.contentpacks.model.entities.EntityDescriptor; import javax.annotation.Nullable; import java.util.Map; From 4eaa1dec3bcc05a9dc05c3a60a2822e8f0bbadd9 Mon Sep 17 00:00:00 2001 From: Jan Heise Date: Thu, 30 Jan 2025 17:01:48 +0100 Subject: [PATCH 07/10] adding null check --- .../aggregation/AggregationEventProcessorConfig.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/graylog2-server/src/main/java/org/graylog/events/processor/aggregation/AggregationEventProcessorConfig.java b/graylog2-server/src/main/java/org/graylog/events/processor/aggregation/AggregationEventProcessorConfig.java index a8d8266de84c..ae9db56b6f7e 100644 --- a/graylog2-server/src/main/java/org/graylog/events/processor/aggregation/AggregationEventProcessorConfig.java +++ b/graylog2-server/src/main/java/org/graylog/events/processor/aggregation/AggregationEventProcessorConfig.java @@ -358,7 +358,10 @@ public void resolveNativeEntity(EntityDescriptor entityDescriptor, MutableGraph< .build(); mutableGraph.putEdge(entityDescriptor, depStream); }); - queryParameters().forEach(parameter -> parameter.resolveNativeEntity(entityDescriptor, mutableGraph)); + // attribute is tagged @Nullable, so do a null check first + if(queryParameters() != null) { + queryParameters().forEach(parameter -> parameter.resolveNativeEntity(entityDescriptor, mutableGraph)); + } filters().forEach(filter -> filter.resolveNativeEntity(entityDescriptor, mutableGraph)); } From b01dd30998593a8dd5e83e80217565cf9b2389dd Mon Sep 17 00:00:00 2001 From: Jan Heise Date: Fri, 31 Jan 2025 10:28:23 +0100 Subject: [PATCH 08/10] changelog --- changelog/unreleased/pr-21349.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/changelog/unreleased/pr-21349.toml b/changelog/unreleased/pr-21349.toml index 16590eb2c792..9434dec74f64 100644 --- a/changelog/unreleased/pr-21349.toml +++ b/changelog/unreleased/pr-21349.toml @@ -1,4 +1,5 @@ type = "fixed" message = "Fix missing Query Parameters in Event Definitions in Content Packs." +issues = ["Graylog2/graylog-plugin-enterprise#9274"] pulls = ["21349"] From 1f8911d342e8f5a13d4206157257c563cc26bf6a Mon Sep 17 00:00:00 2001 From: Jan Heise Date: Fri, 7 Feb 2025 10:51:50 +0100 Subject: [PATCH 09/10] adding the dependency to the lookup adapter for CP creation of a Search --- .../src/main/java/org/graylog/plugins/views/search/Search.java | 1 + 1 file changed, 1 insertion(+) diff --git a/graylog2-server/src/main/java/org/graylog/plugins/views/search/Search.java b/graylog2-server/src/main/java/org/graylog/plugins/views/search/Search.java index a284393ba247..379dcfe3adef 100644 --- a/graylog2-server/src/main/java/org/graylog/plugins/views/search/Search.java +++ b/graylog2-server/src/main/java/org/graylog/plugins/views/search/Search.java @@ -331,5 +331,6 @@ public SearchEntity toContentPackEntity(EntityDescriptorIds entityDescriptorIds) @Override public void resolveNativeEntity(EntityDescriptor entityDescriptor, MutableGraph mutableGraph) { queries().forEach(query -> query.resolveNativeEntity(entityDescriptor, mutableGraph)); + parameters().forEach(parameter -> parameter.resolveNativeEntity(entityDescriptor, mutableGraph)); } } From 04535c97c785cf4ffe3d884561a2817b6a7aa705 Mon Sep 17 00:00:00 2001 From: Jan Heise Date: Fri, 7 Feb 2025 11:00:04 +0100 Subject: [PATCH 10/10] add correct changelog --- changelog/unreleased/pr-21563.toml | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 changelog/unreleased/pr-21563.toml diff --git a/changelog/unreleased/pr-21563.toml b/changelog/unreleased/pr-21563.toml new file mode 100644 index 000000000000..fb99649d45dd --- /dev/null +++ b/changelog/unreleased/pr-21563.toml @@ -0,0 +1,4 @@ +type = "fixed" +message = "Fix missing dependency for Data Adapter when creating Content Pack for Search with Parameters." + +pulls = ["21563"]