Skip to content

Commit

Permalink
Update filter log
Browse files Browse the repository at this point in the history
  • Loading branch information
hexiaofeng committed Jan 10, 2025
1 parent c8fa646 commit c54db05
Show file tree
Hide file tree
Showing 12 changed files with 37 additions and 83 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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.

Expand Down Expand Up @@ -84,7 +88,21 @@ public Chain(final Collection<? extends RouteFilter> filters) {
@Override
public <T extends OutboundRequest> void filter(OutboundInvocation<T> 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 <T extends OutboundRequest> void log(int index, OutboundInvocation<T> 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());
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -57,16 +55,11 @@
@ConditionalOnGovernanceEnabled
public class CellFilter implements RouteFilter {

private static final Logger logger = LoggerFactory.getLogger(CellFilter.class);

@Override
public <T extends OutboundRequest> void filter(OutboundInvocation<T> 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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -65,8 +63,6 @@
@ConditionalOnFlowControlEnabled
public class CircuitBreakerFilter implements RouteFilter, ExtensionInitializer {

private static final Logger logger = LoggerFactory.getLogger(CircuitBreakerFilter.class);

@Inject
private Map<String, CircuitBreakerFactory> factories;

Expand Down Expand Up @@ -116,9 +112,6 @@ public <T extends OutboundRequest> void filter(OutboundInvocation<T> 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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -38,8 +36,6 @@
@ConditionalOnFlowControlEnabled
public class GroupFilter implements RouteFilter {

private static final Logger logger = LoggerFactory.getLogger(GroupFilter.class);

@Override
public <T extends OutboundRequest> void filter(OutboundInvocation<T> invocation, RouteFilterChain chain) {
if (!invocation.getRequest().isNativeGroup()) {
Expand All @@ -54,9 +50,6 @@ public <T extends OutboundRequest> void filter(OutboundInvocation<T> 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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -37,15 +35,10 @@
@ConditionalOnFlowControlEnabled
public class HealthyFilter implements RouteFilter {

private static final Logger logger = LoggerFactory.getLogger(HealthyFilter.class);

@Override
public <T extends OutboundRequest> void filter(OutboundInvocation<T> 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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -43,8 +41,6 @@
@ConditionalOnLaneEnabled
public class LaneFilter implements RouteFilter {

private static final Logger logger = LoggerFactory.getLogger(LaneFilter.class);

@Override
public <T extends OutboundRequest> void filter(OutboundInvocation<T> invocation, RouteFilterChain chain) {
// Retrieve the current route target
Expand All @@ -56,10 +52,6 @@ public <T extends OutboundRequest> void filter(OutboundInvocation<T> 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
Expand All @@ -69,39 +61,23 @@ public <T extends OutboundRequest> void filter(OutboundInvocation<T> 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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -48,8 +46,6 @@
@ConditionalOnFlowControlEnabled
public class LoadBalanceFilter implements RouteFilter {

private static final Logger logger = LoggerFactory.getLogger(LoadBalanceFilter.class);

@Override
public <T extends OutboundRequest> void filter(OutboundInvocation<T> invocation, RouteFilterChain chain) {
RouteTarget target = invocation.getRouteTarget();
Expand All @@ -76,9 +72,6 @@ public <T extends OutboundRequest> void filter(OutboundInvocation<T> invocation,
});
}
}
if (logger.isDebugEnabled()) {
logger.debug("LB filter applied to route target instance size: {}", target.size());
}
chain.filter(invocation);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -36,21 +33,15 @@
@ConditionalOnFlowControlEnabled
public class PortFilter implements RouteFilter {

private static final Logger logger = LoggerFactory.getLogger(PortFilter.class);

@Override
public <T extends OutboundRequest> void filter(OutboundInvocation<T> 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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -46,8 +44,6 @@
@ConditionalOnFlowControlEnabled
public class TagRouteFilter implements RouteFilter {

private static final Logger logger = LoggerFactory.getLogger(TagRouteFilter.class);

@Override
public <T extends OutboundRequest> void filter(OutboundInvocation<T> invocation, RouteFilterChain chain) {
RouteTarget target = invocation.getRouteTarget();
Expand All @@ -62,9 +58,6 @@ public <T extends OutboundRequest> void filter(OutboundInvocation<T> invocation,
}
}
}
if (logger.isDebugEnabled()) {
logger.debug("Tag route filter applied to route target instance size: {}", target.size());
}
chain.filter(invocation);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -58,17 +56,12 @@
@ConditionalOnLiveEnabled
public class UnitFilter implements RouteFilter {

private static final Logger logger = LoggerFactory.getLogger(UnitFilter.class);

@Override
public <T extends OutboundRequest> void filter(OutboundInvocation<T> 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());
Expand Down
3 changes: 3 additions & 0 deletions joylive-package/src/main/assembly/config/logback.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
<property scope="context" name="logger.application" value="${LIVE_APP_NAME}"/>
<property scope="context" name="logger.level" value="${LIVE_LOG_LEVEL:-info}"/>
<property scope="context" name="logger.advice.level" value="${LIVE_LOG_ADVICE_LEVEL:-${logger.level}}"/>
<property scope="context" name="logger.route.level" value="${LIVE_LOG_ROUTE_LEVEL:-${logger.level}}"/>
<property scope="context" name="logger.totalSize" value="${LIVE_LOG_TOTAL_SIZE:-10GB}"/>
<property scope="context" name="logger.maxHistory" value="${LIVE_LOG_MAX_HISTORY:-30}"/>
<property scope="context" name="logger.maxFileSize" value="${LIVE_LOG_MAX_SIZE:-1GB}"/>
Expand Down Expand Up @@ -51,6 +52,8 @@

<logger name="com.jd.live.agent.bootstrap.bytekit.advice.AdviceHandler" level="${logger.advice.level}"/>

<logger name="com.jd.live.agent.governance.invoke.filter.RouteFilterChain" level="${logger.route.level}"/>

<root level="${logger.level}">
<appender-ref ref="${LIVE_LOG_APPENDER:-ROLLING_APPENDER}"/>
</root>
Expand Down

0 comments on commit c54db05

Please sign in to comment.