-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Tolerate unresolvable stream references during content pack install #26581
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
Open
patrickmann
wants to merge
5
commits into
master
Choose a base branch
from
fix/content-pack-tolerate-missing-stream-references
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 3 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
27f4961
Tolerate unresolvable stream references during content pack install
patrickmann 224c101
Add changelog for #26581
patrickmann 7644c4c
unit tests
patrickmann 5d20140
Fix review feedback on stream type errors
Copilot 6c4d373
refactor tests
patrickmann File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| type = "fixed" | ||
| message = "Fix content pack installation failing with \"Missing Stream for widget entity\" when a view references a stream that cannot be resolved. The unresolvable stream reference is now skipped with a warning instead of aborting the whole installation." | ||
|
|
||
| issues = ["Graylog2/graylog-plugin-enterprise#12987"] | ||
| pulls = ["26581"] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
97 changes: 97 additions & 0 deletions
97
...2-server/src/test/java/org/graylog2/contentpacks/model/entities/SearchTypeEntityTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,97 @@ | ||
| /* | ||
| * Copyright (C) 2020 Graylog, Inc. | ||
| * | ||
| * This program is free software: you can redistribute it and/or modify | ||
| * it under the terms of the Server Side Public License, version 1, | ||
| * as published by MongoDB, Inc. | ||
| * | ||
| * This program is distributed in the hope that it will be useful, | ||
| * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| * Server Side Public License for more details. | ||
| * | ||
| * You should have received a copy of the Server Side Public License | ||
| * along with this program. If not, see | ||
| * <http://www.mongodb.com/licensing/server-side-public-license>. | ||
| */ | ||
| package org.graylog2.contentpacks.model.entities; | ||
|
|
||
| import com.google.common.collect.ImmutableSet; | ||
| import org.graylog.plugins.views.search.SearchType; | ||
| import org.graylog2.contentpacks.exceptions.ContentPackException; | ||
| import org.graylog2.contentpacks.model.ModelTypes; | ||
| import org.graylog2.plugin.streams.Stream; | ||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| import java.util.Collections; | ||
| import java.util.Map; | ||
|
|
||
| import static org.assertj.core.api.Assertions.assertThat; | ||
| import static org.assertj.core.api.Assertions.assertThatThrownBy; | ||
| import static org.mockito.Mockito.mock; | ||
| import static org.mockito.Mockito.when; | ||
|
|
||
| class SearchTypeEntityTest { | ||
|
|
||
| @Test | ||
| public void dropsUnresolvableStreamReferenceInsteadOfFailing() { | ||
| final MessageListEntity searchType = MessageListEntity.builder() | ||
| .id("search-type-id") | ||
| .streams(ImmutableSet.of("missing-stream-id")) | ||
| .build(); | ||
|
|
||
| final SearchType nativeEntity = searchType.toNativeEntity(Collections.emptyMap(), Collections.emptyMap()); | ||
|
|
||
| assertThat(nativeEntity.streams()).isEmpty(); | ||
| } | ||
|
|
||
| @Test | ||
| public void keepsResolvableStreamReference() { | ||
| final Stream stream = mock(Stream.class); | ||
| when(stream.getId()).thenReturn("native-stream-id"); | ||
| final Map<EntityDescriptor, Object> nativeEntities = | ||
| Map.of(EntityDescriptor.create("cp-stream-id", ModelTypes.STREAM_REF_V1), stream); | ||
|
|
||
| final MessageListEntity searchType = MessageListEntity.builder() | ||
| .id("search-type-id") | ||
| .streams(ImmutableSet.of("cp-stream-id")) | ||
| .build(); | ||
|
|
||
| final SearchType nativeEntity = searchType.toNativeEntity(Collections.emptyMap(), nativeEntities); | ||
|
|
||
| assertThat(nativeEntity.streams()).containsExactly("native-stream-id"); | ||
| } | ||
|
|
||
| @Test | ||
| public void dropsOnlyUnresolvableStreamReferences() { | ||
| final Stream stream = mock(Stream.class); | ||
| when(stream.getId()).thenReturn("native-stream-id"); | ||
| final Map<EntityDescriptor, Object> nativeEntities = | ||
| Map.of(EntityDescriptor.create("cp-stream-id", ModelTypes.STREAM_REF_V1), stream); | ||
|
|
||
| final MessageListEntity searchType = MessageListEntity.builder() | ||
| .id("search-type-id") | ||
| .streams(ImmutableSet.of("cp-stream-id", "missing-stream-id")) | ||
| .build(); | ||
|
|
||
| final SearchType nativeEntity = searchType.toNativeEntity(Collections.emptyMap(), nativeEntities); | ||
|
|
||
| assertThat(nativeEntity.streams()).containsExactly("native-stream-id"); | ||
| } | ||
|
|
||
| @Test | ||
| public void failsOnWrongTypeStreamReference() { | ||
| // A non-null value that is not a Stream indicates a corrupt entity map, which must still abort the install. | ||
| final Map<EntityDescriptor, Object> nativeEntities = | ||
| Map.of(EntityDescriptor.create("cp-stream-id", ModelTypes.STREAM_REF_V1), "not-a-stream"); | ||
|
|
||
| final MessageListEntity searchType = MessageListEntity.builder() | ||
| .id("search-type-id") | ||
| .streams(ImmutableSet.of("cp-stream-id")) | ||
| .build(); | ||
|
|
||
| assertThatThrownBy(() -> searchType.toNativeEntity(Collections.emptyMap(), nativeEntities)) | ||
| .isInstanceOf(ContentPackException.class) | ||
| .hasMessageContaining("Invalid type for stream"); | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.