raskasa / metrics-okhttp Goto Github PK
View Code? Open in Web Editor NEWAn OkHttp HTTP client wrapper providing Metrics instrumentation of connection pools, request durations and rates, and other useful information.
License: Apache License 2.0
An OkHttp HTTP client wrapper providing Metrics instrumentation of connection pools, request durations and rates, and other useful information.
License: Apache License 2.0
When troubleshooting a single network request it's worthwhile to see how much time passed between submitting the request and actual execution. This duration should preferably be close to 0 (when there was some idle thread in a pool), however it will grow when task has to be "queued". Moreover, if the pool doesn't have a fixed number of threads, running a new task might require spawning thread (also consuming short amount of time).
NOTE: Monitoring how long a task takes to execute is different from how long it took between when the task was submitted and when it was executed.
SEE: http://www.nurkiewicz.com/2014/11/executorservice-10-tips-and-tricks.html
dispatcher-max-connections
and dispatcher-max-connections-per-host
are unnecessary.
If the user wants to use InstrumentedOkHttpClients.create(MetricRegistry, OkHttpClient)
, any custom Dispatcher
thats set on the passed in OkHttpClient
will be overridden.
Resources:
An instrumented OkHttpClient. Metrics to support:
Resources:
http://square.github.io/okhttp/javadoc/index.html
I'd rather do this once the EventListener
API becomes stable.
Resources:
I've tried a couple things, but nothing works at the moment.
We are interested in SSL negotiation times.
Hi,
Maybe I am missing something, but using the master (0.3.0-SNAPSHOT) I keep getting empty reports.
I tried this simple test:
@Test
public void instrumentAndNameDefaultClient2() {
final MetricRegistry registry2 = new MetricRegistry();
final OkHttpClient client = InstrumentedOkHttpClients.create(registry2, "custom");
// The connection, read, and write timeouts are the only configurations applied by default.
assertThat(client.connectTimeoutMillis()).isEqualTo(10_000);
assertThat(client.readTimeoutMillis()).isEqualTo(10_000);
assertThat(client.writeTimeoutMillis()).isEqualTo(10_000);
// Test with echo Postman
final HttpUrl url = new HttpUrl.Builder().scheme("https").host("echo.getpostman.com")
.addPathSegment("get").addQueryParameter("test", "123").build();
final Request request =
new Request.Builder().url(url).get().addHeader("cache-control", "no-cache").build();
Response response = null;
try {
response = client.newCall(request).execute();
assertThat(response.code()).isEqualTo(200);
System.out.println(response.body().string());
} catch (IOException | NullPointerException ex) {
System.out.println("Exception: " + ex);
} finally {
if (response != null) {
response.close();
}
}
final ConsoleReporter reporter =
ConsoleReporter.forRegistry(registry2).convertRatesTo(TimeUnit.SECONDS)
.convertDurationsTo(TimeUnit.MILLISECONDS).build();
reporter.report();
}
And it returns the following. Note, none of the counters are incremented, even though a successful call has been made using the client:
{"args":{"test":"123"},"headers":{"host":"postman-echo.com","accept-encoding":"gzip","cache-control":"no-cache","user-agent":"okhttp/3.6.0","x-forwarded-port":"443","x-forwarded-proto":"https"},"url":"https://postman-echo.com/get?test=123"}
5/3/17 1:08:44 PM ==============================================================
-- Gauges ----------------------------------------------------------------------
okhttp3.OkHttpClient.custom.connection-pool-idle-count
value = 2
okhttp3.OkHttpClient.custom.connection-pool-total-count
value = 2
-- Counters --------------------------------------------------------------------
okhttp3.OkHttpClient.custom.network-requests-running
count = 0
-- Meters ----------------------------------------------------------------------
okhttp3.OkHttpClient.custom.network-requests-completed
count = 0
mean rate = 0.00 events/second
1-minute rate = 0.00 events/second
5-minute rate = 0.00 events/second
15-minute rate = 0.00 events/second
okhttp3.OkHttpClient.custom.network-requests-submitted
count = 0
mean rate = 0.00 events/second
1-minute rate = 0.00 events/second
5-minute rate = 0.00 events/second
15-minute rate = 0.00 events/second
-- Timers ----------------------------------------------------------------------
okhttp3.OkHttpClient.custom.network-requests-duration
count = 0
mean rate = 0.00 calls/second
1-minute rate = 0.00 calls/second
5-minute rate = 0.00 calls/second
15-minute rate = 0.00 calls/second
min = 0.00 milliseconds
max = 0.00 milliseconds
mean = 0.00 milliseconds
stddev = 0.00 milliseconds
median = 0.00 milliseconds
75% <= 0.00 milliseconds
95% <= 0.00 milliseconds
98% <= 0.00 milliseconds
99% <= 0.00 milliseconds
99.9% <= 0.00 milliseconds
Process finished with exit code 0
I tried to debug it, but for some reasons it does not seem to reach the InstrumentedExecutorService. Any idea why it is not reported ?
If you have more than one client in a project (different services with different expected SLAs and demands), it would be useful to give each instrumented client an identifiable name.
You also don't want to in general share threadpools with clients between different services you consume.
When I run mvn clean test
from the terminal, it builds successfully.
When I try to run any unit tests via IntelliJ, I get the following error:
Information:Using Eclipse compiler to compile java sources
Information:Module "metrics-okhttp" was fully rebuilt due to project configuration/dependencies changes
Information:7/19/15, 11:22 PM - Compilation completed with 10 errors and 0 warnings in 3s 902ms
/Users/Kasa/IdeaProjects/metrics-okhttp/src/test/java/com/raskasa/metrics/okhttp/InstrumentedOkHttpClientsTest.java
Error:(1, 1) java: The type java.util.Optional cannot be resolved. It is indirectly referenced from required .class files
Error:(1, 1) java: The type java.util.OptionalDouble cannot be resolved. It is indirectly referenced from required .class files
Error:(1, 1) java: The type java.util.OptionalInt cannot be resolved. It is indirectly referenced from required .class files
Error:(1, 1) java: The type java.util.OptionalLong cannot be resolved. It is indirectly referenced from required .class files
Error:(1, 1) java: The type java.time.ZonedDateTime cannot be resolved. It is indirectly referenced from required .class files
Error:(1, 1) java: The type java.time.LocalDateTime cannot be resolved. It is indirectly referenced from required .class files
Error:(1, 1) java: The type java.time.OffsetDateTime cannot be resolved. It is indirectly referenced from required .class files
Error:(1, 1) java: The type java.time.OffsetTime cannot be resolved. It is indirectly referenced from required .class files
Error:(1, 1) java: The type java.time.LocalTime cannot be resolved. It is indirectly referenced from required .class files
Error:(1, 1) java: The type java.time.LocalDate cannot be resolved. It is indirectly referenced from required .class files
After trying to run any unit tests via IntelliJ, if I go back to the terminal and try to run mvn test
(note that a clean
isn't run), I get the following errors:
-------------------------------------------------------
T E S T S
-------------------------------------------------------
Running com.raskasa.metrics.okhttp.InstrumentedOkHttpClientsTest
Tests run: 2, Failures: 0, Errors: 2, Skipped: 0, Time elapsed: 0.07 sec <<< FAILURE!
createWithClient(com.raskasa.metrics.okhttp.InstrumentedOkHttpClientsTest) Time elapsed: 0.008 sec <<< ERROR!
java.lang.Error: Unresolved compilation problems:
The type java.util.Optional cannot be resolved. It is indirectly referenced from required .class files
The type java.util.OptionalDouble cannot be resolved. It is indirectly referenced from required .class files
The type java.util.OptionalInt cannot be resolved. It is indirectly referenced from required .class files
The type java.util.OptionalLong cannot be resolved. It is indirectly referenced from required .class files
The type java.time.ZonedDateTime cannot be resolved. It is indirectly referenced from required .class files
The type java.time.LocalDateTime cannot be resolved. It is indirectly referenced from required .class files
The type java.time.OffsetDateTime cannot be resolved. It is indirectly referenced from required .class files
The type java.time.OffsetTime cannot be resolved. It is indirectly referenced from required .class files
The type java.time.LocalTime cannot be resolved. It is indirectly referenced from required .class files
The type java.time.LocalDate cannot be resolved. It is indirectly referenced from required .class files
at com.raskasa.metrics.okhttp.InstrumentedOkHttpClientsTest.<init>(InstrumentedOkHttpClientsTest.java:1)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:422)
at org.junit.runners.BlockJUnit4ClassRunner.createTest(BlockJUnit4ClassRunner.java:217)
at org.junit.runners.BlockJUnit4ClassRunner$1.runReflectiveCall(BlockJUnit4ClassRunner.java:266)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.BlockJUnit4ClassRunner.methodBlock(BlockJUnit4ClassRunner.java:263)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.apache.maven.surefire.junit4.JUnit4Provider.execute(JUnit4Provider.java:252)
at org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:141)
at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:112)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at org.apache.maven.surefire.util.ReflectionUtils.invokeMethodWithArray(ReflectionUtils.java:189)
at org.apache.maven.surefire.booter.ProviderFactory$ProviderProxy.invoke(ProviderFactory.java:165)
at org.apache.maven.surefire.booter.ProviderFactory.invokeProvider(ProviderFactory.java:85)
at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:115)
at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:75)
createWithoutClient(com.raskasa.metrics.okhttp.InstrumentedOkHttpClientsTest) Time elapsed: 0.002 sec <<< ERROR!
java.lang.Error: Unresolved compilation problems:
The type java.util.Optional cannot be resolved. It is indirectly referenced from required .class files
The type java.util.OptionalDouble cannot be resolved. It is indirectly referenced from required .class files
The type java.util.OptionalInt cannot be resolved. It is indirectly referenced from required .class files
The type java.util.OptionalLong cannot be resolved. It is indirectly referenced from required .class files
The type java.time.ZonedDateTime cannot be resolved. It is indirectly referenced from required .class files
The type java.time.LocalDateTime cannot be resolved. It is indirectly referenced from required .class files
The type java.time.OffsetDateTime cannot be resolved. It is indirectly referenced from required .class files
The type java.time.OffsetTime cannot be resolved. It is indirectly referenced from required .class files
The type java.time.LocalTime cannot be resolved. It is indirectly referenced from required .class files
The type java.time.LocalDate cannot be resolved. It is indirectly referenced from required .class files
at com.raskasa.metrics.okhttp.InstrumentedOkHttpClientsTest.<init>(InstrumentedOkHttpClientsTest.java:1)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:422)
at org.junit.runners.BlockJUnit4ClassRunner.createTest(BlockJUnit4ClassRunner.java:217)
at org.junit.runners.BlockJUnit4ClassRunner$1.runReflectiveCall(BlockJUnit4ClassRunner.java:266)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.BlockJUnit4ClassRunner.methodBlock(BlockJUnit4ClassRunner.java:263)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.apache.maven.surefire.junit4.JUnit4Provider.execute(JUnit4Provider.java:252)
at org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:141)
at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:112)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at org.apache.maven.surefire.util.ReflectionUtils.invokeMethodWithArray(ReflectionUtils.java:189)
at org.apache.maven.surefire.booter.ProviderFactory$ProviderProxy.invoke(ProviderFactory.java:165)
at org.apache.maven.surefire.booter.ProviderFactory.invokeProvider(ProviderFactory.java:85)
at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:115)
at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:75)
But running mvn clean test
will resolve the errors.
The TravisCI build fails for oraclejdk7
with the following error:
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ metrics-okhttp ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 2 source files to /home/travis/build/raskasa/metrics-okhttp/target/test-classes
An exception has occurred in the compiler (1.7.0_76). Please file a bug at the Java Developer Connection (http://java.sun.com/webapps/bugreport) after checking the Bug Parade for duplicates. Include your program and the following diagnostic in your report. Thank you.
com.sun.tools.javac.code.Symbol$CompletionFailure: class file for java.util.Optional not found
NOTES:
JAVA_HOME
and JAVA8_HOME
is set to my Java 8 installation. JAVA7_HOME
is set to my Java 7 installation.1.7
.I've seen the library has been updated for okhttp3, any chance we can get a 0.3.0 release?
Copy the InstrumentedExecutorService
class into this library in order to rename the metrics for better user readability.
We are interested in DNS resolution/lookup times.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.