Skip to content
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

use interface instead of *stats.Engine in httpstats #101

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions httpstats/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func (n *nullBody) Read(b []byte) (int, error) { return 0, io.EOF }

type requestBody struct {
body io.ReadCloser
eng *stats.Engine
eng Reporter
req *http.Request
metrics *metrics
bytes int
Expand Down Expand Up @@ -92,7 +92,7 @@ func (r *requestBody) complete() {
}

type responseBody struct {
eng *stats.Engine
eng Reporter
res *http.Response
metrics *metrics
body io.ReadCloser
Expand Down
9 changes: 7 additions & 2 deletions httpstats/transport.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ import (
"github.com/segmentio/stats"
)

// Reporter is the interface for reporting stats at a given time
type Reporter interface {
ReportAt(time time.Time, metrics interface{}, tags ...stats.Tag)
}

// NewTransport wraps t to produce metrics on the default engine for every request
// sent and every response received.
func NewTransport(t http.RoundTripper) http.RoundTripper {
Expand All @@ -15,7 +20,7 @@ func NewTransport(t http.RoundTripper) http.RoundTripper {

// NewTransportWith wraps t to produce metrics on eng for every request sent and
// every response received.
func NewTransportWith(eng *stats.Engine, t http.RoundTripper) http.RoundTripper {
func NewTransportWith(eng Reporter, t http.RoundTripper) http.RoundTripper {
return &transport{
transport: t,
eng: eng,
Expand All @@ -24,7 +29,7 @@ func NewTransportWith(eng *stats.Engine, t http.RoundTripper) http.RoundTripper

type transport struct {
transport http.RoundTripper
eng *stats.Engine
eng Reporter
}

func (t *transport) RoundTrip(req *http.Request) (res *http.Response, err error) {
Expand Down