Skip to content

Commit b83f3a8

Browse files
authored
Providee default SDElements that all implementations of EventType share (#71)
* Add explicit SDElements tests to all EventType tests * Add DefaultSDElements that provides SDElements for most of EventTypes * Add missing imports after rebase * Add DefaultSDElements to IstioIngressContainerType and Dataverse related Types * Initial tests for DefaultSDElements * Use Fakes for ADFActivityRunTypeTest.testSdElementReturnValue * Reorder secondary ctor to be before primary ctor in DefaultSDElements * Use SDElements interface for DefaultSDElements
1 parent e18425b commit b83f3a8

36 files changed

Lines changed: 1077 additions & 907 deletions

src/main/java/com/teragrep/nlf_01/types/ADFActivityRunType.java

Lines changed: 4 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,11 @@
4747

4848
import com.teragrep.akv_01.event.ParsedEvent;
4949
import com.teragrep.akv_01.plugin.PluginException;
50-
import com.teragrep.nlf_01.PropertiesJson;
5150
import com.teragrep.nlf_01.util.ASCIIString;
51+
import com.teragrep.nlf_01.util.DefaultSDElements;
5252
import com.teragrep.nlf_01.util.MD5Hash;
5353
import com.teragrep.nlf_01.util.ResourceId;
54+
import com.teragrep.nlf_01.util.SDElements;
5455
import com.teragrep.nlf_01.util.ValidKey;
5556
import com.teragrep.nlf_01.util.ValidStringKey;
5657
import com.teragrep.nlf_01.util.ValidRFC5424AppName;
@@ -60,10 +61,7 @@
6061
import com.teragrep.rlo_14.SDElement;
6162
import com.teragrep.rlo_14.Severity;
6263
import jakarta.json.JsonObject;
63-
import java.time.Instant;
64-
import java.util.HashSet;
6564
import java.util.Set;
66-
import java.util.UUID;
6765

6866
public final class ADFActivityRunType implements EventType {
6967

@@ -112,49 +110,9 @@ public long timestamp() throws PluginException {
112110

113111
@Override
114112
public Set<SDElement> sdElements() {
115-
final Set<SDElement> elems = new HashSet<>();
116-
String time = "";
117-
if (!parsedEvent.enqueuedTimeUtc().isStub()) {
118-
time = parsedEvent.enqueuedTimeUtc().zonedDateTime().toString();
119-
}
120-
121-
String fullyQualifiedNamespace = "";
122-
String eventHubName = "";
123-
String partitionId = "";
124-
String consumerGroup = "";
125-
if (!parsedEvent.partitionCtx().isStub()) {
126-
fullyQualifiedNamespace = String
127-
.valueOf(parsedEvent.partitionCtx().asMap().getOrDefault("FullyQualifiedNamespace", ""));
128-
eventHubName = String.valueOf(parsedEvent.partitionCtx().asMap().getOrDefault("EventHubName", ""));
129-
partitionId = String.valueOf(parsedEvent.partitionCtx().asMap().getOrDefault("PartitionId", ""));
130-
consumerGroup = String.valueOf(parsedEvent.partitionCtx().asMap().getOrDefault("ConsumerGroup", ""));
131-
}
132-
133-
elems
134-
.add(new SDElement("aer_02_partition@48577").addSDParam("fully_qualified_namespace", fullyQualifiedNamespace).addSDParam("eventhub_name", eventHubName).addSDParam("partition_id", partitionId).addSDParam("consumer_group", consumerGroup));
135-
136-
elems
137-
.add(new SDElement("event_id@48577").addSDParam("uuid", UUID.randomUUID().toString()).addSDParam("hostname", realHostname).addSDParam("unixtime", Instant.now().toString()).addSDParam("id_source", "aer_02"));
138-
139-
String partitionKey = "";
140-
if (!parsedEvent.systemProperties().isStub()) {
141-
partitionKey = String.valueOf(parsedEvent.systemProperties().asMap().getOrDefault("PartitionKey", ""));
142-
}
143-
144-
String offset = "";
145-
if (!parsedEvent.offset().isStub()) {
146-
offset = parsedEvent.offset().value();
147-
}
148-
149-
elems
150-
.add(new SDElement("aer_02_event@48577").addSDParam("offset", offset).addSDParam("enqueued_time", time).addSDParam("partition_key", partitionKey).addSDParam("properties", new PropertiesJson(parsedEvent.properties()).toJsonObject().toString()));
151-
152-
elems
153-
.add(new SDElement("aer_02@48577").addSDParam("timestamp_source", time.isEmpty() ? "generated" : "timeEnqueued"));
154-
155-
elems.add(new SDElement("nlf_01@48577").addSDParam("eventType", this.getClass().getSimpleName()));
113+
final SDElements defaultSDElements = new DefaultSDElements(parsedEvent, realHostname, this.getClass());
156114

157-
return elems;
115+
return defaultSDElements.sdElements();
158116
}
159117

160118
@Override

src/main/java/com/teragrep/nlf_01/types/ADFPipelineRunType.java

Lines changed: 4 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,11 @@
4747

4848
import com.teragrep.akv_01.event.ParsedEvent;
4949
import com.teragrep.akv_01.plugin.PluginException;
50-
import com.teragrep.nlf_01.PropertiesJson;
5150
import com.teragrep.nlf_01.util.ASCIIString;
51+
import com.teragrep.nlf_01.util.DefaultSDElements;
5252
import com.teragrep.nlf_01.util.MD5Hash;
5353
import com.teragrep.nlf_01.util.ResourceId;
54+
import com.teragrep.nlf_01.util.SDElements;
5455
import com.teragrep.nlf_01.util.ValidKey;
5556
import com.teragrep.nlf_01.util.ValidStringKey;
5657
import com.teragrep.nlf_01.util.ValidRFC5424AppName;
@@ -60,10 +61,7 @@
6061
import com.teragrep.rlo_14.SDElement;
6162
import com.teragrep.rlo_14.Severity;
6263
import jakarta.json.JsonObject;
63-
import java.time.Instant;
64-
import java.util.HashSet;
6564
import java.util.Set;
66-
import java.util.UUID;
6765

6866
public final class ADFPipelineRunType implements EventType {
6967

@@ -114,49 +112,9 @@ public long timestamp() throws PluginException {
114112

115113
@Override
116114
public Set<SDElement> sdElements() {
117-
final Set<SDElement> elems = new HashSet<>();
118-
String time = "";
119-
if (!parsedEvent.enqueuedTimeUtc().isStub()) {
120-
time = parsedEvent.enqueuedTimeUtc().zonedDateTime().toString();
121-
}
122-
123-
String fullyQualifiedNamespace = "";
124-
String eventHubName = "";
125-
String partitionId = "";
126-
String consumerGroup = "";
127-
if (!parsedEvent.partitionCtx().isStub()) {
128-
fullyQualifiedNamespace = String
129-
.valueOf(parsedEvent.partitionCtx().asMap().getOrDefault("FullyQualifiedNamespace", ""));
130-
eventHubName = String.valueOf(parsedEvent.partitionCtx().asMap().getOrDefault("EventHubName", ""));
131-
partitionId = String.valueOf(parsedEvent.partitionCtx().asMap().getOrDefault("PartitionId", ""));
132-
consumerGroup = String.valueOf(parsedEvent.partitionCtx().asMap().getOrDefault("ConsumerGroup", ""));
133-
}
134-
135-
elems
136-
.add(new SDElement("aer_02_partition@48577").addSDParam("fully_qualified_namespace", fullyQualifiedNamespace).addSDParam("eventhub_name", eventHubName).addSDParam("partition_id", partitionId).addSDParam("consumer_group", consumerGroup));
137-
138-
elems
139-
.add(new SDElement("event_id@48577").addSDParam("uuid", UUID.randomUUID().toString()).addSDParam("hostname", realHostname).addSDParam("unixtime", Instant.now().toString()).addSDParam("id_source", "aer_02"));
140-
141-
String partitionKey = "";
142-
if (!parsedEvent.systemProperties().isStub()) {
143-
partitionKey = String.valueOf(parsedEvent.systemProperties().asMap().getOrDefault("PartitionKey", ""));
144-
}
145-
146-
String offset = "";
147-
if (!parsedEvent.offset().isStub()) {
148-
offset = parsedEvent.offset().value();
149-
}
150-
151-
elems
152-
.add(new SDElement("aer_02_event@48577").addSDParam("offset", offset).addSDParam("enqueued_time", time).addSDParam("partition_key", partitionKey).addSDParam("properties", new PropertiesJson(parsedEvent.properties()).toJsonObject().toString()));
153-
154-
elems
155-
.add(new SDElement("aer_02@48577").addSDParam("timestamp_source", time.isEmpty() ? "generated" : "timeEnqueued"));
156-
157-
elems.add(new SDElement("nlf_01@48577").addSDParam("eventType", this.getClass().getSimpleName()));
115+
final SDElements defaultSDElements = new DefaultSDElements(parsedEvent, realHostname, this.getClass());
158116

159-
return elems;
117+
return defaultSDElements.sdElements();
160118
}
161119

162120
@Override

src/main/java/com/teragrep/nlf_01/types/AppEventsType.java

Lines changed: 4 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,11 @@
4747

4848
import com.teragrep.akv_01.event.ParsedEvent;
4949
import com.teragrep.akv_01.plugin.PluginException;
50-
import com.teragrep.nlf_01.PropertiesJson;
5150
import com.teragrep.nlf_01.util.ASCIIString;
51+
import com.teragrep.nlf_01.util.DefaultSDElements;
5252
import com.teragrep.nlf_01.util.MD5Hash;
5353
import com.teragrep.nlf_01.util.ResourceId;
54+
import com.teragrep.nlf_01.util.SDElements;
5455
import com.teragrep.nlf_01.util.ValidKey;
5556
import com.teragrep.nlf_01.util.ValidRFC5424AppName;
5657
import com.teragrep.nlf_01.util.ValidRFC5424Hostname;
@@ -60,10 +61,7 @@
6061
import com.teragrep.rlo_14.SDElement;
6162
import com.teragrep.rlo_14.Severity;
6263
import jakarta.json.JsonObject;
63-
import java.time.Instant;
64-
import java.util.HashSet;
6564
import java.util.Set;
66-
import java.util.UUID;
6765

6866
public final class AppEventsType implements EventType {
6967

@@ -117,64 +115,9 @@ public long timestamp() throws PluginException {
117115

118116
@Override
119117
public Set<SDElement> sdElements() throws PluginException {
120-
final Set<SDElement> elems = new HashSet<>();
121-
final String time;
122-
if (!parsedEvent.enqueuedTimeUtc().isStub()) {
123-
time = parsedEvent.enqueuedTimeUtc().zonedDateTime().toString();
124-
}
125-
else {
126-
time = "";
127-
}
128-
129-
final String fullyQualifiedNamespace;
130-
final String eventHubName;
131-
final String partitionId;
132-
final String consumerGroup;
133-
if (!parsedEvent.partitionCtx().isStub()) {
134-
fullyQualifiedNamespace = String
135-
.valueOf(parsedEvent.partitionCtx().asMap().getOrDefault("FullyQualifiedNamespace", ""));
136-
eventHubName = String.valueOf(parsedEvent.partitionCtx().asMap().getOrDefault("EventHubName", ""));
137-
partitionId = String.valueOf(parsedEvent.partitionCtx().asMap().getOrDefault("PartitionId", ""));
138-
consumerGroup = String.valueOf(parsedEvent.partitionCtx().asMap().getOrDefault("ConsumerGroup", ""));
139-
}
140-
else {
141-
fullyQualifiedNamespace = "";
142-
eventHubName = "";
143-
partitionId = "";
144-
consumerGroup = "";
145-
}
146-
147-
elems
148-
.add(new SDElement("aer_02_partition@48577").addSDParam("fully_qualified_namespace", fullyQualifiedNamespace).addSDParam("eventhub_name", eventHubName).addSDParam("partition_id", partitionId).addSDParam("consumer_group", consumerGroup));
149-
150-
elems
151-
.add(new SDElement("event_id@48577").addSDParam("uuid", UUID.randomUUID().toString()).addSDParam("hostname", realHostname).addSDParam("unixtime", Instant.now().toString()).addSDParam("id_source", "aer_02"));
152-
153-
final String partitionKey;
154-
if (!parsedEvent.systemProperties().isStub()) {
155-
partitionKey = String.valueOf(parsedEvent.systemProperties().asMap().getOrDefault("PartitionKey", ""));
156-
}
157-
else {
158-
partitionKey = "";
159-
}
160-
161-
final String offset;
162-
if (!parsedEvent.offset().isStub()) {
163-
offset = parsedEvent.offset().value();
164-
}
165-
else {
166-
offset = "";
167-
}
168-
169-
elems
170-
.add(new SDElement("aer_02_event@48577").addSDParam("offset", offset).addSDParam("enqueued_time", time).addSDParam("partition_key", partitionKey).addSDParam("properties", new PropertiesJson(parsedEvent.properties()).toJsonObject().toString()));
171-
172-
elems
173-
.add(new SDElement("aer_02@48577").addSDParam("timestamp_source", time.isEmpty() ? "generated" : "timeEnqueued"));
174-
175-
elems.add(new SDElement("nlf_01@48577").addSDParam("eventType", this.getClass().getSimpleName()));
118+
final SDElements defaultSDElements = new DefaultSDElements(parsedEvent, realHostname, this.getClass());
176119

177-
return elems;
120+
return defaultSDElements.sdElements();
178121
}
179122

180123
@Override

src/main/java/com/teragrep/nlf_01/types/AppInsightType.java

Lines changed: 2 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -47,17 +47,13 @@
4747

4848
import com.teragrep.akv_01.event.ParsedEvent;
4949
import com.teragrep.akv_01.plugin.PluginException;
50-
import com.teragrep.nlf_01.PropertiesJson;
5150
import com.teragrep.nlf_01.util.*;
5251
import com.teragrep.rlo_14.Facility;
5352
import com.teragrep.rlo_14.SDElement;
5453
import com.teragrep.rlo_14.Severity;
5554
import jakarta.json.JsonObject;
5655

57-
import java.time.Instant;
58-
import java.util.HashSet;
5956
import java.util.Set;
60-
import java.util.UUID;
6157

6258
public final class AppInsightType implements EventType {
6359

@@ -109,49 +105,9 @@ public long timestamp() throws PluginException {
109105

110106
@Override
111107
public Set<SDElement> sdElements() {
112-
Set<SDElement> elems = new HashSet<>();
113-
String time = "";
114-
if (!parsedEvent.enqueuedTimeUtc().isStub()) {
115-
time = parsedEvent.enqueuedTimeUtc().zonedDateTime().toString();
116-
}
117-
118-
String fullyQualifiedNamespace = "";
119-
String eventHubName = "";
120-
String partitionId = "";
121-
String consumerGroup = "";
122-
if (!parsedEvent.partitionCtx().isStub()) {
123-
fullyQualifiedNamespace = String
124-
.valueOf(parsedEvent.partitionCtx().asMap().getOrDefault("FullyQualifiedNamespace", ""));
125-
eventHubName = String.valueOf(parsedEvent.partitionCtx().asMap().getOrDefault("EventHubName", ""));
126-
partitionId = String.valueOf(parsedEvent.partitionCtx().asMap().getOrDefault("PartitionId", ""));
127-
consumerGroup = String.valueOf(parsedEvent.partitionCtx().asMap().getOrDefault("ConsumerGroup", ""));
128-
}
129-
130-
elems
131-
.add(new SDElement("aer_02_partition@48577").addSDParam("fully_qualified_namespace", fullyQualifiedNamespace).addSDParam("eventhub_name", eventHubName).addSDParam("partition_id", partitionId).addSDParam("consumer_group", consumerGroup));
132-
133-
elems
134-
.add(new SDElement("event_id@48577").addSDParam("uuid", UUID.randomUUID().toString()).addSDParam("hostname", realHostname).addSDParam("unixtime", Instant.now().toString()).addSDParam("id_source", "aer_02"));
135-
136-
String partitionKey = "";
137-
if (!parsedEvent.systemProperties().isStub()) {
138-
partitionKey = String.valueOf(parsedEvent.systemProperties().asMap().getOrDefault("PartitionKey", ""));
139-
}
140-
141-
String offset = "";
142-
if (!parsedEvent.offset().isStub()) {
143-
offset = parsedEvent.offset().value();
144-
}
145-
146-
elems
147-
.add(new SDElement("aer_02_event@48577").addSDParam("offset", offset).addSDParam("enqueued_time", time).addSDParam("partition_key", partitionKey).addSDParam("properties", new PropertiesJson(parsedEvent.properties()).toJsonObject().toString()));
148-
149-
elems
150-
.add(new SDElement("aer_02@48577").addSDParam("timestamp_source", time.isEmpty() ? "generated" : "timeEnqueued"));
151-
152-
elems.add(new SDElement("nlf_01@48577").addSDParam("eventType", this.getClass().getSimpleName()));
108+
final SDElements defaultSDElements = new DefaultSDElements(parsedEvent, realHostname, this.getClass());
153109

154-
return elems;
110+
return defaultSDElements.sdElements();
155111
}
156112

157113
@Override

0 commit comments

Comments
 (0)