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

Commit

Permalink
Passing handler name down to ReportStats
Browse files Browse the repository at this point in the history
  • Loading branch information
bstanley0811 committed Oct 4, 2018
1 parent 249d2a0 commit b279db1
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
4 changes: 2 additions & 2 deletions rye.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ type MWHandler struct {
// CustomStatter allows the client to log any additional statsD metrics Rye
// computes around the request handler.
type CustomStatter interface {
ReportStats(time.Duration, *http.Request, *Response) error
ReportStats(string, time.Duration, *http.Request, *Response) error
}

// Config struct allows you to set a reference to a statsd.Statter and include it's stats rate.
Expand Down Expand Up @@ -162,7 +162,7 @@ func (m *MWHandler) do(w http.ResponseWriter, r *http.Request, handler Handler)
// If a CustomStatter is set, send the handler metrics to it.
// This allows the client to handle these metrics however it wants.
if m.Config.CustomStatter != nil && resp != nil {
go m.Config.CustomStatter.ReportStats(time.Since(startTime), r, resp)
go m.Config.CustomStatter.ReportStats(handlerName, time.Since(startTime), r, resp)
}
}()

Expand Down
13 changes: 8 additions & 5 deletions rye_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,16 @@ type statsTiming struct {
var reportedStats = make(chan fakeReportedStats)

type fakeReportedStats struct {
Duration time.Duration
Request *http.Request
Response *Response
HandlerName string
Duration time.Duration
Request *http.Request
Response *Response
}

type fakeCustomStatter struct{}

func (fcs *fakeCustomStatter) ReportStats(dur time.Duration, req *http.Request, res *Response) error {
reportedStats <- fakeReportedStats{dur, req, res}
func (fcs *fakeCustomStatter) ReportStats(handler string, dur time.Duration, req *http.Request, res *Response) error {
reportedStats <- fakeReportedStats{handler, dur, req, res}
return nil
}

Expand Down Expand Up @@ -368,6 +369,7 @@ var _ = Describe("Rye", func() {
var resp *Response

Eventually(reportedStats).Should(Receive(&receivedReportedStats))
Expect(receivedReportedStats.HandlerName).To(Equal("successWithResponse"))
Expect(receivedReportedStats.Duration.Seconds()/1000 > 0).To(Equal(true))
Expect(receivedReportedStats.Request).To(BeAssignableToTypeOf(request))
Expect(receivedReportedStats.Response).To(BeAssignableToTypeOf(resp))
Expand Down Expand Up @@ -396,6 +398,7 @@ var _ = Describe("Rye", func() {

var receivedReportedStats fakeReportedStats

Expect(receivedReportedStats.HandlerName).To(Equal(""))
Expect(receivedReportedStats.Duration.Nanoseconds()).To(Equal(int64(0)))
Expect(receivedReportedStats.Request).To(BeNil())
Expect(receivedReportedStats.Response).To(BeNil())
Expand Down

0 comments on commit b279db1

Please sign in to comment.