@Test public void testIoExceptionNotRecordedWhenCanceled() throws IOException { failedRequest(REQUEST_A, true); assertThat(hostMetrics.getMetrics()).isEmpty(); assertThatExceptionOfType(IOException.class).isThrownBy(() -> interceptor.intercept(chain)); assertThat(hostMetrics.getMetrics()).isEmpty(); }
@Override public Response intercept(Chain chain) throws IOException { HttpUrl url = chain.request().url(); String hostname = url.host(); int port = url.port(); Stopwatch stopwatch = Stopwatch.createStarted(); Response response; try { response = chain.proceed(chain.request()); } catch (IOException e) { if (!chain.call().isCanceled()) { hostEventsSink.recordIoException(serviceName, hostname, port); ioExceptionMeter.mark(); } throw e; } long micros = stopwatch.elapsed(TimeUnit.MICROSECONDS); hostEventsSink.record(serviceName, hostname, port, response.code(), micros); responseTimer.update(micros, TimeUnit.MICROSECONDS); return response; }
InstrumentedInterceptor implements Interceptor { @Override public Response intercept(Chain chain) throws IOException { HttpUrl url = chain.request().url(); String hostname = url.host(); int port = url.port(); Stopwatch stopwatch = Stopwatch.createStarted(); Response response; try { response = chain.proceed(chain.request()); } catch (IOException e) { if (!chain.call().isCanceled()) { hostEventsSink.recordIoException(serviceName, hostname, port); ioExceptionMeter.mark(); } throw e; } long micros = stopwatch.elapsed(TimeUnit.MICROSECONDS); hostEventsSink.record(serviceName, hostname, port, response.code(), micros); responseTimer.update(micros, TimeUnit.MICROSECONDS); return response; } }
InstrumentedInterceptor implements Interceptor { @Override public Response intercept(Chain chain) throws IOException { HttpUrl url = chain.request().url(); String hostname = url.host(); int port = url.port(); Stopwatch stopwatch = Stopwatch.createStarted(); Response response; try { response = chain.proceed(chain.request()); } catch (IOException e) { if (!chain.call().isCanceled()) { hostEventsSink.recordIoException(serviceName, hostname, port); ioExceptionMeter.mark(); } throw e; } long micros = stopwatch.elapsed(TimeUnit.MICROSECONDS); hostEventsSink.record(serviceName, hostname, port, response.code(), micros); responseTimer.update(micros, TimeUnit.MICROSECONDS); return response; } InstrumentedInterceptor(ClientMetrics clientMetrics, HostEventsSink hostEventsSink, String serviceName); }
InstrumentedInterceptor implements Interceptor { @Override public Response intercept(Chain chain) throws IOException { HttpUrl url = chain.request().url(); String hostname = url.host(); int port = url.port(); Stopwatch stopwatch = Stopwatch.createStarted(); Response response; try { response = chain.proceed(chain.request()); } catch (IOException e) { if (!chain.call().isCanceled()) { hostEventsSink.recordIoException(serviceName, hostname, port); ioExceptionMeter.mark(); } throw e; } long micros = stopwatch.elapsed(TimeUnit.MICROSECONDS); hostEventsSink.record(serviceName, hostname, port, response.code(), micros); responseTimer.update(micros, TimeUnit.MICROSECONDS); return response; } InstrumentedInterceptor(ClientMetrics clientMetrics, HostEventsSink hostEventsSink, String serviceName); @Override Response intercept(Chain chain); }
InstrumentedInterceptor implements Interceptor { @Override public Response intercept(Chain chain) throws IOException { HttpUrl url = chain.request().url(); String hostname = url.host(); int port = url.port(); Stopwatch stopwatch = Stopwatch.createStarted(); Response response; try { response = chain.proceed(chain.request()); } catch (IOException e) { if (!chain.call().isCanceled()) { hostEventsSink.recordIoException(serviceName, hostname, port); ioExceptionMeter.mark(); } throw e; } long micros = stopwatch.elapsed(TimeUnit.MICROSECONDS); hostEventsSink.record(serviceName, hostname, port, response.code(), micros); responseTimer.update(micros, TimeUnit.MICROSECONDS); return response; } InstrumentedInterceptor(ClientMetrics clientMetrics, HostEventsSink hostEventsSink, String serviceName); @Override Response intercept(Chain chain);  }