Skip to content

Commit

Permalink
Add test for customDimensions for Statsbeat (#2078)
Browse files Browse the repository at this point in the history
* Add test for statsbeat & customDimensions config

* Fix spotless

* Track customDimensions config usage

* Address comment

Co-authored-by: Trask Stalnaker <[email protected]>

Co-authored-by: Trask Stalnaker <[email protected]>
  • Loading branch information
heyams and trask authored Feb 3, 2022
1 parent d99a4dd commit 99c14ba
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ enum Feature {
CAPTURE_HTTP_SERVER_4XX_AS_SUCCESS(26),
CAPTURE_HTTP_SERVER_HEADERS(27),
CAPTURE_HTTP_CLIENT_HEADERS(28),
VERTX_DISABLED(29); // preview instrumentation, vertx is ON by default in OTEL
VERTX_DISABLED(29), // preview instrumentation, vertx is ON by default in OTEL
CUSTOM_DIMENSIONS_ENABLED(30); // enable customDimensions

private static final Map<String, Feature> javaVendorFeatureMap;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,5 +170,10 @@ void trackConfigurationOptions(Configuration config) {
|| !config.preview.captureHttpClientHeaders.responseHeaders.isEmpty()) {
featureList.add(Feature.CAPTURE_HTTP_CLIENT_HEADERS);
}

// customDimensions
if (!config.customDimensions.isEmpty()) {
featureList.add(Feature.CUSTOM_DIMENSIONS_ENABLED);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@

import com.microsoft.applicationinsights.agent.internal.common.PropertyHelper;
import com.microsoft.applicationinsights.agent.internal.common.SystemInformation;
import com.microsoft.applicationinsights.agent.internal.configuration.Configuration;
import com.microsoft.applicationinsights.agent.internal.exporter.models.MetricsData;
import com.microsoft.applicationinsights.agent.internal.exporter.models.TelemetryItem;
import com.microsoft.applicationinsights.agent.internal.telemetry.TelemetryClient;
import java.util.HashMap;
import java.util.Map;
import org.junit.jupiter.api.Test;
Expand Down Expand Up @@ -82,4 +86,43 @@ public void testRuntimeVersion() {

assertThat(properties.get("runtimeVersion")).isEqualTo(System.getProperty("java.version"));
}

@Test
public void testCustomDimensionsConfigShouldNotImpactStatsbeatCustomDimensions() {
Configuration configuration = new Configuration();
configuration.customDimensions.put("firstTag", "abc");
configuration.customDimensions.put("secondTag", "def");
TelemetryClient telemetryClient =
TelemetryClient.builder().setCustomDimensions(configuration.customDimensions).build();
NetworkStatsbeat networkStatsbeat = new NetworkStatsbeat();
TelemetryItem networkItem =
networkStatsbeat.createStatsbeatTelemetry(telemetryClient, "test-network", 0.0);
assertThat(networkItem.getTags()).doesNotContainKey("firstTag");
assertThat(networkItem.getTags()).doesNotContainKey("secondTag");
assertThat(((MetricsData) networkItem.getData().getBaseData()).getProperties())
.doesNotContainKey("firstTag");
assertThat(((MetricsData) networkItem.getData().getBaseData()).getProperties())
.doesNotContainKey("secondTag");

AttachStatsbeat attachStatsbeat = new AttachStatsbeat(new CustomDimensions());
TelemetryItem attachItem =
attachStatsbeat.createStatsbeatTelemetry(telemetryClient, "test-attach", 0.0);
assertThat(attachItem.getTags()).doesNotContainKey("firstTag");
assertThat(attachItem.getTags()).doesNotContainKey("secondTag");
assertThat(((MetricsData) attachItem.getData().getBaseData()).getProperties())
.doesNotContainKey("firstTag");
assertThat(((MetricsData) attachItem.getData().getBaseData()).getProperties())
.doesNotContainKey("secondTag");

FeatureStatsbeat featureStatsbeat =
new FeatureStatsbeat(new CustomDimensions(), FeatureType.FEATURE);
TelemetryItem featureItem =
featureStatsbeat.createStatsbeatTelemetry(telemetryClient, "test-feature", 0.0);
assertThat(featureItem.getTags()).doesNotContainKey("firstTag");
assertThat(featureItem.getTags()).doesNotContainKey("secondTag");
assertThat(((MetricsData) featureItem.getData().getBaseData()).getProperties())
.doesNotContainKey("firstTag");
assertThat(((MetricsData) featureItem.getData().getBaseData()).getProperties())
.doesNotContainKey("secondTag");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@
"disabled": false
}
},
"customDimensions": {
"tag1": "abc",
"tag2": "def",
"service.version": "123"
},
"internal": {
"statsbeat": {
"disabledAll": false,
Expand Down

0 comments on commit 99c14ba

Please sign in to comment.