parent
8975054069
commit
b2081651e9
@ -0,0 +1,43 @@
|
||||
/*
|
||||
* Tencent is pleased to support the open source community by making Spring Cloud Tencent available.
|
||||
*
|
||||
* Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved.
|
||||
*
|
||||
* Licensed under the BSD 3-Clause License (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://opensource.org/licenses/BSD-3-Clause
|
||||
*
|
||||
* 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 com.tencent.cloud.polaris.loadbalancer.reactive;
|
||||
|
||||
import com.tencent.cloud.common.constant.HeaderConstant;
|
||||
import com.tencent.polaris.api.core.ConsumerAPI;
|
||||
import org.springframework.cloud.client.ServiceInstance;
|
||||
import org.springframework.cloud.client.loadbalancer.reactive.LoadBalancerClientRequestTransformer;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.web.reactive.function.client.ClientRequest;
|
||||
|
||||
public class PolarisLoadBalancerClientRequestTransformer implements LoadBalancerClientRequestTransformer {
|
||||
|
||||
private final ConsumerAPI consumerAPI;
|
||||
|
||||
public PolarisLoadBalancerClientRequestTransformer(ConsumerAPI consumerAPI) {
|
||||
this.consumerAPI = consumerAPI;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ClientRequest transformRequest(ClientRequest request, ServiceInstance instance) {
|
||||
if (instance != null) {
|
||||
HttpHeaders headers = request.headers();
|
||||
headers.add(HeaderConstant.INTERNAL_CALLEE_SERVICE_ID, instance.getServiceId());
|
||||
}
|
||||
return request;
|
||||
}
|
||||
}
|
@ -0,0 +1,42 @@
|
||||
/*
|
||||
* Tencent is pleased to support the open source community by making Spring Cloud Tencent available.
|
||||
*
|
||||
* Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved.
|
||||
*
|
||||
* Licensed under the BSD 3-Clause License (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://opensource.org/licenses/BSD-3-Clause
|
||||
*
|
||||
* 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 com.tencent.cloud.common.constant;
|
||||
|
||||
/**
|
||||
* Built-in system http header fields
|
||||
*/
|
||||
public final class HeaderConstant {
|
||||
|
||||
/**
|
||||
* The called service returns the real call result of its own processing request
|
||||
*/
|
||||
public static final String INTERNAL_CALLEE_RET_STATUS = "internal-callee-retstatus";
|
||||
|
||||
/**
|
||||
* The name of the rule that the current limit/circiutbreaker rule takes effect
|
||||
*/
|
||||
public static final String INTERNAL_ACTIVE_RULE_NAME = "internal-callee-activerule";
|
||||
|
||||
/**
|
||||
* The name information of the called service
|
||||
*/
|
||||
public static final String INTERNAL_CALLEE_SERVICE_ID = "internal-callee-serviceid";
|
||||
|
||||
private HeaderConstant() {
|
||||
}
|
||||
}
|
@ -0,0 +1,51 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<artifactId>polaris-ratelimit-example</artifactId>
|
||||
<groupId>com.tencent.cloud</groupId>
|
||||
<version>${revision}</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
<artifactId>ratelimit-caller-service</artifactId>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-webflux</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.tencent.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-tencent-polaris-discovery</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.tencent.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-tencent-polaris-ratelimit</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-actuator</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
</project>
|
@ -0,0 +1,171 @@
|
||||
/*
|
||||
* Tencent is pleased to support the open source community by making Spring Cloud Tencent available.
|
||||
*
|
||||
* Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved.
|
||||
*
|
||||
* Licensed under the BSD 3-Clause License (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://opensource.org/licenses/BSD-3-Clause
|
||||
*
|
||||
* 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 com.tencent.cloud.ratelimit.example.service.caller;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.http.HttpEntity;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.HttpMethod;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.client.HttpClientErrorException.TooManyRequests;
|
||||
import org.springframework.web.client.RestClientException;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
import org.springframework.web.reactive.function.client.WebClient;
|
||||
import org.springframework.web.reactive.function.client.WebClientResponseException;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.concurrent.atomic.AtomicLong;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/business")
|
||||
public class Controller {
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(Controller.class);
|
||||
|
||||
private final AtomicInteger index = new AtomicInteger(0);
|
||||
private final AtomicLong lastTimestamp = new AtomicLong(0);
|
||||
@Autowired
|
||||
private RestTemplate restTemplate;
|
||||
@Autowired
|
||||
private WebClient.Builder webClientBuilder;
|
||||
|
||||
private String appName = "RateLimitCalleeService";
|
||||
|
||||
/**
|
||||
* Get information.
|
||||
* @return information
|
||||
*/
|
||||
@GetMapping("/info")
|
||||
public String info() {
|
||||
return "hello world for ratelimit service " + index.incrementAndGet();
|
||||
}
|
||||
|
||||
@GetMapping("/info/webclient")
|
||||
public Mono<String> infoWebClient() {
|
||||
return Mono.just("hello world for ratelimit service " + index.incrementAndGet());
|
||||
}
|
||||
|
||||
@GetMapping("/invoke/webclient")
|
||||
public String invokeInfoWebClient() throws InterruptedException, ExecutionException {
|
||||
StringBuffer builder = new StringBuffer();
|
||||
WebClient webClient = webClientBuilder.baseUrl("http://" + appName).build();
|
||||
List<Mono<String>> monoList = new ArrayList<>();
|
||||
for (int i = 0; i < 30; i++) {
|
||||
Mono<String> response = webClient.get()
|
||||
.uri(uriBuilder -> uriBuilder
|
||||
.path("/business/info/webclient")
|
||||
.queryParam("yyy", "yyy")
|
||||
.build()
|
||||
)
|
||||
.header("xxx", "xxx")
|
||||
.retrieve()
|
||||
.bodyToMono(String.class)
|
||||
.doOnSuccess(s -> builder.append(s + "\n"))
|
||||
.doOnError(e -> {
|
||||
if (e instanceof WebClientResponseException) {
|
||||
if (((WebClientResponseException) e).getRawStatusCode() == 429) {
|
||||
builder.append("TooManyRequests ").append(index.incrementAndGet() + "\n");
|
||||
}
|
||||
}
|
||||
})
|
||||
.onErrorReturn("");
|
||||
monoList.add(response);
|
||||
}
|
||||
for (Mono<String> mono : monoList) {
|
||||
mono.toFuture().get();
|
||||
}
|
||||
index.set(0);
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get information 30 times per 1 second.
|
||||
*
|
||||
* @return result of 30 calls.
|
||||
* @throws InterruptedException exception
|
||||
*/
|
||||
@GetMapping("/invoke")
|
||||
public String invokeInfo() throws InterruptedException {
|
||||
StringBuffer builder = new StringBuffer();
|
||||
CountDownLatch count = new CountDownLatch(30);
|
||||
for (int i = 0; i < 30; i++) {
|
||||
new Thread(() -> {
|
||||
try {
|
||||
HttpHeaders httpHeaders = new HttpHeaders();
|
||||
httpHeaders.add("xxx", "xxx");
|
||||
ResponseEntity<String> entity = restTemplate.exchange(
|
||||
"http://" + appName + "/business/info?yyy={yyy}",
|
||||
HttpMethod.GET,
|
||||
new HttpEntity<>(httpHeaders),
|
||||
String.class,
|
||||
"yyy"
|
||||
);
|
||||
builder.append(entity.getBody() + "\n");
|
||||
}
|
||||
catch (RestClientException e) {
|
||||
if (e instanceof TooManyRequests) {
|
||||
builder.append("TooManyRequests ").append(index.incrementAndGet() + "\n");
|
||||
}
|
||||
else {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
finally {
|
||||
count.countDown();
|
||||
}
|
||||
}).start();
|
||||
}
|
||||
count.await();
|
||||
index.set(0);
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get information with unirate.
|
||||
*
|
||||
* @return information
|
||||
*/
|
||||
@GetMapping("/unirate")
|
||||
public String unirate() {
|
||||
long currentTimestamp = System.currentTimeMillis();
|
||||
long lastTime = lastTimestamp.get();
|
||||
if (lastTime != 0) {
|
||||
LOG.info("Current timestamp:" + currentTimestamp + ", diff from last timestamp:" + (currentTimestamp - lastTime));
|
||||
}
|
||||
else {
|
||||
LOG.info("Current timestamp:" + currentTimestamp);
|
||||
}
|
||||
lastTimestamp.set(currentTimestamp);
|
||||
return "hello world for ratelimit service with diff from last request:" + (currentTimestamp - lastTime) + "ms.";
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,51 @@
|
||||
/*
|
||||
* Tencent is pleased to support the open source community by making Spring Cloud Tencent available.
|
||||
*
|
||||
* Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved.
|
||||
*
|
||||
* Licensed under the BSD 3-Clause License (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://opensource.org/licenses/BSD-3-Clause
|
||||
*
|
||||
* 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 com.tencent.cloud.ratelimit.example.service.caller;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
import org.springframework.web.reactive.function.client.WebClient;
|
||||
|
||||
@SpringBootApplication
|
||||
public class RateLimitCallerService {
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(RateLimitCallerService.class);
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(RateLimitCallerService.class, args);
|
||||
}
|
||||
|
||||
@Bean
|
||||
@LoadBalanced
|
||||
public RestTemplate restTemplate() {
|
||||
return new RestTemplate();
|
||||
}
|
||||
|
||||
|
||||
@LoadBalanced
|
||||
@Bean
|
||||
WebClient.Builder webClientBuilder() {
|
||||
return WebClient.builder();
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,20 @@
|
||||
server:
|
||||
port: 58080
|
||||
spring:
|
||||
application:
|
||||
name: RateLimitCallerService
|
||||
cloud:
|
||||
polaris:
|
||||
address: grpc://127.0.0.1:8091
|
||||
namespace: default
|
||||
enabled: true
|
||||
|
||||
management:
|
||||
endpoints:
|
||||
web:
|
||||
exposure:
|
||||
include:
|
||||
- polaris-ratelimit
|
||||
logging:
|
||||
level:
|
||||
com.tencent.cloud.polaris: debug
|
@ -0,0 +1,170 @@
|
||||
/*
|
||||
* Tencent is pleased to support the open source community by making Spring Cloud Tencent available.
|
||||
*
|
||||
* Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved.
|
||||
*
|
||||
* Licensed under the BSD 3-Clause License (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://opensource.org/licenses/BSD-3-Clause
|
||||
*
|
||||
* 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 com.tencent.cloud.rpc.enhancement.webclient;
|
||||
|
||||
import com.tencent.cloud.common.constant.HeaderConstant;
|
||||
import com.tencent.cloud.common.constant.RouterConstant;
|
||||
import com.tencent.cloud.common.metadata.MetadataContext;
|
||||
import com.tencent.cloud.rpc.enhancement.AbstractPolarisReporterAdapter;
|
||||
import com.tencent.cloud.rpc.enhancement.config.RpcEnhancementReporterProperties;
|
||||
import com.tencent.polaris.api.core.ConsumerAPI;
|
||||
import com.tencent.polaris.api.pojo.RetStatus;
|
||||
import com.tencent.polaris.api.pojo.ServiceKey;
|
||||
import com.tencent.polaris.api.rpc.ServiceCallResult;
|
||||
import com.tencent.polaris.api.utils.CollectionUtils;
|
||||
import com.tencent.polaris.client.api.SDKContext;
|
||||
import com.tencent.polaris.discovery.client.api.DefaultConsumerAPI;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.web.reactive.function.client.ClientRequest;
|
||||
import org.springframework.web.reactive.function.client.ClientResponse;
|
||||
import org.springframework.web.reactive.function.client.ExchangeFilterFunction;
|
||||
import org.springframework.web.reactive.function.client.ExchangeFunction;
|
||||
import reactor.core.publisher.Mono;
|
||||
import reactor.util.context.Context;
|
||||
import reactor.util.context.ContextView;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.net.SocketTimeoutException;
|
||||
import java.net.URI;
|
||||
import java.net.URLDecoder;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
import static com.tencent.cloud.common.constant.ContextConstant.UTF_8;
|
||||
|
||||
public class EnhancedWebClientReporter extends AbstractPolarisReporterAdapter implements ExchangeFilterFunction {
|
||||
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(EnhancedWebClientReporter.class);
|
||||
|
||||
private static final String METRICS_WEBCLIENT_START_TIME = EnhancedWebClientReporter.class.getName()
|
||||
+ ".START_TIME";
|
||||
|
||||
private final ConsumerAPI consumerAPI;
|
||||
|
||||
private final SDKContext context;
|
||||
|
||||
public EnhancedWebClientReporter(RpcEnhancementReporterProperties reportProperties, ConsumerAPI consumerAPI) {
|
||||
super(reportProperties);
|
||||
this.context = ((DefaultConsumerAPI) consumerAPI).getSDKContext();
|
||||
this.consumerAPI = consumerAPI;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Mono<ClientResponse> filter(ClientRequest request, ExchangeFunction next) {
|
||||
return next.exchange(request).as((responseMono) -> instrumentResponse(request, responseMono))
|
||||
.contextWrite(this::putStartTime);
|
||||
}
|
||||
|
||||
private Mono<ClientResponse> instrumentResponse(ClientRequest request, Mono<ClientResponse> responseMono) {
|
||||
return Mono.deferContextual((ctx) -> responseMono.doOnEach((signal) -> {
|
||||
// report result to polaris
|
||||
if (reportProperties.isEnabled()) {
|
||||
return;
|
||||
}
|
||||
ServiceCallResult callResult = new ServiceCallResult();
|
||||
Long startTime = getStartTime(ctx);
|
||||
callResult.setDelay(System.currentTimeMillis() - startTime);
|
||||
|
||||
callResult.setNamespace(MetadataContext.LOCAL_NAMESPACE);
|
||||
callResult.setService(request.headers().getFirst(HeaderConstant.INTERNAL_CALLEE_SERVICE_ID));
|
||||
String sourceNamespace = MetadataContext.LOCAL_NAMESPACE;
|
||||
String sourceService = MetadataContext.LOCAL_SERVICE;
|
||||
if (StringUtils.isNotBlank(sourceNamespace) && StringUtils.isNotBlank(sourceService)) {
|
||||
callResult.setCallerService(new ServiceKey(sourceNamespace, sourceService));
|
||||
}
|
||||
|
||||
Collection<String> labels = request.headers().get(RouterConstant.ROUTER_LABEL_HEADER);
|
||||
if (CollectionUtils.isNotEmpty(labels) && labels.iterator().hasNext()) {
|
||||
String label = labels.iterator().next();
|
||||
try {
|
||||
label = URLDecoder.decode(label, UTF_8);
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
LOGGER.error("unsupported charset exception " + UTF_8, e);
|
||||
}
|
||||
callResult.setLabels(convertLabel(label));
|
||||
}
|
||||
|
||||
URI uri = request.url();
|
||||
callResult.setMethod(uri.getPath());
|
||||
callResult.setHost(uri.getHost());
|
||||
// -1 means access directly by url, and use http default port number 80
|
||||
callResult.setPort(uri.getPort() == -1 ? 80 : uri.getPort());
|
||||
callResult.setCallerIp(context.getConfig().getGlobal().getAPI().getBindIP());
|
||||
|
||||
RetStatus retStatus = RetStatus.RetSuccess;
|
||||
ClientResponse response = signal.get();
|
||||
if (Objects.nonNull(response)) {
|
||||
callResult.setRuleName(getActiveRuleNameFromRequest(response));
|
||||
if (apply(response.statusCode())) {
|
||||
retStatus = RetStatus.RetFail;
|
||||
}
|
||||
retStatus = getRetStatusFromRequest(response, retStatus);
|
||||
}
|
||||
if (signal.isOnError()) {
|
||||
Throwable throwable = signal.getThrowable();
|
||||
if (throwable instanceof SocketTimeoutException) {
|
||||
retStatus = RetStatus.RetTimeout;
|
||||
}
|
||||
}
|
||||
callResult.setRetStatus(retStatus);
|
||||
|
||||
consumerAPI.updateServiceCallResult(callResult);
|
||||
}));
|
||||
}
|
||||
|
||||
private static RetStatus getRetStatusFromRequest(ClientResponse response, RetStatus defaultVal) {
|
||||
HttpHeaders headers = response.headers().asHttpHeaders();
|
||||
if (headers.containsKey(HeaderConstant.INTERNAL_CALLEE_RET_STATUS)) {
|
||||
List<String> values = headers.get(HeaderConstant.INTERNAL_CALLEE_RET_STATUS);
|
||||
if (CollectionUtils.isNotEmpty(values)) {
|
||||
String retStatusVal = com.tencent.polaris.api.utils.StringUtils.defaultString(values.get(0));
|
||||
if (Objects.equals(retStatusVal, RetStatus.RetFlowControl.getDesc())) {
|
||||
return RetStatus.RetFlowControl;
|
||||
}
|
||||
if (Objects.equals(retStatusVal, RetStatus.RetReject.getDesc())) {
|
||||
return RetStatus.RetReject;
|
||||
}
|
||||
}
|
||||
}
|
||||
return defaultVal;
|
||||
}
|
||||
|
||||
private static String getActiveRuleNameFromRequest(ClientResponse response) {
|
||||
HttpHeaders headers = response.headers().asHttpHeaders();
|
||||
if (headers.containsKey(HeaderConstant.INTERNAL_ACTIVE_RULE_NAME)) {
|
||||
List<String> values = headers.get(HeaderConstant.INTERNAL_ACTIVE_RULE_NAME);
|
||||
if (CollectionUtils.isNotEmpty(values)) {
|
||||
String val = com.tencent.polaris.api.utils.StringUtils.defaultString(values.get(0));
|
||||
return val;
|
||||
}
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
private Long getStartTime(ContextView context) {
|
||||
return context.get(METRICS_WEBCLIENT_START_TIME);
|
||||
}
|
||||
|
||||
private Context putStartTime(Context context) {
|
||||
return context.put(METRICS_WEBCLIENT_START_TIME, System.currentTimeMillis());
|
||||
}
|
||||
}
|
Loading…
Reference in new issue