Skip to content

Commit

Permalink
Add Xds flow control service
Browse files Browse the repository at this point in the history
Signed-off-by: hanbingleixue <[email protected]>
  • Loading branch information
hanbingleixue committed Dec 13, 2024
1 parent 283eaf7 commit 723b3e4
Show file tree
Hide file tree
Showing 36 changed files with 1,047 additions and 156 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,16 @@ public class CommonConstant {
*/
public static final String ARTIFACT_NAME_KEY = "artifact";

/**
* ~ string
*/
public static final String WAVY_LINE = "~";

/**
* | string after escaping
*/
public static final String ESCAPED_VERTICAL_LINE = "\\|";

/**
* The key of agent path
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,11 @@ public interface XdsCoreService extends BaseService {
* @return XdsRoute
*/
XdsLoadBalanceService getLoadBalanceService();

/**
* get XDSFlowControlService
*
* @return XdsFlowControlService
*/
XdsFlowControlService getXdsFlowControlService();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
/*
* Copyright (C) 2024-2024 Sermant Authors. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package io.sermant.core.service.xds;

import io.sermant.core.service.xds.entity.XdsHttpFault;
import io.sermant.core.service.xds.entity.XdsInstanceCircuitBreakers;
import io.sermant.core.service.xds.entity.XdsRateLimit;
import io.sermant.core.service.xds.entity.XdsRequestCircuitBreakers;
import io.sermant.core.service.xds.entity.XdsRetryPolicy;

import java.util.Optional;

/**
* xDS FlowControl service
*
* @author zhp
* @since 2024-11-27
**/
public interface XdsFlowControlService {
/**
* get Circuit breaker information for the client's request, When the number of active requests for an
* instance reaches the specified limit, it will trigger a circuit breaker
*
* @param serviceName service name
* @param clusterName cluster name
* @return circuit breaker rules
*/
Optional<XdsRequestCircuitBreakers> getRequestCircuitBreakers(String serviceName, String clusterName);

/**
* get Circuit breaker information of server instance, The instance has reached the specified number of errors
* and will trigger a circuit breaker and the instance will be removed for a period of time
*
* @param serviceName service name
* @param clusterName cluster name
* @return Outlier Detection rules
*/
Optional<XdsInstanceCircuitBreakers> getInstanceCircuitBreakers(String serviceName, String clusterName);

/**
* get retry policy of route name
*
* @param serviceName service name
* @param routeName route name
* @return retry policy
*/
Optional<XdsRetryPolicy> getRetryPolicy(String serviceName, String routeName);

/**
* get rate limit of route name
*
* @param serviceName service name
* @param routeName route name
* @param port port
* @return rate limit rule
*/
Optional<XdsRateLimit> getRateLimit(String serviceName, String routeName, String port);

/**
* get http fault of route name
*
* @param serviceName service name
* @param routeName route name
* @return http fault rule
*/
Optional<XdsHttpFault> getHttpFault(String serviceName, String routeName);
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public class XdsAbort {
/**
* The percentage of requests/ operations/ connections that will be aborted with the error code
*/
private float percentage;
private int percentage;

public int getHttpStatus() {
return httpStatus;
Expand All @@ -41,11 +41,11 @@ public void setHttpStatus(int httpStatus) {
this.httpStatus = httpStatus;
}

public float getPercentage() {
public int getPercentage() {
return percentage;
}

public void setPercentage(float percentage) {
public void setPercentage(int percentage) {
this.percentage = percentage;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ public class XdsCluster {

private boolean isLocalityLb;

private XdsRequestCircuitBreakers requestCircuitBreakers;

private XdsInstanceCircuitBreakers instanceCircuitBreakers;

public String getClusterName() {
return clusterName;
}
Expand Down Expand Up @@ -62,4 +66,20 @@ public boolean isLocalityLb() {
public void setLocalityLb(boolean localityLb) {
isLocalityLb = localityLb;
}

public XdsRequestCircuitBreakers getRequestCircuitBreakers() {
return requestCircuitBreakers;
}

public void setRequestCircuitBreakers(XdsRequestCircuitBreakers requestCircuitBreakers) {
this.requestCircuitBreakers = requestCircuitBreakers;
}

public XdsInstanceCircuitBreakers getInstanceCircuitBreakers() {
return instanceCircuitBreakers;
}

public void setInstanceCircuitBreakers(XdsInstanceCircuitBreakers instanceCircuitBreakers) {
this.instanceCircuitBreakers = instanceCircuitBreakers;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public class XdsDelay {
/**
* The percentage of requests on which the delay will be injected
*/
private float percentage;
private int percentage;

public long getFixedDelay() {
return fixedDelay;
Expand All @@ -41,11 +41,11 @@ public void setFixedDelay(long fixedDelay) {
this.fixedDelay = fixedDelay;
}

public float getPercentage() {
public int getPercentage() {
return percentage;
}

public void setPercentage(float percentage) {
public void setPercentage(int percentage) {
this.percentage = percentage;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,13 @@
package io.sermant.core.service.xds.entity;

/**
* Xds Outlier Detection information
* Circuit breaker information of server instance, The instance has reached the specified number of errors and will
* trigger a circuit breaker and the instance will be removed for a period of time
*
* @author zhp
* @since 2024-11-18
*/
public class XdsOutlierDetection {
public class XdsInstanceCircuitBreakers {
/**
* Whether to distinguish between local source failures and external errors. When set to true,
* it will detect local source failures.
Expand Down Expand Up @@ -61,12 +62,18 @@ public class XdsOutlierDetection {
/**
* The maximum % of an upstream cluster that can be ejected due to outlier detection
*/
private float maxEjectionPercent;
private int maxEjectionPercent;

/**
* The minimum number of hosts in a cluster in order to perform failure percentage-based ejection
*/
private float failurePercentageMinimumHosts;
private int failurePercentageMinimumHosts;

/**
* Outlier detection will be enabled as long as the associated load balancing pool has at least min_health_percent
* hosts in healthy mode.
*/
private double minHealthPercent;

public boolean isSplitExternalLocalOriginErrors() {
return splitExternalLocalOriginErrors;
Expand Down Expand Up @@ -116,19 +123,27 @@ public void setBaseEjectionTime(long baseEjectionTime) {
this.baseEjectionTime = baseEjectionTime;
}

public float getMaxEjectionPercent() {
public int getMaxEjectionPercent() {
return maxEjectionPercent;
}

public void setMaxEjectionPercent(float maxEjectionPercent) {
public void setMaxEjectionPercent(int maxEjectionPercent) {
this.maxEjectionPercent = maxEjectionPercent;
}

public float getFailurePercentageMinimumHosts() {
public int getFailurePercentageMinimumHosts() {
return failurePercentageMinimumHosts;
}

public void setFailurePercentageMinimumHosts(float failurePercentageMinimumHosts) {
public void setFailurePercentageMinimumHosts(int failurePercentageMinimumHosts) {
this.failurePercentageMinimumHosts = failurePercentageMinimumHosts;
}

public double getMinHealthPercent() {
return minHealthPercent;
}

public void setMinHealthPercent(double minHealthPercent) {
this.minHealthPercent = minHealthPercent;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@

/**
* Xds rate-limiting configuration information
* LocalRateLimit is published through
* <a href="https://istio.io/latest/docs/reference/config/networking/envoy-filter/">EnvoyFilter</a>,
* with routeConfiguration.vhost.name corresponding to the name after
* filling in spec.hosts in
* <a href="https://istio.io/latest/docs/reference/config/networking/virtual-service">VirtualService</a>, and
* routeConfiguration.vhost.route.name corresponding to the name in spec.http
*
* @author zhp
* @since 2024-11-18
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,13 @@
package io.sermant.core.service.xds.entity;

/**
* Xds circuit breaker information
* Circuit breaker information for the client's request, When the number of active requests for an instance
* reaches the specified limit, it will trigger a circuit breaker
*
* @author zhp
* @since 2024-11-18
*/
public class XdsCircuitBreakers {
public class XdsRequestCircuitBreakers {
/**
* Maximum active request count
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ public class XdsRoute {

private XdsRouteAction routeAction;

private XdsHttpFault httpFault;

private XdsRateLimit rateLimit;

public String getName() {
return name;
}
Expand All @@ -52,4 +56,20 @@ public XdsRouteAction getRouteAction() {
public void setRouteAction(XdsRouteAction routeAction) {
this.routeAction = routeAction;
}

public XdsHttpFault getHttpFault() {
return httpFault;
}

public void setHttpFault(XdsHttpFault httpFault) {
this.httpFault = httpFault;
}

public XdsRateLimit getRateLimit() {
return rateLimit;
}

public void setRateLimit(XdsRateLimit rateLimit) {
this.rateLimit = rateLimit;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ public class XdsRouteAction {

private XdsWeightedClusters weightedClusters;

private XdsRetryPolicy retryPolicy;

public String getCluster() {
return cluster;
}
Expand All @@ -55,6 +57,14 @@ public void setWeightedClusters(XdsWeightedClusters weightedClusters) {
this.weightedClusters = weightedClusters;
}

public XdsRetryPolicy getRetryPolicy() {
return retryPolicy;
}

public void setRetryPolicy(XdsRetryPolicy retryPolicy) {
this.retryPolicy = retryPolicy;
}

/**
* xDS WeightedClusters
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import java.util.Collections;
import java.util.Map;
import java.util.Optional;
import java.util.Set;

/**
Expand Down Expand Up @@ -104,4 +105,38 @@ public XdsLbPolicy getBaseLbPolicyOfService() {
}
return xdsCluster.getLbPolicy();
}

/**
* get XdsRequestCircuitBreakers
*
* @param clusterName cluster name
* @return XdsOutlierDetection
*/
public Optional<XdsRequestCircuitBreakers> getRequestCircuitBreakersOfCluster(String clusterName) {
if (clusters == null) {
return Optional.empty();
}
XdsCluster xdsCluster = clusters.get(clusterName);
if (xdsCluster == null) {
return Optional.empty();
}
return Optional.ofNullable(xdsCluster.getRequestCircuitBreakers());
}

/**
* get XdsInstanceCircuitBreakers
*
* @param clusterName cluster name
* @return XdsOutlierDetection
*/
public Optional<XdsInstanceCircuitBreakers> getInstanceCircuitBreakersOfCluster(String clusterName) {
if (clusters == null) {
return Optional.empty();
}
XdsCluster xdsCluster = clusters.get(clusterName);
if (xdsCluster == null) {
return Optional.empty();
}
return Optional.ofNullable(xdsCluster.getInstanceCircuitBreakers());
}
}
Loading

0 comments on commit 723b3e4

Please sign in to comment.