Package list golang-github-go-kit-kit / f6c023e
shipping: Take metrics as dependencies Marcus Olsson 5 years ago
4 changed file(s) with 48 addition(s) and 63 deletion(s). Raw diff Collapse all Expand all
22 import (
33 "time"
44
5 stdprometheus "github.com/prometheus/client_golang/prometheus"
6
75 "github.com/go-kit/kit/metrics"
8 kitprometheus "github.com/go-kit/kit/metrics/prometheus"
96
107 "github.com/go-kit/kit/examples/shipping/cargo"
118 "github.com/go-kit/kit/examples/shipping/location"
1815 }
1916
2017 // NewInstrumentingService returns an instance of an instrumenting Service.
21 func NewInstrumentingService(s Service) Service {
22 fieldKeys := []string{"method"}
23
24 requestCount := kitprometheus.NewCounter(stdprometheus.CounterOpts{
25 Namespace: "api",
26 Subsystem: "booking_service",
27 Name: "request_count",
28 Help: "Number of requests received.",
29 }, fieldKeys)
30
31 requestLatency := metrics.NewTimeHistogram(time.Microsecond, kitprometheus.NewSummary(stdprometheus.SummaryOpts{
32 Namespace: "api",
33 Subsystem: "booking_service",
34 Name: "request_latency_microseconds",
35 Help: "Total duration of requests in microseconds.",
36 }, fieldKeys))
37
18 func NewInstrumentingService(requestCount metrics.Counter, requestLatency metrics.TimeHistogram, s Service) Service {
3819 return &instrumentingService{
3920 requestCount: requestCount,
4021 requestLatency: requestLatency,
33 "time"
44
55 "github.com/go-kit/kit/metrics"
6 kitprometheus "github.com/go-kit/kit/metrics/prometheus"
7 stdprometheus "github.com/prometheus/client_golang/prometheus"
86
97 "github.com/go-kit/kit/examples/shipping/cargo"
108 "github.com/go-kit/kit/examples/shipping/location"
1816 }
1917
2018 // NewInstrumentingService returns an instance of an instrumenting Service.
21 func NewInstrumentingService(s Service) Service {
22 fieldKeys := []string{"method"}
23
24 requestCount := kitprometheus.NewCounter(stdprometheus.CounterOpts{
25 Namespace: "api",
26 Subsystem: "handling_service",
27 Name: "request_count",
28 Help: "Number of requests received.",
29 }, fieldKeys)
30
31 requestLatency := metrics.NewTimeHistogram(time.Microsecond, kitprometheus.NewSummary(stdprometheus.SummaryOpts{
32 Namespace: "api",
33 Subsystem: "handling_service",
34 Name: "request_latency_microseconds",
35 Help: "Total duration of requests in microseconds.",
36 }, fieldKeys))
37
19 func NewInstrumentingService(requestCount metrics.Counter, requestLatency metrics.TimeHistogram, s Service) Service {
3820 return &instrumentingService{
3921 requestCount: requestCount,
4022 requestLatency: requestLatency,
99 "syscall"
1010 "time"
1111
12 "github.com/go-kit/kit/log"
1312 stdprometheus "github.com/prometheus/client_golang/prometheus"
1413 "golang.org/x/net/context"
14
15 "github.com/go-kit/kit/log"
16 "github.com/go-kit/kit/metrics"
17 kitprometheus "github.com/go-kit/kit/metrics/prometheus"
1518
1619 "github.com/go-kit/kit/examples/shipping/booking"
1720 "github.com/go-kit/kit/examples/shipping/cargo"
6871 // Facilitate testing by adding some cargos.
6972 storeTestData(cargos)
7073
74 fieldKeys := []string{"method"}
75
7176 var rs routing.Service
7277 rs = routing.NewProxyingMiddleware(*routingServiceURL, ctx)(rs)
7378
7479 var bs booking.Service
7580 bs = booking.NewService(cargos, locations, handlingEvents, rs)
7681 bs = booking.NewLoggingService(log.NewContext(logger).With("component", "booking"), bs)
77 bs = booking.NewInstrumentingService(bs)
82 bs = booking.NewInstrumentingService(
83 kitprometheus.NewCounter(stdprometheus.CounterOpts{
84 Namespace: "api",
85 Subsystem: "booking_service",
86 Name: "request_count",
87 Help: "Number of requests received.",
88 }, fieldKeys),
89 metrics.NewTimeHistogram(time.Microsecond, kitprometheus.NewSummary(stdprometheus.SummaryOpts{
90 Namespace: "api",
91 Subsystem: "booking_service",
92 Name: "request_latency_microseconds",
93 Help: "Total duration of requests in microseconds.",
94 }, fieldKeys)), bs)
7895
7996 var ts tracking.Service
8097 ts = tracking.NewService(cargos, handlingEvents)
8198 ts = tracking.NewLoggingService(log.NewContext(logger).With("component", "tracking"), ts)
82 ts = tracking.NewInstrumentingService(ts)
99 ts = tracking.NewInstrumentingService(
100 kitprometheus.NewCounter(stdprometheus.CounterOpts{
101 Namespace: "api",
102 Subsystem: "tracking_service",
103 Name: "request_count",
104 Help: "Number of requests received.",
105 }, fieldKeys),
106 metrics.NewTimeHistogram(time.Microsecond, kitprometheus.NewSummary(stdprometheus.SummaryOpts{
107 Namespace: "api",
108 Subsystem: "tracking_service",
109 Name: "request_latency_microseconds",
110 Help: "Total duration of requests in microseconds.",
111 }, fieldKeys)), ts)
83112
84113 var hs handling.Service
85114 hs = handling.NewService(handlingEvents, handlingEventFactory, handlingEventHandler)
86115 hs = handling.NewLoggingService(log.NewContext(logger).With("component", "handling"), hs)
87 hs = handling.NewInstrumentingService(hs)
116 hs = handling.NewInstrumentingService(
117 kitprometheus.NewCounter(stdprometheus.CounterOpts{
118 Namespace: "api",
119 Subsystem: "handling_service",
120 Name: "request_count",
121 Help: "Number of requests received.",
122 }, fieldKeys),
123 metrics.NewTimeHistogram(time.Microsecond, kitprometheus.NewSummary(stdprometheus.SummaryOpts{
124 Namespace: "api",
125 Subsystem: "handling_service",
126 Name: "request_latency_microseconds",
127 Help: "Total duration of requests in microseconds.",
128 }, fieldKeys)), hs)
88129
89130 httpLogger := log.NewContext(logger).With("component", "http")
90131
22 import (
33 "time"
44
5 stdprometheus "github.com/prometheus/client_golang/prometheus"
6
75 "github.com/go-kit/kit/metrics"
8 kitprometheus "github.com/go-kit/kit/metrics/prometheus"
96 )
107
118 type instrumentingService struct {
1512 }
1613
1714 // NewInstrumentingService returns an instance of an instrumenting Service.
18 func NewInstrumentingService(s Service) Service {
19 fieldKeys := []string{"method"}
20
21 requestCount := kitprometheus.NewCounter(stdprometheus.CounterOpts{
22 Namespace: "api",
23 Subsystem: "tracking_service",
24 Name: "request_count",
25 Help: "Number of requests received.",
26 }, fieldKeys)
27
28 requestLatency := metrics.NewTimeHistogram(time.Microsecond, kitprometheus.NewSummary(stdprometheus.SummaryOpts{
29 Namespace: "api",
30 Subsystem: "tracking_service",
31 Name: "request_latency_microseconds",
32 Help: "Total duration of requests in microseconds.",
33 }, fieldKeys))
34
15 func NewInstrumentingService(requestCount metrics.Counter, requestLatency metrics.TimeHistogram, s Service) Service {
3516 return &instrumentingService{
3617 requestCount: requestCount,
3718 requestLatency: requestLatency,