This is an automated email from the ASF dual-hosted git repository.
bbende pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/nifi.git
The following commit(s) were added to refs/heads/main by this push:
new 2a60a2ed4a NIFI-15093 Add Registered Flow Identifier and Version to
MDC Attributes (#10419)
2a60a2ed4a is described below
commit 2a60a2ed4aa2e67184c2ca430055c9c332cf274a
Author: David Handermann <[email protected]>
AuthorDate: Wed Oct 15 12:09:20 2025 -0500
NIFI-15093 Add Registered Flow Identifier and Version to MDC Attributes
(#10419)
---
.../apache/nifi/groups/StandardProcessGroup.java | 19 ++++++++++-
.../nifi/groups/StandardProcessGroupTest.java | 37 ++++++++++++++++++++++
2 files changed, 55 insertions(+), 1 deletion(-)
diff --git
a/nifi-framework-bundle/nifi-framework/nifi-framework-components/src/main/java/org/apache/nifi/groups/StandardProcessGroup.java
b/nifi-framework-bundle/nifi-framework/nifi-framework-components/src/main/java/org/apache/nifi/groups/StandardProcessGroup.java
index 822bf6afdd..bc8d717645 100644
---
a/nifi-framework-bundle/nifi-framework/nifi-framework-components/src/main/java/org/apache/nifi/groups/StandardProcessGroup.java
+++
b/nifi-framework-bundle/nifi-framework/nifi-framework-components/src/main/java/org/apache/nifi/groups/StandardProcessGroup.java
@@ -3594,6 +3594,7 @@ public final class StandardProcessGroup implements
ProcessGroup {
parent.onComponentModified();
}
+ setLoggingAttributes();
scheduler.submitFrameworkTask(() ->
synchronizeWithFlowRegistry(flowManager));
} finally {
writeLock.unlock();
@@ -3668,6 +3669,7 @@ public final class StandardProcessGroup implements
ProcessGroup {
writeLock.lock();
try {
this.versionControlInfo.set(null);
+ setLoggingAttributes();
} finally {
writeLock.unlock();
}
@@ -4564,6 +4566,8 @@ public final class StandardProcessGroup implements
ProcessGroup {
}
private void setLoggingAttributes() {
+ loggingAttributes.clear();
+
loggingAttributes.put(LoggingAttribute.PROCESS_GROUP_ID.attribute, id);
final String processGroupName = name.get();
@@ -4573,6 +4577,15 @@ public final class StandardProcessGroup implements
ProcessGroup {
loggingAttributes.put(LoggingAttribute.PROCESS_GROUP_NAME.attribute,
processGroupName);
setGroupPath();
}
+
+ final VersionControlInformation currentVersionControl =
versionControlInfo.get();
+ if (currentVersionControl != null) {
+ final String registeredFlowIdentifier =
currentVersionControl.getFlowIdentifier();
+
loggingAttributes.put(LoggingAttribute.REGISTERED_FLOW_IDENTIFIER.attribute,
registeredFlowIdentifier);
+
+ final String registeredFlowVersion =
currentVersionControl.getVersion();
+
loggingAttributes.put(LoggingAttribute.REGISTERED_FLOW_VERSION.attribute,
registeredFlowVersion);
+ }
}
private void setGroupPath() {
@@ -4609,7 +4622,11 @@ public final class StandardProcessGroup implements
ProcessGroup {
PROCESS_GROUP_NAME("processGroupName"),
- PROCESS_GROUP_NAME_PATH("processGroupNamePath");
+ PROCESS_GROUP_NAME_PATH("processGroupNamePath"),
+
+ REGISTERED_FLOW_IDENTIFIER("registeredFlowIdentifier"),
+
+ REGISTERED_FLOW_VERSION("registeredFlowVersion");
private final String attribute;
diff --git
a/nifi-framework-bundle/nifi-framework/nifi-framework-components/src/test/java/org/apache/nifi/groups/StandardProcessGroupTest.java
b/nifi-framework-bundle/nifi-framework/nifi-framework-components/src/test/java/org/apache/nifi/groups/StandardProcessGroupTest.java
index 9bebdc4e22..b3f888a339 100644
---
a/nifi-framework-bundle/nifi-framework/nifi-framework-components/src/test/java/org/apache/nifi/groups/StandardProcessGroupTest.java
+++
b/nifi-framework-bundle/nifi-framework/nifi-framework-components/src/test/java/org/apache/nifi/groups/StandardProcessGroupTest.java
@@ -28,6 +28,8 @@ import org.apache.nifi.controller.flow.FlowManager;
import org.apache.nifi.controller.service.ControllerServiceProvider;
import org.apache.nifi.encrypt.PropertyEncryptor;
import org.apache.nifi.nar.ExtensionManager;
+import org.apache.nifi.registry.flow.VersionControlInformation;
+import org.apache.nifi.registry.flow.VersionedFlowStatus;
import org.apache.nifi.util.NiFiProperties;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
@@ -58,6 +60,9 @@ class StandardProcessGroupTest {
private static final String PARENT_NAME = "ParentGroup";
private static final String PARENT_NAME_PATH = "/ParentGroup/TestGroup";
+ private static final String REGISTERED_FLOW_IDENTIFIER = "87654321-4321";
+ private static final String REGISTERED_FLOW_VERSION = "1.0.0";
+
@Mock
private ControllerServiceProvider controllerServiceProvider;
@@ -100,6 +105,12 @@ class StandardProcessGroupTest {
@Mock
private ProcessGroup parentProcessGroup;
+ @Mock
+ private VersionControlInformation versionControlInformation;
+
+ @Mock
+ private VersionedFlowStatus versionedFlowStatus;
+
private StandardProcessGroup processGroup;
@BeforeEach
@@ -164,4 +175,30 @@ class StandardProcessGroupTest {
assertEquals(expected, loggingAttributes);
}
+
+ @Test
+ void testGetLoggingAttributesWithVersionControlInformation() {
+ processGroup.setName(NAME);
+
+
when(versionControlInformation.getFlowIdentifier()).thenReturn(REGISTERED_FLOW_IDENTIFIER);
+
when(versionControlInformation.getVersion()).thenReturn(REGISTERED_FLOW_VERSION);
+
when(versionControlInformation.getStatus()).thenReturn(versionedFlowStatus);
+ processGroup.setVersionControlInformation(versionControlInformation,
Map.of());
+
+ final Map<String, String> loggingAttributes =
processGroup.getLoggingAttributes();
+
+ assertNotNull(loggingAttributes);
+ assertFalse(loggingAttributes.isEmpty());
+
+ final Map<String, String> expected = Map.of(
+
StandardProcessGroup.LoggingAttribute.PROCESS_GROUP_ID.getAttribute(), ID,
+
StandardProcessGroup.LoggingAttribute.PROCESS_GROUP_ID_PATH.getAttribute(),
ID_PATH,
+
StandardProcessGroup.LoggingAttribute.PROCESS_GROUP_NAME.getAttribute(), NAME,
+
StandardProcessGroup.LoggingAttribute.PROCESS_GROUP_NAME_PATH.getAttribute(),
NAME_PATH,
+
StandardProcessGroup.LoggingAttribute.REGISTERED_FLOW_IDENTIFIER.getAttribute(),
REGISTERED_FLOW_IDENTIFIER,
+
StandardProcessGroup.LoggingAttribute.REGISTERED_FLOW_VERSION.getAttribute(),
REGISTERED_FLOW_VERSION
+ );
+
+ assertEquals(expected, loggingAttributes);
+ }
}