Skip to content

Commit 207ff09

Browse files
authored
Add LogicAppWorkflowRuntime support (#48)
* Add LogicAppWorkflowRuntimeType and unit tests for it * Implement LogicAppWorkflowRuntimeType as an option to NLFPlugin.syslogMessage * Wrap WorkflowName in ASCIIString * Make LogicAppWorkflowRuntimeTypeTest a final class
1 parent 1ffc70d commit 207ff09

6 files changed

Lines changed: 590 additions & 0 deletions

File tree

src/main/java/com/teragrep/nlf_01/NLFPlugin.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,9 @@ else if (jsonObject.getString("Type").equals("AppTraces")) {
109109
else if (jsonObject.getString("Type").equals("FunctionAppLogs")) {
110110
eventTypes.add(new FunctionAppLogsType(parsedEvent, realHostname));
111111
}
112+
else if (jsonObject.getString("Type").equals("LogicAppWorkflowRuntime")) {
113+
eventTypes.add(new LogicAppWorkflowRuntimeType(parsedEvent, realHostname));
114+
}
112115
else if (jsonObject.getString("Type").endsWith("_CL")) {
113116
eventTypes.add(new CLType(parsedEvent, realHostname));
114117
}
Lines changed: 191 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,191 @@
1+
/*
2+
* Teragrep Neon log format plugin for AKV_01
3+
* Copyright (C) 2025 Suomen Kanuuna Oy
4+
*
5+
* This program is free software: you can redistribute it and/or modify
6+
* it under the terms of the GNU Affero General Public License as published by
7+
* the Free Software Foundation, either version 3 of the License, or
8+
* (at your option) any later version.
9+
*
10+
* This program is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
* GNU Affero General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU Affero General Public License
16+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
17+
*
18+
*
19+
* Additional permission under GNU Affero General Public License version 3
20+
* section 7
21+
*
22+
* If you modify this Program, or any covered work, by linking or combining it
23+
* with other code, such other code is not for that reason alone subject to any
24+
* of the requirements of the GNU Affero GPL version 3 as long as this Program
25+
* is the same Program as licensed from Suomen Kanuuna Oy without any additional
26+
* modifications.
27+
*
28+
* Supplemented terms under GNU Affero General Public License version 3
29+
* section 7
30+
*
31+
* Origin of the software must be attributed to Suomen Kanuuna Oy. Any modified
32+
* versions must be marked as "Modified version of" The Program.
33+
*
34+
* Names of the licensors and authors may not be used for publicity purposes.
35+
*
36+
* No rights are granted for use of trade names, trademarks, or service marks
37+
* which are in The Program if any.
38+
*
39+
* Licensee must indemnify licensors and authors for any liability that these
40+
* contractual assumptions impose on licensors and authors.
41+
*
42+
* To the extent this program is licensed as part of the Commercial versions of
43+
* Teragrep, the applicable Commercial License may apply to this file if you as
44+
* a licensee so wish it.
45+
*/
46+
package com.teragrep.nlf_01.types;
47+
48+
import com.teragrep.akv_01.event.ParsedEvent;
49+
import com.teragrep.akv_01.plugin.PluginException;
50+
import com.teragrep.nlf_01.PropertiesJson;
51+
import com.teragrep.nlf_01.util.ASCIIString;
52+
import com.teragrep.nlf_01.util.MD5Hash;
53+
import com.teragrep.nlf_01.util.ResourceId;
54+
import com.teragrep.nlf_01.util.ValidRFC5424AppName;
55+
import com.teragrep.nlf_01.util.ValidRFC5424Hostname;
56+
import com.teragrep.nlf_01.util.ValidRFC5424Timestamp;
57+
import com.teragrep.rlo_14.Facility;
58+
import com.teragrep.rlo_14.SDElement;
59+
import com.teragrep.rlo_14.Severity;
60+
import jakarta.json.JsonObject;
61+
import jakarta.json.JsonValue;
62+
import java.time.Instant;
63+
import java.util.HashSet;
64+
import java.util.Set;
65+
import java.util.UUID;
66+
67+
public final class LogicAppWorkflowRuntimeType implements EventType {
68+
69+
private final ParsedEvent parsedEvent;
70+
private final String realHostname;
71+
72+
public LogicAppWorkflowRuntimeType(final ParsedEvent parsedEvent, final String realHostname) {
73+
this.parsedEvent = parsedEvent;
74+
this.realHostname = realHostname;
75+
}
76+
77+
private void assertKey(final JsonObject obj, final String key, final JsonValue.ValueType type)
78+
throws PluginException {
79+
if (!obj.containsKey(key)) {
80+
throw new PluginException(new IllegalArgumentException("Key " + key + " does not exist"));
81+
}
82+
83+
if (!obj.get(key).getValueType().equals(type)) {
84+
throw new PluginException(new IllegalArgumentException("Key " + key + " is not of type " + type));
85+
}
86+
}
87+
88+
@Override
89+
public Severity severity() {
90+
return Severity.NOTICE;
91+
}
92+
93+
@Override
94+
public Facility facility() {
95+
return Facility.AUDIT;
96+
}
97+
98+
@Override
99+
public String hostname() throws PluginException {
100+
final JsonObject record = parsedEvent.asJsonStructure().asJsonObject();
101+
102+
assertKey(record, "_ResourceId", JsonValue.ValueType.STRING);
103+
final String resourceId = record.getString("_ResourceId");
104+
105+
return new ValidRFC5424Hostname(
106+
"md5-".concat(new MD5Hash(resourceId).md5().concat("-").concat(new ASCIIString(new ResourceId(resourceId).resourceName()).withNonAsciiCharsRemoved()))
107+
).hostnameWithInvalidCharsRemoved();
108+
109+
}
110+
111+
@Override
112+
public String appName() throws PluginException {
113+
final JsonObject record = parsedEvent.asJsonStructure().asJsonObject();
114+
115+
assertKey(record, "WorkflowName", JsonValue.ValueType.STRING);
116+
117+
return new ValidRFC5424AppName(new ASCIIString(record.getString("WorkflowName")).withNonAsciiCharsRemoved())
118+
.validAppName();
119+
120+
}
121+
122+
@Override
123+
public long timestamp() throws PluginException {
124+
final JsonObject record = parsedEvent.asJsonStructure().asJsonObject();
125+
126+
assertKey(record, "TimeGenerated", JsonValue.ValueType.STRING);
127+
128+
return new ValidRFC5424Timestamp(record.getString("TimeGenerated")).validTimestamp();
129+
}
130+
131+
@Override
132+
public Set<SDElement> sdElements() {
133+
final Set<SDElement> elems = new HashSet<>();
134+
String time = "";
135+
if (!parsedEvent.enqueuedTimeUtc().isStub()) {
136+
time = parsedEvent.enqueuedTimeUtc().zonedDateTime().toString();
137+
}
138+
139+
String fullyQualifiedNamespace = "";
140+
String eventHubName = "";
141+
String partitionId = "";
142+
String consumerGroup = "";
143+
if (!parsedEvent.partitionCtx().isStub()) {
144+
fullyQualifiedNamespace = String
145+
.valueOf(parsedEvent.partitionCtx().asMap().getOrDefault("FullyQualifiedNamespace", ""));
146+
eventHubName = String.valueOf(parsedEvent.partitionCtx().asMap().getOrDefault("EventHubName", ""));
147+
partitionId = String.valueOf(parsedEvent.partitionCtx().asMap().getOrDefault("PartitionId", ""));
148+
consumerGroup = String.valueOf(parsedEvent.partitionCtx().asMap().getOrDefault("ConsumerGroup", ""));
149+
}
150+
151+
elems
152+
.add(new SDElement("aer_02_partition@48577").addSDParam("fully_qualified_namespace", fullyQualifiedNamespace).addSDParam("eventhub_name", eventHubName).addSDParam("partition_id", partitionId).addSDParam("consumer_group", consumerGroup));
153+
154+
elems
155+
.add(new SDElement("event_id@48577").addSDParam("uuid", UUID.randomUUID().toString()).addSDParam("hostname", realHostname).addSDParam("unixtime", Instant.now().toString()).addSDParam("id_source", "aer_02"));
156+
157+
String partitionKey = "";
158+
if (!parsedEvent.systemProperties().isStub()) {
159+
partitionKey = String.valueOf(parsedEvent.systemProperties().asMap().getOrDefault("PartitionKey", ""));
160+
}
161+
162+
String offset = "";
163+
if (!parsedEvent.offset().isStub()) {
164+
offset = parsedEvent.offset().value();
165+
}
166+
167+
elems
168+
.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()));
169+
170+
elems
171+
.add(new SDElement("aer_02@48577").addSDParam("timestamp_source", time.isEmpty() ? "generated" : "timeEnqueued"));
172+
173+
elems.add(new SDElement("nlf_01@48577").addSDParam("eventType", this.getClass().getSimpleName()));
174+
175+
return elems;
176+
}
177+
178+
@Override
179+
public String msgId() {
180+
String sequenceNumber = "";
181+
if (!parsedEvent.systemProperties().isStub()) {
182+
sequenceNumber = String.valueOf(parsedEvent.systemProperties().asMap().getOrDefault("SequenceNumber", ""));
183+
}
184+
return sequenceNumber;
185+
}
186+
187+
@Override
188+
public String msg() {
189+
return parsedEvent.asString();
190+
}
191+
}

