Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix the issue where the service name is not checked for null when adding to the request header. #1728

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading