Class DatadogUtilities
- java.lang.Object
-
- org.datadog.jenkins.plugins.datadog.DatadogUtilities
-
public class DatadogUtilities extends Object
-
-
Constructor Summary
Constructors Constructor Description DatadogUtilities()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static void
cleanUpTraceActions(Actionable actionable)
Removes all actions related to traces for Jenkins pipelines.static Map<String,Set<String>>
computeTagListFromVarList(EnvVars envVars, String varList)
static List<String>
cstrToList(String str)
Converts a Comma Separated List into a List Objectstatic long
currentTimeMillis()
static double
envVar(String name, double defaultValue)
static int
envVar(String name, int defaultValue)
static String
getAwsInstanceID()
static Map<String,Set<String>>
getBuildTags(Run run, EnvVars envVars)
Builds extraTags if any are configured in the Job.static String
getCatchErrorResult(org.jenkinsci.plugins.workflow.graph.BlockStartNode startNode)
static Map<String,Set<String>>
getComputerTags(Computer computer)
static DatadogGlobalConfiguration
getDatadogGlobalDescriptor()
static DatadogJobProperty
getDatadogJobProperties(Run r)
static String
getDatadogPluginVersion()
static org.jenkinsci.plugins.workflow.graph.BlockStartNode
getEnclosingStageNode(org.jenkinsci.plugins.workflow.graph.FlowNode node)
Returns enclosing stage node for the given node.static Throwable
getErrorObj(org.jenkinsci.plugins.workflow.graph.FlowNode flowNode)
Returns theThrowable
of a certainFlowNode
, if it has errors.static BlockingQueue<org.apache.commons.lang3.tuple.Pair<Date,Throwable>>
getExceptionsBuffer()
static String
getHostname(EnvVars envVars)
Getter function to return either the saved hostname global configuration, or the hostname that is set in the Jenkins host itself.static String
getItemName(Item item)
static String
getJenkinsUrl()
static String
getNodeHostname(EnvVars envVars, Computer computer)
static Set<String>
getNodeLabels(Computer computer)
static String
getNodeName(Computer computer)
static String
getResultTag(org.jenkinsci.plugins.workflow.graph.FlowNode node)
static Long
getRunStartTimeInMillis(Run run)
static Map<String,Set<String>>
getTagsFromGlobalTags()
Getter function for the globalTags global configuration, containing a comma-separated list of tags that should be applied everywhere.static Map<String,Set<String>>
getTagsFromPipelineAction(Run run)
Pipeline extraTags if any are configured in the Job from DatadogPipelineAction.static TaskListener
getTaskListener(Run run)
static long
getTimeMillis(org.jenkinsci.plugins.workflow.graph.FlowNode flowNode)
Returns the startTime of a certainFlowNode
, if it has time information.static String
getUserId()
static boolean
isJobTracked(Run<?,?> run)
Checks inclusion/exclusion filter settings to see if a run should be tracked by the pluginstatic boolean
isJobTracked(String jobName)
Checks if a jobName is excluded, included, or neither.static boolean
isMainNode(String nodeName)
static boolean
isStageNode(org.jenkinsci.plugins.workflow.graph.FlowNode flowNode)
Returns true if aFlowNode
is a Stage node.static Boolean
isValidHostname(String hostname)
Validator function to ensure that the hostname is valid.static boolean
isValidISO8601Date(String date)
static List<String>
linesToList(String str)
Converts a string List into a List Objectstatic void
logException(Logger logger, Level logLevel, String message, Throwable e)
static void
severe(Logger logger, Throwable e, String message)
static boolean
shouldSendEvent(String eventName)
Checks to see if event should be sent to clientstatic String
statusFromResult(String result)
Returns a normalized result for traces.static int
toInt(boolean b)
static String
toISO8601(Date date)
Returns a date as String in the ISO8601 formatstatic String
toJson(Map<String,String> map)
Returns a JSON object string based on the map.static String
toJson(Set<String> set)
Returns a JSON array string based on the set.
-
-
-
Method Detail
-
getDatadogGlobalDescriptor
public static DatadogGlobalConfiguration getDatadogGlobalDescriptor()
- Returns:
- - The descriptor for the Datadog plugin. In this case the global configuration.
-
getDatadogJobProperties
public static DatadogJobProperty getDatadogJobProperties(@Nonnull Run r)
- Parameters:
r
- - Current build.- Returns:
- - The configured
DatadogJobProperty
. Null if not there
-
getBuildTags
public static Map<String,Set<String>> getBuildTags(Run run, EnvVars envVars)
Builds extraTags if any are configured in the Job.- Parameters:
run
- - Current buildenvVars
- - Environment Variables- Returns:
- A
HashMap
containing the key,value pairs of tags if any.
-
getTagsFromPipelineAction
public static Map<String,Set<String>> getTagsFromPipelineAction(Run run)
Pipeline extraTags if any are configured in the Job from DatadogPipelineAction.- Parameters:
run
- - Current build- Returns:
- A
Map
containing the key,value pairs of tags if any.
-
isJobTracked
public static boolean isJobTracked(Run<?,?> run)
Checks inclusion/exclusion filter settings to see if a run should be tracked by the plugin- Parameters:
run
- The run to be checked- Returns:
true
if the run should be tracked by the plugin,false
otherwise
-
isJobTracked
public static boolean isJobTracked(String jobName)
Checks if a jobName is excluded, included, or neither.- Parameters:
jobName
- - A String containing the name of some job.- Returns:
- a boolean to signify if the jobName is or is not excluded or included.
-
getTagsFromGlobalTags
public static Map<String,Set<String>> getTagsFromGlobalTags()
Getter function for the globalTags global configuration, containing a comma-separated list of tags that should be applied everywhere.- Returns:
- a map containing the globalTags global configuration.
-
cstrToList
public static List<String> cstrToList(String str)
Converts a Comma Separated List into a List Object- Parameters:
str
- - A String containing a comma separated list of items.- Returns:
- a String List with all items transform with trim and lower case
-
linesToList
public static List<String> linesToList(String str)
Converts a string List into a List Object- Parameters:
str
- - A String containing a comma separated list of items.- Returns:
- a String List with all items
-
computeTagListFromVarList
public static Map<String,Set<String>> computeTagListFromVarList(EnvVars envVars, String varList)
-
getAwsInstanceID
public static String getAwsInstanceID() throws IOException
- Throws:
IOException
-
getHostname
public static String getHostname(EnvVars envVars)
Getter function to return either the saved hostname global configuration, or the hostname that is set in the Jenkins host itself. Returns null if no valid hostname is found.Tries, in order: Jenkins configuration Jenkins hostname environment variable AWS instance ID, if enabled System hostname environment variable Unix hostname via `/bin/hostname -f` Localhost hostname
- Parameters:
envVars
- - The Jenkins environment variables- Returns:
- a human readable String for the hostname.
-
isValidHostname
public static Boolean isValidHostname(String hostname)
Validator function to ensure that the hostname is valid. Also, fails on empty String.- Parameters:
hostname
- - A String object containing the name of a host.- Returns:
- a boolean representing the validity of the hostname
-
isMainNode
public static boolean isMainNode(String nodeName)
-
getNodeHostname
public static String getNodeHostname(@Nullable EnvVars envVars, @Nullable Computer computer)
-
getUserId
public static String getUserId()
-
currentTimeMillis
public static long currentTimeMillis()
-
getJenkinsUrl
public static String getJenkinsUrl()
-
getResultTag
public static String getResultTag(@Nonnull org.jenkinsci.plugins.workflow.graph.FlowNode node)
-
isStageNode
public static boolean isStageNode(org.jenkinsci.plugins.workflow.graph.FlowNode flowNode)
Returns true if aFlowNode
is a Stage node.- Parameters:
flowNode
- the flow node to evaluate- Returns:
- flag indicating if a flowNode is a Stage node.
-
getEnclosingStageNode
public static org.jenkinsci.plugins.workflow.graph.BlockStartNode getEnclosingStageNode(org.jenkinsci.plugins.workflow.graph.FlowNode node)
Returns enclosing stage node for the given node. Never returns the node itself.
-
statusFromResult
public static String statusFromResult(String result)
Returns a normalized result for traces.- Parameters:
result
- (success, failure, error, aborted, not_build, canceled, skipped, unstable, unknown)- Returns:
- the normalized result for the traces based on the jenkins result
-
logException
public static void logException(Logger logger, Level logLevel, String message, Throwable e)
-
getExceptionsBuffer
public static BlockingQueue<org.apache.commons.lang3.tuple.Pair<Date,Throwable>> getExceptionsBuffer()
-
toInt
public static int toInt(boolean b)
-
toISO8601
public static String toISO8601(Date date)
Returns a date as String in the ISO8601 format- Parameters:
date
- the date object to transform- Returns:
- date as String in the ISO8601 format
-
isValidISO8601Date
public static boolean isValidISO8601Date(String date)
-
toJson
public static String toJson(Set<String> set)
Returns a JSON array string based on the set.- Parameters:
set
- the set to transform into a JSON- Returns:
- json array string
-
toJson
public static String toJson(Map<String,String> map)
Returns a JSON object string based on the map.- Parameters:
map
- the map to transform into a JSON- Returns:
- json object string
-
cleanUpTraceActions
public static void cleanUpTraceActions(Actionable actionable)
Removes all actions related to traces for Jenkins pipelines.- Parameters:
actionable
- a domain object that can contain actions, such as run or flow node.
-
getCatchErrorResult
public static String getCatchErrorResult(org.jenkinsci.plugins.workflow.graph.BlockStartNode startNode)
-
shouldSendEvent
public static boolean shouldSendEvent(String eventName)
Checks to see if event should be sent to client- Parameters:
eventName
- - the event to check- Returns:
- true if event should be sent to client
-
getErrorObj
public static Throwable getErrorObj(org.jenkinsci.plugins.workflow.graph.FlowNode flowNode)
Returns theThrowable
of a certainFlowNode
, if it has errors.- Returns:
- throwable associated with a certain flowNode.
-
getTaskListener
@Nullable public static TaskListener getTaskListener(Run run) throws IOException
- Throws:
IOException
-
getTimeMillis
public static long getTimeMillis(org.jenkinsci.plugins.workflow.graph.FlowNode flowNode)
Returns the startTime of a certainFlowNode
, if it has time information.- Returns:
- startTime of the flowNode in milliseconds.
-
getDatadogPluginVersion
@Nullable public static String getDatadogPluginVersion()
-
envVar
public static int envVar(String name, int defaultValue)
-
envVar
public static double envVar(String name, double defaultValue)
-
-