-
Notifications
You must be signed in to change notification settings - Fork 293
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into alejandro.gonzalez/session_rewriting_detec…
…tion
- Loading branch information
Showing
19 changed files
with
561 additions
and
155 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 7 additions & 1 deletion
8
...gent-ci-visibility/src/main/java/datadog/trace/civisibility/communication/BackendApi.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,19 @@ | ||
package datadog.trace.civisibility.communication; | ||
|
||
import datadog.communication.http.OkHttpUtils; | ||
import datadog.trace.civisibility.utils.IOThrowingFunction; | ||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import javax.annotation.Nullable; | ||
import okhttp3.RequestBody; | ||
|
||
/** API for posting HTTP requests to backend */ | ||
public interface BackendApi { | ||
|
||
<T> T post(String uri, RequestBody requestBody, IOThrowingFunction<InputStream, T> responseParser) | ||
<T> T post( | ||
String uri, | ||
RequestBody requestBody, | ||
IOThrowingFunction<InputStream, T> responseParser, | ||
@Nullable OkHttpUtils.CustomListener requestListener) | ||
throws IOException; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
132 changes: 132 additions & 0 deletions
132
...-visibility/src/main/java/datadog/trace/civisibility/communication/TelemetryListener.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
package datadog.trace.civisibility.communication; | ||
|
||
import datadog.communication.http.OkHttpUtils; | ||
import datadog.trace.api.civisibility.telemetry.CiVisibilityCountMetric; | ||
import datadog.trace.api.civisibility.telemetry.CiVisibilityDistributionMetric; | ||
import datadog.trace.api.civisibility.telemetry.CiVisibilityMetricCollector; | ||
import datadog.trace.api.civisibility.telemetry.tag.ErrorType; | ||
import java.io.IOException; | ||
import javax.annotation.Nullable; | ||
import okhttp3.Call; | ||
import okhttp3.Response; | ||
|
||
public class TelemetryListener extends OkHttpUtils.CustomListener { | ||
|
||
private final CiVisibilityMetricCollector metricCollector; | ||
private final @Nullable CiVisibilityCountMetric requestCountMetric; | ||
private final @Nullable CiVisibilityCountMetric requestErrorsMetric; | ||
private final @Nullable CiVisibilityDistributionMetric requestBytesMetric; | ||
private final @Nullable CiVisibilityDistributionMetric requestDurationMetric; | ||
private final @Nullable CiVisibilityDistributionMetric responseBytesMetric; | ||
private long callStartTimestamp; | ||
|
||
private TelemetryListener( | ||
CiVisibilityMetricCollector metricCollector, | ||
@Nullable CiVisibilityCountMetric requestCountMetric, | ||
@Nullable CiVisibilityCountMetric requestErrorsMetric, | ||
@Nullable CiVisibilityDistributionMetric requestBytesMetric, | ||
@Nullable CiVisibilityDistributionMetric requestDurationMetric, | ||
@Nullable CiVisibilityDistributionMetric responseBytesMetric) { | ||
this.metricCollector = metricCollector; | ||
this.requestCountMetric = requestCountMetric; | ||
this.requestErrorsMetric = requestErrorsMetric; | ||
this.requestBytesMetric = requestBytesMetric; | ||
this.requestDurationMetric = requestDurationMetric; | ||
this.responseBytesMetric = responseBytesMetric; | ||
} | ||
|
||
public void callStart(Call call) { | ||
callStartTimestamp = System.currentTimeMillis(); | ||
if (requestCountMetric != null) { | ||
metricCollector.add(requestCountMetric, 1); | ||
} | ||
} | ||
|
||
public void requestBodyEnd(Call call, long byteCount) { | ||
if (requestBytesMetric != null) { | ||
metricCollector.add(requestBytesMetric, (int) byteCount); | ||
} | ||
} | ||
|
||
public void responseHeadersEnd(Call call, Response response) { | ||
if (requestErrorsMetric != null) { | ||
if (!response.isSuccessful()) { | ||
int responseCode = response.code(); | ||
metricCollector.add(requestErrorsMetric, 1, ErrorType.from(responseCode)); | ||
} | ||
} | ||
} | ||
|
||
@Override | ||
public void responseBodyEnd(Call call, long byteCount) { | ||
if (responseBytesMetric != null) { | ||
metricCollector.add(responseBytesMetric, (int) byteCount); | ||
} | ||
} | ||
|
||
public void callEnd(Call call) { | ||
if (requestDurationMetric != null) { | ||
int durationMillis = (int) (System.currentTimeMillis() - callStartTimestamp); | ||
metricCollector.add(requestDurationMetric, durationMillis); | ||
} | ||
} | ||
|
||
public void callFailed(Call call, IOException ioe) { | ||
if (requestDurationMetric != null) { | ||
int durationMillis = (int) (System.currentTimeMillis() - callStartTimestamp); | ||
metricCollector.add(requestDurationMetric, durationMillis); | ||
} | ||
|
||
if (requestErrorsMetric != null) { | ||
metricCollector.add(requestErrorsMetric, 1, ErrorType.NETWORK); | ||
} | ||
} | ||
|
||
public static final class Builder { | ||
private final CiVisibilityMetricCollector metricCollector; | ||
private @Nullable CiVisibilityCountMetric requestCountMetric; | ||
private @Nullable CiVisibilityCountMetric requestErrorsMetric; | ||
private @Nullable CiVisibilityDistributionMetric requestBytesMetric; | ||
private @Nullable CiVisibilityDistributionMetric requestDurationMetric; | ||
private @Nullable CiVisibilityDistributionMetric responseBytesMetric; | ||
|
||
public Builder(CiVisibilityMetricCollector metricCollector) { | ||
this.metricCollector = metricCollector; | ||
} | ||
|
||
public Builder requestCount(@Nullable CiVisibilityCountMetric requestCountMetric) { | ||
this.requestCountMetric = requestCountMetric; | ||
return this; | ||
} | ||
|
||
public Builder requestErrors(@Nullable CiVisibilityCountMetric requestErrorsMetric) { | ||
this.requestErrorsMetric = requestErrorsMetric; | ||
return this; | ||
} | ||
|
||
public Builder requestBytes(@Nullable CiVisibilityDistributionMetric requestBytesMetric) { | ||
this.requestBytesMetric = requestBytesMetric; | ||
return this; | ||
} | ||
|
||
public Builder requestDuration(@Nullable CiVisibilityDistributionMetric requestDurationMetric) { | ||
this.requestDurationMetric = requestDurationMetric; | ||
return this; | ||
} | ||
|
||
public Builder responseBytes(@Nullable CiVisibilityDistributionMetric responseBytesMetric) { | ||
this.responseBytesMetric = responseBytesMetric; | ||
return this; | ||
} | ||
|
||
public OkHttpUtils.CustomListener build() { | ||
return new TelemetryListener( | ||
metricCollector, | ||
requestCountMetric, | ||
requestErrorsMetric, | ||
requestBytesMetric, | ||
requestDurationMetric, | ||
responseBytesMetric); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.