-
Notifications
You must be signed in to change notification settings - Fork 27
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make StatsdClient more convenient to use #45
Comments
Ha, funny you should mention this. I was just thinking about how to add some sort of Getting rid of the generic param and wrapping the sink in |
The only problem I see with wrapping the sink in an So, So my plan is to deprecate |
Yay, excellent! |
Remove the generic type `<T: MetricSink>` from the StatsdClient to make it more ergonomic to use. Prior to this, the easiest way to use the client was to put it behind a pointer of some kind and reference it like `Box<MetricClient>` or `Arc<MetricClient + Sync + Send>`. This is still possible but is now not required. Users of the client may simply refer to it directly without needing to include the concrete type of the `MetricSink`: `fn foo(some_param: StatsdClient) {}` This commit also introduces some documentation for the `StatsdClient` that describes the various ways this client can be shared between multiple threads. Fixes #45
Remove the generic type `<T: MetricSink>` from the StatsdClient to make it more ergonomic to use. Prior to this, the easiest way to use the client was to put it behind a pointer of some kind and reference it like `Box<MetricClient>` or `Arc<MetricClient + Sync + Send>`. This is still possible but is now not required. Users of the client may simply refer to it directly without needing to include the concrete type of the `MetricSink`: `fn foo(some_param: StatsdClient) {}` This commit also introduces some documentation for the `StatsdClient` that describes the various ways this client can be shared between multiple threads. Fixes #45
Looks good! Just had a single comment. Like the docs as well, very nice. |
Remove the generic type `<T: MetricSink>` from the StatsdClient to make it more ergonomic to use. Prior to this, the easiest way to use the client was to put it behind a pointer of some kind and reference it like `Box<MetricClient>` or `Arc<MetricClient + Sync + Send>`. This is still possible but is now not required. Users of the client may simply refer to it directly without needing to include the concrete type of the `MetricSink`: `fn foo(some_param: StatsdClient) {}` This commit also introduces some documentation for the `StatsdClient` that describes the various ways this client can be shared between multiple threads. Fixes #45
I'm using this crate to add metrics to a small server application that uses the Iron framework.
For a request handler, I have a struct that implements Iron's
Handler
trait (note that it needs to beSend + Sync
because it's used for handling requests in different threads).In the handler struct, I keep things that are needed when handling the requests. One of these things is a slog
Logger
. The nice thing about it is that I can construct it when starting up the application andclone()
it when I put it in the struct. And because it'sSend + Sync
, it works nicely.For metrics, I started out with putting a
StatsdClient<QueuingMetricSink>
into the handler struct.But then ideally, for testing, I'd just want to use a
StatsdClient<NopMetricSink>
instead.So what I ended up with in the end is a struct like this, with some methods that delegate to the client:
Using that, I can easily construct a client that uses
NopMetricSink
if I want to disable metrics.So I'm wondering if it would be generally more useful if
StatsdClient
itself didn't come with generics but instead wrapped its sink in anArc
(see the implementation ofLogger
).That would also make it nicer when code needs to pass a
StatsdClient
around as an argument/field (which happens in my code base and I'd expect in most real-world uses of this).What do you think?
The text was updated successfully, but these errors were encountered: