Class DatadogUtilities


  • public class DatadogUtilities
    extends Object
    • Constructor Detail

      • DatadogUtilities

        public DatadogUtilities()
    • 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 build
        envVars - - 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
      • 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
      • getNodeName

        public static String getNodeName​(Computer computer)
      • isMainNode

        public static boolean isMainNode​(String nodeName)
      • getNodeHostname

        public static String getNodeHostname​(@Nullable
                                             EnvVars envVars,
                                             @Nullable
                                             Computer computer)
      • getUserId

        public static String getUserId()
      • getItemName

        public static String getItemName​(Item item)
      • getRunStartTimeInMillis

        public static Long getRunStartTimeInMillis​(Run run)
      • 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 a FlowNode 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
      • 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
      • 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 the Throwable of a certain FlowNode, if it has errors.
        Returns:
        throwable associated with a certain flowNode.
      • getTimeMillis

        public static long getTimeMillis​(org.jenkinsci.plugins.workflow.graph.FlowNode flowNode)
        Returns the startTime of a certain FlowNode, if it has time information.
        Returns:
        startTime of the flowNode in milliseconds.
      • getDatadogPluginVersion

        @Nullable
        public static String getDatadogPluginVersion()