-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Adds the `outcome` tag to align with the synchronous Apache Http Client instrumentation. Adds instrumentation verification tests to ensure instrumentation is in line with base expectations for all HTTP clients (this would have caught the missing `outcome` tag when we aligned on adding that previously). Resolves gh-3790 Co-authored-by: Tommy Ludwig <8924140+shakuzen@users.noreply.github.com>
- Loading branch information
1 parent
4acbcc1
commit 7927fec
Showing
8 changed files
with
197 additions
and
2 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
82 changes: 82 additions & 0 deletions
82
...rometer/core/instrument/ApacheAsyncHttpClient5TimingInstrumentationVerificationTests.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,82 @@ | ||
/* | ||
* Copyright 2022 VMware, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package io.micrometer.core.instrument; | ||
|
||
import io.micrometer.common.lang.Nullable; | ||
import io.micrometer.core.instrument.binder.httpcomponents.DefaultUriMapper; | ||
import io.micrometer.core.instrument.binder.httpcomponents.hc5.MicrometerHttpClientInterceptor; | ||
import org.apache.hc.client5.http.async.methods.SimpleHttpRequest; | ||
import org.apache.hc.client5.http.async.methods.SimpleHttpResponse; | ||
import org.apache.hc.client5.http.async.methods.SimpleRequestBuilder; | ||
import org.apache.hc.client5.http.impl.async.CloseableHttpAsyncClient; | ||
import org.apache.hc.client5.http.impl.async.HttpAsyncClients; | ||
import org.apache.hc.core5.http.ContentType; | ||
|
||
import java.net.URI; | ||
import java.util.concurrent.ExecutionException; | ||
import java.util.concurrent.Future; | ||
|
||
class ApacheAsyncHttpClient5TimingInstrumentationVerificationTests | ||
extends HttpClientTimingInstrumentationVerificationTests<CloseableHttpAsyncClient> { | ||
|
||
@Override | ||
protected CloseableHttpAsyncClient clientInstrumentedWithMetrics() { | ||
MicrometerHttpClientInterceptor interceptor = new MicrometerHttpClientInterceptor(getRegistry(), Tags.empty(), | ||
true); | ||
CloseableHttpAsyncClient client = HttpAsyncClients.custom() | ||
.addRequestInterceptorFirst(interceptor.getRequestInterceptor()) | ||
.addResponseInterceptorLast(interceptor.getResponseInterceptor()) | ||
.build(); | ||
client.start(); | ||
return client; | ||
} | ||
|
||
@Nullable | ||
@Override | ||
protected CloseableHttpAsyncClient clientInstrumentedWithObservations() { | ||
return null; | ||
} | ||
|
||
@Override | ||
protected String timerName() { | ||
return "httpcomponents.httpclient.request"; | ||
} | ||
|
||
@Override | ||
protected void sendHttpRequest(CloseableHttpAsyncClient instrumentedClient, HttpMethod method, | ||
@Nullable byte[] body, URI baseUri, String templatedPath, String... pathVariables) { | ||
try { | ||
Future<SimpleHttpResponse> future = instrumentedClient | ||
.execute(makeRequest(method, body, baseUri, templatedPath, pathVariables), null); | ||
future.get(); | ||
} | ||
catch (InterruptedException | ExecutionException e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
|
||
private SimpleHttpRequest makeRequest(HttpMethod method, @Nullable byte[] body, URI baseUri, String templatedPath, | ||
String... pathVariables) { | ||
SimpleRequestBuilder builder = SimpleRequestBuilder.create(method.name()); | ||
if (body != null) { | ||
builder.setBody(body, ContentType.TEXT_PLAIN); | ||
} | ||
builder.setUri(URI.create(baseUri + substitutePathVariables(templatedPath, pathVariables))); | ||
builder.setHeader(DefaultUriMapper.URI_PATTERN_HEADER, templatedPath); | ||
return builder.build(); | ||
} | ||
|
||
} |
90 changes: 90 additions & 0 deletions
90
...crometer/core/instrument/ApacheAsyncHttpClientTimingInstrumentationVerificationTests.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,90 @@ | ||
/* | ||
* Copyright 2022 VMware, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package io.micrometer.core.instrument; | ||
|
||
import io.micrometer.common.lang.Nullable; | ||
import io.micrometer.core.instrument.binder.httpcomponents.DefaultUriMapper; | ||
import io.micrometer.core.instrument.binder.httpcomponents.MicrometerHttpClientInterceptor; | ||
import org.apache.http.HttpResponse; | ||
import org.apache.http.client.methods.HttpEntityEnclosingRequestBase; | ||
import org.apache.http.client.methods.HttpUriRequest; | ||
import org.apache.http.entity.BasicHttpEntity; | ||
import org.apache.http.impl.nio.client.CloseableHttpAsyncClient; | ||
import org.apache.http.impl.nio.client.HttpAsyncClients; | ||
|
||
import java.io.ByteArrayInputStream; | ||
import java.net.URI; | ||
import java.util.concurrent.ExecutionException; | ||
import java.util.concurrent.Future; | ||
|
||
class ApacheAsyncHttpClientTimingInstrumentationVerificationTests | ||
extends HttpClientTimingInstrumentationVerificationTests<CloseableHttpAsyncClient> { | ||
|
||
@Override | ||
protected CloseableHttpAsyncClient clientInstrumentedWithMetrics() { | ||
MicrometerHttpClientInterceptor interceptor = new MicrometerHttpClientInterceptor(getRegistry(), Tags.empty(), | ||
true); | ||
CloseableHttpAsyncClient client = HttpAsyncClients.custom() | ||
.addInterceptorFirst(interceptor.getRequestInterceptor()) | ||
.addInterceptorLast(interceptor.getResponseInterceptor()) | ||
.build(); | ||
client.start(); | ||
return client; | ||
} | ||
|
||
@Nullable | ||
@Override | ||
protected CloseableHttpAsyncClient clientInstrumentedWithObservations() { | ||
return null; | ||
} | ||
|
||
@Override | ||
protected String timerName() { | ||
return "httpcomponents.httpclient.request"; | ||
} | ||
|
||
@Override | ||
protected void sendHttpRequest(CloseableHttpAsyncClient instrumentedClient, HttpMethod method, | ||
@Nullable byte[] body, URI baseUri, String templatedPath, String... pathVariables) { | ||
try { | ||
Future<HttpResponse> future = instrumentedClient | ||
.execute(makeRequest(method, body, baseUri, templatedPath, pathVariables), null); | ||
future.get(); | ||
} | ||
catch (InterruptedException | ExecutionException e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
|
||
private HttpUriRequest makeRequest(HttpMethod method, @Nullable byte[] body, URI baseUri, String templatedPath, | ||
String... pathVariables) { | ||
HttpEntityEnclosingRequestBase request = new HttpEntityEnclosingRequestBase() { | ||
@Override | ||
public String getMethod() { | ||
return method.name(); | ||
} | ||
}; | ||
if (body != null) { | ||
BasicHttpEntity entity = new BasicHttpEntity(); | ||
entity.setContent(new ByteArrayInputStream(body)); | ||
request.setEntity(entity); | ||
} | ||
request.setURI(URI.create(baseUri + substitutePathVariables(templatedPath, pathVariables))); | ||
request.setHeader(DefaultUriMapper.URI_PATTERN_HEADER, templatedPath); | ||
return request; | ||
} | ||
|
||
} |