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

TracingHttpServiceFilter should implement requiredOffloads() #2260

Merged
merged 1 commit into from
Jul 5, 2022
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 @@ -124,7 +124,6 @@ public Single<StreamingHttpResponse> request(final StreamingHttpRequest request)

@Override
public HttpExecutionStrategy requiredOffloads() {
// No influence since we do not block.
return HttpExecutionStrategies.offloadNone();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import io.servicetalk.concurrent.api.Publisher;
import io.servicetalk.concurrent.api.Single;
import io.servicetalk.http.api.HttpExecutionStrategy;
import io.servicetalk.http.api.HttpHeaders;
import io.servicetalk.http.api.HttpRequestMetaData;
import io.servicetalk.http.api.HttpResponseMetaData;
Expand All @@ -42,6 +43,7 @@
import static io.opentracing.tag.Tags.HTTP_URL;
import static io.opentracing.tag.Tags.SPAN_KIND;
import static io.opentracing.tag.Tags.SPAN_KIND_SERVER;
import static io.servicetalk.http.api.HttpExecutionStrategies.offloadNone;

/**
* A {@link StreamingHttpService} that supports open tracing.
Expand Down Expand Up @@ -106,6 +108,11 @@ public Single<StreamingHttpResponse> handle(final HttpServiceContext ctx,
};
}

@Override
public HttpExecutionStrategy requiredOffloads() {
return offloadNone();
}

private Single<StreamingHttpResponse> trackRequest(final StreamingHttpService delegate,
final HttpServiceContext ctx,
final StreamingHttpRequest request,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/*
* Copyright © 2022 Apple Inc. and the ServiceTalk project authors
*
* 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.servicetalk.opentracing.http;

import io.servicetalk.opentracing.inmemory.DefaultInMemoryTracer;

import io.opentracing.Tracer;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;

import javax.annotation.Nullable;

import static io.servicetalk.http.api.HttpExecutionStrategies.offloadNone;
import static io.servicetalk.opentracing.asynccontext.AsyncContextInMemoryScopeManager.SCOPE_MANAGER;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;

class ExecutionStrategyTest {

@Nullable
private static Tracer tracer;

@BeforeAll
static void setUp() {
tracer = new DefaultInMemoryTracer.Builder(SCOPE_MANAGER).build();
}

@AfterAll
static void tearDown() {
if (tracer != null) {
tracer.close();
}
}

@Test
void serviceFilter() {
assert tracer != null;
assertThat(new TracingHttpServiceFilter(tracer, "test").requiredOffloads(), is(offloadNone()));
}

@Test
void requesterFilter() {
assert tracer != null;
assertThat(new TracingHttpRequesterFilter(tracer, "test").requiredOffloads(), is(offloadNone()));
}
}