Skip to content

Commit

Permalink
Merge branch 'master' into smola/dd-static-rules-refine
Browse files Browse the repository at this point in the history
  • Loading branch information
smola authored Jul 12, 2024
2 parents 4a51397 + 0e5e274 commit 9a0bc53
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,11 @@ public void publish() {
datadogProfiler.recordSetting(JFR_IMPLEMENTATION_KEY, "ddprof");
datadogProfiler.recordSetting(STACK_DEPTH_KEY, String.valueOf(stackDepth));
datadogProfiler.recordSetting(SELINUX_STATUS_KEY, seLinuxStatus);
if (serviceInstrumentationType != null) {
datadogProfiler.recordSetting(SERVICE_INSTRUMENTATION_TYPE, serviceInstrumentationType);
}
if (serviceInjection != null) {
datadogProfiler.recordSetting(SERVICE_INJECTION, serviceInjection);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,12 @@ public void publish() {
if (ddprofUnavailableReason != null) {
new ProfilerSettingEvent(DDPROF_UNAVAILABLE_REASON_KEY, ddprofUnavailableReason).commit();
}
if (serviceInstrumentationType != null) {
new ProfilerSettingEvent(SERVICE_INSTRUMENTATION_TYPE, serviceInstrumentationType).commit();
}
if (serviceInjection != null) {
new ProfilerSettingEvent(SERVICE_INJECTION, serviceInjection).commit();
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ public abstract class ProfilerSettingsSupport {
protected static final String NATIVE_STACKS_KEY = "Native Stacks";
protected static final String STACK_DEPTH_KEY = "Stack Depth";
protected static final String SELINUX_STATUS_KEY = "SELinux Status";
protected static final String SERVICE_INSTRUMENTATION_TYPE = "Service Instrumentation Type";
protected static final String SERVICE_INJECTION = "Service Injection";

protected static final String DDPROF_UNAVAILABLE_REASON_KEY = "DDProf Unavailable Reason";

Expand All @@ -50,6 +52,8 @@ public abstract class ProfilerSettingsSupport {
protected final String perfEventsParanoid;
protected final boolean hasNativeStacks;
protected final String seLinuxStatus;
protected final String serviceInstrumentationType;
protected final String serviceInjection;

protected final String ddprofUnavailableReason;

Expand Down Expand Up @@ -122,6 +126,13 @@ protected ProfilerSettingsSupport(
seLinuxStatus = getSELinuxStatus();
this.ddprofUnavailableReason = ddprofUnavailableReason;
this.hasJfrStackDepthApplied = hasJfrStackDepthApplied;

serviceInjection =
configProvider.getString(
"injection.enabled"); // usually set via DD_INJECTION_ENABLED env var
serviceInstrumentationType =
// usually set via DD_INSTRUMENTATION_INSTALL_TYPE env var
configProvider.getString("instrumentation.install.type");
}

private String getSELinuxStatus() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
package datadog.trace.instrumentation.gradle;

import org.gradle.initialization.ClassLoaderRegistry;
import org.gradle.internal.service.ServiceRegistration;
import org.gradle.internal.service.ServiceRegistry;
import org.gradle.internal.service.scopes.BuildScopeServices;

public class CiVisibilityGradleListenerProvider {
private final ClassLoaderRegistry classLoaderRegistry;
public class CiVisibilityGradleListenerInjector {

public CiVisibilityGradleListenerProvider(ClassLoaderRegistry classLoaderRegistry) {
this.classLoaderRegistry = classLoaderRegistry;
}

public void configure(ServiceRegistration serviceRegistration) {
Class<?> ciVisibilityGradleListener = loadCiVisibilityGradleListener();
serviceRegistration.add(ciVisibilityGradleListener);
public static void inject(ServiceRegistry parentServices, BuildScopeServices buildScopeServices) {
ClassLoaderRegistry classLoaderRegistry = parentServices.get(ClassLoaderRegistry.class);
Class<?> ciVisibilityGradleListener = loadCiVisibilityGradleListener(classLoaderRegistry);
buildScopeServices.register(
serviceRegistration -> serviceRegistration.add(ciVisibilityGradleListener));
}

/**
Expand All @@ -24,7 +22,7 @@ public void configure(ServiceRegistration serviceRegistration) {
* org.gradle.api.tasks.testing.Test} task), which is a plugin. Therefore, we cannot reference its
* {@code Class} instance directly, and instead have to load it explicitly.
*/
private Class<?> loadCiVisibilityGradleListener() {
private static Class<?> loadCiVisibilityGradleListener(ClassLoaderRegistry classLoaderRegistry) {
try {
return classLoaderRegistry
.getPluginsClassLoader()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import java.util.Set;
import net.bytebuddy.asm.Advice;
import net.bytebuddy.matcher.ElementMatcher;
import org.gradle.initialization.ClassLoaderRegistry;
import org.gradle.internal.service.ServiceRegistry;
import org.gradle.internal.service.scopes.BuildScopeServices;

Expand All @@ -36,7 +35,7 @@ public String instrumentedType() {
@Override
public String[] helperClassNames() {
return new String[] {
packageName + ".CiVisibilityGradleListenerProvider",
packageName + ".CiVisibilityGradleListenerInjector",
};
}

Expand All @@ -55,9 +54,8 @@ public static class Construct {
@Advice.OnMethodExit(suppress = Throwable.class)
public static void afterConstructor(
@Advice.This final BuildScopeServices buildScopeServices,
@Advice.Argument(0) final ServiceRegistry parent) {
ClassLoaderRegistry classLoaderRegistry = parent.get(ClassLoaderRegistry.class);
buildScopeServices.addProvider(new CiVisibilityGradleListenerProvider(classLoaderRegistry));
@Advice.Argument(0) final ServiceRegistry parentServices) {
CiVisibilityGradleListenerInjector.inject(parentServices, buildScopeServices);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1122,9 +1122,11 @@ private static String getSparkServiceName(SparkConf conf, boolean isRunningOnDat
return null;
}

// Keep service set by user, except if it is only "spark" that can be set by USM
// Keep service set by user, except if it is only "spark" or "hadoop" that can be set by USM
String serviceName = Config.get().getServiceName();
if (Config.get().isServiceNameSetByUser() && !"spark".equals(serviceName)) {
if (Config.get().isServiceNameSetByUser()
&& !"spark".equals(serviceName)
&& !"hadoop".equals(serviceName)) {
log.debug("Service '{}' explicitly set by user, not using the application name", serviceName);
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -686,6 +686,7 @@ abstract class AbstractSparkTest extends AgentTestRunner {
ddService | sparkAppNameAsService | appName | isRunningOnDatabricks | expectedService
"foobar" | true | "some_app" | false | "(?!.*some_app).*"
"spark" | true | "some_app" | false | "some_app"
"hadoop" | true | "some_app" | false | "some_app"
null | true | "some_app" | true | "(?!.*some_app).*"
null | true | "some_app" | false | "some_app"
null | false | "some_app" | false | "(?!.*some_app).*"
Expand Down

0 comments on commit 9a0bc53

Please sign in to comment.