From b72bc934bf0bb1908e692e1064fe9e964ef69db1 Mon Sep 17 00:00:00 2001 From: hanbingleixue Date: Tue, 26 Nov 2024 17:44:01 +0800 Subject: [PATCH] Add the entity class for Xds flow control functionality Signed-off-by: hanbingleixue --- .../service/xds/entity/FractionalPercent.java | 52 +++++++ .../core/service/xds/entity/XdsAbort.java | 51 +++++++ .../xds/entity/XdsCircuitBreakers.java | 38 +++++ .../core/service/xds/entity/XdsDelay.java | 51 +++++++ .../core/service/xds/entity/XdsHeader.java | 51 +++++++ .../service/xds/entity/XdsHeaderOption.java | 51 +++++++ .../core/service/xds/entity/XdsHttpFault.java | 51 +++++++ .../xds/entity/XdsOutlierDetection.java | 134 ++++++++++++++++++ .../core/service/xds/entity/XdsRateLimit.java | 66 +++++++++ .../service/xds/entity/XdsRetryPolicy.java | 78 ++++++++++ .../service/xds/entity/XdsTokenBucket.java | 64 +++++++++ .../xds/entity/FractionalPercentTest.java | 37 +++++ .../core/service/xds/entity/XdsAbortTest.java | 37 +++++ .../xds/entity/XdsCircuitBreakersTest.java | 35 +++++ .../core/service/xds/entity/XdsDelayTest.java | 37 +++++ .../xds/entity/XdsHeaderOptionTest.java | 38 +++++ .../service/xds/entity/XdsHeaderTest.java | 37 +++++ .../service/xds/entity/XdsHttpFaultTest.java | 39 +++++ .../xds/entity/XdsOutlierDetectionTest.java | 54 +++++++ .../service/xds/entity/XdsRateLimitTest.java | 45 ++++++ .../xds/entity/XdsRetryPolicyTest.java | 41 ++++++ .../xds/entity/XdsTokenBucketTest.java | 39 +++++ 22 files changed, 1126 insertions(+) create mode 100644 sermant-agentcore/sermant-agentcore-core/src/main/java/io/sermant/core/service/xds/entity/FractionalPercent.java create mode 100644 sermant-agentcore/sermant-agentcore-core/src/main/java/io/sermant/core/service/xds/entity/XdsAbort.java create mode 100644 sermant-agentcore/sermant-agentcore-core/src/main/java/io/sermant/core/service/xds/entity/XdsCircuitBreakers.java create mode 100644 sermant-agentcore/sermant-agentcore-core/src/main/java/io/sermant/core/service/xds/entity/XdsDelay.java create mode 100644 sermant-agentcore/sermant-agentcore-core/src/main/java/io/sermant/core/service/xds/entity/XdsHeader.java create mode 100644 sermant-agentcore/sermant-agentcore-core/src/main/java/io/sermant/core/service/xds/entity/XdsHeaderOption.java create mode 100644 sermant-agentcore/sermant-agentcore-core/src/main/java/io/sermant/core/service/xds/entity/XdsHttpFault.java create mode 100644 sermant-agentcore/sermant-agentcore-core/src/main/java/io/sermant/core/service/xds/entity/XdsOutlierDetection.java create mode 100644 sermant-agentcore/sermant-agentcore-core/src/main/java/io/sermant/core/service/xds/entity/XdsRateLimit.java create mode 100644 sermant-agentcore/sermant-agentcore-core/src/main/java/io/sermant/core/service/xds/entity/XdsRetryPolicy.java create mode 100644 sermant-agentcore/sermant-agentcore-core/src/main/java/io/sermant/core/service/xds/entity/XdsTokenBucket.java create mode 100644 sermant-agentcore/sermant-agentcore-core/src/test/java/io/sermant/core/service/xds/entity/FractionalPercentTest.java create mode 100644 sermant-agentcore/sermant-agentcore-core/src/test/java/io/sermant/core/service/xds/entity/XdsAbortTest.java create mode 100644 sermant-agentcore/sermant-agentcore-core/src/test/java/io/sermant/core/service/xds/entity/XdsCircuitBreakersTest.java create mode 100644 sermant-agentcore/sermant-agentcore-core/src/test/java/io/sermant/core/service/xds/entity/XdsDelayTest.java create mode 100644 sermant-agentcore/sermant-agentcore-core/src/test/java/io/sermant/core/service/xds/entity/XdsHeaderOptionTest.java create mode 100644 sermant-agentcore/sermant-agentcore-core/src/test/java/io/sermant/core/service/xds/entity/XdsHeaderTest.java create mode 100644 sermant-agentcore/sermant-agentcore-core/src/test/java/io/sermant/core/service/xds/entity/XdsHttpFaultTest.java create mode 100644 sermant-agentcore/sermant-agentcore-core/src/test/java/io/sermant/core/service/xds/entity/XdsOutlierDetectionTest.java create mode 100644 sermant-agentcore/sermant-agentcore-core/src/test/java/io/sermant/core/service/xds/entity/XdsRateLimitTest.java create mode 100644 sermant-agentcore/sermant-agentcore-core/src/test/java/io/sermant/core/service/xds/entity/XdsRetryPolicyTest.java create mode 100644 sermant-agentcore/sermant-agentcore-core/src/test/java/io/sermant/core/service/xds/entity/XdsTokenBucketTest.java diff --git a/sermant-agentcore/sermant-agentcore-core/src/main/java/io/sermant/core/service/xds/entity/FractionalPercent.java b/sermant-agentcore/sermant-agentcore-core/src/main/java/io/sermant/core/service/xds/entity/FractionalPercent.java new file mode 100644 index 0000000000..b612450c09 --- /dev/null +++ b/sermant-agentcore/sermant-agentcore-core/src/main/java/io/sermant/core/service/xds/entity/FractionalPercent.java @@ -0,0 +1,52 @@ +/* + * 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.entity; + +/** + * FractionalPercent configuration information + * + * @author zhp + * @since 2024-11-18 + */ +public class FractionalPercent { + /** + * The value of numerator + */ + private int numerator; + + /** + * Specifies the denominator. If the denominator specified is less than the numerator, the final fractional + * percentage is capped at 1 (100%) + */ + private int denominator; + + public int getNumerator() { + return numerator; + } + + public void setNumerator(int numerator) { + this.numerator = numerator; + } + + public int getDenominator() { + return denominator; + } + + public void setDenominator(int denominator) { + this.denominator = denominator; + } +} diff --git a/sermant-agentcore/sermant-agentcore-core/src/main/java/io/sermant/core/service/xds/entity/XdsAbort.java b/sermant-agentcore/sermant-agentcore-core/src/main/java/io/sermant/core/service/xds/entity/XdsAbort.java new file mode 100644 index 0000000000..013340dea7 --- /dev/null +++ b/sermant-agentcore/sermant-agentcore-core/src/main/java/io/sermant/core/service/xds/entity/XdsAbort.java @@ -0,0 +1,51 @@ +/* + * 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.entity; + +/** + * Xds Abort information + * + * @author zhp + * @since 2024-11-18 + */ +public class XdsAbort { + /** + * HTTP status code to use to abort the HTTP request + */ + private int httpStatus; + + /** + * The percentage of requests/ operations/ connections that will be aborted with the error code + */ + private float percentage; + + public int getHttpStatus() { + return httpStatus; + } + + public void setHttpStatus(int httpStatus) { + this.httpStatus = httpStatus; + } + + public float getPercentage() { + return percentage; + } + + public void setPercentage(float percentage) { + this.percentage = percentage; + } +} diff --git a/sermant-agentcore/sermant-agentcore-core/src/main/java/io/sermant/core/service/xds/entity/XdsCircuitBreakers.java b/sermant-agentcore/sermant-agentcore-core/src/main/java/io/sermant/core/service/xds/entity/XdsCircuitBreakers.java new file mode 100644 index 0000000000..b1e242fc61 --- /dev/null +++ b/sermant-agentcore/sermant-agentcore-core/src/main/java/io/sermant/core/service/xds/entity/XdsCircuitBreakers.java @@ -0,0 +1,38 @@ +/* + * 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.entity; + +/** + * Xds circuit breaker information + * + * @author zhp + * @since 2024-11-18 + */ +public class XdsCircuitBreakers { + /** + * Maximum active request count + */ + private int maxRequests; + + public int getMaxRequests() { + return maxRequests; + } + + public void setMaxRequests(int maxRequests) { + this.maxRequests = maxRequests; + } +} diff --git a/sermant-agentcore/sermant-agentcore-core/src/main/java/io/sermant/core/service/xds/entity/XdsDelay.java b/sermant-agentcore/sermant-agentcore-core/src/main/java/io/sermant/core/service/xds/entity/XdsDelay.java new file mode 100644 index 0000000000..803bae277a --- /dev/null +++ b/sermant-agentcore/sermant-agentcore-core/src/main/java/io/sermant/core/service/xds/entity/XdsDelay.java @@ -0,0 +1,51 @@ +/* + * 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.entity; + +/** + * Xds Delay information + * + * @author zhp + * @since 2024-11-18 + */ +public class XdsDelay { + /** + * the specified delay will be injected before a new request, in milliseconds. + */ + private long fixedDelay; + + /** + * The percentage of requests on which the delay will be injected + */ + private float percentage; + + public long getFixedDelay() { + return fixedDelay; + } + + public void setFixedDelay(long fixedDelay) { + this.fixedDelay = fixedDelay; + } + + public float getPercentage() { + return percentage; + } + + public void setPercentage(float percentage) { + this.percentage = percentage; + } +} diff --git a/sermant-agentcore/sermant-agentcore-core/src/main/java/io/sermant/core/service/xds/entity/XdsHeader.java b/sermant-agentcore/sermant-agentcore-core/src/main/java/io/sermant/core/service/xds/entity/XdsHeader.java new file mode 100644 index 0000000000..5f7bca1d07 --- /dev/null +++ b/sermant-agentcore/sermant-agentcore-core/src/main/java/io/sermant/core/service/xds/entity/XdsHeader.java @@ -0,0 +1,51 @@ +/* + * 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.entity; + +/** + * Header name/ value pair + * + * @author zhp + * @since 2024-11-21 + */ +public class XdsHeader { + /** + * Header name + */ + private String key; + + /** + * Header value + */ + private String value; + + public String getKey() { + return key; + } + + public void setKey(String key) { + this.key = key; + } + + public String getValue() { + return value; + } + + public void setValue(String value) { + this.value = value; + } +} diff --git a/sermant-agentcore/sermant-agentcore-core/src/main/java/io/sermant/core/service/xds/entity/XdsHeaderOption.java b/sermant-agentcore/sermant-agentcore-core/src/main/java/io/sermant/core/service/xds/entity/XdsHeaderOption.java new file mode 100644 index 0000000000..1df7fb9f91 --- /dev/null +++ b/sermant-agentcore/sermant-agentcore-core/src/main/java/io/sermant/core/service/xds/entity/XdsHeaderOption.java @@ -0,0 +1,51 @@ +/* + * 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.entity; + +/** + * Header name/ value pair plus option to control append behavior + * + * @author zhp + * @since 2024-11-21 + */ +public class XdsHeaderOption { + /** + * Header name/ value pair that this option applies to + */ + private XdsHeader header; + + /** + * Should the value be appended + */ + private boolean enabledAppend; + + public XdsHeader getHeader() { + return header; + } + + public void setHeader(XdsHeader header) { + this.header = header; + } + + public boolean isEnabledAppend() { + return enabledAppend; + } + + public void setEnabledAppend(boolean enabledAppend) { + this.enabledAppend = enabledAppend; + } +} diff --git a/sermant-agentcore/sermant-agentcore-core/src/main/java/io/sermant/core/service/xds/entity/XdsHttpFault.java b/sermant-agentcore/sermant-agentcore-core/src/main/java/io/sermant/core/service/xds/entity/XdsHttpFault.java new file mode 100644 index 0000000000..8000f6bf2a --- /dev/null +++ b/sermant-agentcore/sermant-agentcore-core/src/main/java/io/sermant/core/service/xds/entity/XdsHttpFault.java @@ -0,0 +1,51 @@ +/* + * 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.entity; + +/** + * Xds fault information + * + * @author zhp + * @since 2024-11-18 + */ +public class XdsHttpFault { + /** + * abort information, If specified, the filter will abort requests based on the values in the object + */ + private XdsAbort abort; + + /** + * delay information, If specified, the filter will inject delays based on the values in the object + */ + private XdsDelay delay; + + public XdsAbort getAbort() { + return abort; + } + + public void setAbort(XdsAbort abort) { + this.abort = abort; + } + + public XdsDelay getDelay() { + return delay; + } + + public void setDelay(XdsDelay delay) { + this.delay = delay; + } +} diff --git a/sermant-agentcore/sermant-agentcore-core/src/main/java/io/sermant/core/service/xds/entity/XdsOutlierDetection.java b/sermant-agentcore/sermant-agentcore-core/src/main/java/io/sermant/core/service/xds/entity/XdsOutlierDetection.java new file mode 100644 index 0000000000..450147802e --- /dev/null +++ b/sermant-agentcore/sermant-agentcore-core/src/main/java/io/sermant/core/service/xds/entity/XdsOutlierDetection.java @@ -0,0 +1,134 @@ +/* + * 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.entity; + +/** + * Xds Outlier Detection information + * + * @author zhp + * @since 2024-11-18 + */ +public class XdsOutlierDetection { + /** + * Whether to distinguish between local source failures and external errors. When set to true, + * it will detect local source failures. + */ + private boolean splitExternalLocalOriginErrors; + + /** + * The number of consecutive locally originated failures before ejection occurs + */ + private int consecutiveLocalOriginFailure; + + /** + * The number of consecutive gateway failures (502, 503, 504 status codes) before a consecutive gateway failure + * ejection occurs + */ + private int consecutiveGatewayFailure; + + /** + * The number of consecutive 5xx responses or local origin errors that are mapped to 5xx error codes before a + * consecutive 5xx ejection occurs + */ + private int consecutive5xxFailure; + + /** + * The time interval between ejection analysis sweeps. This can result in both new ejections as well as hosts being + * returned to service + */ + private long interval; + + /** + * The base time that a host is ejected for. The real time is equal to the base time multiplied by the number of + * times the host has been ejected + */ + private long baseEjectionTime; + + /** + * The maximum % of an upstream cluster that can be ejected due to outlier detection + */ + private float maxEjectionPercent; + + /** + * The minimum number of hosts in a cluster in order to perform failure percentage-based ejection + */ + private float failurePercentageMinimumHosts; + + public boolean isSplitExternalLocalOriginErrors() { + return splitExternalLocalOriginErrors; + } + + public void setSplitExternalLocalOriginErrors(boolean splitExternalLocalOriginErrors) { + this.splitExternalLocalOriginErrors = splitExternalLocalOriginErrors; + } + + public int getConsecutiveLocalOriginFailure() { + return consecutiveLocalOriginFailure; + } + + public void setConsecutiveLocalOriginFailure(int consecutiveLocalOriginFailure) { + this.consecutiveLocalOriginFailure = consecutiveLocalOriginFailure; + } + + public int getConsecutiveGatewayFailure() { + return consecutiveGatewayFailure; + } + + public void setConsecutiveGatewayFailure(int consecutiveGatewayFailure) { + this.consecutiveGatewayFailure = consecutiveGatewayFailure; + } + + public int getConsecutive5xxFailure() { + return consecutive5xxFailure; + } + + public void setConsecutive5xxFailure(int consecutive5xxFailure) { + this.consecutive5xxFailure = consecutive5xxFailure; + } + + public long getInterval() { + return interval; + } + + public void setInterval(long interval) { + this.interval = interval; + } + + public long getBaseEjectionTime() { + return baseEjectionTime; + } + + public void setBaseEjectionTime(long baseEjectionTime) { + this.baseEjectionTime = baseEjectionTime; + } + + public float getMaxEjectionPercent() { + return maxEjectionPercent; + } + + public void setMaxEjectionPercent(float maxEjectionPercent) { + this.maxEjectionPercent = maxEjectionPercent; + } + + public float getFailurePercentageMinimumHosts() { + return failurePercentageMinimumHosts; + } + + public void setFailurePercentageMinimumHosts(float failurePercentageMinimumHosts) { + this.failurePercentageMinimumHosts = failurePercentageMinimumHosts; + } +} diff --git a/sermant-agentcore/sermant-agentcore-core/src/main/java/io/sermant/core/service/xds/entity/XdsRateLimit.java b/sermant-agentcore/sermant-agentcore-core/src/main/java/io/sermant/core/service/xds/entity/XdsRateLimit.java new file mode 100644 index 0000000000..a5d8848f50 --- /dev/null +++ b/sermant-agentcore/sermant-agentcore-core/src/main/java/io/sermant/core/service/xds/entity/XdsRateLimit.java @@ -0,0 +1,66 @@ +/* + * 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.entity; + +import java.util.List; + +/** + * Xds rate-limiting configuration information + * + * @author zhp + * @since 2024-11-18 + */ +public class XdsRateLimit { + /** + * configuration for token bucket + */ + private XdsTokenBucket tokenBucket; + + /** + * Configuration for Response Header Operations + */ + private List responseHeaderOption; + + /** + * The value of FractionalPercent,If set, the rate limit decisions for the given fraction of requests + */ + private FractionalPercent percent; + + public XdsTokenBucket getTokenBucket() { + return tokenBucket; + } + + public void setTokenBucket(XdsTokenBucket tokenBucket) { + this.tokenBucket = tokenBucket; + } + + public List getResponseHeaderOption() { + return responseHeaderOption; + } + + public void setResponseHeaderOption(List responseHeaderOption) { + this.responseHeaderOption = responseHeaderOption; + } + + public FractionalPercent getPercent() { + return percent; + } + + public void setPercent(FractionalPercent percent) { + this.percent = percent; + } +} diff --git a/sermant-agentcore/sermant-agentcore-core/src/main/java/io/sermant/core/service/xds/entity/XdsRetryPolicy.java b/sermant-agentcore/sermant-agentcore-core/src/main/java/io/sermant/core/service/xds/entity/XdsRetryPolicy.java new file mode 100644 index 0000000000..c4e031efd2 --- /dev/null +++ b/sermant-agentcore/sermant-agentcore-core/src/main/java/io/sermant/core/service/xds/entity/XdsRetryPolicy.java @@ -0,0 +1,78 @@ +/* + * 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.entity; + +/** + * Xds Retry Policy information + * + * @author zhp + * @since 2024-11-18 + */ +public class XdsRetryPolicy { + /** + * The maximum number of times host selection will be reattempted before giving up, at which point the host + * that was last selected will be routed to + */ + private long maxAttempts; + + /** + * Specifies a non-zero upstream timeout per retry attempt (including the initial attempt) + */ + private long perTryTimeout; + + /** + * Specifies the conditions under which retry takes place + */ + private String retryOn; + + /** + * Specifies the conditions under which retry takes place + */ + private String retryHostPredicate; + + public long getMaxAttempts() { + return maxAttempts; + } + + public void setMaxAttempts(long maxAttempts) { + this.maxAttempts = maxAttempts; + } + + public long getPerTryTimeout() { + return perTryTimeout; + } + + public void setPerTryTimeout(long perTryTimeout) { + this.perTryTimeout = perTryTimeout; + } + + public String getRetryOn() { + return retryOn; + } + + public void setRetryOn(String retryOn) { + this.retryOn = retryOn; + } + + public String getRetryHostPredicate() { + return retryHostPredicate; + } + + public void setRetryHostPredicate(String retryHostPredicate) { + this.retryHostPredicate = retryHostPredicate; + } +} diff --git a/sermant-agentcore/sermant-agentcore-core/src/main/java/io/sermant/core/service/xds/entity/XdsTokenBucket.java b/sermant-agentcore/sermant-agentcore-core/src/main/java/io/sermant/core/service/xds/entity/XdsTokenBucket.java new file mode 100644 index 0000000000..1908e34798 --- /dev/null +++ b/sermant-agentcore/sermant-agentcore-core/src/main/java/io/sermant/core/service/xds/entity/XdsTokenBucket.java @@ -0,0 +1,64 @@ +/* + * 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.entity; + +/** + * The token bucket configuration to use for rate limiting requests + * + * @author zhp + * @since 2024-11-21 + */ +public class XdsTokenBucket { + /** + * The maximum tokens that the bucket can hold + */ + private int maxTokens; + + /** + * The number of tokens added to the bucket during each fill interval + */ + private int tokensPerFill; + + /** + * The fill interval that tokens are added to the bucket + */ + private long fillInterval; + + public int getMaxTokens() { + return maxTokens; + } + + public void setMaxTokens(int maxTokens) { + this.maxTokens = maxTokens; + } + + public int getTokensPerFill() { + return tokensPerFill; + } + + public void setTokensPerFill(int tokensPerFill) { + this.tokensPerFill = tokensPerFill; + } + + public long getFillInterval() { + return fillInterval; + } + + public void setFillInterval(long fillInterval) { + this.fillInterval = fillInterval; + } +} diff --git a/sermant-agentcore/sermant-agentcore-core/src/test/java/io/sermant/core/service/xds/entity/FractionalPercentTest.java b/sermant-agentcore/sermant-agentcore-core/src/test/java/io/sermant/core/service/xds/entity/FractionalPercentTest.java new file mode 100644 index 0000000000..b639f66653 --- /dev/null +++ b/sermant-agentcore/sermant-agentcore-core/src/test/java/io/sermant/core/service/xds/entity/FractionalPercentTest.java @@ -0,0 +1,37 @@ +/* + * 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.entity; + +import org.junit.Assert; +import org.junit.Test; + +/** + * FractionalPercent configuration information Test + * + * @author zhp + * @since 2024-11-18 + */ +public class FractionalPercentTest { + @Test + public void testFractionalPercent() { + FractionalPercent percent = new FractionalPercent(); + percent.setNumerator(100); + percent.setDenominator(100); + Assert.assertEquals(100, percent.getNumerator()); + Assert.assertEquals(100, percent.getDenominator()); + } +} diff --git a/sermant-agentcore/sermant-agentcore-core/src/test/java/io/sermant/core/service/xds/entity/XdsAbortTest.java b/sermant-agentcore/sermant-agentcore-core/src/test/java/io/sermant/core/service/xds/entity/XdsAbortTest.java new file mode 100644 index 0000000000..5da560ade1 --- /dev/null +++ b/sermant-agentcore/sermant-agentcore-core/src/test/java/io/sermant/core/service/xds/entity/XdsAbortTest.java @@ -0,0 +1,37 @@ +/* + * 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.entity; + +import org.junit.Assert; +import org.junit.Test; + +/** + * XdsAbortTest + * + * @author zhp + * @since 2024-11-21 + **/ +public class XdsAbortTest { + @Test + public void testXdsAbort() { + XdsAbort abort = new XdsAbort(); + abort.setPercentage(0.1f); + abort.setHttpStatus(200); + Assert.assertEquals(200, abort.getHttpStatus()); + Assert.assertEquals(0.1f, abort.getPercentage(), 0); + } +} diff --git a/sermant-agentcore/sermant-agentcore-core/src/test/java/io/sermant/core/service/xds/entity/XdsCircuitBreakersTest.java b/sermant-agentcore/sermant-agentcore-core/src/test/java/io/sermant/core/service/xds/entity/XdsCircuitBreakersTest.java new file mode 100644 index 0000000000..fd9ffb72c6 --- /dev/null +++ b/sermant-agentcore/sermant-agentcore-core/src/test/java/io/sermant/core/service/xds/entity/XdsCircuitBreakersTest.java @@ -0,0 +1,35 @@ +/* + * 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.entity; + +import org.junit.Assert; +import org.junit.Test; + +/** + * XdsCircuitBreakersTest + * + * @author zhp + * @since 2024-11-21 + **/ +public class XdsCircuitBreakersTest { + @Test + public void testXdsCircuitBreakers() { + XdsCircuitBreakers circuitBreakers = new XdsCircuitBreakers(); + circuitBreakers.setMaxRequests(200); + Assert.assertEquals(200, circuitBreakers.getMaxRequests()); + } +} diff --git a/sermant-agentcore/sermant-agentcore-core/src/test/java/io/sermant/core/service/xds/entity/XdsDelayTest.java b/sermant-agentcore/sermant-agentcore-core/src/test/java/io/sermant/core/service/xds/entity/XdsDelayTest.java new file mode 100644 index 0000000000..2463676ef6 --- /dev/null +++ b/sermant-agentcore/sermant-agentcore-core/src/test/java/io/sermant/core/service/xds/entity/XdsDelayTest.java @@ -0,0 +1,37 @@ +/* + * 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.entity; + +import org.junit.Assert; +import org.junit.Test; + +/** + * XdsDelayTest + * + * @author zhp + * @since 2024-11-21 + **/ +public class XdsDelayTest { + @Test + public void testXdsDelay() { + XdsDelay delay = new XdsDelay(); + delay.setPercentage(0.1f); + delay.setFixedDelay(200L); + Assert.assertEquals(200, delay.getFixedDelay()); + Assert.assertEquals(0.1f, delay.getPercentage(), 0); + } +} diff --git a/sermant-agentcore/sermant-agentcore-core/src/test/java/io/sermant/core/service/xds/entity/XdsHeaderOptionTest.java b/sermant-agentcore/sermant-agentcore-core/src/test/java/io/sermant/core/service/xds/entity/XdsHeaderOptionTest.java new file mode 100644 index 0000000000..92258585b2 --- /dev/null +++ b/sermant-agentcore/sermant-agentcore-core/src/test/java/io/sermant/core/service/xds/entity/XdsHeaderOptionTest.java @@ -0,0 +1,38 @@ +/* + * 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.entity; + +import org.junit.Assert; +import org.junit.Test; + +/** + * XdsHeaderOptionTest + * + * @author zhp + * @since 2024-11-21 + **/ +public class XdsHeaderOptionTest { + @Test + public void testXdsHeaderOption() { + XdsHeaderOption xdsHeaderOption = new XdsHeaderOption(); + XdsHeader xdsHeader = new XdsHeader(); + xdsHeaderOption.setHeader(xdsHeader); + xdsHeaderOption.setEnabledAppend(true); + Assert.assertEquals(xdsHeaderOption.getHeader(), xdsHeader); + Assert.assertTrue(xdsHeaderOption.isEnabledAppend()); + } +} diff --git a/sermant-agentcore/sermant-agentcore-core/src/test/java/io/sermant/core/service/xds/entity/XdsHeaderTest.java b/sermant-agentcore/sermant-agentcore-core/src/test/java/io/sermant/core/service/xds/entity/XdsHeaderTest.java new file mode 100644 index 0000000000..0b892d71db --- /dev/null +++ b/sermant-agentcore/sermant-agentcore-core/src/test/java/io/sermant/core/service/xds/entity/XdsHeaderTest.java @@ -0,0 +1,37 @@ +/* + * 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.entity; + +import org.junit.Assert; +import org.junit.Test; + +/** + * XdsHeaderTest + * + * @author zhp + * @since 2024-11-21 + **/ +public class XdsHeaderTest { + @Test + public void testXdsDelay() { + XdsHeader header = new XdsHeader(); + header.setKey("version"); + header.setValue("1.0"); + Assert.assertEquals("version", header.getKey()); + Assert.assertEquals("1.0", header.getValue()); + } +} diff --git a/sermant-agentcore/sermant-agentcore-core/src/test/java/io/sermant/core/service/xds/entity/XdsHttpFaultTest.java b/sermant-agentcore/sermant-agentcore-core/src/test/java/io/sermant/core/service/xds/entity/XdsHttpFaultTest.java new file mode 100644 index 0000000000..9ed5f406f7 --- /dev/null +++ b/sermant-agentcore/sermant-agentcore-core/src/test/java/io/sermant/core/service/xds/entity/XdsHttpFaultTest.java @@ -0,0 +1,39 @@ +/* + * 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.entity; + +import org.junit.Assert; +import org.junit.Test; + +/** + * XdsHttpFaultTest + * + * @author zhp + * @since 2024-11-21 + **/ +public class XdsHttpFaultTest { + @Test + public void testXdsDelay() { + XdsHttpFault fault = new XdsHttpFault(); + XdsDelay delay = new XdsDelay(); + XdsAbort abort = new XdsAbort(); + fault.setDelay(delay); + fault.setAbort(abort); + Assert.assertEquals(delay, fault.getDelay()); + Assert.assertEquals(abort, fault.getAbort()); + } +} diff --git a/sermant-agentcore/sermant-agentcore-core/src/test/java/io/sermant/core/service/xds/entity/XdsOutlierDetectionTest.java b/sermant-agentcore/sermant-agentcore-core/src/test/java/io/sermant/core/service/xds/entity/XdsOutlierDetectionTest.java new file mode 100644 index 0000000000..c6b74ac343 --- /dev/null +++ b/sermant-agentcore/sermant-agentcore-core/src/test/java/io/sermant/core/service/xds/entity/XdsOutlierDetectionTest.java @@ -0,0 +1,54 @@ +/* + * 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.entity; + +import org.junit.Assert; +import org.junit.Test; + +/** + * XdsOutlierDetectionTest + * + * @author zhp + * @since 2024-11-21 + **/ +public class XdsOutlierDetectionTest { + @Test + public void testXdsOutlierDetection() { + XdsOutlierDetection xdsOutlierDetection = initOutlierDetection(); + Assert.assertEquals(1.0f, xdsOutlierDetection.getFailurePercentageMinimumHosts(), 0.0f); + Assert.assertEquals(10, xdsOutlierDetection.getConsecutiveGatewayFailure(), 0.0f); + Assert.assertEquals(10, xdsOutlierDetection.getMaxEjectionPercent(), 0.0f); + Assert.assertEquals(20, xdsOutlierDetection.getConsecutiveLocalOriginFailure(), 0.0f); + Assert.assertTrue(xdsOutlierDetection.isSplitExternalLocalOriginErrors()); + Assert.assertEquals(1000L, xdsOutlierDetection.getInterval()); + Assert.assertEquals(1000L, xdsOutlierDetection.getBaseEjectionTime()); + Assert.assertEquals(30, xdsOutlierDetection.getConsecutive5xxFailure()); + } + + private XdsOutlierDetection initOutlierDetection() { + XdsOutlierDetection xdsOutlierDetection = new XdsOutlierDetection(); + xdsOutlierDetection.setFailurePercentageMinimumHosts(1.0f); + xdsOutlierDetection.setConsecutiveGatewayFailure(10); + xdsOutlierDetection.setMaxEjectionPercent(10f); + xdsOutlierDetection.setConsecutiveLocalOriginFailure(20); + xdsOutlierDetection.setSplitExternalLocalOriginErrors(true); + xdsOutlierDetection.setInterval(1000L); + xdsOutlierDetection.setBaseEjectionTime(1000L); + xdsOutlierDetection.setConsecutive5xxFailure(30); + return xdsOutlierDetection; + } +} diff --git a/sermant-agentcore/sermant-agentcore-core/src/test/java/io/sermant/core/service/xds/entity/XdsRateLimitTest.java b/sermant-agentcore/sermant-agentcore-core/src/test/java/io/sermant/core/service/xds/entity/XdsRateLimitTest.java new file mode 100644 index 0000000000..13b6d41fed --- /dev/null +++ b/sermant-agentcore/sermant-agentcore-core/src/test/java/io/sermant/core/service/xds/entity/XdsRateLimitTest.java @@ -0,0 +1,45 @@ +/* + * 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.entity; + +import org.junit.Assert; +import org.junit.Test; + +import java.util.ArrayList; +import java.util.List; + +/** + * XdsRateLimitTest + * + * @author zhp + * @since 2024-11-21 + **/ +public class XdsRateLimitTest { + @Test + public void testXdsRateLimit() { + XdsRateLimit xdsRateLimit = new XdsRateLimit(); + XdsTokenBucket xdsTokenBucket = new XdsTokenBucket(); + xdsRateLimit.setTokenBucket(xdsTokenBucket); + FractionalPercent fractionalPercent = new FractionalPercent(); + xdsRateLimit.setPercent(fractionalPercent); + List xdsHeaderOptionList = new ArrayList<>(); + xdsRateLimit.setResponseHeaderOption(xdsHeaderOptionList); + Assert.assertEquals(xdsRateLimit.getTokenBucket(), xdsTokenBucket); + Assert.assertEquals(xdsRateLimit.getResponseHeaderOption(), xdsHeaderOptionList); + Assert.assertEquals(fractionalPercent, xdsRateLimit.getPercent()); + } +} diff --git a/sermant-agentcore/sermant-agentcore-core/src/test/java/io/sermant/core/service/xds/entity/XdsRetryPolicyTest.java b/sermant-agentcore/sermant-agentcore-core/src/test/java/io/sermant/core/service/xds/entity/XdsRetryPolicyTest.java new file mode 100644 index 0000000000..def6954bcf --- /dev/null +++ b/sermant-agentcore/sermant-agentcore-core/src/test/java/io/sermant/core/service/xds/entity/XdsRetryPolicyTest.java @@ -0,0 +1,41 @@ +/* + * 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.entity; + +import org.junit.Assert; +import org.junit.Test; + +/** + * XdsRetryPolicyTest + * + * @author zhp + * @since 2024-11-21 + **/ +public class XdsRetryPolicyTest { + @Test + public void testXdsRetryPolicy() { + XdsRetryPolicy xdsRetryPolicy = new XdsRetryPolicy(); + xdsRetryPolicy.setRetryHostPredicate("PreviousHostsPredicate"); + xdsRetryPolicy.setRetryOn("503"); + xdsRetryPolicy.setMaxAttempts(8); + xdsRetryPolicy.setPerTryTimeout(2000); + Assert.assertEquals("PreviousHostsPredicate", xdsRetryPolicy.getRetryHostPredicate()); + Assert.assertEquals("503", xdsRetryPolicy.getRetryOn()); + Assert.assertEquals(8, xdsRetryPolicy.getMaxAttempts()); + Assert.assertEquals(2000, xdsRetryPolicy.getPerTryTimeout()); + } +} diff --git a/sermant-agentcore/sermant-agentcore-core/src/test/java/io/sermant/core/service/xds/entity/XdsTokenBucketTest.java b/sermant-agentcore/sermant-agentcore-core/src/test/java/io/sermant/core/service/xds/entity/XdsTokenBucketTest.java new file mode 100644 index 0000000000..7259e8dcf4 --- /dev/null +++ b/sermant-agentcore/sermant-agentcore-core/src/test/java/io/sermant/core/service/xds/entity/XdsTokenBucketTest.java @@ -0,0 +1,39 @@ +/* + * 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.entity; + +import org.junit.Assert; +import org.junit.Test; + +/** + * XdsTokenBucketTest + * + * @author zhp + * @since 2024-11-21 + **/ +public class XdsTokenBucketTest { + @Test + public void testXdsTokenBucket() { + XdsTokenBucket xdsTokenBucket = new XdsTokenBucket(); + xdsTokenBucket.setTokensPerFill(4); + xdsTokenBucket.setMaxTokens(4); + xdsTokenBucket.setFillInterval(1000); + Assert.assertEquals(4, xdsTokenBucket.getTokensPerFill()); + Assert.assertEquals(4, xdsTokenBucket.getMaxTokens()); + Assert.assertEquals(1000, xdsTokenBucket.getFillInterval()); + } +}