Skip to content

Commit

Permalink
Merge pull request #2 from caraboides/master
Browse files Browse the repository at this point in the history
Add new API backend for Datadog EU
  • Loading branch information
gheine authored Dec 4, 2024
2 parents 100ce9d + ba0c9a1 commit 56548de
Showing 1 changed file with 17 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ public class HttpTransport implements Transport {

private static final Logger LOG = LoggerFactory.getLogger(HttpTransport.class);

private final static String BASE_URL = "https://api.datadoghq.com/api/v1";
private final static String BASE_URL_US = "https://api.datadoghq.com/api/v1";
private final static String BASE_URL_EU = "https://api.datadoghq.eu/api/v1";

private final String seriesUrl;
private final int connectTimeout; // in milliseconds
private final int socketTimeout; // in milliseconds
Expand All @@ -44,8 +46,10 @@ private HttpTransport(String apiKey,
int socketTimeout,
HttpHost proxy,
Executor executor,
boolean useCompression) {
this.seriesUrl = String.format("%s/series?api_key=%s", BASE_URL, apiKey);
boolean useCompression,
boolean euSite) {
final String baseUrl = euSite ? BASE_URL_EU: BASE_URL_US;
this.seriesUrl = String.format("%s/series?api_key=%s", baseUrl, apiKey);
this.connectTimeout = connectTimeout;
this.socketTimeout = socketTimeout;
this.proxy = proxy;
Expand All @@ -64,6 +68,7 @@ public static class Builder {
HttpHost proxy;
Executor executor;
boolean useCompression = false;
boolean euSite = false;

public Builder withApiKey(String key) {
this.apiKey = key;
Expand Down Expand Up @@ -95,8 +100,16 @@ public Builder withCompression(boolean compression) {
return this;
}

/**
* Send Metrics to Datadog EU site instead of US.
*/
public Builder withEuSite() {
this.euSite = true;
return this;
}

public HttpTransport build() {
return new HttpTransport(apiKey, connectTimeout, socketTimeout, proxy, executor, useCompression);
return new HttpTransport(apiKey, connectTimeout, socketTimeout, proxy, executor, useCompression, euSite);
}
}

Expand Down

0 comments on commit 56548de

Please sign in to comment.