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

Support for WildFly version detection #57

Merged
merged 4 commits into from
Dec 10, 2020
Merged
Show file tree
Hide file tree
Changes from 2 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
7 changes: 7 additions & 0 deletions instrumentation/wildfly/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
plugins {
id "java"
}

dependencies {
compileOnly('org.wildfly.core:wildfly-version:13.0.0.Final')
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
/*
* 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.isStatic;
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.jboss.as.version.ProductConfig;

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

public WildFlyAttributesInstrumentationModule() {
super("wildfly");
}

@Override
public ElementMatcher.Junction<ClassLoader> classLoaderMatcher() {
return hasClassesNamed("org.jboss.as.version.ProductConfig");
}

@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.jboss.as.version.ProductConfig");
}

@Override
public Map<? extends ElementMatcher<? super MethodDescription>, String> transformers() {
return Collections.singletonMap(
isMethod().and(isStatic()).and(named("fromFilesystemSlot")),
iNikem marked this conversation as resolved.
Show resolved Hide resolved
WildFlyAttributesInstrumentationModule.class.getName() + "$MiddlewareInitializedAdvice");
}
}

@SuppressWarnings("unused")
public static class MiddlewareInitializedAdvice {
@Advice.OnMethodExit(suppress = Throwable.class)
public static void onExit(@Advice.Return ProductConfig productConfig) {
if (productConfig != null) {
MiddlewareHolder.trySetName(productConfig.resolveName());
MiddlewareHolder.trySetVersion(productConfig.resolveVersion());
}
}
}
}
1 change: 1 addition & 0 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,6 @@ include("agent",
"instrumentation:jetty",
"instrumentation:glassfish",
"instrumentation:tomcat",
"instrumentation:wildfly",
"smoke-tests",
"matrix")
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ protected Map<String, String> getExtraEnv() {
@Override
protected WaitStrategy getWaitStrategy() {
return Wait.forLogMessage(".*app was successfully deployed.*", 1)
.withStartupTimeout(Duration.ofMinutes(15));
.withStartupTimeout(Duration.ofMinutes(5));
}

@ParameterizedTest
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/*
* 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 WildFlySmokeTest extends AppServerTest {

public static final ExpectedServerAttributes WILDFLY_13_SERVER_ATTRIBUTES =
new ExpectedServerAttributes(
"/this-is-definitely-not-there-but-there-should-be-a-trace-nevertheless",
"WildFly Full",
"13.0.0.Final");
public static final ExpectedServerAttributes WILDFLY_17_SERVER_ATTRIBUTES =
new ExpectedServerAttributes(
"/this-is-definitely-not-there-but-there-should-be-a-trace-nevertheless",
"WildFly Full",
"17.0.1.Final");
public static final ExpectedServerAttributes WILDFLY_21_SERVER_ATTRIBUTES =
new ExpectedServerAttributes(
"/this-is-definitely-not-there-but-there-should-be-a-trace-nevertheless",
"WildFly Full",
"21.0.0.Final");

private static Stream<Arguments> supportedConfigurations() {
return Stream.of(
arguments(
"ghcr.io/open-telemetry/java-test-containers:wildfly-13.0.0.Final-jdk8-20201207.405832649",
WILDFLY_13_SERVER_ATTRIBUTES),
arguments(
"ghcr.io/open-telemetry/java-test-containers:wildfly-17.0.1.Final-jdk8-20201207.405832649",
WILDFLY_17_SERVER_ATTRIBUTES),
arguments(
"ghcr.io/open-telemetry/java-test-containers:wildfly-17.0.1.Final-jdk11-20201207.405832649",
WILDFLY_17_SERVER_ATTRIBUTES),
arguments(
"ghcr.io/open-telemetry/java-test-containers:wildfly-21.0.0.Final-jdk8-20201207.405832649",
WILDFLY_21_SERVER_ATTRIBUTES),
arguments(
"ghcr.io/open-telemetry/java-test-containers:wildfly-21.0.0.Final-jdk11-20201207.405832649",
WILDFLY_21_SERVER_ATTRIBUTES));
}

@ParameterizedTest
iNikem marked this conversation as resolved.
Show resolved Hide resolved
@MethodSource("supportedConfigurations")
void wildflySmokeTest(String imageName, ExpectedServerAttributes expectedServerAttributes)
throws IOException, InterruptedException {
startTarget(imageName);

// TODO support 404
// assertServerHandler(expectedServerAttributes);
assertWebAppTrace(expectedServerAttributes);
}
}