Shopify/statsd-instrument — pull request #39 by wvanbergen (2014-04-13 19:54:18+00:00)
Title: Refactor: pluggable backends

This is a big refactor.

Primarily, this PR adds pluggable backends:
- `UDPBackend` which actually sends UDP packets. Default in *production* environment. For now, the different variations are still all implemented in this class with if statements. Potentially we can make them separate backends.
- `LoggerBackend` which will log every StatsD call. Default in *development* environment.
- `NullBackend`: black hole. Default in *test* environment.
- `CaptureBackend`: a backend that can be used to capture StatsD calls so you can run assertions on it. A `capture_statsd_call` helper which uses this backend, and a bunch of assertion methods, are defined in the `StatsD::Instrument::Assertions` module to make writing tests easier.

All the stuff that is shared between backends now lives in the `StatsD::Instrument::Metric` class. This includes default values, prefix handling, cleaning up tags, etc. The `StatsD::Instrument::Environment` class contains all the ugly environment detection to find a default backend for your environment.

### Other things of note

- Drops support for Ruby 1.8.
- Tests are ported to Minitest, and increased coverage.
- `StatsD.mode` and `StatsD.enabled` have been removed.
- `StatsD.implementation`, `StatsD.server`, `StatsD.host`, `StatsD.port` settings are moved to the UDP backend, but they are preferably set using environment variables.
- Final remaining singleton state variables are `StatsD.default_sample_rate`, `StatsD.prefix`, `StatsD.logger` (initialized to `Rails.logger` if available), and `StatsD.backend`, the currently active backend.

### Points for discussion

- Instead of exceptions, the library now warns (to `StatsD.logger`) if you use features that your implementation does not support. I changed this because the library should not raise exceptions.
- The main API is the same as before, but the API for configuring the has changed. So we probably should do a major API version bump.
- De we want to change anything else if we do a major version bump with backwards incompatible changes?