pvillard31 commented on code in PR #11330:
URL: https://github.com/apache/nifi/pull/11330#discussion_r3400565540
##########
nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/controller/FlowController.java:
##########
@@ -810,11 +810,12 @@ private FlowController(
}
eventAccess = new StandardEventAccess(flowManager,
flowFileEventRepository, processScheduler, authorizer, provenanceRepository,
- auditService, analyticsEngine, flowFileRepository,
contentRepository);
+ auditService, analyticsEngine, flowFileRepository,
contentRepository, connectorRepository);
timerDrivenEngineRef.get().scheduleWithFixedDelay(() -> {
try {
- statusHistoryRepository.capture(getNodeStatusSnapshot(),
eventAccess.getControllerStatus(), getGarbageCollectionStatus(), new Date());
+ statusHistoryRepository.capture(getNodeStatusSnapshot(),
eventAccess.getControllerStatus(), eventAccess.getConnectorStatuses(),
Review Comment:
Since no `StatusHistoryRepository` overrides the new `capture` overload yet,
the `connectorStatuses` are dropped today; is the consuming implementation
planned for a later milestone?
##########
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:
Could `getLoggingAttributes()` and `setCustomLoggingAttributes(...)` be
`default` methods so other implementations of `ConnectorNode` keep compiling?
##########
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:
Should this method carry `@Override`, since it now implements the new
`ConnectorNode.getLoggingAttributes()`?
##########
nifi-framework-bundle/nifi-framework/nifi-framework-components/src/main/java/org/apache/nifi/groups/StandardProcessGroup.java:
##########
@@ -308,6 +309,14 @@ public ProcessGroup getParent() {
@Override
public void setParent(final ProcessGroup newParent) {
parent.set(newParent);
+ // If the process group is part of a Connector flow, inherit
connector-supplied MDC attributes.
Review Comment:
These four new comment lines have trailing whitespace and fail the
checkstyle check in CI. Can you remove the trailing spaces?
##########
nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/controller/ExtensionBuilder.java:
##########
@@ -538,11 +539,16 @@ public Resource getResource() {
connectorValidationTrigger,
false
);
+ // Late-bind the logging context to the connector node so that MDC
attributes assembled by
+ // the node (framework keys + provider-supplied custom keys) flow
through the connector's
+ // own ComponentLog as well as the managed flow's nested components.
Provider-supplied custom
+ // attributes are sourced and applied by the ConnectorRepository when
the node is added/restored.
+ loggingContext.setComponent(connectorNode);
Review Comment:
CI fails to compile here because `connectorNode` is typed as
`ConnectorNode`, which does not extend `GroupedComponent` that `setComponent`
requires. Should `ConnectorNode` extend `GroupedComponent`, or should this call
use the `StandardConnectorNode` type?
--
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]