kevdoran commented on code in PR #11330:
URL: https://github.com/apache/nifi/pull/11330#discussion_r3403859305


##########
nifi-framework-bundle/nifi-framework/nifi-framework-core-api/src/main/java/org/apache/nifi/components/connector/ConnectorNode.java:
##########
@@ -67,6 +68,25 @@ public interface ConnectorNode extends 
ComponentAuthorizable, VersionedComponent
 
     BundleCoordinate getBundleCoordinate();
 
+    /**
+     * @return an immutable map of the Connector's logging attributes: the 
framework-managed identity keys
+     *         (such as connector identifier, name, component type, and bundle 
coordinate) merged with any
+     *         provider-supplied custom attributes. These are the attributes 
applied to the MDC of the Connector's
+     *         managed flow and surfaced on Connector metrics. Never {@code 
null}.
+     */
+    Map<String, String> getLoggingAttributes();

Review Comment:
   Done — both getLoggingAttributes() (defaults to Map.of()) and 
setCustomLoggingAttributes(...) (default no-op) are now default methods; 
StandardConnectorNode overrides both.



##########
nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/components/connector/StandardConnectorNode.java:
##########
@@ -149,6 +157,103 @@ public String getName() {
     @Override
     public void setName(final String name) {
         this.name = name;
+        rebuildLoggingAttributes();
+    }
+
+    /**
+     * Returns the {@link ProcessGroup} that holds the connector-managed flow 
(the connector's active
+     * managed root group), or {@code null} before the active flow context has 
been established.
+     *
+     * <p>This serves two purposes:
+     * <ul>
+     *   <li>It satisfies the {@link GroupedComponent} contract. The 
connector's own {@code ComponentLog}
+     *       uses a {@code StandardLoggingContext} bound to this node (see 
{@code ExtensionBuilder}), so the
+     *       connector's own log lines source their MDC from this group's
+     *       {@link ProcessGroup#getLoggingAttributes() logging 
attributes}.</li>
+     *   <li>It is the target onto which {@link #rebuildLoggingAttributes()} 
pushes the merged connector
+     *       logging attributes (via {@code 
StandardProcessGroup.setConnectorLoggingAttributes}); those then
+     *       cascade down the managed flow so components running inside it 
inherit the connector MDC through
+     *       their own logging contexts.</li>
+     * </ul>
+     */
+    @Override
+    public ProcessGroup getProcessGroup() {
+        final FrameworkFlowContext context = activeFlowContext;
+        return context == null ? null : context.getManagedProcessGroup();
+    }
+
+    /**
+     * Replaces the connector-supplied custom logging attributes. Reserved 
keys (those used by the
+     * framework, see {@link ConnectorLoggingAttribute}) are filtered out and 
a WARN is logged for
+     * each dropped entry.
+     *
+     * @param attributes the proposed custom attributes; {@code null} or empty 
clears the current set
+     */
+    @Override
+    public void setCustomLoggingAttributes(final Map<String, String> 
attributes) {
+        final Map<String, String> filtered = filterReservedKeys(attributes);
+
+        synchronized (loggingAttributesLock) {
+            this.customLoggingAttributes = filtered;
+        }
+        rebuildLoggingAttributes();
+    }
+
+    /**
+     * Returns an immutable snapshot of the merged framework + custom logging 
attributes currently
+     * advertised by this connector. The framework keys are populated by the 
framework from the
+     * connector's identifier, name, component type, and bundle coordinate.
+     */
+    public Map<String, String> getLoggingAttributes() {

Review Comment:
   Yep, added



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to