Skip to content

Conversation

@dtregonning
Copy link
Contributor

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:

  • "splunk.header.support";
  • "splunk.header.custom";
  • "splunk.header.index";
  • "splunk.header.source";
  • "splunk.header.sourcetype";
  • "splunk.header.host";
    Inclusion of splunk.hec.json.event.formatted for events store in Kafka already configured in the HEC Format to ensure correct metadata extraction.

if(records != null) { handleRecordsWithHeader(records); }
}

else if (connectorConfig.hasMetaDataConfigured()) {
Copy link
Contributor

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 {
Copy link
Contributor

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");
Copy link
Contributor

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

Copy link
Contributor Author

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) &&
Copy link
Contributor

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");
Copy link
Contributor

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());
Copy link
Contributor

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 ?

Copy link
Contributor

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
Copy link
Contributor

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 ","

Copy link
Contributor Author

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());
Copy link
Contributor

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) {
Copy link
Contributor

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;
Copy link
Contributor

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();
Copy link
Contributor

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)

Copy link
Contributor Author

@dtregonning dtregonning Aug 29, 2018

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)
Copy link
Contributor

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) {
Copy link
Contributor

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;
}
Copy link
Contributor

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) {
Copy link
Contributor

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 "$$$";
Copy link
Contributor

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.");
Copy link
Contributor

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 :)

chenziliang
chenziliang previously approved these changes Aug 29, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants