Skip to content

Commit

Permalink
Revert "Support linking downstream pipelines to upstream pipelines in…
Browse files Browse the repository at this point in the history
… CI Visibility (#405)"

This reverts commit 3e74749.
  • Loading branch information
nikita-tkachenko-datadog committed May 3, 2024
1 parent 4db75a0 commit 452ef86
Show file tree
Hide file tree
Showing 16 changed files with 59 additions and 305 deletions.
1 change: 0 additions & 1 deletion DEVELOPMENT.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ To spin up a development environment for the *jenkins-datadog* plugin repository

1. Set the `JENKINS_PLUGIN` environment variable to point to the directory where this repository is cloned/forked.
1. Set the `JENKINS_PLUGIN_DATADOG_API_KEY` environment variable with your api key.
1. Set the `JENKINS_PLUGIN_DATADOG_CI_INSTANCE_NAME` to a name you would like your instance to have (makes it easier to identify your pipeline executions by setting `@ci.provider.instance:your-instance-name` filter in the Datadog UI).
1. Optionally set the `GITHUB_SSH_KEY` and `GITHUB_SSH_KEY_PASSPHRASE` environment variables with the key and passphrase that can be used to access GitHub. This allows to automatically create GitHub credentials in Jenkins.
1. Run `mvn clean package -DskipTests` and `docker-compose -p datadog-jenkins-plugin -f docker/docker-compose.yaml up` from the directory where this repository is cloned/forked (if the `docker-compose` command fails with a `path ... not found` error, try updating it to the latest version).
- NOTE: This spins up the Jenkins docker image and auto mounts the target folder of this repository (the location where the binary is built).
Expand Down
3 changes: 0 additions & 3 deletions docker/controller-node/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@ USER jenkins
COPY plugin-dependencies.txt /var/jenkins_home/plugin-dependencies.txt
RUN jenkins-plugin-cli --latest-specified --plugin-file /var/jenkins_home/plugin-dependencies.txt

# this is not a dependency of the Datadog plugin, it is just needed to test upstream/downstream pipeline linking
RUN jenkins-plugin-cli --latest-specified --plugins pipeline-build-step

COPY jobs /var/jenkins_home/sample-jobs

COPY 10-create-admin-user.groovy /usr/share/jenkins/ref/init.groovy.d/10-create-admin-user.groovy
Expand Down
12 changes: 0 additions & 12 deletions docker/controller-node/jobs/test-pipeline-downstream.cps

This file was deleted.

13 changes: 0 additions & 13 deletions docker/controller-node/jobs/test-pipeline-upstream.cps

This file was deleted.

2 changes: 0 additions & 2 deletions docker/docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ services:
DATADOG_JENKINS_PLUGIN_TARGET_HOST: datadog # `dogstatsd` or `datadog` based on the container you wish to use
DATADOG_JENKINS_PLUGIN_TARGET_LOG_COLLECTION_PORT: 10518
DATADOG_JENKINS_PLUGIN_TARGET_API_KEY: $JENKINS_PLUGIN_DATADOG_API_KEY
DATADOG_JENKINS_PLUGIN_ENABLE_CI_VISIBILITY: true
DATADOG_JENKINS_PLUGIN_CI_VISIBILITY_CI_INSTANCE_NAME: $JENKINS_PLUGIN_DATADOG_CI_INSTANCE_NAME
volumes:
- jenkins_shared:/var/jenkins_home/shared
- $JENKINS_PLUGIN/target/datadog.hpi:/var/jenkins_home/plugins/datadog.hpi
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,21 +114,10 @@ public void onInitialize(Run run) {
return;
}

TraceSpan.TraceSpanContext buildSpanContext = new TraceSpan.TraceSpanContext();
BuildSpanManager.get().put(buildData.getBuildTag(""), buildSpanContext);

TraceSpan.TraceSpanContext upstreamBuildSpanContext = null;
String upstreamBuildTag = buildData.getUpstreamBuildTag("");
if (upstreamBuildTag != null) {
// try to find upstream build context saved earlier
upstreamBuildSpanContext = BuildSpanManager.get().get(upstreamBuildTag);
if (upstreamBuildSpanContext == null) {
logger.warning("Could not find upstream build span context for tag: " + upstreamBuildTag +
". Try increasing " + BuildSpanManager.DD_JENKINS_SPAN_CONTEXT_STORAGE_MAX_SIZE_ENV + " if this happens regularly.");
}
}
final TraceSpan buildSpan = new TraceSpan("jenkins.build", TimeUnit.MILLISECONDS.toNanos(buildData.getStartTime(0L)));
BuildSpanManager.get().put(buildData.getBuildTag(""), buildSpan);

final BuildSpanAction buildSpanAction = new BuildSpanAction(buildSpanContext, upstreamBuildSpanContext);
final BuildSpanAction buildSpanAction = new BuildSpanAction(buildSpan.context());
run.addAction(buildSpanAction);

run.addAction(new GitCommitAction());
Expand Down Expand Up @@ -415,6 +404,8 @@ public void onFinalized(Run run) {
traceWriter.submitBuild(buildData, run);
logger.fine("End DatadogBuildListener#onFinalized");

BuildSpanManager.get().remove(buildData.getBuildTag(""));

} catch (InterruptedException e) {
Thread.currentThread().interrupt();
DatadogUtilities.severe(logger, e, "Interrupted while processing build finalization");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ of this software and associated documentation files (the "Software"), to deal
import org.datadog.jenkins.plugins.datadog.DatadogUtilities;
import org.datadog.jenkins.plugins.datadog.traces.BuildConfigurationParser;
import org.datadog.jenkins.plugins.datadog.traces.BuildSpanAction;
import org.datadog.jenkins.plugins.datadog.traces.BuildSpanManager;
import org.datadog.jenkins.plugins.datadog.traces.message.TraceSpan;
import org.datadog.jenkins.plugins.datadog.util.TagsUtil;
import org.datadog.jenkins.plugins.datadog.util.git.GitUtils;
Expand All @@ -83,6 +84,7 @@ public class BuildData implements Serializable {
private static final long serialVersionUID = 1L;

private static transient final Logger LOGGER = Logger.getLogger(BuildData.class.getName());

private String buildNumber;
private String buildId;
private String buildUrl;
Expand All @@ -92,8 +94,6 @@ public class BuildData implements Serializable {
private String jobName;
private Map<String, String> buildConfigurations;
private String buildTag;
@Nullable
private String upstreamBuildTag;
private String jenkinsUrl;
private String executorNumber;
private String javaHome;
Expand Down Expand Up @@ -149,13 +149,8 @@ public class BuildData implements Serializable {
* The backend needs version to determine the relative order of these multiple events.
*/
private Integer version;
private Long traceId;
private Long spanId;

@Nullable
private String upstreamPipelineUrl;
@Nullable
private Long upstreamPipelineTraceId;
private String traceId;
private String spanId;

public BuildData(Run<?, ?> run, @Nullable TaskListener listener) throws IOException, InterruptedException {
if (run == null) {
Expand All @@ -173,10 +168,6 @@ public BuildData(Run<?, ?> run, @Nullable TaskListener listener) throws IOExcept
this.buildUrl = buildSpanAction.getBuildUrl();
}
this.version = buildSpanAction.getAndIncrementVersion();

TraceSpan.TraceSpanContext buildSpanContext = buildSpanAction.getBuildSpanContext();
this.traceId = buildSpanContext.getTraceId();
this.spanId = buildSpanContext.getSpanId();
}

// Populate instance using environment variables.
Expand Down Expand Up @@ -273,36 +264,11 @@ public BuildData(Run<?, ?> run, @Nullable TaskListener listener) throws IOExcept
// Build parameters
populateBuildParameters(run);

populateUpstreamPipelineData(run, envVars);
}

private void populateUpstreamPipelineData(Run<?, ?> run, EnvVars envVars) {
CauseAction causeAction = run.getAction(CauseAction.class);
if (causeAction == null) {
return;
}
Cause.UpstreamCause upstreamCause = causeAction.findCause(Cause.UpstreamCause.class);
if (upstreamCause == null) {
return;
}

String upstreamUrl = upstreamCause.getUpstreamUrl();
int upstreamBuild = upstreamCause.getUpstreamBuild();
if (this.jenkinsUrl != null && upstreamUrl != null) {
this.upstreamPipelineUrl = jenkinsUrl + upstreamUrl + upstreamBuild + "/";
}

String upstreamProject = upstreamCause.getUpstreamProject();
if (upstreamProject != null) {
this.upstreamBuildTag = "jenkins-" + upstreamProject.replace('/', '-') + "-" + upstreamBuild;

BuildSpanAction buildSpanAction = run.getAction(BuildSpanAction.class);
if (buildSpanAction != null) {
TraceSpan.TraceSpanContext upstreamSpanContext = buildSpanAction.getUpstreamSpanContext();
if (upstreamSpanContext != null) {
this.upstreamPipelineTraceId = upstreamSpanContext.getTraceId();
}
}
// Set Tracing IDs
final TraceSpan buildSpan = BuildSpanManager.get().get(getBuildTag(""));
if(buildSpan !=null) {
this.traceId = Long.toUnsignedString(buildSpan.context().getTraceId());
this.spanId = Long.toUnsignedString(buildSpan.context().getSpanId());
}
}

Expand Down Expand Up @@ -704,23 +670,10 @@ public Integer getVersion() {
return version;
}

public Long getTraceId() {
return traceId;
}

public Long getSpanId() {
return spanId;
}

public String getBuildTag(String value) {
return defaultIfNull(buildTag, value);
}

@Nullable
public String getUpstreamBuildTag(String value) {
return defaultIfNull(upstreamBuildTag, value);
}

public String getJenkinsUrl(String value) {
return defaultIfNull(jenkinsUrl, value);
}
Expand Down Expand Up @@ -863,16 +816,6 @@ private String getUserEmailByUserId(String userId) {
}
}

@Nullable
public String getUpstreamPipelineUrl() {
return upstreamPipelineUrl;
}

@Nullable
public Long getUpstreamPipelineTraceId() {
return upstreamPipelineTraceId;
}

public JSONObject addLogAttributes(){

JSONObject payload = new JSONObject();
Expand Down Expand Up @@ -940,11 +883,11 @@ public JSONObject addLogAttributes(){
payload.put("hostname", this.hostname);

if(traceId != null){
payload.put("dd.trace_id", Long.toUnsignedString(this.traceId));
payload.put("dd.trace_id", this.traceId);
}

if(spanId != null) {
payload.put("dd.span_id", Long.toUnsignedString(this.spanId));
payload.put("dd.span_id", this.spanId);
}
return payload;
} catch (Exception e){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import com.thoughtworks.xstream.io.HierarchicalStreamWriter;
import java.util.Objects;
import java.util.concurrent.atomic.AtomicInteger;
import javax.annotation.Nullable;
import org.datadog.jenkins.plugins.datadog.model.DatadogPluginAction;
import org.datadog.jenkins.plugins.datadog.traces.message.TraceSpan;
import org.datadog.jenkins.plugins.datadog.util.conversion.DatadogActionConverter;
Expand All @@ -21,19 +20,16 @@ public class BuildSpanAction extends DatadogPluginAction {
private static final long serialVersionUID = 1L;

private final TraceSpan.TraceSpanContext buildSpanContext;
private final TraceSpan.TraceSpanContext upstreamSpanContext;
private final AtomicInteger version;
private volatile String buildUrl;

public BuildSpanAction(final TraceSpan.TraceSpanContext buildSpanContext, @Nullable final TraceSpan.TraceSpanContext upstreamSpanContext) {
this.buildSpanContext = buildSpanContext;
this.upstreamSpanContext = upstreamSpanContext;
this.version = new AtomicInteger(0);
public BuildSpanAction(final TraceSpan.TraceSpanContext buildSpanContext){
this.buildSpanContext = buildSpanContext;
this.version = new AtomicInteger(0);
}

public BuildSpanAction(TraceSpan.TraceSpanContext buildSpanContext, @Nullable TraceSpan.TraceSpanContext upstreamSpanContext, int version, String buildUrl) {
public BuildSpanAction(TraceSpan.TraceSpanContext buildSpanContext, int version, String buildUrl) {
this.buildSpanContext = buildSpanContext;
this.upstreamSpanContext = upstreamSpanContext;
this.version = new AtomicInteger(version);
this.buildUrl = buildUrl;
}
Expand All @@ -42,10 +38,6 @@ public TraceSpan.TraceSpanContext getBuildSpanContext() {
return buildSpanContext;
}

public TraceSpan.TraceSpanContext getUpstreamSpanContext() {
return upstreamSpanContext;
}

public String getBuildUrl() {
return buildUrl;
}
Expand Down Expand Up @@ -82,7 +74,7 @@ public String toString() {

public static final class ConverterImpl extends DatadogActionConverter<BuildSpanAction> {
public ConverterImpl(XStream xs) {
super(new ConverterV1(), new ConverterV2());
super(new ConverterV1());
}
}

Expand Down Expand Up @@ -118,50 +110,7 @@ public BuildSpanAction unmarshal(HierarchicalStreamReader reader, UnmarshallingC
reader.moveUp();
}

return new BuildSpanAction(spanContext, null, version, buildUrl);
}
}

public static final class ConverterV2 extends VersionedConverter<BuildSpanAction> {

private static final int VERSION = 2;

public ConverterV2() {
super(VERSION);
}

@Override
public void marshal(BuildSpanAction action, HierarchicalStreamWriter writer, MarshallingContext context) {
writeField("version", action.version.get(), writer, context);
writeField("spanContext", action.buildSpanContext, writer, context);
if (action.upstreamSpanContext != null) {
writeField("upstreamSpanContext", action.upstreamSpanContext, writer, context);
}
if (action.buildUrl != null) {
writeField("buildUrl", action.buildUrl, writer, context);
}
}

@Override
public BuildSpanAction unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) {
int version = readField(reader, context, int.class);
TraceSpan.TraceSpanContext spanContext = readField(reader, context, TraceSpan.TraceSpanContext.class);

String buildUrl = null;
TraceSpan.TraceSpanContext upstreamSpanContext = null;
while (reader.hasMoreChildren()) {
reader.moveDown();
String fieldName = reader.getNodeName();
if ("buildUrl".equals(fieldName)) {
buildUrl = (String) context.convertAnother(null, String.class);
}
if ("upstreamSpanContext".equals(fieldName)) {
upstreamSpanContext= readField(reader, context, TraceSpan.TraceSpanContext.class);
}
reader.moveUp();
}

return new BuildSpanAction(spanContext, upstreamSpanContext, version, buildUrl);
return new BuildSpanAction(spanContext, version, buildUrl);
}
}
}
Loading

0 comments on commit 452ef86

Please sign in to comment.