Skip to content

Commit

Permalink
Resolve conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
drodriguezhdez committed Jun 14, 2021
2 parents bcc573d + 6edc1fc commit e850c94
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,11 @@ private void completeInformation(final List<BuildPipelineNode> nodes, final Buil
}
}

// Propagate error to all parent stages
if(node.isError() && !parent.isError()) {
propagateErrorToAllParents(node);
}

// Notice we cannot propagate the worker node info
// to the root span at this point, because this method is executed
// after the root span is sent. To propagate worker node info
Expand All @@ -147,6 +152,14 @@ private void completeInformation(final List<BuildPipelineNode> nodes, final Buil
}
}

private void propagateErrorToAllParents(BuildPipelineNode node) {
for(BuildPipelineNode parent : node.getParents()) {
propagateErrorToAllParents(parent);
}
node.setError(true);
node.setPropagatedResult("error");
}

private BuildPipelineNode searchExecutableChildNode(BuildPipelineNode node) {
if(!node.isInternal() && BuildPipelineNode.NodeType.STEP.equals(node.getType())){
return node;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ public String getBuildLevel() {
private long nanosInQueue = -1L;
private long propagatedNanosInQueue = -1L;
private String result;
private String propagatedResult;

// Flag that indicates if the node must be marked as error.
private boolean error;
Expand Down Expand Up @@ -306,6 +307,14 @@ public String getResult() {
return result;
}

public String getPropagatedResult() {
return this.propagatedResult;
}

public void setPropagatedResult(final String propagatedResult) {
this.propagatedResult = propagatedResult;
}

public Throwable getErrorObj() {
return errorObj;
}
Expand All @@ -314,6 +323,10 @@ public boolean isError() {
return error;
}

public void setError(boolean error) {
this.error = error;
}

public List<BuildPipelineNode> getParents(){ return parents; }

public List<BuildPipelineNode> getChildren() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ private Map<String, Object> buildTraceTags(final Run run, final BuildPipelineNod
tags.put(CITags.CI_PROVIDER_NAME, CI_PROVIDER);
tags.put(prefix + CITags._NAME, current.getName());
tags.put(prefix + CITags._NUMBER, current.getId());
final String status = getNormalizedResultForTraces(current.getResult());
final String status = getNormalizedResultForTraces(getResult(current));
tags.put(prefix + CITags._RESULT, status);
tags.put(CITags.STATUS, status);

Expand Down Expand Up @@ -388,27 +388,28 @@ private Map<String, Object> buildTraceTags(final Run run, final BuildPipelineNod
return tags;
}


@SuppressFBWarnings("NP_NULL_ON_SOME_PATH_FROM_RETURN_VALUE")
private Set<String> getNodeLabels(Run run, BuildPipelineNode current, String nodeName) {
final PipelineNodeInfoAction pipelineNodeInfoAction = run.getAction(PipelineNodeInfoAction.class);
if(current.getPropagatedNodeLabels() != null && !current.getPropagatedNodeLabels().isEmpty()) {
if (current.getPropagatedNodeLabels() != null && !current.getPropagatedNodeLabels().isEmpty()) {
return current.getPropagatedNodeLabels();
} else if(current.getNodeLabels() != null && !current.getNodeLabels().isEmpty()) {
} else if (current.getNodeLabels() != null && !current.getNodeLabels().isEmpty()) {
return current.getNodeLabels();
} else if(pipelineNodeInfoAction != null && !pipelineNodeInfoAction.getNodeLabels().isEmpty()) {
} else if (pipelineNodeInfoAction != null && !pipelineNodeInfoAction.getNodeLabels().isEmpty()) {
return pipelineNodeInfoAction.getNodeLabels();
}

if(run.getExecutor() != null && run.getExecutor().getOwner() != null) {
if (run.getExecutor() != null && run.getExecutor().getOwner() != null) {
Set<String> nodeLabels = DatadogUtilities.getNodeLabels(run.getExecutor().getOwner());
if(nodeLabels != null && !nodeLabels.isEmpty()) {
if (nodeLabels != null && !nodeLabels.isEmpty()) {
return nodeLabels;
}
}

// If there is no labels and the node name is master,
// we force the label "master".
if("master".equalsIgnoreCase(nodeName)){
if ("master".equalsIgnoreCase(nodeName)) {
final Set<String> masterLabels = new HashSet<>();
masterLabels.add("master");
return masterLabels;
Expand All @@ -417,6 +418,10 @@ private Set<String> getNodeLabels(Run run, BuildPipelineNode current, String nod
return Collections.emptySet();
}

private String getResult(BuildPipelineNode current) {
return (current.getPropagatedResult() != null) ? current.getPropagatedResult() : current.getResult();
}

private String getNodeName(Run<?, ?> run, BuildPipelineNode current, BuildData buildData) {
final PipelineNodeInfoAction pipelineNodeInfoAction = run.getAction(PipelineNodeInfoAction.class);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -787,6 +787,39 @@ public void testGlobalTagsPropagationsTraces() throws Exception {
assertEquals("pipeline_tag", stepSpan.getTag("pipeline_tag_v2"));
}

@Test
public void testErrorPropagationOnStages() throws Exception {
WorkflowJob job = jenkinsRule.jenkins.createProject(WorkflowJob.class, "pipelineIntegration-errorPropagationStages");
String definition = IOUtils.toString(
this.getClass().getResourceAsStream("testPipelineErrorOnStages.txt"),
"UTF-8"
);
job.setDefinition(new CpsFlowDefinition(definition, true));
job.scheduleBuild2(0).get();

//Traces
final ListWriter tracerWriter = clientStub.tracerWriter();
tracerWriter.waitForTraces(2);
assertEquals(2, tracerWriter.size());

final List<DDSpan> buildTrace = tracerWriter.get(0);
assertEquals(1, buildTrace.size());
final DDSpan buildSpan = buildTrace.get(0);
assertEquals("error", buildSpan.getTag(CITags.STATUS));

final List<DDSpan> pipelineTrace = tracerWriter.get(1);
assertEquals(3, pipelineTrace.size());

final DDSpan stageSpan = pipelineTrace.get(0);
assertEquals("error", stageSpan.getTag(CITags.STATUS));

final DDSpan stepSpan = pipelineTrace.get(1);
assertEquals("error", stepSpan.getTag(CITags.STATUS));

final DDSpan step2Span = pipelineTrace.get(2);
assertEquals("error", step2Span.getTag(CITags.STATUS));
}

private void assertNodeNameParallelBlock(DDSpan stageSpan, DumbSlave worker01, DumbSlave worker02) {
switch ((String)stageSpan.getResourceName()){
case "Prepare01":
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
pipeline {
agent none
stages {
stage('test'){
steps {
sh "this-does-not-exist"
}
}
}
}

0 comments on commit e850c94

Please sign in to comment.