add feature-env plugin & add spring cloud gateway staining plugin.

pull/533/head
Haotian Zhang 3 years ago
parent a9d1747256
commit 0c774b1eb8

@ -26,6 +26,9 @@ import java.util.Map;
import com.tencent.cloud.common.constant.MetadataConstant;
import com.tencent.cloud.common.metadata.MetadataContext;
import com.tencent.cloud.common.metadata.MetadataContextHolder;
import com.tencent.cloud.common.util.JacksonUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import reactor.core.publisher.Mono;
import org.springframework.cloud.gateway.filter.GatewayFilterChain;
@ -43,6 +46,8 @@ import static org.springframework.cloud.gateway.filter.RouteToRequestUrlFilter.R
*/
public class TrafficStainingGatewayFilter implements GlobalFilter, Ordered {
private static final Logger LOGGER = LoggerFactory.getLogger(TrafficStainingGatewayFilter.class);
private final List<TrafficStainer> trafficStainers;
public TrafficStainingGatewayFilter(List<TrafficStainer> trafficStainers) {
@ -87,13 +92,23 @@ public class TrafficStainingGatewayFilter implements GlobalFilter, Ordered {
Map<String, String> getStainedLabels(ServerWebExchange exchange) {
Map<String, String> stainedLabels = new HashMap<>();
int size = trafficStainers.size();
TrafficStainer stainer = null;
for (int i = size - 1; i >= 0; i--) {
TrafficStainer stainer = trafficStainers.get(i);
Map<String, String> labels = stainer.apply(exchange);
if (!CollectionUtils.isEmpty(labels)) {
stainedLabels.putAll(labels);
try {
stainer = trafficStainers.get(i);
Map<String, String> labels = stainer.apply(exchange);
if (!CollectionUtils.isEmpty(labels)) {
stainedLabels.putAll(labels);
}
}
catch (Exception e) {
if (stainer != null) {
LOGGER.error("[SCT] traffic stained error. stainer = {}", stainer.getClass().getName(), e);
}
}
}
LOGGER.debug("[SCT] traffic stained labels. {}", JacksonUtils.serialize2Json(stainedLabels));
return stainedLabels;
}

@ -9,7 +9,7 @@
{
"name": "spring.cloud.tencent.plugin.scg.staining.enabled",
"type": "java.lang.Boolean",
"defaultValue": true,
"defaultValue": false,
"description": "the switch for spring cloud gateway staining plugin."
},
{

Loading…
Cancel
Save