Skip to content

Commit 233328f

Browse files
traskheyams
andauthored
Disable _otelresource_ custom metric in non-AKS envs (#3710)
Co-authored-by: heyams <[email protected]> Co-authored-by: Helen <[email protected]>
1 parent 50c8feb commit 233328f

File tree

9 files changed

+102
-66
lines changed

9 files changed

+102
-66
lines changed

.github/workflows/build-common.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ on:
88
required: false
99

1010
env:
11-
EXPORTER_VERSION: 1.0.0-beta.22 # to be updated with the latest version
11+
EXPORTER_VERSION: 1.0.0-beta.23 # to be updated with the latest version
1212

1313
jobs:
1414
spotless:

agent/agent-tooling/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ dependencies {
2121
implementation(project(":agent:agent-profiler:agent-diagnostics"))
2222
implementation(project(":etw:java"))
2323

24-
implementation("com.azure:azure-monitor-opentelemetry-exporter:1.0.0-beta.22")
24+
implementation("com.azure:azure-monitor-opentelemetry-exporter:1.0.0-beta.23")
2525
compileOnly("io.opentelemetry.javaagent:opentelemetry-javaagent-bootstrap")
2626
compileOnly("io.opentelemetry.javaagent:opentelemetry-javaagent-tooling")
2727
compileOnly("io.opentelemetry.javaagent.instrumentation:opentelemetry-javaagent-servlet-common-bootstrap")

agent/agent-tooling/gradle.lockfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ com.azure:azure-core-http-netty:1.14.2=runtimeClasspath
99
com.azure:azure-core:1.48.0=runtimeClasspath
1010
com.azure:azure-identity:1.12.1=runtimeClasspath
1111
com.azure:azure-json:1.1.0=runtimeClasspath
12-
com.azure:azure-monitor-opentelemetry-exporter:1.0.0-beta.22=runtimeClasspath
12+
com.azure:azure-monitor-opentelemetry-exporter:1.0.0-beta.23=runtimeClasspath
1313
com.azure:azure-sdk-bom:1.2.23=runtimeClasspath
1414
com.azure:azure-storage-blob:12.25.4=runtimeClasspath
1515
com.azure:azure-storage-common:12.24.4=runtimeClasspath

licenses/more-licenses.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,7 @@ _2024-05-27 03:31:29 UTC_
350350
> - **POM Project URL**: [https://github.com/Azure/azure-sdk-for-java](https://github.com/Azure/azure-sdk-for-java)
351351
> - **POM License**: MIT License - [https://opensource.org/licenses/MIT](https://opensource.org/licenses/MIT)
352352
353-
**67** **Group:** `com.azure` **Name:** `azure-monitor-opentelemetry-exporter` **Version:** `1.0.0-beta.22`
353+
**67** **Group:** `com.azure` **Name:** `azure-monitor-opentelemetry-exporter` **Version:** `1.0.0-beta.23`
354354
> - **POM License**: MIT License - [https://opensource.org/licenses/MIT](https://opensource.org/licenses/MIT)
355355
356356
**68** **Group:** `com.azure` **Name:** `azure-storage-blob` **Version:** `12.25.4`

smoke-tests/apps/ConnectionStringOverrides/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/ConnectionStringOverridesTest.java

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,7 @@
2929
@UseAgent
3030
abstract class ConnectionStringOverridesTest {
3131

32-
@RegisterExtension
33-
static final SmokeTestExtension testing =
34-
SmokeTestExtension.builder().otelResourceAttributesEnvVar("key1=value1,key2=value2").build();
32+
@RegisterExtension static final SmokeTestExtension testing = SmokeTestExtension.create();
3533

3634
@Test
3735
@TargetUri("/app2")
@@ -46,11 +44,6 @@ void testApp3() throws Exception {
4644
}
4745

4846
private static void testApp(String iKey) throws Exception {
49-
// verify _OTELRESOURCE_ custom metric per connection string
50-
List<Envelope> otelResourceMetrics =
51-
testing.mockedIngestion.waitForMetricItems("_OTELRESOURCE_", iKey, 1, false);
52-
verifyOtelResourceAttributeCustomMetric(otelResourceMetrics, iKey);
53-
5447
List<Envelope> rdList = testing.mockedIngestion.waitForItems("RequestData", 1);
5548

5649
Envelope rdEnvelope = rdList.get(0);
@@ -106,21 +99,6 @@ private static void testApp(String iKey) throws Exception {
10699
verifyHttpServerPreAggregatedMetrics(serverMetrics, iKey);
107100
}
108101

109-
private static void verifyOtelResourceAttributeCustomMetric(
110-
List<Envelope> otelResourceMetrics, String iKey) {
111-
Map<String, String> tags = otelResourceMetrics.get(0).getTags();
112-
assertThat(otelResourceMetrics.get(0).getIKey()).isEqualTo(iKey);
113-
assertThat(tags.get("ai.internal.sdkVersion")).isNotNull();
114-
assertThat(tags.get("ai.cloud.roleInstance")).isNotNull();
115-
assertThat(tags.get("ai.cloud.role")).isEqualTo("testrolename");
116-
117-
MetricData otelResourceMetricData =
118-
(MetricData) ((Data<?>) otelResourceMetrics.get(0).getData()).getBaseData();
119-
Map<String, String> properties = otelResourceMetricData.getProperties();
120-
assertThat(properties.get("key1")).isEqualTo("value1");
121-
assertThat(properties.get("key2")).isEqualTo("value2");
122-
}
123-
124102
private static void verifyHttpClientPreAggregatedMetrics(List<Envelope> metrics, String iKey) {
125103
assertThat(metrics.size()).isEqualTo(1);
126104

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
4+
package com.microsoft.applicationinsights.smoketest;
5+
6+
import static com.microsoft.applicationinsights.smoketest.EnvironmentValue.TOMCAT_8_JAVA_11;
7+
import static com.microsoft.applicationinsights.smoketest.EnvironmentValue.TOMCAT_8_JAVA_11_OPENJ9;
8+
import static com.microsoft.applicationinsights.smoketest.EnvironmentValue.TOMCAT_8_JAVA_17;
9+
import static com.microsoft.applicationinsights.smoketest.EnvironmentValue.TOMCAT_8_JAVA_21;
10+
import static com.microsoft.applicationinsights.smoketest.EnvironmentValue.TOMCAT_8_JAVA_8;
11+
import static com.microsoft.applicationinsights.smoketest.EnvironmentValue.TOMCAT_8_JAVA_8_OPENJ9;
12+
import static com.microsoft.applicationinsights.smoketest.EnvironmentValue.WILDFLY_13_JAVA_8;
13+
import static com.microsoft.applicationinsights.smoketest.EnvironmentValue.WILDFLY_13_JAVA_8_OPENJ9;
14+
import static org.assertj.core.api.Assertions.assertThat;
15+
16+
import com.microsoft.applicationinsights.smoketest.schemav2.Data;
17+
import com.microsoft.applicationinsights.smoketest.schemav2.Envelope;
18+
import com.microsoft.applicationinsights.smoketest.schemav2.MetricData;
19+
import java.util.List;
20+
import org.junit.jupiter.api.Test;
21+
import org.junit.jupiter.api.extension.RegisterExtension;
22+
23+
@UseAgent
24+
abstract class DefaultOtelResourceAttributesTest {
25+
26+
@RegisterExtension static final SmokeTestExtension testing = SmokeTestExtension.create();
27+
28+
@Test
29+
@TargetUri(value = "/app")
30+
void testApp() {
31+
List<Envelope> metricsEnvelops = testing.mockedIngestion.getItemsEnvelopeDataType("MetricData");
32+
metricsEnvelops.stream()
33+
.map(envelope -> (MetricData) ((Data<?>) envelope.getData()).getBaseData())
34+
.map(metricData -> metricData.getMetrics().get(0).getName())
35+
.forEach(name -> assertThat(name).isNotEqualTo("_OTELRESOURCE_"));
36+
}
37+
38+
@Environment(TOMCAT_8_JAVA_8)
39+
static class Tomcat8Java8Test extends DefaultOtelResourceAttributesTest {}
40+
41+
@Environment(TOMCAT_8_JAVA_8_OPENJ9)
42+
static class Tomcat8Java8OpenJ9Test extends DefaultOtelResourceAttributesTest {}
43+
44+
@Environment(TOMCAT_8_JAVA_11)
45+
static class Tomcat8Java11Test extends DefaultOtelResourceAttributesTest {}
46+
47+
@Environment(TOMCAT_8_JAVA_11_OPENJ9)
48+
static class Tomcat8Java11OpenJ9Test extends DefaultOtelResourceAttributesTest {}
49+
50+
@Environment(TOMCAT_8_JAVA_17)
51+
static class Tomcat8Java17Test extends DefaultOtelResourceAttributesTest {}
52+
53+
@Environment(TOMCAT_8_JAVA_21)
54+
static class Tomcat8Java21Test extends DefaultOtelResourceAttributesTest {}
55+
56+
@Environment(WILDFLY_13_JAVA_8)
57+
static class Wildfly13Java8Test extends DefaultOtelResourceAttributesTest {}
58+
59+
@Environment(WILDFLY_13_JAVA_8_OPENJ9)
60+
static class Wildfly13Java8OpenJ9Test extends DefaultOtelResourceAttributesTest {}
61+
}
Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
import org.junit.jupiter.api.extension.RegisterExtension;
2626

2727
@UseAgent
28-
abstract class OtelResourceCustomMetricTest {
28+
abstract class EnvVarOtelResourceAttributesTest {
2929

3030
private static final String OTEL_RESOURCE_ATTRIBUTES =
3131
"cloud.resource_id=/subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxdfcdaa1/resourceGroups/fake-aks-cluster-name/providers/Microsoft.ContainerService/managedClusters/aks-vanilla-1,cloud.region=eastus,k8s.cluster.name=aks-vanilla-1,k8s.pod.namespace=default,k8s.node.name=aks-agentpool-19737836-vmss000001,k8s.pod.name=customer-test-app-78d8bf887c-nplmk,k8s.pod.uid=efa8fdda-873c-4a6f-b02a-8d3b00bc34a7,k8s.container.name=test-app-java,cloud.provider=Azure,cloud.platform=azure_aks,k8s.replicaset.name=customer-java-very-big-756899c8b6,k8s.deployment.name=customer-java-very-big,k8s.replicaset.uid=69ef5d52-c770-4ec7-a3a2-2e2e8e885b3d";
@@ -34,10 +34,8 @@ abstract class OtelResourceCustomMetricTest {
3434
static final SmokeTestExtension testing =
3535
SmokeTestExtension.builder().otelResourceAttributesEnvVar(OTEL_RESOURCE_ATTRIBUTES).build();
3636

37-
private static final int COUNT = 100;
38-
3937
@Test
40-
@TargetUri(value = "/app", callCount = COUNT)
38+
@TargetUri(value = "/app")
4139
void testApp() {
4240
List<Envelope> metricsEnvelops = testing.mockedIngestion.getItemsEnvelopeDataType("MetricData");
4341
List<Envelope> otelResourceCustomMetrics = new ArrayList<>();
@@ -62,7 +60,8 @@ private static void verify(List<Envelope> metrics) {
6260

6361
private static void validateTags(Envelope envelope) {
6462
Map<String, String> tags = envelope.getTags();
65-
assertThat(tags.get("ai.internal.sdkVersion")).isNotNull();
63+
assertThat(tags).hasSize(3);
64+
assertThat(tags).containsKey("ai.internal.sdkVersion");
6665
assertThat(tags).containsEntry("ai.cloud.roleInstance", "customer-test-app-78d8bf887c-nplmk");
6766
assertThat(tags).containsEntry("ai.cloud.role", "customer-java-very-big");
6867
}
@@ -87,26 +86,26 @@ private static Map<String, String> parseOtelResourceAttributes() {
8786
}
8887

8988
@Environment(TOMCAT_8_JAVA_8)
90-
static class Tomcat8Java8Test extends OtelResourceCustomMetricTest {}
89+
static class Tomcat8Java8Test extends EnvVarOtelResourceAttributesTest {}
9190

9291
@Environment(TOMCAT_8_JAVA_8_OPENJ9)
93-
static class Tomcat8Java8OpenJ9Test extends OtelResourceCustomMetricTest {}
92+
static class Tomcat8Java8OpenJ9Test extends EnvVarOtelResourceAttributesTest {}
9493

9594
@Environment(TOMCAT_8_JAVA_11)
96-
static class Tomcat8Java11Test extends OtelResourceCustomMetricTest {}
95+
static class Tomcat8Java11Test extends EnvVarOtelResourceAttributesTest {}
9796

9897
@Environment(TOMCAT_8_JAVA_11_OPENJ9)
99-
static class Tomcat8Java11OpenJ9Test extends OtelResourceCustomMetricTest {}
98+
static class Tomcat8Java11OpenJ9Test extends EnvVarOtelResourceAttributesTest {}
10099

101100
@Environment(TOMCAT_8_JAVA_17)
102-
static class Tomcat8Java17Test extends OtelResourceCustomMetricTest {}
101+
static class Tomcat8Java17Test extends EnvVarOtelResourceAttributesTest {}
103102

104103
@Environment(TOMCAT_8_JAVA_21)
105-
static class Tomcat8Java21Test extends OtelResourceCustomMetricTest {}
104+
static class Tomcat8Java21Test extends EnvVarOtelResourceAttributesTest {}
106105

107106
@Environment(WILDFLY_13_JAVA_8)
108-
static class Wildfly13Java8Test extends OtelResourceCustomMetricTest {}
107+
static class Wildfly13Java8Test extends EnvVarOtelResourceAttributesTest {}
109108

110109
@Environment(WILDFLY_13_JAVA_8_OPENJ9)
111-
static class Wildfly13Java8OpenJ9Test extends OtelResourceCustomMetricTest {}
110+
static class Wildfly13Java8OpenJ9Test extends EnvVarOtelResourceAttributesTest {}
112111
}

smoke-tests/apps/RoleNameOverrides/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/AksRoleNameOverridesTest.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
import com.microsoft.applicationinsights.smoketest.schemav2.Data;
1717
import com.microsoft.applicationinsights.smoketest.schemav2.Envelope;
18+
import com.microsoft.applicationinsights.smoketest.schemav2.MetricData;
1819
import com.microsoft.applicationinsights.smoketest.schemav2.RequestData;
1920
import java.util.List;
2021
import java.util.Map;
@@ -39,6 +40,12 @@ void test() throws Exception {
3940

4041
private static void verifyRoleNameAndInstance(String roleName, String roleInstance)
4142
throws Exception {
43+
44+
// verify _OTELRESOURCE_ custom metric per role name
45+
List<Envelope> otelResourceMetrics =
46+
testing.mockedIngestion.waitForMetricItems("_OTELRESOURCE_", roleName, 1, true);
47+
verifyOtelResourceAttributeCustomMetric(otelResourceMetrics);
48+
4249
List<Envelope> rdList = testing.mockedIngestion.waitForItems("RequestData", 1);
4350
Envelope rdEnvelope = rdList.get(0);
4451
assertThat(rdEnvelope.getTags()).containsEntry("ai.cloud.role", roleName);
@@ -69,6 +76,22 @@ private static void verifyRoleNameAndInstance(String roleName, String roleInstan
6976
assertThat(serverTags.get("ai.cloud.roleInstance")).isEqualTo(roleInstance);
7077
}
7178

79+
private static void verifyOtelResourceAttributeCustomMetric(List<Envelope> otelResourceMetrics) {
80+
Map<String, String> tags = otelResourceMetrics.get(0).getTags();
81+
assertThat(tags.get("ai.internal.sdkVersion")).isNotNull();
82+
assertThat(tags.get("ai.cloud.roleInstance")).isEqualTo("test-pod-name");
83+
assertThat(tags.get("ai.cloud.role")).isEqualTo("test-deployment-name");
84+
85+
MetricData otelResourceMetricData =
86+
(MetricData) ((Data<?>) otelResourceMetrics.get(0).getData()).getBaseData();
87+
Map<String, String> properties = otelResourceMetricData.getProperties();
88+
assertThat(properties.get("cloud.provider")).isEqualTo("Azure");
89+
assertThat(properties.get("cloud.platform")).isEqualTo("azure_aks");
90+
assertThat(properties.get("telemetry.sdk.language")).isEqualTo("java");
91+
assertThat(properties.get("service.name")).isEqualTo("test-deployment-name");
92+
assertThat(properties.get("service.instance.id")).isEqualTo("test-pod-name");
93+
}
94+
7295
@Environment(TOMCAT_8_JAVA_8)
7396
static class Tomcat8Java8Test extends AksRoleNameOverridesTest {}
7497

smoke-tests/apps/RoleNameOverrides/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/RoleNameOverridesTest.java

Lines changed: 1 addition & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,7 @@
2929
@UseAgent("overrides_applicationinsights.json")
3030
abstract class RoleNameOverridesTest {
3131

32-
@RegisterExtension
33-
static final SmokeTestExtension testing =
34-
SmokeTestExtension.builder()
35-
.otelResourceAttributesEnvVar(
36-
"fakeOtelResourceKey1=fakeValue1,fakeOtelResourceKey2=fakeValue2,fakeOtelResourceKey3=fakeValue3")
37-
.build();
32+
@RegisterExtension static final SmokeTestExtension testing = SmokeTestExtension.create();
3833

3934
@Test
4035
@TargetUri("/app2")
@@ -49,11 +44,6 @@ void testApp3() throws Exception {
4944
}
5045

5146
private static void testApp(String roleName) throws Exception {
52-
// verify _OTELRESOURCE_ custom metric per role name
53-
List<Envelope> otelResourceMetrics =
54-
testing.mockedIngestion.waitForMetricItems("_OTELRESOURCE_", roleName, 1, true);
55-
verifyOtelResourceAttributeCustomMetric(otelResourceMetrics, roleName);
56-
5747
List<Envelope> rdList = testing.mockedIngestion.waitForItems("RequestData", 1);
5848
Envelope rdEnvelope = rdList.get(0);
5949
String operationId = rdEnvelope.getTags().get("ai.operation.id");
@@ -106,21 +96,6 @@ private static void testApp(String roleName) throws Exception {
10696
verifyHttpServerPreAggregatedMetrics(serverMetrics, roleName);
10797
}
10898

109-
private static void verifyOtelResourceAttributeCustomMetric(
110-
List<Envelope> otelResourceMetrics, String rolename) {
111-
Map<String, String> tags = otelResourceMetrics.get(0).getTags();
112-
assertThat(tags.get("ai.internal.sdkVersion")).isNotNull();
113-
assertThat(tags.get("ai.cloud.roleInstance")).isNotNull();
114-
assertThat(tags.get("ai.cloud.role")).isEqualTo(rolename);
115-
116-
MetricData otelResourceMetricData =
117-
(MetricData) ((Data<?>) otelResourceMetrics.get(0).getData()).getBaseData();
118-
Map<String, String> properties = otelResourceMetricData.getProperties();
119-
assertThat(properties.get("fakeOtelResourceKey1")).isEqualTo("fakeValue1");
120-
assertThat(properties.get("fakeOtelResourceKey2")).isEqualTo("fakeValue2");
121-
assertThat(properties.get("fakeOtelResourceKey3")).isEqualTo("fakeValue3");
122-
}
123-
12499
private static void verifyHttpClientPreAggregatedMetrics(
125100
List<Envelope> metrics, String roleName) {
126101
assertThat(metrics.size()).isEqualTo(1);

0 commit comments

Comments
 (0)