src/test/java/com/teragrep/nlf_01/NLFPluginTest.java

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -480,6 +480,66 @@ void testPostgreSQLType() {
480480
Assertions.assertTrue(sdElementMap.get("aer_02_event@48577").containsKey("properties"));
481481
}
482482

483+
@Test
484+
void logicAppWorkflowRuntimeTest() {
485+
final String json = Assertions
486+
.assertDoesNotThrow(() -> Files.readString(Paths.get("src/test/resources/logicapp_workflow_runtime.json")));
487+
final ParsedEvent parsedEvent = new ParsedEventFactory(
488+
new UnparsedEventImpl(json, new EventPartitionContextImpl(new HashMap<>()), new EventPropertiesImpl(new HashMap<>()), new EventSystemPropertiesImpl(new HashMap<>()), new EnqueuedTimeImpl("2020-01-01T00:00:00"), new EventOffsetImpl("0"))
489+
).parsedEvent();
490+
491+
final NLFPlugin plugin = new NLFPlugin(new FakeSourceable());
492+
final List<SyslogMessage> syslogMessages = Assertions
493+
.assertDoesNotThrow(() -> plugin.syslogMessage(parsedEvent));
494+
Assertions.assertEquals(1, syslogMessages.size());
495+
496+
final SyslogMessage syslogMessage = syslogMessages.get(0);
497+
Assertions
498+
.assertEquals(
499+
"{\n" + " \"ActionName\": \"ActionName-1\",\n"
500+
+ " \"ActionTrackingId\": \"bb41a487-309b-4d21-9ab8-2a8b948b2d18\",\n"
501+
+ " \"ClientKeywords\": \"{}\",\n"
502+
+ " \"ClientTrackingId\": \"bb41a487-309b-4d21-9ab8-2a8b948b2d18\",\n"
503+
+ " \"Code\": \"400\",\n" + " \"EndTime\": \"2025-10-06T00:00:00.0000000Z\",\n"
504+
+ " \"Error\": \"Error 2\",\n" + " \"Location\": \"locationcentral\",\n"
505+
+ " \"OperationName\": \"Operation-1\",\n"
506+
+ " \"OriginRunId\": \"bb41a487-309b-4d21-9ab8-2a8b948b2d18\",\n"
507+
+ " \"RetryHistory\": \"None\",\n"
508+
+ " \"RunId\": \"bb41a487-309b-4d21-9ab8-2a8b948b2d18\",\n"
509+
+ " \"StartTime\": \"2025-10-06T00:00:00.0000000Z\",\n"
510+
+ " \"TrackedProperties\": \"{}\",\n"
511+
+ " \"PipelineRunId\": \"bb41a487-309b-4d21-9ab8-2a8b948b2d18\",\n"
512+
+ " \"ResourceId\": \"/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/{resourceType}/{resourceName}\",\n"
513+
+ " \"SourceSystem\": \"Azure\",\n" + " \"Status\": \"Failed\",\n"
514+
+ " \"Tags\": \"{}\",\n" + " \"Type\": \"LogicAppWorkflowRuntime\",\n"
515+
+ " \"WorkflowId\": \"bb41a487-309b-4d21-9ab8-2a8b948b2d18\",\n"
516+
+ " \"WorkflowName\": \"Workflow-2\",\n" + " \"TriggerName\": \"Trigger-1\",\n"
517+
+ " \"TimeGenerated\": \"2025-10-06T00:00:00.0000000Z\",\n"
518+
+ " \"_ItemId\": \"bb41a487-309b-4d21-9ab8-2a8b948b2d18\",\n"
519+
+ " \"TenantId\": \"bb41a487-309b-4d21-9ab8-2a8b948b2d18\",\n"
520+
+ " \"_ResourceId\": \"/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/{resourceType}/{resourceName}\",\n"
521+
+ " \"_SubscriptionId\": \"bb41a487-309b-4d21-9ab8-2a8b948b2d18\",\n"
522+
+ " \"_TimeReceived\": \"2025-10-06T00:00:00.0000000Z\",\n"
523+
+ " \"_Internal_WorkspaceResourceId\": \"/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/{resourceType}/{resourceName}\"\n"
524+
+ "}",
525+
syslogMessage.getMsg()
526+
);
527+
Assertions.assertEquals("md5-0ded52ef915af563e25778bf26b0f129-resourceName", syslogMessage.getHostname());
528+
Assertions.assertEquals("Workflow-2", syslogMessage.getAppName());
529+
Assertions.assertEquals("2025-10-06T00:00:00Z", syslogMessage.getTimestamp());
530+
531+
final Map<String, Map<String, String>> sdElementMap = syslogMessage
532+
.getSDElements()
533+
.stream()
534+
.collect(Collectors.toMap((SDElement::getSdID), (sdElem) -> sdElem.getSdParams().stream().collect(Collectors.toMap(SDParam::getParamName, SDParam::getParamValue))));
535+
536+
Assertions.assertEquals(1, sdElementMap.get("nlf_01@48577").size());
537+
Assertions
538+
.assertEquals(LogicAppWorkflowRuntimeType.class.getSimpleName(), sdElementMap.get("nlf_01@48577").get("eventType"));
539+
540+
Assertions.assertTrue(sdElementMap.get("aer_02_event@48577").containsKey("properties"));
541+
}
542+
483543
@Test
484544
void unexpectedType() {
485545
final String json = Assertions

0 commit comments

Comments
 (0)