diff --git a/apm-agent-core/src/test/java/co/elastic/apm/agent/impl/context/ServiceResourceTest.java b/apm-agent-core/src/test/java/co/elastic/apm/agent/impl/context/ServiceResourceTest.java index ceda768f37..7dfad3fd21 100644 --- a/apm-agent-core/src/test/java/co/elastic/apm/agent/impl/context/ServiceResourceTest.java +++ b/apm-agent-core/src/test/java/co/elastic/apm/agent/impl/context/ServiceResourceTest.java @@ -31,6 +31,8 @@ import specs.TestJsonSpec; import javax.annotation.Nullable; +import java.net.URI; +import java.net.URISyntaxException; import java.util.Iterator; import java.util.Objects; import java.util.Spliterator; @@ -126,13 +128,13 @@ private Span createSpan(JsonNode testCase) { } JsonNode httpJson = contextJson.get("http"); if (httpJson != null) { - JsonNode urlJson = httpJson.get("url"); - if (urlJson != null) { + String urlValue = getTextValueOrNull(httpJson, "url"); + if (urlValue != null) { Url url = context.getHttp().getInternalUrl(); - url.withHostname(getTextValueOrNull(urlJson, "host")); - JsonNode portJson = urlJson.get("port"); - if (portJson != null) { - url.withPort(portJson.intValue()); + try { + url.fillFrom(new URI(urlValue)); + } catch (URISyntaxException e) { + throw new RuntimeException(e); } } } diff --git a/apm-agent-core/src/test/resources/json-specs/service_resource_inference.json b/apm-agent-core/src/test/resources/json-specs/service_resource_inference.json index e5ced98a39..12ef6b13e8 100644 --- a/apm-agent-core/src/test/resources/json-specs/service_resource_inference.json +++ b/apm-agent-core/src/test/resources/json-specs/service_resource_inference.json @@ -130,10 +130,7 @@ "type": "elasticsearch" }, "http": { - "url": { - "host": "my-cluster.com", - "port": 9200 - } + "url": "https://my-cluster.com:9200" } } }, @@ -153,10 +150,7 @@ "body": "Text message" }, "http": { - "url": { - "host": "my-broker.com", - "port": 8888 - } + "url": "https://my-broker.com:8888" } } }, @@ -173,10 +167,7 @@ "subtype": "http", "context": { "http": { - "url": { - "host": "my-cluster.com", - "port": 9200 - } + "url": "http://my-cluster.com:9200" } } }, @@ -185,7 +176,7 @@ "type": "http", "name": "my-cluster.com:9200" }, - "failure_message": "If `context.http.url` exists, output should be `${context.http.url.host}:${context.http.url.port}" + "failure_message": "If `context.http.url` exists, output should be `${context.http.url}`" }, { "span": { @@ -194,19 +185,16 @@ "subtype": "http", "context": { "http": { - "url": { - "host": "my-cluster.com", - "port": -1 - } + "url": "https://my-cluster.com" } } }, - "expected_resource": "my-cluster.com", + "expected_resource": "my-cluster.com:443", "expected_service_target": { "type": "http", - "name": "my-cluster.com" + "name": "my-cluster.com:443" }, - "failure_message": "Negative `context.http.url.port` should be omitted from output" + "failure_message": "`context.http.url` without an explicit default HTTPS port, output should be reported as `${context.http.url}:443`" }, { "span": { @@ -215,18 +203,16 @@ "subtype": "http", "context": { "http": { - "url": { - "host": "my-cluster.com" - } + "url": "http://my-cluster.com" } } }, - "expected_resource": "my-cluster.com", + "expected_resource": "my-cluster.com:80", "expected_service_target": { "type": "http", - "name": "my-cluster.com" + "name": "my-cluster.com:80" }, - "failure_message": "If `context.http.url.port` does not exist, output should be `${context.http.url.host}`" + "failure_message": "`context.http.url` without an explicit default HTTP port, output should be reported as `${context.http.url}:80`" }, { "span": {