Skip to content

Commit

Permalink
Merge branch 'master' into sarah/add-event-filters
Browse files Browse the repository at this point in the history
  • Loading branch information
sarah-witt authored Sep 14, 2023
2 parents e09eedc + 788cd11 commit bad5a60
Show file tree
Hide file tree
Showing 11 changed files with 389 additions and 341 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@ of this software and associated documentation files (the "Software"), to deal
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.net.Inet4Address;
import java.net.MalformedURLException;
import java.net.URL;
Expand All @@ -51,25 +49,28 @@ of this software and associated documentation files (the "Software"), to deal
import java.util.Arrays;
import java.util.Collections;
import java.util.Date;
import java.util.function.Function;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.TimeZone;
import java.util.function.Function;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import jenkins.model.Jenkins;
import org.apache.commons.lang.StringEscapeUtils;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang.exception.ExceptionUtils;
import org.datadog.jenkins.plugins.datadog.audit.DatadogAudit;
import org.datadog.jenkins.plugins.datadog.clients.HttpClient;
import org.datadog.jenkins.plugins.datadog.model.BuildPipelineNode;
import org.datadog.jenkins.plugins.datadog.model.CIGlobalTagsAction;
import org.datadog.jenkins.plugins.datadog.model.GitCommitAction;
import org.datadog.jenkins.plugins.datadog.model.GitRepositoryAction;
Expand All @@ -93,6 +94,7 @@ of this software and associated documentation files (the "Software"), to deal
import org.jenkinsci.plugins.workflow.actions.StageAction;
import org.jenkinsci.plugins.workflow.actions.ThreadNameAction;
import org.jenkinsci.plugins.workflow.actions.WarningAction;
import org.jenkinsci.plugins.workflow.cps.nodes.StepAtomNode;
import org.jenkinsci.plugins.workflow.flow.FlowExecution;
import org.jenkinsci.plugins.workflow.graph.BlockEndNode;
import org.jenkinsci.plugins.workflow.graph.BlockStartNode;
Expand Down Expand Up @@ -1064,4 +1066,18 @@ private static List<String> createIncludeLists() {

return includedEvents;
}
}
* Check if flowNode is the last node of the pipeline.
* @param flowNode
* @return true if flowNode is the last node of the pipeline
*/
public static boolean isLastNode(FlowNode flowNode) {
return flowNode instanceof FlowEndNode;
}

public static Long getNanosInQueue(BuildPipelineNode current) {
// If the concrete queue time for this node is not set
// we look for the queue time propagated by its children.
return Math.max(Math.max(current.getNanosInQueue(), current.getPropagatedNanosInQueue()), 0);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ of this software and associated documentation files (the "Software"), to deal
import org.datadog.jenkins.plugins.datadog.events.BuildStartedEventImpl;
import org.datadog.jenkins.plugins.datadog.model.BuildData;
import org.datadog.jenkins.plugins.datadog.traces.BuildSpanAction;

import org.datadog.jenkins.plugins.datadog.traces.BuildSpanManager;
import org.datadog.jenkins.plugins.datadog.traces.StepDataAction;
import org.datadog.jenkins.plugins.datadog.traces.message.TraceSpan;
import org.jenkinsci.plugins.workflow.job.WorkflowRun;

Expand Down Expand Up @@ -104,6 +107,21 @@ public void onInitialize(Run run) {
return;
}

final TraceSpan buildSpan = new TraceSpan("jenkins.build", TimeUnit.MILLISECONDS.toNanos(buildData.getStartTime(0L)));
BuildSpanManager.get().put(buildData.getBuildTag(""), buildSpan);

// The buildData object is stored in the BuildSpanAction to be updated
// by the information that will be calculated when the pipeline listeners
// were executed. This is needed because if the user build is based on
// Jenkins Pipelines, there are many information that is missing when the
// root span is created, such as Git info (this is calculated in an inner step
// of the pipeline)
final BuildSpanAction buildSpanAction = new BuildSpanAction(buildData, buildSpan.context());
run.addAction(buildSpanAction);

final StepDataAction stepDataAction = new StepDataAction();
run.addAction(stepDataAction);

// Traces
client.startBuildTrace(buildData, run);
logger.fine("End DatadogBuildListener#onInitialize");
Expand Down Expand Up @@ -365,6 +383,9 @@ public void onFinalized(Run run) {
// APM Traces
client.finishBuildTrace(buildData, run);
logger.fine("End DatadogBuildListener#onFinalized");

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

} catch (Exception e) {
DatadogUtilities.severe(logger, e, "Failed to process build finalization");
} finally {
Expand Down
Loading

0 comments on commit bad5a60

Please sign in to comment.