OSDN Git Service

delete miner
[bytom/vapor.git] / vendor / github.com / go-kit / kit / examples / shipping / handling / instrumenting.go
1 package handling
2
3 import (
4         "time"
5
6         "github.com/go-kit/kit/metrics"
7
8         "github.com/go-kit/kit/examples/shipping/cargo"
9         "github.com/go-kit/kit/examples/shipping/location"
10         "github.com/go-kit/kit/examples/shipping/voyage"
11 )
12
13 type instrumentingService struct {
14         requestCount   metrics.Counter
15         requestLatency metrics.Histogram
16         Service
17 }
18
19 // NewInstrumentingService returns an instance of an instrumenting Service.
20 func NewInstrumentingService(counter metrics.Counter, latency metrics.Histogram, s Service) Service {
21         return &instrumentingService{
22                 requestCount:   counter,
23                 requestLatency: latency,
24                 Service:        s,
25         }
26 }
27
28 func (s *instrumentingService) RegisterHandlingEvent(completed time.Time, id cargo.TrackingID, voyageNumber voyage.Number,
29         loc location.UNLocode, eventType cargo.HandlingEventType) error {
30
31         defer func(begin time.Time) {
32                 s.requestCount.With("method", "register_incident").Add(1)
33                 s.requestLatency.With("method", "register_incident").Observe(time.Since(begin).Seconds())
34         }(time.Now())
35
36         return s.Service.RegisterHandlingEvent(completed, id, voyageNumber, loc, eventType)
37 }