Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rework CI Visibility spans batching #379

Merged
Original file line number Diff line number Diff line change
Expand Up @@ -26,32 +26,29 @@ of this software and associated documentation files (the "Software"), to deal
package org.datadog.jenkins.plugins.datadog;

import com.timgroup.statsd.ServiceCheck;
import hudson.model.Run;
import hudson.util.Secret;
import java.util.Map;
import java.util.Set;
import org.datadog.jenkins.plugins.datadog.clients.Metrics;
import org.datadog.jenkins.plugins.datadog.model.BuildData;
import org.jenkinsci.plugins.workflow.graph.FlowNode;
import org.datadog.jenkins.plugins.datadog.traces.write.TraceWriteStrategy;

public interface DatadogClient {

public static enum ClientType {
enum ClientType {
HTTP,
DSD;

private ClientType() { }
ClientType() { }
}

public static enum Status {
enum Status {
OK(0),
WARNING(1),
CRITICAL(2),
UNKNOWN(3);

private final int val;

private Status(int val) {
Status(int val) {
this.val = val;
}

Expand All @@ -64,39 +61,13 @@ public ServiceCheck.Status toServiceCheckStatus(){
}
}

public void setUrl(String url);

public void setLogIntakeUrl(String logIntakeUrl);

public void setWebhookIntakeUrl(String webhookIntakeUrl);

public void setApiKey(Secret apiKey);

public void setHostname(String hostname);

public void setPort(Integer port);

public void setLogCollectionPort(Integer logCollectionPort);

public boolean isDefaultIntakeConnectionBroken();

public void setDefaultIntakeConnectionBroken(boolean defaultIntakeConnectionBroken);

public boolean isLogIntakeConnectionBroken();

public boolean isWebhookIntakeConnectionBroken();

public void setLogIntakeConnectionBroken(boolean logIntakeConnectionBroken);

public void setWebhookIntakeConnectionBroken(boolean webhookIntakeConnectionBroken);

/**
* Sends an event to the Datadog API, including the event payload.
*
* @param event - a DatadogEvent object
* @return a boolean to signify the success or failure of the HTTP POST request.
*/
public boolean event(DatadogEvent event);
boolean event(DatadogEvent event);

/**
* Increment a counter for the given metrics.
Expand All @@ -107,14 +78,14 @@ public ServiceCheck.Status toServiceCheckStatus(){
* @param tags - metric tags
* @return a boolean to signify the success or failure of increment submission.
*/
public boolean incrementCounter(String name, String hostname, Map<String, Set<String>> tags);
boolean incrementCounter(String name, String hostname, Map<String, Set<String>> tags);

/**
* Submit all your counters as rate with 10 seconds intervals.
*/
public void flushCounters();
void flushCounters();

public Metrics metrics();
Metrics metrics();

/**
* Sends a service check to the Datadog API, including the check name, and status.
Expand All @@ -125,45 +96,15 @@ public ServiceCheck.Status toServiceCheckStatus(){
* @param tags - A Map containing the tags to submit.
* @return a boolean to signify the success or failure of the HTTP POST request.
*/
public boolean serviceCheck(String name, Status status, String hostname, Map<String, Set<String>> tags);
boolean serviceCheck(String name, Status status, String hostname, Map<String, Set<String>> tags);

/**
* Send log message.
* @param payload log payload to submit JSON object as String
* @return a boolean to signify the success or failure of the request.
*/
public boolean sendLogs(String payload);
boolean sendLogs(String payload);

/**
* Send a webhook payload to the webhooks intake.
*
* @param payload - A webhooks payload.
* @return a boolean to signify the success or failure of the HTTP POST request.
*/
public boolean postWebhook(String payload);

/**
* Start the trace of a certain Jenkins build.
* @param buildData build data to use in the pipeline trace
* @param run a particular execution of a Jenkins build
* @return a boolean to signify the success or failure of the request.
*/
boolean startBuildTrace(BuildData buildData, Run<?, ?> run);

/**
* Finish the trace of a certain Jenkins build.
* @param buildData build data to use in the pipeline trace
* @param run the run to create a pipeline trace for
* @return a boolean to signify the success or failure of the request.
*/
boolean finishBuildTrace(BuildData buildData, Run<?, ?> run);

/**
* Send all traces related to a certain Jenkins pipeline.
* @param run a particular execution of a Jenkins build
* @param flowNode current flowNode
* @return a boolean to signify the success or failure of the request.
*/
boolean sendPipelineTrace(Run<?, ?> run, FlowNode flowNode);
TraceWriteStrategy createTraceWriteStrategy();

}
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,14 @@ of this software and associated documentation files (the "Software"), to deal
import com.cloudbees.plugins.credentials.common.StandardListBoxModel;
import com.cloudbees.plugins.credentials.domains.URIRequirementBuilder;
import org.datadog.jenkins.plugins.datadog.clients.HttpClient;
import org.datadog.jenkins.plugins.datadog.traces.write.TraceWriterFactory;
import org.jenkinsci.plugins.plaincredentials.StringCredentials;

import net.sf.json.JSONObject;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang.math.NumberUtils;
import org.datadog.jenkins.plugins.datadog.clients.ClientFactory;
import org.datadog.jenkins.plugins.datadog.clients.DatadogHttpClient;
import org.datadog.jenkins.plugins.datadog.clients.DatadogApiClient;
import org.datadog.jenkins.plugins.datadog.clients.DatadogAgentClient;
import org.datadog.jenkins.plugins.datadog.util.SuppressFBWarnings;
import org.datadog.jenkins.plugins.datadog.util.config.DatadogAgentConfiguration;
Expand Down Expand Up @@ -445,7 +446,7 @@ public FormValidation doTestConnection(
throws IOException, ServletException {
Jenkins.getInstance().checkPermission(Jenkins.ADMINISTER);
final Secret secret = findSecret(targetApiKey, targetCredentialsApiKey);
if (DatadogHttpClient.validateDefaultIntakeConnection(new HttpClient(60_000), targetApiURL, secret)) {
if (DatadogApiClient.validateDefaultIntakeConnection(new HttpClient(60_000), targetApiURL, secret)) {
return FormValidation.ok("Great! Your API key is valid.");
} else {
return FormValidation.error("Hmmm, your API key seems to be invalid.");
Expand Down Expand Up @@ -839,9 +840,9 @@ public boolean configure(final StaplerRequest req, final JSONObject formData) th
if(client == null) {
return false;
}
client.setDefaultIntakeConnectionBroken(false);
client.setLogIntakeConnectionBroken(false);
client.setWebhookIntakeConnectionBroken(false);

TraceWriterFactory.onDatadogClientUpdate(client);

// Persist global configuration information
save();
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -987,19 +987,6 @@ public static boolean isPipeline(final Run<?, ?> run) {
return run != null && run.getAction(IsPipelineAction.class) != null;
}

/**
* Returns an HTTP URL
*
* @param hostname - the Hostname
* @param port - the port to use
* @param path - the path
* @return the HTTP URL
* @throws MalformedURLException if the URL is not in a valid format
*/
public static URL buildHttpURL(final String hostname, final Integer port, final String path) throws MalformedURLException {
return new URL(String.format("http://%s:%d" + path, hostname, port));
}

public static String getCatchErrorResult(BlockStartNode startNode) {
String displayFunctionName = startNode.getDisplayFunctionName();
if ("warnError".equals(displayFunctionName)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,15 @@ of this software and associated documentation files (the "Software"), to deal
import org.datadog.jenkins.plugins.datadog.DatadogClient;
import org.datadog.jenkins.plugins.datadog.DatadogGlobalConfiguration;
import org.datadog.jenkins.plugins.datadog.DatadogUtilities;
import org.datadog.jenkins.plugins.datadog.traces.write.TraceWriterFactory;

public class ClientFactory {
private static DatadogClient testClient;

public static void setTestClient(DatadogClient testClient){
// Only used for tests
ClientFactory.testClient = testClient;
TraceWriterFactory.onDatadogClientUpdate(testClient);
}

public static DatadogClient getClient(DatadogClient.ClientType type, String apiUrl, String logIntakeUrl,
Expand All @@ -47,7 +49,7 @@ public static DatadogClient getClient(DatadogClient.ClientType type, String apiU
}
switch(type){
case HTTP:
return DatadogHttpClient.getInstance(apiUrl, logIntakeUrl, webhookIntakeUrl, apiKey);
return DatadogApiClient.getInstance(apiUrl, logIntakeUrl, webhookIntakeUrl, apiKey);
case DSD:
return DatadogAgentClient.getInstance(host, port, logCollectionPort, traceCollectionPort);
default:
Expand Down
Loading
Loading