Skip to content

Commit 7bfa6b5

Browse files
committed
Benchmark telemetry when USTs are configured with sysprops
1 parent 3a35f77 commit 7bfa6b5

File tree

2 files changed

+98
-1
lines changed

2 files changed

+98
-1
lines changed
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
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+
}

telemetry/src/main/java/datadog/telemetry/TelemetryRunnable.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ private void mainLoopIteration() throws InterruptedException {
140140
}
141141
}
142142

143-
private void collectConfigChanges() {
143+
void collectConfigChanges() {
144144
Map<String, ConfigSetting> collectedConfig = ConfigCollector.get().collect();
145145
if (!collectedConfig.isEmpty()) {
146146
telemetryService.addConfiguration(collectedConfig);

0 commit comments

Comments
 (0)