Skip to content
This repository has been archived by the owner on Dec 23, 2024. It is now read-only.

Adding custom statter option for clients to optionally use #36

Merged
merged 4 commits into from
Oct 4, 2018

Conversation

bstanley0811
Copy link
Contributor

The custom statter option will allow the client to receive all the metrics that Rye calculates around a request. The custom statter must contain a ReportStats method which will then receive information around the request, response, as well as the duration of the request handler. This is ideal for clients that would prefer to use the datadog-go library or any other library. Additionally, this is a potential option to move the Rye middleware away from any kind of statsD reporting.

The custom statter will allow the client to receive all the metrics
that Rye calculates around a request.  If a custom statter is
supplied, it must contain a ReportStats method which will then
recieve information around the request, response, as well as the
duration of the request handler.
Copy link
Contributor

@reybard reybard left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was mentioning to @caledhwa that I really dig this approach. Abstracting any potential interfaces for metrics reporters behind our own extra general interface is probably how it should have been done originally. As is, we married Rye a little too closely to the original StatsD lib and made it less extensible as a result.

I would like to hear what my teammates have to say, but this has a soft approval from me. I think there is a conversation that could be had here to remove the original Statter from Rye entirely and maybe just have this new CustomStatter iface be the main one, with possibly a pre-loaded StatsD-ready implementation of this iface that a user could opt to use without creating their own struct to satisfy it. On the other hand if we keep the original Statter in addition to this new one, we take nothing away from Rye's current functionality and add the ability to tee out metrics to StatsD AND/OR another sink.

Just my thoughts.

Copy link
Contributor

@caledhwa caledhwa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 Jeff makes a great case for your PR. I fully agree. I also don't want to introduce breaking change so I'm all for leaving the existing Config with the existing statsd Statter. That being said, I assume that your implementation of the custom reporter is to both do timing and counting? You have a single func you're representing.

@bstanley0811
Copy link
Contributor Author

The single func passes down data to the client (if it's set) and they can implement the inc method if they want to or not. Inc is great for metrics but not necessarily for monitoring, which is why I went with this approach of allowing the client to do whatever they want with the data.

FWIW, I was planning to parse the URL out from the request and not use the handler name, but after looking at this again, it would probably be nice to pass the handler name down and make this a little bit friendler so that the client won't have to derive that. Will update the PR to pass that along as well.

@codecov
Copy link

codecov bot commented Oct 4, 2018

Codecov Report

Merging #36 into master will not change coverage.
The diff coverage is 100%.

@@          Coverage Diff          @@
##           master    #36   +/-   ##
=====================================
  Coverage     100%   100%           
=====================================
  Files          10     10           
  Lines         259    261    +2     
=====================================
+ Hits          259    261    +2
Impacted Files Coverage Δ
rye.go 100% <100%> (ø) ⬆️

@bstanley0811
Copy link
Contributor Author

@caledhwa @jescochu - Added the handlerName to the ReportStats method to make it easier for the client to build metrics around it. Can I get another CR on this please?

Copy link
Contributor

@dselans dselans left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good to me; +1 for having a handler name in there. I would leave Statter as is for the time being.

rye.go Outdated
// CustomStatter allows the client to log any additional statsD metrics Rye
// computes around the request handler.
type CustomStatter interface {
ReportStats(string, time.Duration, *http.Request, *Response) error
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: I would name each arg in the interface - it makes the purpose more obvious.

As in:

ReportStats(name string, elapsed time.Duration, req *http.Request, resp *Response) error

@dselans dselans merged commit 9befe3a into master Oct 4, 2018
@dselans dselans deleted the send-metrics-to-client-statter branch October 4, 2018 14:55
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants