Skip to content

Commit 1dbb511

Browse files
apmmachineapmmachineJonasKunz
authored
test: synchronizing json spec (#2894)
Co-authored-by: apmmachine <[email protected]> Co-authored-by: Jonas Kunz <[email protected]>
1 parent 5c24d68 commit 1dbb511

File tree

2 files changed

+20
-32
lines changed

2 files changed

+20
-32
lines changed

apm-agent-core/src/test/java/co/elastic/apm/agent/impl/context/ServiceResourceTest.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@
3131
import specs.TestJsonSpec;
3232

3333
import javax.annotation.Nullable;
34+
import java.net.URI;
35+
import java.net.URISyntaxException;
3436
import java.util.Iterator;
3537
import java.util.Objects;
3638
import java.util.Spliterator;
@@ -126,13 +128,13 @@ private Span createSpan(JsonNode testCase) {
126128
}
127129
JsonNode httpJson = contextJson.get("http");
128130
if (httpJson != null) {
129-
JsonNode urlJson = httpJson.get("url");
130-
if (urlJson != null) {
131+
String urlValue = getTextValueOrNull(httpJson, "url");
132+
if (urlValue != null) {
131133
Url url = context.getHttp().getInternalUrl();
132-
url.withHostname(getTextValueOrNull(urlJson, "host"));
133-
JsonNode portJson = urlJson.get("port");
134-
if (portJson != null) {
135-
url.withPort(portJson.intValue());
134+
try {
135+
url.fillFrom(new URI(urlValue));
136+
} catch (URISyntaxException e) {
137+
throw new RuntimeException(e);
136138
}
137139
}
138140
}

apm-agent-core/src/test/resources/json-specs/service_resource_inference.json

Lines changed: 12 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -130,10 +130,7 @@
130130
"type": "elasticsearch"
131131
},
132132
"http": {
133-
"url": {
134-
"host": "my-cluster.com",
135-
"port": 9200
136-
}
133+
"url": "https://my-cluster.com:9200"
137134
}
138135
}
139136
},
@@ -153,10 +150,7 @@
153150
"body": "Text message"
154151
},
155152
"http": {
156-
"url": {
157-
"host": "my-broker.com",
158-
"port": 8888
159-
}
153+
"url": "https://my-broker.com:8888"
160154
}
161155
}
162156
},
@@ -173,10 +167,7 @@
173167
"subtype": "http",
174168
"context": {
175169
"http": {
176-
"url": {
177-
"host": "my-cluster.com",
178-
"port": 9200
179-
}
170+
"url": "http://my-cluster.com:9200"
180171
}
181172
}
182173
},
@@ -185,7 +176,7 @@
185176
"type": "http",
186177
"name": "my-cluster.com:9200"
187178
},
188-
"failure_message": "If `context.http.url` exists, output should be `${context.http.url.host}:${context.http.url.port}"
179+
"failure_message": "If `context.http.url` exists, output should be `${context.http.url}`"
189180
},
190181
{
191182
"span": {
@@ -194,19 +185,16 @@
194185
"subtype": "http",
195186
"context": {
196187
"http": {
197-
"url": {
198-
"host": "my-cluster.com",
199-
"port": -1
200-
}
188+
"url": "https://my-cluster.com"
201189
}
202190
}
203191
},
204-
"expected_resource": "my-cluster.com",
192+
"expected_resource": "my-cluster.com:443",
205193
"expected_service_target": {
206194
"type": "http",
207-
"name": "my-cluster.com"
195+
"name": "my-cluster.com:443"
208196
},
209-
"failure_message": "Negative `context.http.url.port` should be omitted from output"
197+
"failure_message": "`context.http.url` without an explicit default HTTPS port, output should be reported as `${context.http.url}:443`"
210198
},
211199
{
212200
"span": {
@@ -215,18 +203,16 @@
215203
"subtype": "http",
216204
"context": {
217205
"http": {
218-
"url": {
219-
"host": "my-cluster.com"
220-
}
206+
"url": "http://my-cluster.com"
221207
}
222208
}
223209
},
224-
"expected_resource": "my-cluster.com",
210+
"expected_resource": "my-cluster.com:80",
225211
"expected_service_target": {
226212
"type": "http",
227-
"name": "my-cluster.com"
213+
"name": "my-cluster.com:80"
228214
},
229-
"failure_message": "If `context.http.url.port` does not exist, output should be `${context.http.url.host}`"
215+
"failure_message": "`context.http.url` without an explicit default HTTP port, output should be reported as `${context.http.url}:80`"
230216
},
231217
{
232218
"span": {

0 commit comments

Comments
 (0)