-
Notifications
You must be signed in to change notification settings - Fork 188
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
Tagging Events in Data Prepper. Issue #629 #2629
Conversation
Signed-off-by: Krishna Kondaka <krishkdk@amazon.com>
Codecov Report
📣 This organization is not using Codecov’s GitHub App Integration. We recommend you install it so Codecov can continue to function properly for your repositories. Learn more @@ Coverage Diff @@
## main #2629 +/- ##
============================================
+ Coverage 93.46% 93.53% +0.06%
- Complexity 2185 2220 +35
============================================
Files 258 258
Lines 6107 6230 +123
Branches 497 512 +15
============================================
+ Hits 5708 5827 +119
+ Misses 268 266 -2
- Partials 131 137 +6
|
} | ||
|
||
@Override | ||
public void setTag(final String tag) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not a big deal but should rename this function to addTag
@Override | ||
public String toJsonStringWithTags(final String tagsKey) { | ||
String result = jsonNode.toString(); | ||
return result.substring(0, result.length()-1) + ",\""+tagsKey+"\":"+ getMetadata().getTags()+"}"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this need quotes around the getMetadata().getTags
? Right now the final json would look like this
end_of_event, "tagsKey": [tag1, tag2]}
Should it look like this instead? I'm not sure if it's a requirement from json but looking at this (https://www.microfocus.com/documentation/silk-performer/205/en/silkperformer-205-webhelp-en/GUID-0847DE13-2A2F-44F2-A6E7-214CD703BF84.html) seems like we want the following
end_of_event, "tagsKey": ["tag1", "tag2"]}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could do that. By default toString()
of a Set
does not put quotes around the individual tags. If we want quotes around each tag, then we will have to manually generate it like that. I am OK, if that's what we want.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can this JsonString be re-serialized into an event in its current form?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think so. It's one way (ie event to string with tags) when we want to send to sink with tags.
Signed-off-by: Krishna Kondaka <krishkdk@amazon.com>
@Override | ||
public String toJsonStringWithTags(final String tagsKey) { | ||
String result = jsonNode.toString(); | ||
return result.substring(0, result.length()-1) + ",\""+tagsKey+"\":"+ getMetadata().getTags()+"}"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can this JsonString be re-serialized into an event in its current form?
Boolean hasTag(final String tag); | ||
|
||
/** | ||
* Returns the attributes |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Copy and paste error?
This method does not return attributes.
@@ -35,4 +36,26 @@ public interface EventMetadata extends Serializable { | |||
* @since 1.2 | |||
*/ | |||
Map<String, Object> getAttributes(); | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we want to support removing tags as well? Do we need that for this initial implementation or is that something we can add later?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think initial implementation is fine as is. When we add the tag_manager
processor we will need to add support for removing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1, I was just not sure of the requirements for this feature in the near term.
String separator = ""; | ||
|
||
result = result.substring(0, result.length()-1) + ",\"tags\":["; | ||
for (final String tag: getMetadata().getTags()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This works as is but could be done with a stream like this
String tagSetString = String.join(",", tagSet
.stream()
.map(tagName -> ("\"" + tagName + "\""))
.collect(Collectors.toList()));
which would mean only a single append (instead of one per tag) is needed. It will be more performant than appending a bunch of times
result += tagSetString
@@ -276,6 +276,20 @@ public String toJsonString() { | |||
return jsonNode.toString(); | |||
} | |||
|
|||
@Override | |||
public String toJsonStringWithTags(final String tagsKey) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure this is a very extensible approach. Perhaps some form of JSON string builder would be more appropriate.
As a caller, perhaps I could call:
event.jsonStringBuilder()
.includeTags("tags")
.toJsonString()
Over time we may find other features that we want to include in the event.
String separator = ""; | ||
|
||
result = result.substring(0, result.length()-1) + ",\"tags\":["; | ||
for (final String tag: getMetadata().getTags()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we should be manipulating JSON manually. Let's do this with Jackson.
You can create a JsonNode
and then add the value.
…nt to return event with additinal info (like tags) as json string Signed-off-by: Krishna Kondaka <krishkdk@amazon.com>
Description
Added support to add tags to events.
Tags can be added at the time of creation of a event or after creating it. The tags are added to event meta data as per the discussion in issue #629.
Resolves #629
Issues Resolved
#629
Check List
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.