Previously, all the get-client-metrics* functions had two arities - one with a
metric type and one without. This commit removes the arity with a metric type
from all these functions since currently we only have one metric type and
since we aren't entirely certain of what we want the API to be when we add
additional metric types. When we add more metric types, we will change the API
in a backward compatible way.
Rather than having e.g a nil url and method in the metric data when metric-id
is filtered on, or a nil metric id if url and method are filtered on, use
specific schemas for metrics data returned for each metric category - metric
id, url, and url and method.
* Don't pass args into `isMatch()` in `ClientMetricFilter`, since this method
isn't static and so has access to the member variables.
Relevant gif: https://aphyr.com/data/posts/317/state.gif.
* Remove unused `metricTypeString` method
Rename the Metric Types from `bytes-read`/`init-repsonse` to
`full-response`/`initial-response` (note that the `initial-response` timer has
not yet been implemented, but when it is this will be its name).
We are subclassing `Timer` to create our own `ClientTimer` instances.
Unfortunately, the method we would like to use to register these on the
MetricRegistry, `getOrAdd()`, is private. Instead, we have to have our own
`getOrAddTimer()` to handle getting the timer if it has already been
registered, or registering a new one. This commit updates our implementation
of `getOrAddTimer()` to match the logic of `getOrAdd()`.
This commit does several things to improve the metrics API:
* Move get-client-metrics(-data) functions off of client:
Previously, the `get-client-metrics(-data)`/`.getClientMetrics(Data)`
functions were on the client. This didn't entirely make sense because if two
clients were using the same metric registry, these functions would actually
return metrics data for *all* clients, rather than just for the client the
function was called on. This commit removes these functions and changes the
tests to use the metrics namepsace/Metrics class versions instead, which take
a metric registry return all http-client related metrics on that metric
registry.
* Add a `with-url-and-method` namespace:
Move the timers that have both the url and the method from the `with-url`
namespace to a new `with-url-and-method` namepsace. This better matches the
data structure are returned in and the filtering mechanisms for getting them
back out (discussed below), and also removes a slight chance of having a
conflict with a url timer.
* Add a ClientTimer class:
Add a ClientTimer class that wraps the Timer class and also holds onto the
url, method, or metric id used to create the timer. Use this to add url,
method, metricId to ClientMetricData.
* Change the `getClientMetrics(Data)` methods to return a map of metric
category to an array of timers or timer data:
Previously, the methods for getting http client metrics/metric data out of a
metric registry returned a map of metric name to timer instance or metric
data. However, the metric name was most likely not useful to users, who
probably just want to iterate through the timers/data. This commit makes the
output of these functions more useful by returning arrays of timers/data
sorted into a map indexed by metric category (url, url and method, or metric
id).
* Add `getClientMetricsBy*` methods:
Add `getClientMetrics(Data)ByUrl`, `getClientMetrics(Data)ByUrlAndMethod`, and
`getClientMetrics(Data)ByMetricId` methods (and clojure versions) that allow
for filtering by a specific metric category and return an array of timers or
timer data that match the url, url and method, or metric id specified.
* Remove the filter-builder functions:
Previously, the `get-client-metrics(-data)` functions did filtering by taking
a filter map, and there were filter-builder functions to build these filter
maps. Now that there are separate filtering methods, these filter maps are no
longer used and the filter-builder functions are removed.
This commit adds metrics support to the http client (clojure and java, sync
and async). A metric registry can optionally be passed into the client as a
client option on creation. If a metric registry is present, timers will be
added to time each request.
By default, a timer is added for the URL (stripped of username, password,
query string, and path fragments) and the URL plus the method used for the
request. In addition, a request can include a `metric-id` option, which takes
a tuple of metric ids. If this request option is specified, a timer will be
created for each element of the metric id tuple - thus if the tuple is [:foo
:bar :baz] there will be a foo timer, a foo.bar timer, and a foo.bar.baz
timer.
In addition, each timer has a "MetricType" - currently there is only one
metric type, bytes-read, which is stopped when the full response has been
read. In the future, we may add "response-init" timers that get stopped when
the first byte of the response has been read.
This commit also adds a `get-client-metrics`/`.getClientMetrics` function that
takes a client instance and returns the http client-specific metrics from the
metric registry and a `get-client-metrics-data`/`.getClientMetricsData`
function for clojure and java sync and async clients to get out metrics data
from the client. This function takes a client instance and returns a map of
metric name to a map of metric data (for clojure) or a ClientMetricData object
(for java), both of which include the mean, count, and aggregate for the timer
These `get-client-metrics*`/`.getClientMetrics*` functions also have versions
that take a url, url and method, or metric id to allow for filtering of the
timers/metrics data returned by these functions.
The clojure versions of these functions take a metric filter map. There are
also metric filter builder functions to build up the type of metric filter
desired from a url, a url and method, or a metric id. These will prevent users
from having to know the specifics of how to build a metric themselves; instead
they can use a convenience function.
An empty metric id can be passed in to the filter to return all metric-id
timers.
Previously, anything that called `JavaClient/createClient` performed the same
coercion on the client options before passing them in as the argument. This
commit refactors `createClient` to do this coercion itself, thereby removing a
bunch of duplication.
Also, remove the `common/Client` schema and replace it with the
`HttpAsyncClient` interface, and remove an unnecessary call to `.start` in the
clojure `create-client`.
* Remove comment about :sslengine as an option, because it no longer seems to
be supported.
* Remove duplicate `.setSslContext`
* Use -> macro to clean up client creation and coersion of options
* Remove outdated TODO on the `common/Client` schema
* Remove unused `SslOptions` schema
* Remove unused imports
These functions were previously used for initializing an ssl context for the
clojure http client. However, with the clojure client initialization now just
wrapping the java code, these are no longer needed.
Previously, there were two completely separate code paths for java and clojure
http client initialization. This meant that there was a lot of duplicated
logic between them for handling a number of client options, such as redirect
strategy, ssl protocols and ciphers, and ssl setup.
This refactors clojure client initialization to use JavaClient/createClient,
thereby removing a lot of this duplication.
This commit removes duplicate functionality from the Clojure implementation and reuses the Java request/response handling impl. It doesn't address client creation so there are still two distinct paths for that.
The main changes are Ring <-> Java request/response conversion and the addition of interface ResponseDeliveryDelegate. The delegate implementations take care of the language-specific aspects of response building and promise delivery. One of the Clojure test namespaces is removed too.
There are a few places where we map request method keywords to
http-client function. The http client then maps them back to keywords
which is redundant. This adds a general request function to the protocol
that accepts a keyword method.
This commit updates us to the latest version of the Apache
HTTPAsyncClient. This is necessary in order to make it
possible to use this library in the same VM as the latest
version of clj-http, because they have some common dependencies.
The commit also cleans up some other dependencies while I was
in there.
- Fixes to ExceptionInsertingPipedInputStream
- Fix to async consumer and removal of decompression code
- Use ResponseContentEncoding to do all decompression including removing previous approach
- Clarify tests and add ConnectionException
Adds a new :as option that uses Apache's AsyncConsumer to return the response as quickly as possible then asynchronously stream the response body using piped input/output streams.