-
Notifications
You must be signed in to change notification settings - Fork 210
Use upstream micrometer instrumentation #3245
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from 7 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
6e249c1
Use upstream micrometer instrumentation
trask 7f277c4
Spotless
trask 7192e69
Handle micrometer metric namespace
trask cc800f7
fix
trask 6a1251d
Spotless
trask 963ae41
comment
trask d3475a4
fix
trask 18f44be
Merge remote-tracking branch 'origin/main' into use-upstream-micromet…
trask df1bb68
rename
trask 7538b19
comment
trask b665472
Merge remote-tracking branch 'origin/main' into use-upstream-micromet…
trask File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
78 changes: 78 additions & 0 deletions
78
.../java/com/microsoft/applicationinsights/agent/internal/exporter/BackCompatMetricData.java
This file contains hidden or 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,78 @@ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // Licensed under the MIT License. | ||
|
|
||
| package com.microsoft.applicationinsights.agent.internal.exporter; | ||
|
|
||
| import io.opentelemetry.sdk.common.InstrumentationScopeInfo; | ||
| import io.opentelemetry.sdk.metrics.data.Data; | ||
| import io.opentelemetry.sdk.metrics.data.MetricData; | ||
| import io.opentelemetry.sdk.metrics.data.MetricDataType; | ||
| import io.opentelemetry.sdk.resources.Resource; | ||
| import java.util.Arrays; | ||
| import java.util.Objects; | ||
| import java.util.regex.Pattern; | ||
| import java.util.stream.Collectors; | ||
|
|
||
| class BackCompatMetricData implements MetricData { | ||
|
|
||
| private static final Pattern NAME_AND_TAG_KEY_PATTERN = Pattern.compile("[^a-zA-Z0-9\\-]"); | ||
|
|
||
| private final MetricData delegate; | ||
| private final String name; | ||
|
|
||
| BackCompatMetricData(MetricData delegate) { | ||
| this.delegate = delegate; | ||
| this.name = backCompatName(delegate.getName()); | ||
| } | ||
|
|
||
| private static String backCompatName(String name) { | ||
| return NAME_AND_TAG_KEY_PATTERN.matcher(toSnakeCase(name)).replaceAll("_"); | ||
| } | ||
|
|
||
| private static String toSnakeCase(String value) { | ||
| // same logic as micrometer's NamingConvention.snakeCase | ||
| return Arrays.stream(value.split("\\.")) | ||
| .filter(Objects::nonNull) | ||
| .collect(Collectors.joining("_")); | ||
| } | ||
|
|
||
| @Override | ||
| public Resource getResource() { | ||
| return delegate.getResource(); | ||
| } | ||
|
|
||
| @Override | ||
| public InstrumentationScopeInfo getInstrumentationScopeInfo() { | ||
| return delegate.getInstrumentationScopeInfo(); | ||
| } | ||
|
|
||
| @Override | ||
| public String getName() { | ||
| return name; | ||
| } | ||
|
|
||
| @Override | ||
| public String getDescription() { | ||
| return delegate.getDescription(); | ||
| } | ||
|
|
||
| @Override | ||
| public String getUnit() { | ||
| return delegate.getUnit(); | ||
| } | ||
|
|
||
| @Override | ||
| public MetricDataType getType() { | ||
| return delegate.getType(); | ||
| } | ||
|
|
||
| @Override | ||
| public Data<?> getData() { | ||
| return delegate.getData(); | ||
| } | ||
|
|
||
| @Override | ||
| public boolean isEmpty() { | ||
| return delegate.isEmpty(); | ||
| } | ||
| } | ||
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,8 @@ | ||
| plugins { | ||
|
trask marked this conversation as resolved.
|
||
| id("ai.smoke-test-jar") | ||
| } | ||
|
|
||
| dependencies { | ||
| implementation("org.springframework.boot:spring-boot-starter-web:2.5.12") | ||
| implementation("io.micrometer:micrometer-core:1.4.1") | ||
| } | ||
16 changes: 16 additions & 0 deletions
16
...ldVersion/src/main/java/com/microsoft/applicationinsights/smoketestapp/SpringBootApp.java
This file contains hidden or 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,16 @@ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // Licensed under the MIT License. | ||
|
|
||
| package com.microsoft.applicationinsights.smoketestapp; | ||
|
|
||
| import org.springframework.boot.SpringApplication; | ||
| import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
|
|
||
| @SpringBootApplication | ||
| public class SpringBootApp { | ||
|
|
||
| public static void main(String[] args) { | ||
|
|
||
| SpringApplication.run(SpringBootApp.class, args); | ||
| } | ||
| } |
30 changes: 30 additions & 0 deletions
30
...dVersion/src/main/java/com/microsoft/applicationinsights/smoketestapp/TestController.java
This file contains hidden or 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,30 @@ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // Licensed under the MIT License. | ||
|
|
||
| package com.microsoft.applicationinsights.smoketestapp; | ||
|
|
||
| import io.micrometer.core.instrument.Counter; | ||
| import io.micrometer.core.instrument.Metrics; | ||
| import org.springframework.web.bind.annotation.GetMapping; | ||
| import org.springframework.web.bind.annotation.RestController; | ||
|
|
||
| @RestController | ||
| public class TestController { | ||
|
|
||
| private final Counter counter = Metrics.counter("test.counter", "tag1", "value1"); | ||
| private final Counter excludedCounter = Metrics.counter("test.counter.exclude.me"); | ||
| private final Counter anotherExcludedCounter = Metrics.counter("exclude.me.test.counter"); | ||
|
|
||
| @GetMapping("/") | ||
| public String root() { | ||
| return "OK"; | ||
| } | ||
|
|
||
| @GetMapping("/test") | ||
| public String test() { | ||
| excludedCounter.increment(); | ||
| anotherExcludedCounter.increment(); | ||
| counter.increment(); | ||
| return "OK!"; | ||
| } | ||
| } |
1 change: 1 addition & 0 deletions
1
smoke-tests/apps/MicrometerOldVersion/src/main/resources/application.properties
This file contains hidden or 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 @@ | ||
| management.metrics.export.azuremonitor.instrumentation-key=00000000-0000-0000-0000-000000000000 |
31 changes: 31 additions & 0 deletions
31
...rc/smokeTest/java/com/microsoft/applicationinsights/smoketest/MicrometerDisabledTest.java
This file contains hidden or 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,31 @@ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // Licensed under the MIT License. | ||
|
|
||
| package com.microsoft.applicationinsights.smoketest; | ||
|
|
||
| import static com.microsoft.applicationinsights.smoketest.EnvironmentValue.JAVA_8; | ||
| import static org.assertj.core.api.Assertions.assertThat; | ||
|
|
||
| import org.junit.jupiter.api.Test; | ||
| import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
|
||
| @Environment(JAVA_8) | ||
| @UseAgent("disabled_applicationinsights.json") | ||
| class MicrometerDisabledTest { | ||
|
|
||
| @RegisterExtension static final SmokeTestExtension testing = SmokeTestExtension.create(); | ||
|
|
||
| @Test | ||
| @TargetUri("/test") | ||
| void doMostBasicTest() throws Exception { | ||
| Telemetry telemetry = testing.getTelemetry(0); | ||
|
|
||
| assertThat(telemetry.rd.getName()).isEqualTo("GET /test"); | ||
| assertThat(telemetry.rd.getSuccess()).isTrue(); | ||
|
|
||
| // sleep a bit and make sure no micrometer metrics are reported | ||
| Thread.sleep(10000); | ||
| assertThat(testing.mockedIngestion.getItemsEnvelopeDataType("MetricData")) | ||
| .noneMatch(MicrometerTest::isMicrometerMetricWithValueOne); | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.