Commit graph

17 commits

Author SHA1 Message Date
Ruth Linehan
4f92c1ba55 (TK-402) Allow metric namespace to be configurable
Add two new client options - `server-id` and `metric-prefix` that allow the
metric namespace to be configured rather than always
`puppetlabs.http-client.experimental`.

If `server-id` is set, the metric namespace becomes
`puppetlabs.<server-id>.http-client.experimental`.

If `metric-prefix` is set, the metric namespace becomes
`<metric-prefix>.http-client.experimental`.

If both are set, `metric-prefix` wins out and a warning message is logged.

Also add a `get-client-metric-namespace`/`getMetricNamespace` method on the
client (clojure and java) to get back the metric namespace.
2016-10-03 12:06:15 -07:00
Ruth Linehan
d3325c494e (TK-316) Add back accidentally deleted test 2016-05-05 09:36:56 -07:00
Chris Price
6ec92839c1 (TK-316) More explicit methods for timer/data lists 2016-05-05 04:48:07 -07:00
Ruth Linehan
e403b2abc8 (TK-316) Add public url conversion method
When constructing url timers for request metrics, we strip off any username,
password, query params, and path fragments on the request uri. This commit
provides a public method to do this conversion of a url, so that users can
take the url they used for their request and easily figure out the url we used
for the metric.
2016-05-04 16:25:52 -07:00
Chris Price
f43594eddb (TK-316) Move private Metrics methods to impl class 2016-05-04 15:52:00 -07:00
Chris Price
e8a4ff4707 (TK-316) Move Java classes to separate metrics namespaces 2016-05-04 15:25:58 -07:00
Ruth Linehan
2e99e8a08c (TK-316) Throw error if no metric registry passed into get-client-metrics* fns
Previously, if any of the `get-client-metrics*` methods (in Clojure or Java)
had a nil metric registry passed into them, they would return nil. This commit
updates the behavior of all of these methods to instead return an error - a
schema error (clojure.lang.ExceptionInfo) for the clojure functions, and an
IllegalArgumentException for the java methods.
2016-05-04 15:10:24 -07:00
Ruth Linehan
da4d59fb7d (TK-316) Remove second arity of get-client-metrics* functions
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.
2016-05-04 10:38:41 -07:00
Ruth Linehan
43cdd07580 (TK-316) Add specific schemas for different categories of metrics data
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.
2016-05-04 10:07:48 -07:00
Ruth Linehan
55d565acd7 (TK-316) Rename bytes-read to full-response
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).
2016-04-22 15:08:52 -07:00
Ruth Linehan
b744e99749 (TK-316) Improve metrics API
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.
2016-04-19 13:13:10 -07:00
Ruth Linehan
df4e36a1aa (TK-316) Add metrics support
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.
2016-04-19 13:13:10 -07:00
Joe Pinsonault
c5489e0e43 (MAINT) Added fix/test for java coerceBodyType 2015-04-24 10:17:30 -07:00
Kevin Corcoran
95a88286ce (TK-145) fix default charset in Java client
Fix a bug in which a default charset of UTF-8 would be added to the
Content-Type header for certain requests.  This change restricts that
behavior to cases in which the body is a string and there is no charset
provided by the caller.
2015-02-13 11:32:04 -08:00
Jeremy Barlow
c1abea3e37 (TK-103) Remove AsyncClose class and references
This commit removes the `AsyncClose` class and references to it.  These
changes are in preparation for making the close call after the response
has been dereferenced - to be done in a later commit.  The `persistent`
flag/option was also removed from request handling as it will no longer
be used for determining whether or not the client should be closed
following a request.
2014-11-12 11:37:44 -08:00
Jeremy Barlow
f859bd907a (TK-101) Move closing of http clients to a separate thread
This commit moves each close call made on a `CloseableHttpAsyncClient`
from the thread on which the request callback is made over to a
different thread in order to avoid a deadlock.

Previously, the client close call was made in the context of thread from
which the callback was invoked.  The Apache HTTP async client library
makes these calls from one of its i/o reactor threads.  In the case of a
"failed" request, e.g., failure to make the client connection, this call
occurs in the context of the primary i/o reactor thread.  The client
close call does an indefinite join on the primary i/o reactor thread
and, therefore, this call causes a deadlock.  The client never closes
and all resources associated with it - threads, file descriptors, etc. -
remain open until the process is shutdown.

This commit introduces a new class, `AsyncClose`, which manages a small,
fixed size thread pool from which client close calls can be executed.
The `async` Clojure and `JavaClient` APIs were updated to use `AsyncClose`
whenever a client needs to be closed from a callback.
2014-10-20 14:22:56 -07:00
Chris Price
88a6e83d48 (PE-5567) Fix bug if content-type header has no charset
Prior to this commit, the Java client API would throw an NPE if
it got a response from a server where the Content-Type header
did not include a charset.
2014-08-22 08:03:36 -07:00