-
Notifications
You must be signed in to change notification settings - Fork 202
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support dots in jmx attribute names (#2921)
- Loading branch information
Showing
10 changed files
with
235 additions
and
14 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
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
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,13 @@ | ||
plugins { | ||
id("ai.smoke-test-war") | ||
} | ||
|
||
dependencies { | ||
implementation("org.springframework.boot:spring-boot-starter-web:2.1.7.RELEASE") { | ||
exclude("org.springframework.boot", "spring-boot-starter-tomcat") | ||
} | ||
// this dependency is needed to make wildfly happy | ||
implementation("org.reactivestreams:reactive-streams:1.0.3") | ||
|
||
implementation("org.weakref:jmxutils:1.22") | ||
} |
41 changes: 41 additions & 0 deletions
41
...JmxMetric/src/main/java/com/microsoft/applicationinsights/smoketestapp/SpringBootApp.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,41 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
package com.microsoft.applicationinsights.smoketestapp; | ||
|
||
import java.lang.management.ManagementFactory; | ||
import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
import org.springframework.boot.builder.SpringApplicationBuilder; | ||
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer; | ||
import org.weakref.jmx.MBeanExporter; | ||
import org.weakref.jmx.Managed; | ||
import org.weakref.jmx.Nested; | ||
|
||
@SpringBootApplication | ||
public class SpringBootApp extends SpringBootServletInitializer { | ||
|
||
@Override | ||
protected SpringApplicationBuilder configure(SpringApplicationBuilder applicationBuilder) { | ||
|
||
MBeanExporter exporter = new MBeanExporter(ManagementFactory.getPlatformMBeanServer()); | ||
exporter.export("test:name=X", new NestedExample()); | ||
|
||
return applicationBuilder.sources(SpringBootApp.class); | ||
} | ||
|
||
public static class NestedExample { | ||
private final NestedObject nestedObject = new NestedObject(); | ||
|
||
@Nested | ||
public NestedObject getNestedObject() { | ||
return nestedObject; | ||
} | ||
|
||
public static final class NestedObject { | ||
@Managed | ||
public int getValue() { | ||
return 5; | ||
} | ||
} | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
...mxMetric/src/main/java/com/microsoft/applicationinsights/smoketestapp/TestController.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,21 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
package com.microsoft.applicationinsights.smoketestapp; | ||
|
||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
@RestController | ||
public class TestController { | ||
|
||
@GetMapping("/") | ||
public String root() { | ||
return "OK"; | ||
} | ||
|
||
@GetMapping("/test") | ||
public String test() { | ||
return "OK!"; | ||
} | ||
} |
68 changes: 68 additions & 0 deletions
68
...ic/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/DotInJmxMetricTest.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,68 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
package com.microsoft.applicationinsights.smoketest; | ||
|
||
import static com.microsoft.applicationinsights.smoketest.EnvironmentValue.TOMCAT_8_JAVA_11; | ||
import static com.microsoft.applicationinsights.smoketest.EnvironmentValue.TOMCAT_8_JAVA_17; | ||
import static com.microsoft.applicationinsights.smoketest.EnvironmentValue.TOMCAT_8_JAVA_19; | ||
import static com.microsoft.applicationinsights.smoketest.EnvironmentValue.TOMCAT_8_JAVA_20; | ||
import static com.microsoft.applicationinsights.smoketest.EnvironmentValue.TOMCAT_8_JAVA_8; | ||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import com.microsoft.applicationinsights.smoketest.schemav2.Data; | ||
import com.microsoft.applicationinsights.smoketest.schemav2.DataPoint; | ||
import com.microsoft.applicationinsights.smoketest.schemav2.Envelope; | ||
import com.microsoft.applicationinsights.smoketest.schemav2.MetricData; | ||
import java.util.List; | ||
import java.util.concurrent.TimeUnit; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
@UseAgent | ||
abstract class DotInJmxMetricTest { | ||
|
||
@RegisterExtension | ||
static final SmokeTestExtension testing = | ||
SmokeTestExtension.builder().setSelfDiagnosticsLevel("debug").build(); | ||
|
||
@Test | ||
@TargetUri("/test") | ||
void doMostBasicTest() throws Exception { | ||
testing.getTelemetry(0); | ||
|
||
List<Envelope> metricItems = | ||
testing.mockedIngestion.waitForItems( | ||
envelope -> isMetricWithName(envelope, "NameWithDot"), 1, 10, TimeUnit.SECONDS); | ||
|
||
MetricData data = (MetricData) ((Data<?>) metricItems.get(0).getData()).getBaseData(); | ||
List<DataPoint> points = data.getMetrics(); | ||
assertThat(points).hasSize(1); | ||
|
||
DataPoint point = points.get(0); | ||
assertThat(point.getValue()).isEqualTo(5); | ||
} | ||
|
||
private static boolean isMetricWithName(Envelope envelope, String metricName) { | ||
if (!envelope.getData().getBaseType().equals("MetricData")) { | ||
return false; | ||
} | ||
MetricData md = SmokeTestExtension.getBaseData(envelope); | ||
return metricName.equals(md.getMetrics().get(0).getName()); | ||
} | ||
|
||
@Environment(TOMCAT_8_JAVA_8) | ||
static class Tomcat8Java8Test extends DotInJmxMetricTest {} | ||
|
||
@Environment(TOMCAT_8_JAVA_11) | ||
static class Tomcat8Java11Test extends DotInJmxMetricTest {} | ||
|
||
@Environment(TOMCAT_8_JAVA_17) | ||
static class Tomcat8Java17Test extends DotInJmxMetricTest {} | ||
|
||
@Environment(TOMCAT_8_JAVA_19) | ||
static class Tomcat8Java19Test extends DotInJmxMetricTest {} | ||
|
||
@Environment(TOMCAT_8_JAVA_20) | ||
static class Tomcat8Java20Test extends DotInJmxMetricTest {} | ||
} |
17 changes: 17 additions & 0 deletions
17
smoke-tests/apps/DotInJmxMetric/src/smokeTest/resources/applicationinsights.json
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,17 @@ | ||
{ | ||
"role": { | ||
"name": "testrolename", | ||
"instance": "testroleinstance" | ||
}, | ||
"sampling": { | ||
"percentage": 100 | ||
}, | ||
"jmxMetrics": [ | ||
{ | ||
"name": "NameWithDot", | ||
"objectName": "test:name=X", | ||
"attribute": "NestedObject\\.Value" | ||
} | ||
], | ||
"metricIntervalSeconds": 5 | ||
} |
11 changes: 11 additions & 0 deletions
11
smoke-tests/apps/DotInJmxMetric/src/smokeTest/resources/logback-test.xml
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,11 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<configuration> | ||
<appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender"> | ||
<encoder> | ||
<pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} %-5level %logger{36} - %msg%n</pattern> | ||
</encoder> | ||
</appender> | ||
<root level="warn"> | ||
<appender-ref ref="CONSOLE"/> | ||
</root> | ||
</configuration> |