Skip to content
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

Fix sampling overrides for http.target when url.query is present #3588

Merged
merged 5 commits into from
Mar 12, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -291,10 +291,12 @@ private LazyHttpTarget(Attributes attributes) {
this.attributes = attributes;
}

@SuppressWarnings("SystemOut")
trask marked this conversation as resolved.
Show resolved Hide resolved
private String get() {
if (!initialized) {
String urlQuery = attributes.get(SemanticAttributes.URL_QUERY);
value = attributes.get(SemanticAttributes.URL_PATH) + (urlQuery != null ? urlQuery : "");
value =
attributes.get(SemanticAttributes.URL_PATH) + (urlQuery != null ? "?" + urlQuery : "");
initialized = true;
}
return value;
Expand Down
1 change: 1 addition & 0 deletions smoke-tests/apps/SamplingOverrides/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ plugins {

dependencies {
implementation("org.hsqldb:hsqldb:2.5.1")
implementation("ch.qos.logback:logback-classic")
heyams marked this conversation as resolved.
Show resolved Hide resolved
}
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@ private int doGetInternal(HttpServletRequest req) throws Exception {
executeStatement(connection);
connection.close();
return 200;
} else if (pathInfo.equals("/test")) {
Connection connection = getHsqldbConnection();
connection.clearWarnings();
return 200;
} else {
throw new ServletException("Unexpected url: " + pathInfo);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
// 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_11_OPENJ9;
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 com.microsoft.applicationinsights.smoketest.EnvironmentValue.TOMCAT_8_JAVA_8_OPENJ9;
import static com.microsoft.applicationinsights.smoketest.EnvironmentValue.WILDFLY_13_JAVA_8;
import static com.microsoft.applicationinsights.smoketest.EnvironmentValue.WILDFLY_13_JAVA_8_OPENJ9;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.AssertionsForClassTypes.entry;

import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;

@UseAgent("applicationinsights-urlquery.json")
abstract class UrlQuerySamplingOverridesTest {

@RegisterExtension static final SmokeTestExtension testing = SmokeTestExtension.create();

@Test
@TargetUri(value = "/test?query")
void testUrlQuery() throws Exception {
Telemetry telemetry = testing.getTelemetry(0);

assertThat(telemetry.rd.getName()).isEqualTo("GET /SamplingOverrides/*");
assertThat(telemetry.rd.getUrl()).endsWith("http://localhost/SamplingOverrides/test?query");
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this assert is depended on #3581 fix.

assertThat(telemetry.rd.getResponseCode()).isEqualTo("200");
assertThat(telemetry.rd.getSuccess()).isTrue();
assertThat(telemetry.rd.getSource()).isNull();
assertThat(telemetry.rd.getProperties())
.containsExactly(entry("_MS.ProcessedByMetricExtractors", "True"));
}

@Environment(TOMCAT_8_JAVA_8)
static class Tomcat8Java8Test extends UrlQuerySamplingOverridesTest {}

@Environment(TOMCAT_8_JAVA_8_OPENJ9)
static class Tomcat8Java8OpenJ9Test extends UrlQuerySamplingOverridesTest {}

@Environment(TOMCAT_8_JAVA_11)
static class Tomcat8Java11Test extends UrlQuerySamplingOverridesTest {}

@Environment(TOMCAT_8_JAVA_11_OPENJ9)
static class Tomcat8Java11OpenJ9Test extends UrlQuerySamplingOverridesTest {}

@Environment(TOMCAT_8_JAVA_17)
static class Tomcat8Java17Test extends UrlQuerySamplingOverridesTest {}

@Environment(TOMCAT_8_JAVA_19)
static class Tomcat8Java19Test extends UrlQuerySamplingOverridesTest {}

@Environment(TOMCAT_8_JAVA_20)
static class Tomcat8Java20Test extends UrlQuerySamplingOverridesTest {}

@Environment(WILDFLY_13_JAVA_8)
static class Wildfly13Java8Test extends UrlQuerySamplingOverridesTest {}

@Environment(WILDFLY_13_JAVA_8_OPENJ9)
static class Wildfly13Java8OpenJ9Test extends UrlQuerySamplingOverridesTest {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"role": {
"name": "testrolename",
"instance": "testroleinstance"
},
"sampling": {
"percentage": 50,
"overrides": [
{
"telemetryType": "request",
"attributes": [
{
"key": "http.target",
"value": "/SamplingOverrides/test?query",
"matchType": "strict"
}
],
"percentage": 100
}
]
}
}
Loading