-
Notifications
You must be signed in to change notification settings - Fork 48
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
Implement automatic Test Visibility instrumentation for .NET projects #400
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package org.datadog.jenkins.plugins.datadog.apm; | ||
|
||
import hudson.FilePath; | ||
import hudson.model.Node; | ||
import hudson.model.TaskListener; | ||
import java.io.File; | ||
import java.util.Collections; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
public class DotnetConfigurator implements TracerConfigurator { | ||
private static final int GET_DOTNET_VERSION_TIMEOUT_MILLIS = 30_000; | ||
private static final int INSTALL_TRACER_TIMEOUT_MILLIS = 300_000; | ||
private static final int SHOW_TRACER_VARS_TIMEOUT_MILLIS = 30_000; | ||
|
||
@Override | ||
public Map<String, String> configure(DatadogTracerJobProperty<?> tracerConfig, Node node, FilePath workspacePath, Map<String, String> envs, TaskListener listener) throws Exception { | ||
String dotnetVersion = workspacePath.act(new ShellCommandCallable(Collections.emptyMap(), GET_DOTNET_VERSION_TIMEOUT_MILLIS, "dotnet", "--version")); | ||
listener.getLogger().println("[datadog] Configuring DD .NET tracer: got .NET version " + dotnetVersion + " from " + workspacePath + " on " + node); | ||
|
||
String installTracerOutput = workspacePath.act(new ShellCommandCallable(Collections.emptyMap(), INSTALL_TRACER_TIMEOUT_MILLIS, "dotnet", "tool", "update", "--tool-path", workspacePath.getRemote(), "dd-trace")); | ||
listener.getLogger().println("[datadog] Configuring DD .NET tracer: tracer installed in " + workspacePath + " on " + node + "; output: " + installTracerOutput); | ||
|
||
String tracerVarOutput = workspacePath.act(new ShellCommandCallable(Collections.emptyMap(), SHOW_TRACER_VARS_TIMEOUT_MILLIS, workspacePath.getRemote() + File.separator + "dd-trace", "ci", "configure", "jenkins")); | ||
|
||
Map<String, String> variables = new HashMap<>(); | ||
for (String line : tracerVarOutput.split("\n")) { | ||
if (!line.contains("=")) { | ||
continue; | ||
} | ||
String[] tokens = line.split("="); | ||
variables.put(tokens[0], tokens.length == 2 ? tokens[1] : ""); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What happens if the variables.get(key) returns empty string. Is this expected from the DotNet configuration perspective? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, some of the variables can (maybe even should) have an empty value, checked this with an actual .NET project |
||
} | ||
return variables; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can
tracerVarOutput
benull
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That'd be an exceptional situation, so a
NullPointerException
would be appropriate (the job itself won't fail anyway, it's just that we'll see the error in the logs)