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

Add Mutate event processor doc. #3234

Merged
merged 56 commits into from
Apr 3, 2023
Merged
Changes from 5 commits
Commits
Show all changes
56 commits
Select commit Hold shift + click to select a range
bcdae54
Opening new PR for file.
carolxob Mar 6, 2023
25d1500
Minor adjustements.
carolxob Mar 7, 2023
8f87f99
Adjustements to tables.
carolxob Mar 7, 2023
ae81c0b
Removed some markdown comments.
carolxob Mar 7, 2023
58cf072
Minor updates.
carolxob Mar 7, 2023
f18444d
Minor edit.
carolxob Mar 8, 2023
755c7cf
Adjustements to tables.
carolxob Mar 8, 2023
3ae7fe5
Updates based on doc review feedback.
carolxob Mar 8, 2023
a5ae6bf
MAde changes based on tech review feedback.
carolxob Mar 9, 2023
0be3d4a
Updated text for YAML file path locations.
carolxob Mar 13, 2023
7b164fd
Edits made based on technical review feedback.
carolxob Mar 13, 2023
156ab94
Minor edits from tech review feedback.
carolxob Mar 13, 2023
3129091
Minor edits.
carolxob Mar 13, 2023
6c1b75f
Updates based on tech review feedback and formatting.
carolxob Mar 14, 2023
9a88f1c
Minor upate from doc review feedback.
carolxob Mar 16, 2023
b4d07bb
Edits from doc review feedback.
carolxob Mar 16, 2023
dc7f22c
Updates based on doc review feedback.
carolxob Mar 17, 2023
5a29f34
Minor updates.
carolxob Mar 17, 2023
d9a8dac
Minor edits.
carolxob Mar 17, 2023
ba2291e
Minor edits.
carolxob Mar 17, 2023
901b80a
Added copy button to relevant code blocks.
carolxob Mar 17, 2023
7bacf22
Minor edits.
carolxob Mar 17, 2023
d8e5b8a
Added links.
carolxob Mar 17, 2023
169f650
Minor edits.
carolxob Mar 17, 2023
54c9011
Minor edits.
carolxob Mar 20, 2023
18fd978
Minor updates.
carolxob Mar 20, 2023
52e1a74
Minor edits.
carolxob Mar 20, 2023
a865221
Minor updates.
carolxob Mar 23, 2023
7bcaa95
Minor edits based on doc review.
carolxob Mar 29, 2023
5167be1
Minor edits based on doc review feedback.
carolxob Mar 29, 2023
f98259e
Edits made based on doc review feedback.
carolxob Mar 29, 2023
f1ee5d9
Minor update to include key examples.
carolxob Mar 31, 2023
4e34b02
Update _data-prepper/pipelines/configuration/processors/mutate-event.md
carolxob Mar 31, 2023
4f76945
Update _data-prepper/pipelines/configuration/processors/mutate-event.md
carolxob Mar 31, 2023
3bd9536
Update _data-prepper/pipelines/configuration/processors/mutate-event.md
carolxob Mar 31, 2023
6154709
Update _data-prepper/pipelines/configuration/processors/mutate-event.md
carolxob Mar 31, 2023
94e3fe1
Update _data-prepper/pipelines/configuration/processors/mutate-event.md
carolxob Mar 31, 2023
ce7d1e0
Update _data-prepper/pipelines/configuration/processors/mutate-event.md
carolxob Mar 31, 2023
cf16ba6
Update _data-prepper/pipelines/configuration/processors/mutate-event.md
carolxob Mar 31, 2023
3762955
Update _data-prepper/pipelines/configuration/processors/mutate-event.md
carolxob Mar 31, 2023
8130321
Update _data-prepper/pipelines/configuration/processors/mutate-event.md
carolxob Mar 31, 2023
ae3c018
Fixing commit.
carolxob Mar 31, 2023
3f64023
Minor edits.
carolxob Mar 31, 2023
46ce3a7
Update _data-prepper/pipelines/configuration/processors/mutate-event.md
carolxob Mar 31, 2023
c2828a4
Update _data-prepper/pipelines/configuration/processors/mutate-event.md
carolxob Mar 31, 2023
6e7e912
Update _data-prepper/pipelines/configuration/processors/mutate-event.md
carolxob Mar 31, 2023
3f12c9f
Update _data-prepper/pipelines/configuration/processors/mutate-event.md
carolxob Mar 31, 2023
ca11e27
Update _data-prepper/pipelines/configuration/processors/mutate-event.md
carolxob Mar 31, 2023
a74d6ff
Update _data-prepper/pipelines/configuration/processors/mutate-event.md
carolxob Mar 31, 2023
3c9314f
Update _data-prepper/pipelines/configuration/processors/mutate-event.md
carolxob Mar 31, 2023
70d7fd3
Update _data-prepper/pipelines/configuration/processors/mutate-event.md
carolxob Mar 31, 2023
6e46643
Update _data-prepper/pipelines/configuration/processors/mutate-event.md
carolxob Mar 31, 2023
5d972d6
Update _data-prepper/pipelines/configuration/processors/mutate-event.md
carolxob Mar 31, 2023
cabfd54
Incorporating editorial review changes.
carolxob Mar 31, 2023
bc17286
Incorporated the rest of editorial feedback received.
carolxob Mar 31, 2023
ada0724
Minor updates based on feedback comments.
carolxob Apr 3, 2023
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
306 changes: 306 additions & 0 deletions _data-prepper/pipelines/configuration/processors/mutate-event.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,306 @@
---
layout: default
title: Mutate event
parent: Processors
grand_parent: Pipelines
nav_order: 45
---

