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

Drop processor #801

Merged
merged 7 commits into from
Jan 4, 2022
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions data-prepper-plugins/drop-events-processor/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Drop Events Processor
This is a processor that drops all messages that are passed into it.

## Basic Usage
To get started, create the following `pipeline.yaml`.
```yaml
drop-pipeline:
source:
file:
path: "/full/path/to/logs_json.log"
record_type: "event"
format: "json"
prepper:
- drop_events:
sink:
- stdout:
```

Create the following file named `logs_json.log` and replace the `path` in the file source of your `pipeline.yaml` with the path of this file.

```
{"message": "127.0.0.1 198.126.12 [10/Oct/2000:13:55:36 -0700] 200"}
```

When run, the processor will filter out and drop all messages.

## Developer Guide
This plugin is compatible with Java 14. See
- [CONTRIBUTING](https://github.com/opensearch-project/data-prepper/blob/main/CONTRIBUTING.md)
- [monitoring](https://github.com/opensearch-project/data-prepper/blob/main/docs/readme/monitoring.md)
24 changes: 24 additions & 0 deletions data-prepper-plugins/drop-events-processor/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/

plugins {
id 'java'
}

dependencies {
implementation project(':data-prepper-api')
implementation project(':data-prepper-plugins:common')
}

jacocoTestCoverageVerification {
dependsOn jacocoTestReport
violationRules {
rule {
limit {
minimum = 1.0
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/

package com.amazon.dataprepper.plugins.processor.drop;

import com.amazon.dataprepper.model.annotations.DataPrepperPlugin;
import com.amazon.dataprepper.model.annotations.DataPrepperPluginConstructor;
import com.amazon.dataprepper.model.configuration.PluginSetting;
import com.amazon.dataprepper.model.event.Event;
import com.amazon.dataprepper.model.record.Record;
import com.amazon.dataprepper.model.processor.AbstractProcessor;
import com.amazon.dataprepper.model.processor.Processor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.Collection;
import java.util.Collections;

@DataPrepperPlugin(name = "drop_events", pluginType = Processor.class)
public class DropEventsProcessor extends AbstractProcessor<Record<Event>, Record<Event>> {

private static final Logger LOG = LoggerFactory.getLogger(DropEventsProcessor.class);

@DataPrepperPluginConstructor
public DropEventsProcessor(final PluginSetting pluginSetting) {
super(pluginSetting);
}

@Override
public Collection<Record<Event>> doExecute(Collection<Record<Event>> records) {
return Collections.emptyList();
}

@Override
public void prepareForShutdown() {
}

@Override
public boolean isReadyForShutdown() {
return true;
}

@Override
public void shutdown() {
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/

package com.amazon.dataprepper.plugins.processor.drop;

import com.amazon.dataprepper.model.configuration.PluginSetting;
import com.amazon.dataprepper.model.event.Event;
import com.amazon.dataprepper.model.event.JacksonEvent;
import com.amazon.dataprepper.model.record.Record;
import org.junit.jupiter.api.Test;

import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.UUID;

import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.MatcherAssert.assertThat;

public class DropEventsProcessorTests {
sbayer55 marked this conversation as resolved.
Show resolved Hide resolved
private String messageInput;
private DropEventsProcessor dropProcessor;
private PluginSetting pluginSetting;
private final String PLUGIN_NAME = "drop_events";

@Test
void doExecute() {
sbayer55 marked this conversation as resolved.
Show resolved Hide resolved
pluginSetting = getDefaultPluginSetting();
pluginSetting.setPipelineName("dropProcessorPipeline");
dropProcessor = new DropEventsProcessor(pluginSetting);

final Map<String, Object> testData = new HashMap();
messageInput = UUID.randomUUID().toString();
testData.put("message", messageInput);
final Record<Event> record = buildRecordWithEvent(testData);

final List<Record<Event>> droppedRecords = (List<Record<Event>>) dropProcessor.doExecute(Collections.singletonList(record));
sbayer55 marked this conversation as resolved.
Show resolved Hide resolved

assertThat(droppedRecords.size(), equalTo(0));
sbayer55 marked this conversation as resolved.
Show resolved Hide resolved
}

@Test
void doExecuteMulti() {
pluginSetting = getDefaultPluginSetting();
pluginSetting.setPipelineName("dropProcessorPipeline");
dropProcessor = new DropEventsProcessor(pluginSetting);

final Map<String, Object> testData = new HashMap();
messageInput = UUID.randomUUID().toString();
testData.put("message", messageInput);
final Record<Event> record = buildRecordWithEvent(testData);

messageInput = UUID.randomUUID().toString();
testData.put("message", messageInput);
final Record<Event> record2 = buildRecordWithEvent(testData);

final List<Record<Event>> multiSet = new LinkedList<>();
sbayer55 marked this conversation as resolved.
Show resolved Hide resolved
multiSet.add(record);
multiSet.add(record2);

final List<Record<Event>> droppedRecords = (List<Record<Event>>) dropProcessor.doExecute(multiSet);
sbayer55 marked this conversation as resolved.
Show resolved Hide resolved

assertThat(droppedRecords.size(), equalTo(0));
}

private PluginSetting getDefaultPluginSetting() {
final Map<String, Object> settings = new HashMap<>();
return new PluginSetting(PLUGIN_NAME, settings);
}

static Record<Event> buildRecordWithEvent(final Map<String, Object> data) {
return new Record<>(JacksonEvent.builder()
.withData(data)
.withEventType("event")
.build());
}
}
1 change: 1 addition & 0 deletions settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ include 'data-prepper-plugins:otel-trace-source'
include 'data-prepper-plugins:peer-forwarder'
include 'data-prepper-plugins:blocking-buffer'
include 'data-prepper-plugins:http-source'
include 'data-prepper-plugins:drop-events-processor'
include 'data-prepper-plugins:grok-prepper'
include 'data-prepper-logstash-configuration'
include 'e2e-test'
Expand Down