Skip to content

Commit

Permalink
Fix the issue where the service name is not checked for null when add…
Browse files Browse the repository at this point in the history
…ing to the request header.

Signed-off-by: hanbingleixue <[email protected]>
  • Loading branch information
hanbingleixue committed Jan 2, 2025
1 parent f0f096d commit 639d931
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import feign.Response;
import io.sermant.core.common.LoggerFactory;
import io.sermant.core.plugin.agent.entity.ExecuteContext;
import io.sermant.core.utils.StringUtils;
import io.sermant.flowcontrol.common.config.ConfigConst;
import io.sermant.flowcontrol.common.entity.FlowControlResult;
import io.sermant.flowcontrol.common.entity.FlowControlServiceMeta;
Expand Down Expand Up @@ -121,9 +122,12 @@ protected final ExecuteContext doBefore(ExecuteContext context) throws Exception

private Request getRequest(ExecuteContext context) {
final Request request = (Request) context.getArguments()[0];
String serviceName = FlowControlServiceMeta.getInstance().getServiceName();
if (StringUtils.isEmpty(serviceName)) {
return request;
}
final HashMap<String, Collection<String>> headers = new HashMap<>(request.headers());
headers.put(ConfigConst.FLOW_REMOTE_SERVICE_NAME_HEADER_KEY,
Collections.singletonList(FlowControlServiceMeta.getInstance().getServiceName()));
headers.put(ConfigConst.FLOW_REMOTE_SERVICE_NAME_HEADER_KEY, Collections.singletonList(serviceName));
final Request newRequest = Request
.create(request.method(), request.url(), headers, request.body(), request.charset());
context.getArguments()[0] = newRequest;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import io.github.resilience4j.retry.Retry;
import io.sermant.core.common.LoggerFactory;
import io.sermant.core.plugin.agent.entity.ExecuteContext;
import io.sermant.core.utils.StringUtils;
import io.sermant.flowcontrol.common.config.ConfigConst;
import io.sermant.flowcontrol.common.entity.FlowControlResult;
import io.sermant.flowcontrol.common.entity.FlowControlServiceMeta;
Expand Down Expand Up @@ -88,8 +89,11 @@ private Optional<HttpRequestEntity> convertToHttpEntity(HttpRequest request) {
protected final ExecuteContext doBefore(ExecuteContext context) {
final FlowControlResult flowControlResult = new FlowControlResult();
final HttpRequest request = (HttpRequest) context.getObject();
request.getHeaders().put(ConfigConst.FLOW_REMOTE_SERVICE_NAME_HEADER_KEY,
Collections.singletonList(FlowControlServiceMeta.getInstance().getServiceName()));
String serviceName = FlowControlServiceMeta.getInstance().getServiceName();
if (!StringUtils.isEmpty(serviceName)) {
request.getHeaders().put(ConfigConst.FLOW_REMOTE_SERVICE_NAME_HEADER_KEY,
Collections.singletonList(serviceName));
}
final Optional<HttpRequestEntity> httpRequestEntity = convertToHttpEntity(request);
if (!httpRequestEntity.isPresent()) {
return context;
Expand Down

0 comments on commit 639d931

Please sign in to comment.