|
| 1 | +package datadog.telemetry; |
| 2 | + |
| 3 | +import static datadog.trace.api.config.GeneralConfig.ENV; |
| 4 | +import static datadog.trace.api.config.GeneralConfig.SERVICE_NAME; |
| 5 | +import static datadog.trace.api.config.GeneralConfig.VERSION; |
| 6 | +import static java.util.concurrent.TimeUnit.MILLISECONDS; |
| 7 | + |
| 8 | +import datadog.communication.ddagent.DDAgentFeaturesDiscovery; |
| 9 | +import datadog.communication.http.HttpRetryPolicy; |
| 10 | +import datadog.communication.monitor.Monitoring; |
| 11 | +import datadog.trace.api.Config; |
| 12 | +import java.util.ArrayList; |
| 13 | +import java.util.Properties; |
| 14 | +import okhttp3.HttpUrl; |
| 15 | +import okhttp3.OkHttpClient; |
| 16 | +import okhttp3.Request; |
| 17 | +import org.openjdk.jmh.annotations.Benchmark; |
| 18 | +import org.openjdk.jmh.annotations.BenchmarkMode; |
| 19 | +import org.openjdk.jmh.annotations.Level; |
| 20 | +import org.openjdk.jmh.annotations.Mode; |
| 21 | +import org.openjdk.jmh.annotations.OutputTimeUnit; |
| 22 | +import org.openjdk.jmh.annotations.Scope; |
| 23 | +import org.openjdk.jmh.annotations.Setup; |
| 24 | +import org.openjdk.jmh.annotations.State; |
| 25 | + |
| 26 | +@OutputTimeUnit(MILLISECONDS) |
| 27 | +@BenchmarkMode(Mode.Throughput) |
| 28 | +@State(Scope.Benchmark) |
| 29 | +public class ConfigSourcesBenchmark { |
| 30 | + |
| 31 | + // Simple mock for DDAgentFeaturesDiscovery for benchmarking purposes |
| 32 | + private static class MockFeaturesDiscovery extends DDAgentFeaturesDiscovery { |
| 33 | + private final boolean supportsDataStreams; |
| 34 | + |
| 35 | + public MockFeaturesDiscovery(boolean supportsDataStreams) { |
| 36 | + super(null, Monitoring.DISABLED, null, true, true); |
| 37 | + this.supportsDataStreams = supportsDataStreams; |
| 38 | + } |
| 39 | + |
| 40 | + @Override |
| 41 | + public void discover() {} |
| 42 | + |
| 43 | + @Override |
| 44 | + public void discoverIfOutdated() {} |
| 45 | + |
| 46 | + @Override |
| 47 | + public boolean supportsDataStreams() { |
| 48 | + return supportsDataStreams; |
| 49 | + } |
| 50 | + } |
| 51 | + |
| 52 | + private static class NoopTelemetryClient extends TelemetryClient { |
| 53 | + |
| 54 | + public NoopTelemetryClient( |
| 55 | + OkHttpClient okHttpClient, |
| 56 | + HttpRetryPolicy.Factory httpRetryPolicy, |
| 57 | + HttpUrl url, |
| 58 | + String apiKey) { |
| 59 | + super(okHttpClient, httpRetryPolicy, url, apiKey); |
| 60 | + } |
| 61 | + |
| 62 | + @Override |
| 63 | + public Result sendHttpRequest(Request.Builder httpRequestBuilder) { |
| 64 | + return Result.SUCCESS; |
| 65 | + } |
| 66 | + } |
| 67 | + |
| 68 | + private Properties props; |
| 69 | + TelemetryService service; |
| 70 | + |
| 71 | + @Setup(Level.Iteration) |
| 72 | + public void setUp() { |
| 73 | + props = new Properties(); |
| 74 | + props.setProperty(SERVICE_NAME, "benchmark-service"); |
| 75 | + props.setProperty(ENV, "benchmark-env"); |
| 76 | + props.setProperty(VERSION, "1"); |
| 77 | + DDAgentFeaturesDiscovery featuresDiscovery = new MockFeaturesDiscovery(false); |
| 78 | + HttpUrl url = |
| 79 | + new HttpUrl.Builder() |
| 80 | + .scheme("https") |
| 81 | + .host("example.com") |
| 82 | + .addPathSegment("path") |
| 83 | + .addQueryParameter("key", "value") |
| 84 | + .build(); |
| 85 | + NoopTelemetryClient telemetryClient = |
| 86 | + new NoopTelemetryClient(null, HttpRetryPolicy.Factory.NEVER_RETRY, url, ""); |
| 87 | + service = TelemetryService.build(featuresDiscovery, telemetryClient, null, false, false); |
| 88 | + } |
| 89 | + |
| 90 | + @Benchmark |
| 91 | + public void appStartedEventBenchmark() { |
| 92 | + Config c = Config.get(props); |
| 93 | + TelemetryRunnable telemetryRunnable = new TelemetryRunnable(service, new ArrayList<>()); |
| 94 | + telemetryRunnable.collectConfigChanges(); |
| 95 | + service.sendAppStartedEvent(); |
| 96 | + } |
| 97 | +} |
0 commit comments