# Mutate event processors

You can use mutate event processors to add entries to an event, delete entries from an event, rename keys in an event, copy values within an event, and convert value types in an event. <!---Need a better overall description to explain what they do in general.--->
carolxob marked this conversation as resolved.
Show resolved Hide resolved

The following processors allow you to mutate an event:

<!--- Need to find out why links below aren't working correctly.>

* [AddEntry] (#AddEntry)
* [CopyValue] (#CopyValue)
* [DeleteEntry] (#DeleteEntry)
* [RenameKey] (#RenameKey)
* [ConvertEntry] (#ConvertEntry)

--->

## AddEntries

The `AddEntries` processor adds entries to an event.

### Configuration

You can configure the `AddEntries` processor with the following options.

Option | Required | Description
:--- | :--- | :---
|`entries` | Yes | A list of entries to add to an event. |
|`key` | Yes | The key of the new entry to be added. |
|`value` | Yes | The value of the new entry to be added. You can use the following data types: strings, booleans, numbers, null, nested objects, and arrays. |
|`overwrite_if_key_exists` | No | When set to `true`, if `key` already exists in the event, then the existing value is overwritten. The default value is `false`. |
carolxob marked this conversation as resolved.
Show resolved Hide resolved

### Basic usage

To get started, create the following `pipeline.yaml` file:
carolxob marked this conversation as resolved.
Show resolved Hide resolved

```yaml
pipeline:
source:
file:
path: "/full/path/to/logs_json.log"
record_type: "event"
format: "json"
processor:
- add_entries:
entries:
- key: "newMessage"
value: 3
overwrite_if_key_exists: true
sink:
- stdout:
```

Create a log file named `logs_json.log` and replace the `path` in the file source of your `pipeline.yaml` with this filepath.
carolxob marked this conversation as resolved.
Show resolved Hide resolved

```json
carolxob marked this conversation as resolved.
Show resolved Hide resolved
{"message": "value"}
```

When you run this processor, it parses the message into the following output:

```json
{"message": "value", "newMessage": 3}
carolxob marked this conversation as resolved.
Show resolved Hide resolved
```

> If `newMessage` already exists, its existing value is overwritten with a value of `3`.

## copy value

The `copy value` processor copies values within an event.
carolxob marked this conversation as resolved.
Show resolved Hide resolved

### Configuration
carolxob marked this conversation as resolved.
Show resolved Hide resolved

You can configure the `copy value` processor with the following options.

Option | Required | Description
:--- | :--- | :---
| `entries` | Yes | A list of entries to be copied in an event. |
| `from_key` | Yes | The key of the entry to be copied.
| `to_key` | Yes | The key of the new entry to be added.
| `overwrite_if_to_key_exists` | No | When set to a value of `true`, if `to_key` already exists in the event, then the existing value will be overwritten. The default value is `false`. |
carolxob marked this conversation as resolved.
Show resolved Hide resolved

### Basic usage

To get started, create the following `pipeline.yaml` file:
carolxob marked this conversation as resolved.
Show resolved Hide resolved

```yaml
pipeline:
source:
file:
path: "/full/path/to/logs_json.log"
record_type: "event"
format: "json"
processor:
- copy_values:
entries:
- from_key: "message"
to_key: "newMessage"
overwrite_if_to_key_exists: true
sink:
- stdout:
```

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

```json
carolxob marked this conversation as resolved.
Show resolved Hide resolved
{"message": "value"}
```

When you run this processor, it parses the message into the following output:

```json
{"message": "value", "newMessage": "value"}
```

> If `newMessage` had already exists, its current value is overwritten with `value`.


## DeleteEntry

The `DeleteEntry` processor deletes entries in an event.
carolxob marked this conversation as resolved.
Show resolved Hide resolved

### Configuration

You can configure the `DeleteEntry` processor with the following options.

Option | Required | Description
:--- | :--- | :---
| `with_keys` | Yes | An array of keys of the entries to be deleted. |

### Basic usage

To get started, create the following `pipeline.yaml` file:

```yaml
pipeline:
source:
file:
path: "/full/path/to/logs_json.log"
record_type: "event"
format: "json"
processor:
- delete_entries:
with_keys: ["message"]
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.
carolxob marked this conversation as resolved.
Show resolved Hide resolved

```json
carolxob marked this conversation as resolved.
Show resolved Hide resolved
{"message": "value", "message2": "value2"}
```

When you run the `DeleteEntry` processor, it parses the message into the following output:

```json
{"message2": "value2"}
```

> If `message` does not exist in the event, then no action occurs.


## RenameKey
carolxob marked this conversation as resolved.
Show resolved Hide resolved

The `rename key` processor renames keys in an event.

### Configuration

You can configure the `rename key` processor with the following options.

Option | Required | Description
:--- | :--- | :---
| `entries` | Yes | A list of entries to rename in an event. |
| `from_key` | Yes | The key of the entry to be renamed. |
| `to_key` | Yes | The new key of the entry.
| `overwrite_if_to_key_exists` | No | When set to a value of`true`, if `to_key` already exists in the event, then the existing value will be overwritten. The default value is `false`.

### Basic usage

To get started, create the following `pipeline.yaml` file:

```yaml
pipeline:
source:
file:
path: "/full/path/to/logs_json.log"
record_type: "event"
format: "json"
processor:
- rename_keys:
entries:
- from_key: "message"
to_key: "newMessage"
overwrite_if_to_key_exists: true
sink:
- stdout:
```

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

```json
carolxob marked this conversation as resolved.
Show resolved Hide resolved
{"message": "value"}
```

When run, the processor parses the message into the following output:

```json
{"newMessage": "value"}
carolxob marked this conversation as resolved.
Show resolved Hide resolved
```

> If `newMessage` already exists, its existing value is overwritten with `value`.

### Special considerations

The renaming operation occurs in a defined order. This means that chaining is implicit with the `RenameKey` processor. See the following `piplines.yaml` file example:
carolxob marked this conversation as resolved.
Show resolved Hide resolved

```yaml
pipeline:
source:
file:
path: "/full/path/to/logs_json.log"
record_type: "event"
format: "json"
processor:
- rename_key:
entries:
- from_key: "message"
to_key: "message2"
- from_key: "message2"
to_key: "message3"
sink:
- stdout:
```

Add the following contents to the `logs_json.log` file:

```json
{"message": "value"}
```

After the processor runs, the following output appears:

```json
{"message3": "value"}
```

## ConvertEntry

The `ConvertEntry` processor converts a value type associated with the specified key in a message to the specified type. It is a casting processor that changes the types of some fields in the event or message. Some of inputted data may need to be converted to different types, such as an integer or a double, so that it will pass the events through condition-based processors, or to perform conditional routing.

### Configuration

You can configure the `ConvertEntry` processor with the following options.
carolxob marked this conversation as resolved.
Show resolved Hide resolved

Option | Required | Description
:--- | :--- | :---
| `key`| Yes | Keys whose value needs to be converted to a different type. |
| `type` | No | Target type for key value. Possible values are `integer`, `double`, `string`, and `boolean`. Default value is `integer`.|
carolxob marked this conversation as resolved.
Show resolved Hide resolved

### Basic usage

To get started with type conversion processor using Data Prepper, create the following `pipeline.yaml` file:
carolxob marked this conversation as resolved.
Show resolved Hide resolved

```yaml
type-conv-pipeline:
source:
file:
path: "/full/path/to/logs_json.log"
record_type: "event"
format: "json"
processor:
- grok:
match:
message: ['%{IPORHOST:clientip} \[%{HTTPDATE:timestamp}\] %{NUMBER:response_status}']
- convert_entry_type:
key: "response_status"
type: "integer"
sink:
- stdout:
```

Create a log file named `logs_json.log` and replace the `path` in the file source of your `pipeline.yaml` with the path of this file.
carolxob marked this conversation as resolved.
Show resolved Hide resolved

```json
{"message": "10.10.10.19 [19/Feb/2015:15:50:36 -0500] 200"}
```

When you run the `Grok` processor, it processor parses the message into the following output:

```json
carolxob marked this conversation as resolved.
Show resolved Hide resolved
{"message": "10.10.10.10 [19/Feb/2015:15:50:36 -0500] 200", "clientip":"10.10.10.10", "timestamp": "19/Feb/2015:15:50:36 -0500", "response_status": "200"}
```

The type conversion processor changes the output received into the following output, where the type of `response_status` value changes to an integer:

```json
{"message": "10.10.10.10 [19/Feb/2015:15:50:36 -0500] 200", "clientip":"10.10.10.10", "timestamp": "19/Feb/2015:15:50:36 -0500", "response_status": 200}
```