public class DatadogUtilities extends Object
Constructor and Description |
---|
DatadogUtilities() |
Modifier and Type | Method and Description |
---|---|
static URL |
buildHttpURL(String hostname,
Integer port,
String path)
Returns an HTTP URL
|
static void |
cleanUpTraceActions(Run<?,?> run)
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 Object
|
static long |
currentTimeMillis() |
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 |
getFileName(XmlFile file) |
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 Optional<String> |
getHostnameFromWorkerEnv(Run run)
Fetches the environment variables from the worker and returns the value
of DD_CI_HOSTNAME if set.
|
static HttpURLConnection |
getHttpURLConnection(URL url,
int timeoutMS)
Returns an HTTP url connection given a url object.
|
static String |
getItemName(Item item) |
static String |
getJenkinsUrl() |
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 String |
getUserId() |
static boolean |
isJobTracked(String jobName)
Checks if a jobName is excluded, included, or neither.
|
static boolean |
isMainNode(String nodeName) |
static boolean |
isPipeline(Run<?,?> run)
Check if a run is from a Jenkins pipeline.
|
static boolean |
isPipelineNode(org.jenkinsci.plugins.workflow.graph.FlowNode flowNode)
Returns true if a
FlowNode is a Pipeline node. |
static boolean |
isStageNode(org.jenkinsci.plugins.workflow.graph.BlockStartNode flowNode)
Returns true if a
FlowNode is a Stage node. |
static Boolean |
isValidHostname(String hostname)
Validator function to ensure that the hostname is valid.
|
static List<String> |
linesToList(String str)
Converts a string List into a List Object
|
static void |
severe(Logger logger,
Throwable e,
String message) |
static 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 format
|
static 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.
|
public static DatadogGlobalConfiguration getDatadogGlobalDescriptor()
public static DatadogJobProperty getDatadogJobProperties(@Nonnull Run r)
r
- - Current build.DatadogJobProperty
. Null if not therepublic static Map<String,Set<String>> getBuildTags(Run run, EnvVars envVars)
run
- - Current buildenvVars
- - Environment VariablesHashMap
containing the key,value pairs of tags if any.public static Map<String,Set<String>> getTagsFromPipelineAction(Run run)
run
- - Current buildHashMap
containing the key,value pairs of tags if any.public static boolean isJobTracked(String jobName)
jobName
- - A String containing the name of some job.public static Map<String,Set<String>> getTagsFromGlobalTags()
public static List<String> cstrToList(String str)
str
- - A String containing a comma separated list of items.public static List<String> linesToList(String str)
str
- - A String containing a comma separated list of items.public static Map<String,Set<String>> computeTagListFromVarList(EnvVars envVars, String varList)
public static String getAwsInstanceID() throws IOException
IOException
public static String getHostname(EnvVars envVars)
envVars
- - The Jenkins environment variablespublic static Optional<String> getHostnameFromWorkerEnv(Run run)
run
- - Current buildpublic static Boolean isValidHostname(String hostname)
hostname
- - A String object containing the name of a host.public static boolean isMainNode(String nodeName)
public static String getUserId()
public static long currentTimeMillis()
public static String getJenkinsUrl()
public static String getResultTag(@Nonnull org.jenkinsci.plugins.workflow.graph.FlowNode node)
public static boolean isStageNode(org.jenkinsci.plugins.workflow.graph.BlockStartNode flowNode)
FlowNode
is a Stage node.flowNode
- the flow node to evaluatepublic static boolean isPipelineNode(org.jenkinsci.plugins.workflow.graph.FlowNode flowNode)
FlowNode
is a Pipeline node.flowNode
- the flow node to evaluatepublic static String statusFromResult(String result)
result
- (success, failure, error, aborted, not_build, canceled, skipped, unknown)public static int toInt(boolean b)
public static String toISO8601(Date date)
date
- the date object to transformpublic static String toJson(Set<String> set)
set
- the set to transform into a JSONpublic static String toJson(Map<String,String> map)
map
- the map to transform into a JSONpublic static void cleanUpTraceActions(Run<?,?> run)
run
- the current run.public static boolean isPipeline(Run<?,?> run)
run
- the current run.public static HttpURLConnection getHttpURLConnection(URL url, int timeoutMS) throws IOException
url
- - a URL object containing the URL to open a connection to.timeoutMS
- - the timeout in MSIOException
- if HttpURLConnection fails to open connectionpublic static URL buildHttpURL(String hostname, Integer port, String path) throws MalformedURLException
hostname
- - the Hostnameport
- - the port to usepath
- - the pathMalformedURLException
- if the URL is not in a valid formatpublic static String getCatchErrorResult(org.jenkinsci.plugins.workflow.graph.BlockStartNode startNode)
Copyright © 2016–2023. All rights reserved.