This is an automated email from the ASF dual-hosted git repository.

bamaer pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/hop.git


The following commit(s) were added to refs/heads/main by this push:
     new 805a90244d Lineage file I/O events are built even when lineage is 
disabled, fixes  #9161 (#9163)
805a90244d is described below

commit 805a90244deb1127d6d7e940733dd91ad243c024
Author: Hans Van Akelyen <[email protected]>
AuthorDate: Sat Oct 31 07:36:20 2026 +0100

    Lineage file I/O events are built even when lineage is disabled, fixes  
#9161 (#9163)
---
 .../apache/hop/lineage/LineageFileIoEmitter.java   | 17 +++++++++++++---
 .../hop/lineage/LineageFileIoEmitterTest.java      | 23 ++++++++++++++++++++++
 2 files changed, 37 insertions(+), 3 deletions(-)

diff --git 
a/engine/src/main/java/org/apache/hop/lineage/LineageFileIoEmitter.java 
b/engine/src/main/java/org/apache/hop/lineage/LineageFileIoEmitter.java
index 9ac829a081..d9d45b8588 100644
--- a/engine/src/main/java/org/apache/hop/lineage/LineageFileIoEmitter.java
+++ b/engine/src/main/java/org/apache/hop/lineage/LineageFileIoEmitter.java
@@ -39,6 +39,14 @@ public final class LineageFileIoEmitter {
 
   private LineageFileIoEmitter() {}
 
+  /**
+   * Whether lineage is enabled. Callers that do extra work only to fill in an 
event (a file size, a
+   * URI) can check this first; the emit methods check it too.
+   */
+  public static boolean isEnabled() {
+    return LineageHub.getInstance().isEnabled();
+  }
+
   /**
    * Records a file/object-store operation performed by a workflow action 
during {@link
    * IAction#execute}.
@@ -87,7 +95,7 @@ public final class LineageFileIoEmitter {
       boolean success,
       String message,
       FileIoContentSchema contentSchema) {
-    if (workflow == null || action == null || operation == null) {
+    if (workflow == null || action == null || operation == null || 
!isEnabled()) {
       return;
     }
     emit(
@@ -113,7 +121,7 @@ public final class LineageFileIoEmitter {
       Long bytesTransferred,
       boolean success,
       String message) {
-    if (workflow == null || action == null || operation == null) {
+    if (workflow == null || action == null || operation == null || 
!isEnabled()) {
       return;
     }
     emitWorkflowActionFileIo(
@@ -168,7 +176,7 @@ public final class LineageFileIoEmitter {
       boolean success,
       String message,
       FileIoContentSchema contentSchema) {
-    if (transform == null || operation == null) {
+    if (transform == null || operation == null || !isEnabled()) {
       return;
     }
     LineageContext.Builder ctx = 
LineageRunLifecycleEmitter.transformContextBuilder(transform);
@@ -225,6 +233,9 @@ public final class LineageFileIoEmitter {
       boolean success,
       String message,
       FileIoContentSchema contentSchema) {
+    if (!isEnabled()) {
+      return;
+    }
     emitTransformFileIo(
         transform,
         operation,
diff --git 
a/engine/src/test/java/org/apache/hop/lineage/LineageFileIoEmitterTest.java 
b/engine/src/test/java/org/apache/hop/lineage/LineageFileIoEmitterTest.java
index 4d73f083c3..7f7f3117ab 100644
--- a/engine/src/test/java/org/apache/hop/lineage/LineageFileIoEmitterTest.java
+++ b/engine/src/test/java/org/apache/hop/lineage/LineageFileIoEmitterTest.java
@@ -50,6 +50,7 @@ class LineageFileIoEmitterTest {
   @Test
   void emitWorkflowActionFileIo_postsFileIoEventToLineageHub() {
     LineageHub hub = mock(LineageHub.class);
+    when(hub.isEnabled()).thenReturn(true);
 
     WorkflowMeta meta = new WorkflowMeta();
     meta.setName("wf1");
@@ -122,6 +123,7 @@ class LineageFileIoEmitterTest {
   @Test
   void 
emitWorkflowActionFileIo_fallsBackToWorkflowLogChannelWhenActionHasNone() {
     LineageHub hub = mock(LineageHub.class);
+    when(hub.isEnabled()).thenReturn(true);
 
     WorkflowMeta meta = new WorkflowMeta();
     meta.setName("wf1");
@@ -153,6 +155,7 @@ class LineageFileIoEmitterTest {
   @Test
   void emitWorkflowActionFileIo_withFileObjects_setsUriFromFileName() throws 
Exception {
     LineageHub hub = mock(LineageHub.class);
+    when(hub.isEnabled()).thenReturn(true);
 
     WorkflowMeta meta = new WorkflowMeta();
     meta.setName("wf1");
@@ -197,6 +200,7 @@ class LineageFileIoEmitterTest {
   @Test
   void emitTransformFileIo_withContentSchema_passesPayload() {
     LineageHub hub = mock(LineageHub.class);
+    when(hub.isEnabled()).thenReturn(true);
 
     ITransform tr = mock(ITransform.class);
     ILogChannel logCh = mock(ILogChannel.class);
@@ -248,6 +252,7 @@ class LineageFileIoEmitterTest {
   @Test
   void emitTransformFileIo_postsFileIoEventWithTransformContext() throws 
Exception {
     LineageHub hub = mock(LineageHub.class);
+    when(hub.isEnabled()).thenReturn(true);
 
     ITransform tr = mock(ITransform.class);
     ILogChannel logCh = mock(ILogChannel.class);
@@ -303,6 +308,7 @@ class LineageFileIoEmitterTest {
   @Test
   void emitTransformFileIo_stringUris_postsFileIoEvent() throws Exception {
     LineageHub hub = mock(LineageHub.class);
+    when(hub.isEnabled()).thenReturn(true);
 
     ITransform tr = mock(ITransform.class);
     ILogChannel logCh = mock(ILogChannel.class);
@@ -358,4 +364,21 @@ class LineageFileIoEmitterTest {
 
     verify(hub, Mockito.never()).emit(Mockito.any());
   }
+
+  @Test
+  void emitTransformFileIo_lineageDisabled_skipsTheEventAndTheUriLookup() {
+    LineageHub hub = mock(LineageHub.class);
+    ITransform tr = mock(ITransform.class);
+    FileObject source = mock(FileObject.class);
+
+    try (MockedStatic<LineageHub> staticHub = 
Mockito.mockStatic(LineageHub.class)) {
+      staticHub.when(LineageHub::getInstance).thenReturn(hub);
+
+      LineageFileIoEmitter.emitTransformFileIo(
+          tr, FileIoOperation.COPY, source, source, 1L, true, null);
+    }
+
+    verify(hub, Mockito.never()).emit(Mockito.any());
+    Mockito.verifyNoInteractions(tr, source);
+  }
 }

Reply via email to