Skip to content

Commit

Permalink
add null check for enqueuedTime in EventDataConsumer, ignore resource…
Browse files Browse the repository at this point in the history
…_leak in DefaultOutput.java. (#34)

* add null check for enqueuedTime in EventDataConsumer

* change to instant.now()

* add coverity resource_leak comment to DefaultOutput

* change coverity[RESOURCE_LEAK] to [leaked_resource], add info about source of timestamp to structured data
  • Loading branch information
eemhu authored Nov 11, 2024
1 parent ad22238 commit 3ca061c
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/main/java/com/teragrep/aer_02/DefaultOutput.java
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ private void connect() {
while (!connected) {
final Timer.Context context = connectLatency.time(); // reset the time (new context)
try {
// coverity[leaked_resource]
connected = this.relpConnection.connect(relpAddress, relpPort);
/*
Not closing the context in case of an exception thrown in .connect() will leave the timer.context
Expand Down
6 changes: 5 additions & 1 deletion src/main/java/com/teragrep/aer_02/EventDataConsumer.java
Original file line number Diff line number Diff line change
Expand Up @@ -143,15 +143,19 @@ public Long getValue() {
//.addSDParam("correlation_id", correlationId == null ? "" : correlationId);
props.forEach((key, value) -> sdEvent.addSDParam("property_" + key, value.toString()));

SDElement sdComponentInfo = new SDElement("aer_02@48577")
.addSDParam("timestamp_source", enqueuedTime == null ? "generated" : "timeEnqueued");

SyslogMessage syslogMessage = new SyslogMessage()
.withSeverity(Severity.INFORMATIONAL)
.withFacility(Facility.LOCAL0)
.withTimestamp(enqueuedTime.toInstant())
.withTimestamp(enqueuedTime == null ? Instant.now() : enqueuedTime.toInstant())
.withHostname(syslogConfig.hostName())
.withAppName(syslogConfig.appName())
.withSDElement(sdId)
.withSDElement(sdPartition)
.withSDElement(sdEvent)
.withSDElement(sdComponentInfo)
//.withSDElement(sdCorId)
.withMsgId(String.valueOf(systemProps.getOrDefault("SequenceNumber", "0")))
.withMsg(eventData);
Expand Down

0 comments on commit 3ca061c

Please sign in to comment.