Skip to content
This repository has been archived by the owner on Mar 21, 2023. It is now read-only.

Add clone_message() function #153

Merged
merged 2 commits into from Jan 4, 2017
Merged

Add clone_message() function #153

merged 2 commits into from Jan 4, 2017

Conversation

joschi
Copy link
Contributor

@joschi joschi commented Jan 3, 2017

Closes #138

@joschi joschi added this to the 2.2.0 milestone Jan 3, 2017
public FunctionDescriptor<Message> descriptor() {
return FunctionDescriptor.<Message>builder()
.name(NAME)
.params(new ParameterDescriptor[0])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add an optional message parameter here (analogous to https://github.com/Graylog2/graylog-plugin-pipeline-processor/blob/master/plugin/src/main/java/org/graylog/plugins/pipelineprocessor/functions/messages/RemoveField.java#L34)?

That way we could support cloning other messages than the one from the context, as well:

let x = create_message("foo", "source");
let y = clone_message(x);
let z = clone_message();

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Totally makes sense.


final Message origMessage = context.currentMessage();
final Message newMessage = Iterables.getOnlyElement(context.createdMessages());

assertThat(origMessage).isNotSameAs(newMessage);
assertThat(newMessage.getMessage()).isEqualTo("new");
assertThat(newMessage.getSource()).isEqualTo("synthetic");
assertThat(newMessage.getStreams()).isEmpty();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@kroepke
Copy link
Member

kroepke commented Jan 4, 2017

lgtm!

@kroepke kroepke merged commit d58accf into master Jan 4, 2017
@kroepke kroepke deleted the issue-138 branch January 4, 2017 13:22
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants