Skip to content

Commit

Permalink
remove "records" array from appinsight.json; remove appinsight_2.json…
Browse files Browse the repository at this point in the history
…; remove multirecord.json; remove MultiRecordEvent usage from NLFPlugin; remove appInsightType_MultipleRecords test; remove multiRecordWithDifferentTypes test; (#28)
  • Loading branch information
eemhu authored Feb 20, 2025
1 parent fcbe758 commit 570f5d7
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 350 deletions.
63 changes: 18 additions & 45 deletions src/main/java/com/teragrep/nlf_01/NLFPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@
*/
package com.teragrep.nlf_01;

import com.teragrep.akv_01.event.MultiRecordEvent;
import com.teragrep.akv_01.event.ParsedEvent;
import com.teragrep.akv_01.plugin.Plugin;
import com.teragrep.akv_01.plugin.PluginException;
Expand Down Expand Up @@ -80,7 +79,6 @@ public NLFPlugin(final Sourceable source) {
public List<SyslogMessage> syslogMessage(final ParsedEvent parsedEvent) throws PluginException {
final List<EventType> eventTypes = new ArrayList<>();
final List<SyslogMessage> syslogMessages = new ArrayList<>();
final List<ParsedEvent> parsedEvents = new ArrayList<>();
final String containerLogAppNameKey = source.source("containerlog.appname.annotation");
final String containerLogHostnameKey = source.source("containerlog.hostname.annotation");

Expand All @@ -95,52 +93,31 @@ public List<SyslogMessage> syslogMessage(final ParsedEvent parsedEvent) throws P
throw new PluginException(new JsonException("Event was not a JSON object"));
}

final MultiRecordEvent mre = new MultiRecordEvent(parsedEvent);
if (mre.isValid()) {
for (final ParsedEvent recordEvent : mre.records()) {
if (!recordEvent.isJsonStructure()) {
throw new PluginException(new JsonException("Record in MultiRecordEvent was not a JSON structure"));
}
final JsonStructure recordJson = recordEvent.asJsonStructure();
if (!recordJson.getValueType().equals(JsonValue.ValueType.OBJECT)) {
throw new PluginException(new JsonException("Record in MultiRecordEvent was not a JSON object"));
}
final JsonObject jsonObject = parsedEvent.asJsonStructure().asJsonObject();
if (
jsonObject.containsKey("Type") && jsonObject.get("Type").getValueType().equals(JsonValue.ValueType.STRING)
) {

parsedEvents.add(recordEvent);
if (jsonObject.getString("Type").equals("AppTraces")) {
eventTypes.add(new AppInsightType(parsedEvent));
}
}
else {
parsedEvents.add(parsedEvent);
}

for (final ParsedEvent pe : parsedEvents) {
final JsonObject jsonObject = pe.asJsonStructure().asJsonObject();
if (
jsonObject.containsKey("Type")
&& jsonObject.get("Type").getValueType().equals(JsonValue.ValueType.STRING)
) {

if (jsonObject.getString("Type").equals("AppTraces")) {
eventTypes.add(new AppInsightType(pe));
}
else if (jsonObject.getString("Type").endsWith("_CL")) {
eventTypes.add(new CLType(pe));
}
else if (jsonObject.getString("Type").equals("ContainerLogV2")) {
eventTypes.add(new ContainerType(containerLogHostnameKey, containerLogAppNameKey, pe));
}
else {
throw new PluginException(
new IllegalArgumentException("Invalid event type: " + jsonObject.getString("Type"))
);
}

else if (jsonObject.getString("Type").endsWith("_CL")) {
eventTypes.add(new CLType(parsedEvent));
}
else if (jsonObject.getString("Type").equals("ContainerLogV2")) {
eventTypes.add(new ContainerType(containerLogHostnameKey, containerLogAppNameKey, parsedEvent));
}
else {
throw new PluginException(
new IllegalArgumentException("Event was not of expected log format or type was not found")
new IllegalArgumentException("Invalid event type: " + jsonObject.getString("Type"))
);
}

}
else {
throw new PluginException(
new IllegalArgumentException("Event was not of expected log format or type was not found")
);
}

for (final EventType eventType : eventTypes) {
Expand All @@ -156,10 +133,6 @@ else if (jsonObject.getString("Type").equals("ContainerLogV2")) {
syslogMessages.add(syslogMessage);
}

if (syslogMessages.isEmpty()) {
throw new PluginException(new IllegalArgumentException("No events processable by NLFPlugin found"));
}

return syslogMessages;
}
}
Loading

0 comments on commit 570f5d7

Please sign in to comment.