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

Java Phase 1, Tomcat support and test. #50

Merged
merged 4 commits into from
Dec 2, 2020
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
2 changes: 1 addition & 1 deletion custom/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ plugins {
val versions: Map<String, String> by extra

dependencies {
implementation(project(":bootstrap"))
compileOnly(project(":bootstrap"))
implementation("io.opentelemetry:opentelemetry-sdk:${versions["opentelemetry"]}")
implementation("io.opentelemetry:opentelemetry-exporter-jaeger-thrift:${versions["opentelemetry"]}")
implementation("io.opentelemetry.javaagent:opentelemetry-javaagent-spi:${versions["opentelemetryJavaagent"]}")
Expand Down
2 changes: 1 addition & 1 deletion instrumentation/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ subprojects {
annotationProcessor("com.google.auto:auto-common:0.8")
implementation("com.google.auto.service:auto-service:1.0-rc3")
implementation("com.google.auto:auto-common:0.8")
implementation(project(":bootstrap"))
compileOnly(project(":bootstrap"))
}

compileJava {
Expand Down
7 changes: 7 additions & 0 deletions instrumentation/tomcat/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
plugins {
id "java"
}

dependencies {
compileOnly('org.apache.tomcat:tomcat-catalina:9.0.40')
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
/*
* Copyright Splunk Inc.
*
* 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 com.splunk.opentelemetry.middleware;

import static io.opentelemetry.javaagent.tooling.ClassLoaderMatcher.hasClassesNamed;
import static net.bytebuddy.matcher.ElementMatchers.isMethod;
import static net.bytebuddy.matcher.ElementMatchers.isPublic;
import static net.bytebuddy.matcher.ElementMatchers.named;

import com.google.auto.service.AutoService;
import com.splunk.opentelemetry.javaagent.bootstrap.MiddlewareHolder;
import io.opentelemetry.javaagent.tooling.InstrumentationModule;
import io.opentelemetry.javaagent.tooling.TypeInstrumentation;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import net.bytebuddy.asm.Advice;
import net.bytebuddy.description.method.MethodDescription;
import net.bytebuddy.description.type.TypeDescription;
import net.bytebuddy.matcher.ElementMatcher;
import org.apache.catalina.util.ServerInfo;

@AutoService(InstrumentationModule.class)
public class TomcatAttributesInstrumentationModule extends InstrumentationModule {

public TomcatAttributesInstrumentationModule() {
super("tomcat");
}

@Override
public ElementMatcher.Junction<ClassLoader> classLoaderMatcher() {
return hasClassesNamed(
"org.apache.catalina.startup.Catalina", "org.apache.catalina.util.ServerInfo");
}

@Override
public List<TypeInstrumentation> typeInstrumentations() {
return Collections.singletonList(new Instrumentation());
}

public static class Instrumentation implements TypeInstrumentation {

@Override
public ElementMatcher<? super TypeDescription> typeMatcher() {
return named("org.apache.catalina.startup.Catalina");
}

@Override
public Map<? extends ElementMatcher<? super MethodDescription>, String> transformers() {
return Collections.singletonMap(
isMethod().and(isPublic()).and(named("start")),
TomcatAttributesInstrumentationModule.class.getName() + "$MiddlewareInitializedAdvice");
}
}

@SuppressWarnings("unused")
public static class MiddlewareInitializedAdvice {
@Advice.OnMethodEnter(suppress = Throwable.class)
public static void onEnter() {
MiddlewareHolder.trySetVersion(ServerInfo.getServerNumber());
MiddlewareHolder.trySetName("tomcat");
}
}
}
8 changes: 4 additions & 4 deletions matrix/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,14 @@ val buildTestImagesTask = tasks.create("buildTestImages") {
val targets = mapOf(
"jetty" to mapOf(
"9.4" to listOf("8", "11", "15"),
"10.0.0.beta3" to listOf("11", "15"),
"11.0.0.beta3" to listOf("11", "15")
"10.0.0.beta3" to listOf("11", "15")
// "11.0.0.beta3" to listOf("11", "15") TODO - enable when out of beta
),
"tomcat" to mapOf(
"7" to listOf("8"),
"8" to listOf("8", "11"),
"9" to listOf("8", "11"),
"10" to listOf("8", "11")
"9" to listOf("8", "11")
// "10" to listOf("8", "11") TODO - enable when out of beta
),
"payara" to mapOf(
"5.2020.6" to listOf("8"),
Expand Down
1 change: 1 addition & 0 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,6 @@ include("agent",
"custom",
"instrumentation",
"instrumentation:jetty",
"instrumentation:tomcat",
"smoke-tests",
"matrix")
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ private static Stream<Arguments> supportedConfigurations() {
arguments("splunk-jetty:10.0.0.beta3-jdk15", JETTY10_SERVER_ATTRIBUTES));
}

@ParameterizedTest
@ParameterizedTest(name = "[{index}] {0}")
@MethodSource("supportedConfigurations")
void jettySmokeTest(String imageName, ExpectedServerAttributes expectedServerAttributes)
throws IOException, InterruptedException {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/*
* Copyright Splunk Inc.
*
* 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 com.splunk.opentelemetry;

import static org.junit.jupiter.params.provider.Arguments.arguments;

import java.io.IOException;
import java.util.stream.Stream;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;

public class TomcatSmokeTest extends AppServerTest {

public static final ExpectedServerAttributes TOMCAT7_SERVER_ATTRIBUTES =
new TomcatAttributes("7.0.107.0");
vovencij marked this conversation as resolved.
Show resolved Hide resolved
public static final ExpectedServerAttributes TOMCAT8_SERVER_ATTRIBUTES =
new TomcatAttributes("8.5.60.0");
public static final ExpectedServerAttributes TOMCAT9_SERVER_ATTRIBUTES =
new TomcatAttributes("9.0.40.0");

private static Stream<Arguments> supportedConfigurations() {
return Stream.of(
arguments("splunk-tomcat:7-jdk8", TOMCAT7_SERVER_ATTRIBUTES),
arguments("splunk-tomcat:8-jdk8", TOMCAT8_SERVER_ATTRIBUTES),
arguments("splunk-tomcat:8-jdk11", TOMCAT8_SERVER_ATTRIBUTES),
arguments("splunk-tomcat:9-jdk8", TOMCAT9_SERVER_ATTRIBUTES),
arguments("splunk-tomcat:9-jdk11", TOMCAT9_SERVER_ATTRIBUTES));
}

@ParameterizedTest(name = "[{index}] {0}")
@MethodSource("supportedConfigurations")
void jettySmokeTest(String imageName, ExpectedServerAttributes expectedServerAttributes)
throws IOException, InterruptedException {
startTarget(imageName);

assertServerHandler(expectedServerAttributes);
assertWebAppTrace(expectedServerAttributes);
}

public static class TomcatAttributes extends ExpectedServerAttributes {
public TomcatAttributes(String version) {
super(
"/this-is-definitely-not-there-but-there-should-be-a-trace-nevertheless",
"tomcat",
version);
}
}
}