From c54db0511ad5698586865d4b89845702a85c8fa6 Mon Sep 17 00:00:00 2001 From: hexiaofeng Date: Fri, 10 Jan 2025 16:12:00 +0800 Subject: [PATCH] Update filter log --- .../governance/invoke/OutboundInvocation.java | 15 ++++++++++++ .../invoke/filter/RouteFilterChain.java | 20 +++++++++++++++- .../invoke/filter/route/CellFilter.java | 7 ------ .../filter/route/CircuitBreakerFilter.java | 7 ------ .../invoke/filter/route/GroupFilter.java | 7 ------ .../invoke/filter/route/HealthyFilter.java | 7 ------ .../invoke/filter/route/LaneFilter.java | 24 ------------------- .../filter/route/LoadBalanceFilter.java | 7 ------ .../invoke/filter/route/PortFilter.java | 9 ------- .../invoke/filter/route/TagRouteFilter.java | 7 ------ .../invoke/filter/route/UnitFilter.java | 7 ------ .../src/main/assembly/config/logback.xml | 3 +++ 12 files changed, 37 insertions(+), 83 deletions(-) diff --git a/joylive-core/joylive-governance-api/src/main/java/com/jd/live/agent/governance/invoke/OutboundInvocation.java b/joylive-core/joylive-governance-api/src/main/java/com/jd/live/agent/governance/invoke/OutboundInvocation.java index f220b5e77..21f72b4e8 100644 --- a/joylive-core/joylive-governance-api/src/main/java/com/jd/live/agent/governance/invoke/OutboundInvocation.java +++ b/joylive-core/joylive-governance-api/src/main/java/com/jd/live/agent/governance/invoke/OutboundInvocation.java @@ -178,6 +178,21 @@ public void onFailure(Endpoint endpoint, Throwable throwable) { } } + /** + * Returns the size of the endpoint collection based on the current state of instances and routeTarget. + * + * @return the size of the endpoint collection + */ + public int getEndpointSize() { + if (instances == null) { + return 0; + } else if (routeTarget == null) { + return instances.size(); + } else { + return routeTarget.getEndpoints().size(); + } + } + /** * Retrieves the endpoints targeted by this outbound invocation. * diff --git a/joylive-core/joylive-governance-api/src/main/java/com/jd/live/agent/governance/invoke/filter/RouteFilterChain.java b/joylive-core/joylive-governance-api/src/main/java/com/jd/live/agent/governance/invoke/filter/RouteFilterChain.java index 6c207a64f..d4257cded 100644 --- a/joylive-core/joylive-governance-api/src/main/java/com/jd/live/agent/governance/invoke/filter/RouteFilterChain.java +++ b/joylive-core/joylive-governance-api/src/main/java/com/jd/live/agent/governance/invoke/filter/RouteFilterChain.java @@ -15,6 +15,8 @@ */ package com.jd.live.agent.governance.invoke.filter; +import com.jd.live.agent.bootstrap.logger.Logger; +import com.jd.live.agent.bootstrap.logger.LoggerFactory; import com.jd.live.agent.governance.invoke.OutboundInvocation; import com.jd.live.agent.governance.request.ServiceRequest.OutboundRequest; @@ -49,6 +51,8 @@ public interface RouteFilterChain { */ class Chain implements RouteFilterChain { + private static final Logger logger = LoggerFactory.getLogger(Chain.class); + private int index; // Tracks the current position in the filter chain. private final RouteFilter[] filters; // Array of filters in the chain. @@ -84,7 +88,21 @@ public Chain(final Collection filters) { @Override public void filter(OutboundInvocation invocation) { if (index < filters.length) { - filters[index++].filter(invocation, this); + log(index - 1, invocation); + RouteFilter filter = filters[index++]; + filter.filter(invocation, this); + } else if (index == filters.length) { + log(index - 1, invocation); + } + } + + private void log(int index, OutboundInvocation invocation) { + if (logger.isDebugEnabled()) { + if (index < 0) { + logger.debug("Before apply any filter, endpoint size: " + invocation.getEndpointSize()); + } else { + logger.debug("After apply " + filters[index].getClass().getSimpleName() + ", endpoint size: " + invocation.getEndpointSize()); + } } } } diff --git a/joylive-core/joylive-governance-api/src/main/java/com/jd/live/agent/governance/invoke/filter/route/CellFilter.java b/joylive-core/joylive-governance-api/src/main/java/com/jd/live/agent/governance/invoke/filter/route/CellFilter.java index 9df81deb3..55d09b6b9 100644 --- a/joylive-core/joylive-governance-api/src/main/java/com/jd/live/agent/governance/invoke/filter/route/CellFilter.java +++ b/joylive-core/joylive-governance-api/src/main/java/com/jd/live/agent/governance/invoke/filter/route/CellFilter.java @@ -15,8 +15,6 @@ */ package com.jd.live.agent.governance.invoke.filter.route; -import com.jd.live.agent.bootstrap.logger.Logger; -import com.jd.live.agent.bootstrap.logger.LoggerFactory; import com.jd.live.agent.core.extension.annotation.Extension; import com.jd.live.agent.core.instance.Location; import com.jd.live.agent.governance.annotation.ConditionalOnGovernanceEnabled; @@ -57,16 +55,11 @@ @ConditionalOnGovernanceEnabled public class CellFilter implements RouteFilter { - private static final Logger logger = LoggerFactory.getLogger(CellFilter.class); - @Override public void filter(OutboundInvocation invocation, RouteFilterChain chain) { RouteTarget target = invocation.getRouteTarget(); UnitAction action = target.getUnitAction(); if (action.getType() == UnitActionType.FORWARD && forward(invocation, target)) { - if (logger.isDebugEnabled()) { - logger.debug("Cell filter applied to route target instance size: {}", target.size()); - } chain.filter(invocation); } else { invocation.reject(FaultType.CELL, action.getMessage()); diff --git a/joylive-core/joylive-governance-api/src/main/java/com/jd/live/agent/governance/invoke/filter/route/CircuitBreakerFilter.java b/joylive-core/joylive-governance-api/src/main/java/com/jd/live/agent/governance/invoke/filter/route/CircuitBreakerFilter.java index 26cf5f57f..1e93ab4cc 100644 --- a/joylive-core/joylive-governance-api/src/main/java/com/jd/live/agent/governance/invoke/filter/route/CircuitBreakerFilter.java +++ b/joylive-core/joylive-governance-api/src/main/java/com/jd/live/agent/governance/invoke/filter/route/CircuitBreakerFilter.java @@ -16,8 +16,6 @@ package com.jd.live.agent.governance.invoke.filter.route; import com.jd.live.agent.bootstrap.exception.RejectException.RejectCircuitBreakException; -import com.jd.live.agent.bootstrap.logger.Logger; -import com.jd.live.agent.bootstrap.logger.LoggerFactory; import com.jd.live.agent.core.extension.ExtensionInitializer; import com.jd.live.agent.core.extension.annotation.Extension; import com.jd.live.agent.core.inject.annotation.Inject; @@ -65,8 +63,6 @@ @ConditionalOnFlowControlEnabled public class CircuitBreakerFilter implements RouteFilter, ExtensionInitializer { - private static final Logger logger = LoggerFactory.getLogger(CircuitBreakerFilter.class); - @Inject private Map factories; @@ -116,9 +112,6 @@ public void filter(OutboundInvocation invocation, // filter broken instance filterHealthy(invocation, instancePolicies); } - if (logger.isDebugEnabled()) { - logger.debug("Cell filter applied to route target instance size: {}", invocation.getRouteTarget().size()); - } chain.filter(invocation); } diff --git a/joylive-core/joylive-governance-api/src/main/java/com/jd/live/agent/governance/invoke/filter/route/GroupFilter.java b/joylive-core/joylive-governance-api/src/main/java/com/jd/live/agent/governance/invoke/filter/route/GroupFilter.java index 3a7d31db5..388b6ed86 100644 --- a/joylive-core/joylive-governance-api/src/main/java/com/jd/live/agent/governance/invoke/filter/route/GroupFilter.java +++ b/joylive-core/joylive-governance-api/src/main/java/com/jd/live/agent/governance/invoke/filter/route/GroupFilter.java @@ -15,8 +15,6 @@ */ package com.jd.live.agent.governance.invoke.filter.route; -import com.jd.live.agent.bootstrap.logger.Logger; -import com.jd.live.agent.bootstrap.logger.LoggerFactory; import com.jd.live.agent.core.extension.annotation.Extension; import com.jd.live.agent.core.inject.annotation.Injectable; import com.jd.live.agent.governance.annotation.ConditionalOnFlowControlEnabled; @@ -38,8 +36,6 @@ @ConditionalOnFlowControlEnabled public class GroupFilter implements RouteFilter { - private static final Logger logger = LoggerFactory.getLogger(GroupFilter.class); - @Override public void filter(OutboundInvocation invocation, RouteFilterChain chain) { if (!invocation.getRequest().isNativeGroup()) { @@ -54,9 +50,6 @@ public void filter(OutboundInvocation invocation, // default group target.filter(endpoint -> endpoint.isGroup(null)); } - if (logger.isDebugEnabled()) { - logger.debug("Group filter applied to route target instance size: {}", target.size()); - } } chain.filter(invocation); } diff --git a/joylive-core/joylive-governance-api/src/main/java/com/jd/live/agent/governance/invoke/filter/route/HealthyFilter.java b/joylive-core/joylive-governance-api/src/main/java/com/jd/live/agent/governance/invoke/filter/route/HealthyFilter.java index 845685e61..36c75ec2d 100644 --- a/joylive-core/joylive-governance-api/src/main/java/com/jd/live/agent/governance/invoke/filter/route/HealthyFilter.java +++ b/joylive-core/joylive-governance-api/src/main/java/com/jd/live/agent/governance/invoke/filter/route/HealthyFilter.java @@ -15,8 +15,6 @@ */ package com.jd.live.agent.governance.invoke.filter.route; -import com.jd.live.agent.bootstrap.logger.Logger; -import com.jd.live.agent.bootstrap.logger.LoggerFactory; import com.jd.live.agent.core.extension.annotation.Extension; import com.jd.live.agent.governance.annotation.ConditionalOnFlowControlEnabled; import com.jd.live.agent.governance.instance.Endpoint; @@ -37,15 +35,10 @@ @ConditionalOnFlowControlEnabled public class HealthyFilter implements RouteFilter { - private static final Logger logger = LoggerFactory.getLogger(HealthyFilter.class); - @Override public void filter(OutboundInvocation invocation, RouteFilterChain chain) { RouteTarget target = invocation.getRouteTarget(); target.filter(Endpoint::isAccessible); - if (logger.isDebugEnabled()) { - logger.debug("Healthy filter applied to route target instance size: {}", target.size()); - } chain.filter(invocation); } } diff --git a/joylive-core/joylive-governance-api/src/main/java/com/jd/live/agent/governance/invoke/filter/route/LaneFilter.java b/joylive-core/joylive-governance-api/src/main/java/com/jd/live/agent/governance/invoke/filter/route/LaneFilter.java index 84290c661..9bf7ae88b 100644 --- a/joylive-core/joylive-governance-api/src/main/java/com/jd/live/agent/governance/invoke/filter/route/LaneFilter.java +++ b/joylive-core/joylive-governance-api/src/main/java/com/jd/live/agent/governance/invoke/filter/route/LaneFilter.java @@ -15,8 +15,6 @@ */ package com.jd.live.agent.governance.invoke.filter.route; -import com.jd.live.agent.bootstrap.logger.Logger; -import com.jd.live.agent.bootstrap.logger.LoggerFactory; import com.jd.live.agent.core.extension.annotation.Extension; import com.jd.live.agent.core.inject.annotation.Injectable; import com.jd.live.agent.governance.annotation.ConditionalOnLaneEnabled; @@ -43,8 +41,6 @@ @ConditionalOnLaneEnabled public class LaneFilter implements RouteFilter { - private static final Logger logger = LoggerFactory.getLogger(LaneFilter.class); - @Override public void filter(OutboundInvocation invocation, RouteFilterChain chain) { // Retrieve the current route target @@ -56,10 +52,6 @@ public void filter(OutboundInvocation invocation, String defaultSpaceId = metadata.getDefaultSpaceId(); String defaultLaneId = metadata.getDefaultLaneId(); - if (logger.isDebugEnabled()) { - logger.debug("Lane filter, targetSpaceId: {}, targetLaneId:{}, defaultSpaceId:{}, defaultLaneId:{}, targetSpace:{}", - targetSpaceId, targetLaneId, defaultSpaceId, defaultLaneId, targetSpace); - } // Check if a target lane is specified if (targetSpace != null) { // redirect according to the service policy @@ -69,39 +61,23 @@ public void filter(OutboundInvocation invocation, Lane targetLane = redirect == null || redirect.isEmpty() ? metadata.getTargetLaneOrDefault(targetSpace.getDefaultLane()) : targetSpace.getOrDefault(redirect); - if (targetLane != null) { Lane defaultLane = targetSpace.getDefaultLane(); boolean redirectDefaultLane = defaultLane != null && targetLane != defaultLane; - if (logger.isDebugEnabled()) { - logger.debug("Lane filter, targetSpaceId: {}, targetLane:{}, defaultSpaceId:{}, defaultLaneId:{}", - targetSpaceId, targetLane.getCode(), defaultSpaceId, defaultLaneId); - } // Filter the route target based on the lane space ID and route lane code int count = target.filter(e -> e.isLane(targetSpaceId, targetLane.getCode(), defaultSpaceId, defaultLaneId), -1, !redirectDefaultLane); // If no matches and a default lane exists, use the default lane if (count <= 0 && redirectDefaultLane) { - if (logger.isDebugEnabled()) { - logger.debug("Lane filter, count is 0, redirect to defaultLane, targetSpaceId: {}, code:{}, defaultSpaceId:{}, defaultLaneId:{}", - targetSpaceId, defaultLane.getCode(), defaultSpaceId, defaultLaneId); - } target.filter(e -> e.isLane(targetSpaceId, defaultLane.getCode(), defaultSpaceId, defaultLaneId), -1, true); } } else { String code = redirect == null || redirect.isEmpty() ? targetLaneId : redirect; - if (logger.isDebugEnabled()) { - logger.debug("Lane filter, target lane is null, targetSpaceId: {}, code:{}, defaultSpaceId:{}, defaultLaneId:{}", - targetSpaceId, code, defaultSpaceId, defaultLaneId); - } target.filter(e -> e.isLane(targetSpaceId, code, defaultSpaceId, defaultLaneId), -1, true); } } else { // target space is not exists. or empty target space id and without default lane space. target.filter(e -> e.isLane(targetSpaceId, targetLaneId, defaultSpaceId, defaultLaneId), -1, true); } - if (logger.isDebugEnabled()) { - logger.debug("Lane filter applied to route target instance size: {}", target.size()); - } // Proceed with the next filter in the chain chain.filter(invocation); } diff --git a/joylive-core/joylive-governance-api/src/main/java/com/jd/live/agent/governance/invoke/filter/route/LoadBalanceFilter.java b/joylive-core/joylive-governance-api/src/main/java/com/jd/live/agent/governance/invoke/filter/route/LoadBalanceFilter.java index 85cd1c8f1..63c112d87 100644 --- a/joylive-core/joylive-governance-api/src/main/java/com/jd/live/agent/governance/invoke/filter/route/LoadBalanceFilter.java +++ b/joylive-core/joylive-governance-api/src/main/java/com/jd/live/agent/governance/invoke/filter/route/LoadBalanceFilter.java @@ -15,8 +15,6 @@ */ package com.jd.live.agent.governance.invoke.filter.route; -import com.jd.live.agent.bootstrap.logger.Logger; -import com.jd.live.agent.bootstrap.logger.LoggerFactory; import com.jd.live.agent.core.extension.annotation.Extension; import com.jd.live.agent.governance.annotation.ConditionalOnFlowControlEnabled; import com.jd.live.agent.governance.context.RequestContext; @@ -48,8 +46,6 @@ @ConditionalOnFlowControlEnabled public class LoadBalanceFilter implements RouteFilter { - private static final Logger logger = LoggerFactory.getLogger(LoadBalanceFilter.class); - @Override public void filter(OutboundInvocation invocation, RouteFilterChain chain) { RouteTarget target = invocation.getRouteTarget(); @@ -76,9 +72,6 @@ public void filter(OutboundInvocation invocation, }); } } - if (logger.isDebugEnabled()) { - logger.debug("LB filter applied to route target instance size: {}", target.size()); - } chain.filter(invocation); } diff --git a/joylive-core/joylive-governance-api/src/main/java/com/jd/live/agent/governance/invoke/filter/route/PortFilter.java b/joylive-core/joylive-governance-api/src/main/java/com/jd/live/agent/governance/invoke/filter/route/PortFilter.java index 8eff78552..86ff6aa56 100644 --- a/joylive-core/joylive-governance-api/src/main/java/com/jd/live/agent/governance/invoke/filter/route/PortFilter.java +++ b/joylive-core/joylive-governance-api/src/main/java/com/jd/live/agent/governance/invoke/filter/route/PortFilter.java @@ -15,12 +15,9 @@ */ package com.jd.live.agent.governance.invoke.filter.route; -import com.jd.live.agent.bootstrap.logger.Logger; -import com.jd.live.agent.bootstrap.logger.LoggerFactory; import com.jd.live.agent.core.extension.annotation.Extension; import com.jd.live.agent.governance.annotation.ConditionalOnFlowControlEnabled; import com.jd.live.agent.governance.invoke.OutboundInvocation; -import com.jd.live.agent.governance.invoke.RouteTarget; import com.jd.live.agent.governance.invoke.filter.RouteFilter; import com.jd.live.agent.governance.invoke.filter.RouteFilterChain; import com.jd.live.agent.governance.request.Portable; @@ -36,21 +33,15 @@ @ConditionalOnFlowControlEnabled public class PortFilter implements RouteFilter { - private static final Logger logger = LoggerFactory.getLogger(PortFilter.class); - @Override public void filter(OutboundInvocation invocation, RouteFilterChain chain) { T request = invocation.getRequest(); - RouteTarget target = invocation.getRouteTarget(); if (request instanceof Portable) { Integer port = ((Portable) request).getPort(); if (port != null) { invocation.getRouteTarget().filter(e -> e.isPort(port)); } } - if (logger.isDebugEnabled()) { - logger.debug("Port filter applied to route target instance size: {}", target.size()); - } chain.filter(invocation); } } diff --git a/joylive-core/joylive-governance-api/src/main/java/com/jd/live/agent/governance/invoke/filter/route/TagRouteFilter.java b/joylive-core/joylive-governance-api/src/main/java/com/jd/live/agent/governance/invoke/filter/route/TagRouteFilter.java index 4720b28b1..fb5d57e8e 100644 --- a/joylive-core/joylive-governance-api/src/main/java/com/jd/live/agent/governance/invoke/filter/route/TagRouteFilter.java +++ b/joylive-core/joylive-governance-api/src/main/java/com/jd/live/agent/governance/invoke/filter/route/TagRouteFilter.java @@ -15,8 +15,6 @@ */ package com.jd.live.agent.governance.invoke.filter.route; -import com.jd.live.agent.bootstrap.logger.Logger; -import com.jd.live.agent.bootstrap.logger.LoggerFactory; import com.jd.live.agent.core.extension.annotation.Extension; import com.jd.live.agent.core.inject.annotation.Injectable; import com.jd.live.agent.governance.annotation.ConditionalOnFlowControlEnabled; @@ -46,8 +44,6 @@ @ConditionalOnFlowControlEnabled public class TagRouteFilter implements RouteFilter { - private static final Logger logger = LoggerFactory.getLogger(TagRouteFilter.class); - @Override public void filter(OutboundInvocation invocation, RouteFilterChain chain) { RouteTarget target = invocation.getRouteTarget(); @@ -62,9 +58,6 @@ public void filter(OutboundInvocation invocation, } } } - if (logger.isDebugEnabled()) { - logger.debug("Tag route filter applied to route target instance size: {}", target.size()); - } chain.filter(invocation); } diff --git a/joylive-core/joylive-governance-api/src/main/java/com/jd/live/agent/governance/invoke/filter/route/UnitFilter.java b/joylive-core/joylive-governance-api/src/main/java/com/jd/live/agent/governance/invoke/filter/route/UnitFilter.java index 222e3c1da..5d66b52ea 100644 --- a/joylive-core/joylive-governance-api/src/main/java/com/jd/live/agent/governance/invoke/filter/route/UnitFilter.java +++ b/joylive-core/joylive-governance-api/src/main/java/com/jd/live/agent/governance/invoke/filter/route/UnitFilter.java @@ -15,8 +15,6 @@ */ package com.jd.live.agent.governance.invoke.filter.route; -import com.jd.live.agent.bootstrap.logger.Logger; -import com.jd.live.agent.bootstrap.logger.LoggerFactory; import com.jd.live.agent.core.extension.annotation.Extension; import com.jd.live.agent.core.inject.annotation.Injectable; import com.jd.live.agent.governance.annotation.ConditionalOnLiveEnabled; @@ -58,17 +56,12 @@ @ConditionalOnLiveEnabled public class UnitFilter implements RouteFilter { - private static final Logger logger = LoggerFactory.getLogger(UnitFilter.class); - @Override public void filter(OutboundInvocation invocation, RouteFilterChain chain) { RouteTarget target = route(invocation); invocation.setRouteTarget(target); UnitAction action = target.getUnitAction(); if (action.getType() == UnitActionType.FORWARD) { - if (logger.isDebugEnabled()) { - logger.debug("Unit filter applied to route target instance size: {}", target.size()); - } chain.filter(invocation); } else { invocation.reject(FaultType.UNIT, action.getMessage()); diff --git a/joylive-package/src/main/assembly/config/logback.xml b/joylive-package/src/main/assembly/config/logback.xml index 314d05843..06626e11b 100644 --- a/joylive-package/src/main/assembly/config/logback.xml +++ b/joylive-package/src/main/assembly/config/logback.xml @@ -20,6 +20,7 @@ + @@ -51,6 +52,8 @@ + +