Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
nikita-tkachenko-datadog committed Feb 27, 2024
1 parent e15c169 commit 52fc282
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,10 @@ of this software and associated documentation files (the "Software"), to deal
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.CITags;
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;
import org.jenkinsci.plugins.workflow.cps.EnvActionImpl;
import org.jenkinsci.plugins.workflow.graph.FlowNode;

public class BuildData implements Serializable {

Expand Down Expand Up @@ -128,6 +126,7 @@ public class BuildData implements Serializable {

private String result;
private boolean isCompleted;
private boolean isBuilding;
private String hostname;
private String userId;
private String userEmail;
Expand Down Expand Up @@ -192,10 +191,11 @@ public BuildData(Run<?, ?> run, @Nullable TaskListener listener) throws IOExcept
if (runResult != null) {
this.result = runResult.toString();
this.isCompleted = runResult.completeBuild;
} else if (run.isBuilding()) {
this.result = CITags.STATUS_RUNNING;
} else {
this.result = null;
this.isCompleted = false;
}
this.isBuilding = run.isBuilding();

// Set StartTime, EndTime and Duration
this.startTime = run.getStartTimeInMillis();
Expand All @@ -204,7 +204,7 @@ public BuildData(Run<?, ?> run, @Nullable TaskListener listener) throws IOExcept
durationInMs = System.currentTimeMillis() - startTime;
}
this.duration = durationInMs;
if (duration != 0 && startTime != 0 && !CITags.STATUS_RUNNING.equals(this.result)) {
if (duration != 0 && startTime != 0 && !isBuilding) {
this.endTime = startTime + duration;
}

Expand Down Expand Up @@ -604,6 +604,10 @@ public boolean isCompleted() {
return isCompleted;
}

public boolean isBuilding() {
return isBuilding;
}

public String getHostname(String value) {
return defaultIfNull(hostname, value);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public TraceSpan toSpan(final BuildData buildData, final Run<?,?> run) {
return null;
}

if (CITags.STATUS_RUNNING.equals(buildData.getResult(null))) {
if (buildData.isBuilding()) {
// APM track does not support in-progress pipelines
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public JSONObject toJson(final BuildData buildData, final Run<?,?> run) {
}

final String jenkinsResult = buildData.getResult("");
final String status = statusFromResult(jenkinsResult);
final String status = buildData.isBuilding() ? CITags.STATUS_RUNNING : statusFromResult(jenkinsResult);
final String prefix = PipelineStepData.StepType.PIPELINE.getTagName();
final String rawGitBranch = buildData.getBranch("");
final String gitBranch = normalizeBranch(rawGitBranch);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ private static final class StubTraceWriteStrategy implements TraceWriteStrategy
@Nullable
@Override
public Payload serialize(BuildData buildData, Run<?, ?> run) {
if (!buildData.isCompleted()) {
if (buildData.isBuilding()) {
// ignore in-progress pipeline events for now
return null;
}
Expand Down

0 comments on commit 52fc282

Please sign in to comment.