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

Exclude keys #3055

Merged
merged 13 commits into from
Jul 27, 2023
Original file line number Diff line number Diff line change
Expand Up @@ -100,18 +100,20 @@ public KeyValueProcessor(final PluginMetrics pluginMetrics, final KeyValueProces
throw new PatternSyntaxException("delete_value_regex is not a valid regex string", keyValueProcessorConfig.getDeleteValueRegex(), -1);
}

if (keyValueProcessorConfig.getIncludeKeys() != null) {
if (keyValueProcessorConfig.getExcludeKeys() != null) {
if (keyValueProcessorConfig.getIncludeKeys().equals(keyValueProcessorConfig.getExcludeKeys())) {
if (!keyValueProcessorConfig.getIncludeKeys().isEmpty()) {
throw new IllegalStateException("Include keys and exclude keys set cannot be the same", null);
}
}

excludeKeysSet.addAll(keyValueProcessorConfig.getExcludeKeys());
if (keyValueProcessorConfig.getIncludeKeys().equals(keyValueProcessorConfig.getExcludeKeys())) {
shenkw1 marked this conversation as resolved.
Show resolved Hide resolved
if (!keyValueProcessorConfig.getIncludeKeys().isEmpty()) {
throw new IllegalArgumentException("Include keys and exclude keys set cannot be the same", null);
}
}

includeKeysSet.addAll(keyValueProcessorConfig.getIncludeKeys());
excludeKeysSet.addAll(keyValueProcessorConfig.getExcludeKeys());

includeKeysSet.addAll(keyValueProcessorConfig.getIncludeKeys());
Set<String> intersectionSet = new HashSet<String>(includeKeysSet);
if (intersectionSet.retainAll(excludeKeysSet)) {
shenkw1 marked this conversation as resolved.
Show resolved Hide resolved
if (!intersectionSet.isEmpty()) {
throw new IllegalArgumentException("Include keys and exclude keys set cannot have any overlap", null);
}
}

if (!validTransformOptionSet.contains(keyValueProcessorConfig.getTransformKey())) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -264,8 +264,8 @@ void testIncludeKeysNoMatchKeyValueProcessor() {
}

@Test
void testIncludeKeysAsNullKeyValueProcessor() {
when(mockConfig.getIncludeKeys()).thenReturn(null);
void testIncludeKeysAsDefaultKeyValueProcessor() {
when(mockConfig.getIncludeKeys()).thenReturn(List.of());
keyValueProcessor = new KeyValueProcessor(pluginMetrics, mockConfig);

final Record<Event> record = getMessage("key1=value1&key2=value2");
Expand All @@ -292,8 +292,8 @@ void testExcludeKeysKeyValueProcessor() {
}

@Test
void testExcludeKeysAsNullKeyValueProcessor() {
when(mockConfig.getExcludeKeys()).thenReturn(null);
void testExcludeKeysAsDefaultKeyValueProcessor() {
when(mockConfig.getExcludeKeys()).thenReturn(List.of());
keyValueProcessor = new KeyValueProcessor(pluginMetrics, mockConfig);

final Record<Event> record = getMessage("key1=value1&key2=value2");
Expand All @@ -305,6 +305,16 @@ void testExcludeKeysAsNullKeyValueProcessor() {
assertThatKeyEquals(parsed_message, "key2", "value2");
}

shenkw1 marked this conversation as resolved.
Show resolved Hide resolved
@Test
void testIncludeExcludeKeysOverlapKeyValueProcessor() {
final List<String> includeKeys = List.of("key1", "key3");
final List<String> excludeKeys = List.of("key3");
when(mockConfig.getIncludeKeys()).thenReturn(includeKeys);
when(mockConfig.getExcludeKeys()).thenReturn(excludeKeys);

assertThrows(IllegalArgumentException.class, () -> new KeyValueProcessor(pluginMetrics, mockConfig));
}

@Test
void testCustomPrefixKvProcessor() {
when(mockConfig.getPrefix()).thenReturn("TEST_");
Expand Down
Loading