-
Notifications
You must be signed in to change notification settings - Fork 107
Issue 138/header support #168
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
Conversation
Modified test for headers to work update version
Issue 165 modify record sort for raw
| if(records != null) { handleRecordsWithHeader(records); } | ||
| } | ||
|
|
||
| else if (connectorConfig.hasMetaDataConfigured()) { |
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.
Let's move else if to line 145
| .append(source, other.source) | ||
| .append(host, other.host) | ||
| .isEquals(); | ||
| } else { |
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.
don't need else, a direct return false shall be fine
| this.connectorConfig = connectorConfig; | ||
| this.headers = record.headers(); | ||
| if(this.headers != null) { | ||
| log.info("not null headers"); |
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 we get rid of this log as it will be too many and didn't provide much valuable information
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.
haha - yeah :)
| String source = headers.lastWithName(connectorConfig.headerSource).value().toString(); | ||
| String sourcetype = headers.lastWithName(connectorConfig.headerSourcetype).value().toString(); | ||
|
|
||
| if(splunkHeaderIndex.equals(index) && splunkHeaderHost.equals(host) && |
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 we just
return splunkHeaderIndex.equals(index) &&
splunkHeaderHost.equals(host) &&
splunkHeaderSource.equals(source) &&
splunkHeaderSourcetype.equals(sourcetype);
| } | ||
|
|
||
| private void setMetadataValues() { | ||
| log.info("Made it to setMetadataValues"); |
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.
let's get rid of this log
|
|
||
| if (headers.lastWithName(connectorConfig.headerIndex) != null) { | ||
| //log.debug("splunk_index header detected, value is: " + headers.lastWithName(connectorConfig.headerIndex).value().toString()); | ||
| event.setIndex(headers.lastWithName(connectorConfig.headerIndex).value().toString()); |
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.
let's pay attention to the indent in this func ?
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 we cache headers.lastWithName(connectorConfig.headerIndex) to avoid looking up again ?
| event.setSourcetype(headers.lastWithName(connectorConfig.headerSourcetype).value().toString()); | ||
| } | ||
|
|
||
| // Custom headers are configured with a comma separated list passed in configuration |
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.
Let's make sure, these are header keys, not headers and we don't support key containing ","
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 will support a comma separated list of custom headers provided to the configuration to index as extra fields
| Map<String, String> headerMap = new HashMap<>(); | ||
| for (String header : customHeaders) { | ||
| if (headers.lastWithName(header) != null) { | ||
| log.debug(header + " header detected, value is: " + headers.lastWithName(header).value().toString()); |
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 we get rid of this debug log ?
| String[] customHeaders = connectorConfig.headerCustom.split(","); | ||
| Map<String, String> headerMap = new HashMap<>(); | ||
| for (String header : customHeaders) { | ||
| if (headers.lastWithName(header) != null) { |
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 we cache headers.lastWithName(header) and we don't need to do lookup everytime ?
| @Override | ||
| public boolean equals(Object obj) { | ||
| if (obj instanceof JsonEventBatch) { | ||
| final JsonEventBatch other = (JsonEventBatch) obj; |
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.
what is the difference just doing this.endpoint.equals(other.endpoint)
| .append(sourcetype, other.sourcetype) | ||
| .append(source, other.source) | ||
| .append(host, other.host) | ||
| .isEquals(); |
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 the following 2 meta tuple equal ?
(idx1, sourcetype2, source3, host4)
(idx, 1sourcetype2, source, 3host4)
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.
No. Added Test to check condition
public void checkEquals() {
RawEventBatch batchOne = RawEventBatch.factory()
.setSource("source3")
.setIndex("idx1")
.setSourcetype("sourcetype2")
.setHost("host4")
.build();
RawEventBatch batchTwo = RawEventBatch.factory()
.setSource("source")
.setIndex("idx")
.setSourcetype("1sourcetype2")
.setHost("3host4")
.build();
Assert.assertFalse(batchOne.equals(batchTwo));
}
}```
| .setTrustStorePath(trustStorePath) | ||
| .setTrustStorePassword(trustStorePassword) | ||
| .setHasCustomTrustStore(hasTrustStorePath); | ||
| .setSocketTimeout(socketTimeout) |
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.
Identing problem ?
| } | ||
|
|
||
| private void setMetadataValues() { | ||
| if(this.headers.lastWithName(connectorConfig.headerIndex) != null) { |
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 would introduce a variable to hold this.headers.lastWithName(connectorConfig.headerIndex) to avoid re-computation
| } | ||
| public String getSplunkHeaderSource() { | ||
| return splunkHeaderSource; | ||
| } |
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.
Let's separate each function with an empty line :)
|
|
||
| StringBuilder headerString = new StringBuilder(); | ||
|
|
||
| if(headers.lastWithName(connectorConfig.headerIndex) != null) { |
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 we use a variable to hold the result of headers.lastWithName(connectorConfig.headerIndex) to avoid call this again ?
| } | ||
|
|
||
| public String insertHeaderToken() { | ||
| return "$$$"; |
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 can make this a const string
| if (customHeader != null) { | ||
| headerMap.put(header, customHeader.value().toString()); | ||
| } else { | ||
| log.debug(header + " header value not present in event."); |
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 would like to get rid of this in prod :)
Resubmitted PR including Header work and re=categorization function defined in issue-165.
PR encompasses all Header related work to date.
Inclusion of config parameters:
Inclusion of splunk.hec.json.event.formatted for events store in Kafka already configured in the HEC Format to ensure correct metadata extraction.