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

Implements parsing of http route and uses it by default for span name #602

Merged
merged 1 commit into from
Feb 22, 2018
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
@@ -0,0 +1,139 @@
package brave.jersey.server;

import java.net.URI;
import java.util.List;
import java.util.regex.MatchResult;
import javax.ws.rs.core.MultivaluedMap;
import javax.ws.rs.core.PathSegment;
import javax.ws.rs.core.UriBuilder;
import org.glassfish.jersey.server.ExtendedUriInfo;
import org.glassfish.jersey.server.model.Resource;
import org.glassfish.jersey.server.model.ResourceMethod;
import org.glassfish.jersey.server.model.RuntimeResource;
import org.glassfish.jersey.uri.UriTemplate;

class FakeExtendedUriInfo implements ExtendedUriInfo {
final URI baseURI;
final List<UriTemplate> matchedTemplates;

FakeExtendedUriInfo(URI baseURI, List<UriTemplate> matchedTemplates) {
this.baseURI = baseURI;
this.matchedTemplates = matchedTemplates;
}

@Override public Throwable getMappedThrowable() {
return null;
}

@Override public List<MatchResult> getMatchedResults() {
return null;
}

@Override public List<UriTemplate> getMatchedTemplates() {
return matchedTemplates;
}

@Override public List<PathSegment> getPathSegments(String name) {
return null;
}

@Override public List<PathSegment> getPathSegments(String name, boolean decode) {
return null;
}

@Override public List<RuntimeResource> getMatchedRuntimeResources() {
return null;
}

@Override public ResourceMethod getMatchedResourceMethod() {
return null;
}

@Override public Resource getMatchedModelResource() {
return null;
}

@Override public List<ResourceMethod> getMatchedResourceLocators() {
return null;
}

@Override public List<Resource> getLocatorSubResources() {
return null;
}

@Override public String getPath() {
return null;
}

@Override public String getPath(boolean decode) {
return null;
}

@Override public List<PathSegment> getPathSegments() {
return null;
}

@Override public List<PathSegment> getPathSegments(boolean decode) {
return null;
}

@Override public URI getRequestUri() {
return null;
}

@Override public UriBuilder getRequestUriBuilder() {
return null;
}

@Override public URI getAbsolutePath() {
return null;
}

@Override public UriBuilder getAbsolutePathBuilder() {
return null;
}

@Override public URI getBaseUri() {
return baseURI;
}

@Override public UriBuilder getBaseUriBuilder() {
return null;
}

@Override public MultivaluedMap<String, String> getPathParameters() {
return null;
}

@Override public MultivaluedMap<String, String> getPathParameters(boolean decode) {
return null;
}

@Override public MultivaluedMap<String, String> getQueryParameters() {
return null;
}

@Override public MultivaluedMap<String, String> getQueryParameters(boolean decode) {
return null;
}

@Override public List<String> getMatchedURIs() {
return null;
}

@Override public List<String> getMatchedURIs(boolean decode) {
return null;
}

@Override public List<Object> getMatchedResources() {
return null;
}

@Override public URI resolve(URI uri) {
return null;
}

@Override public URI relativize(URI uri) {
return null;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
/**
* Copyright 2015-2016 The OpenZipkin 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 brave.jersey.server;

import java.net.URI;
import java.util.Arrays;
import java.util.concurrent.TimeUnit;
import org.glassfish.jersey.internal.MapPropertiesDelegate;
import org.glassfish.jersey.server.ContainerRequest;
import org.glassfish.jersey.server.ContainerResponse;
import org.glassfish.jersey.server.ExtendedUriInfo;
import org.glassfish.jersey.uri.PathTemplate;
import org.jboss.resteasy.core.ServerResponse;
import org.openjdk.jmh.annotations.Benchmark;
import org.openjdk.jmh.annotations.BenchmarkMode;
import org.openjdk.jmh.annotations.Fork;
import org.openjdk.jmh.annotations.Measurement;
import org.openjdk.jmh.annotations.Mode;
import org.openjdk.jmh.annotations.OutputTimeUnit;
import org.openjdk.jmh.annotations.Scope;
import org.openjdk.jmh.annotations.State;
import org.openjdk.jmh.annotations.Warmup;
import org.openjdk.jmh.runner.Runner;
import org.openjdk.jmh.runner.RunnerException;
import org.openjdk.jmh.runner.options.Options;
import org.openjdk.jmh.runner.options.OptionsBuilder;

@Measurement(iterations = 5, time = 1)
@Warmup(iterations = 10, time = 1)
@Fork(3)
@BenchmarkMode(Mode.Throughput)
@OutputTimeUnit(TimeUnit.MICROSECONDS)
@State(Scope.Thread)
public class TracingApplicationEventListenerAdapterBenchmarks {
FakeExtendedUriInfo uriInfo = new FakeExtendedUriInfo(URI.create("/"),
Arrays.asList(
new PathTemplate("/"),
new PathTemplate("/items/{itemId}")
)
);
ContainerResponse response = new ContainerResponse(
new ContainerRequest(
URI.create("/"), null, null, null, new MapPropertiesDelegate()
) {
@Override public ExtendedUriInfo getUriInfo() {
return uriInfo;
}
}, new ServerResponse());

FakeExtendedUriInfo nestedUriInfo = new FakeExtendedUriInfo(URI.create("/"),
Arrays.asList(
new PathTemplate("/"),
new PathTemplate("/items/{itemId}"),
new PathTemplate("/"),
new PathTemplate("/nested")
)
);
ContainerResponse nestedResponse = new ContainerResponse(
new ContainerRequest(
URI.create("/"), null, null, null, new MapPropertiesDelegate()
) {
@Override public ExtendedUriInfo getUriInfo() {
return nestedUriInfo;
}
}, new ServerResponse());

TracingApplicationEventListener.Adapter adapter = new TracingApplicationEventListener.Adapter();

@Benchmark public String parseRoute() {
return adapter.route(response);
}

@Benchmark public String parseRoute_nested() {
return adapter.route(nestedResponse);
}

// Convenience main entry-point
public static void main(String[] args) throws RunnerException {
Options opt = new OptionsBuilder()
.include(".*" + TracingApplicationEventListenerAdapterBenchmarks.class.getSimpleName())
.build();

new Runner(opt).run();
}
}
Loading