examples: fixes for new metrics
Peter Bourgon
7 years ago
9 | 9 | "os/signal" |
10 | 10 | "strings" |
11 | 11 | "syscall" |
12 | "time" | |
13 | 12 | |
14 | 13 | "github.com/apache/thrift/lib/go/thrift" |
15 | 14 | lightstep "github.com/lightstep/lightstep-tracer-go" |
60 | 59 | var ints, chars metrics.Counter |
61 | 60 | { |
62 | 61 | // Business level metrics. |
63 | ints = prometheus.NewCounter(stdprometheus.CounterOpts{ | |
62 | ints = prometheus.NewCounterFrom(stdprometheus.CounterOpts{ | |
64 | 63 | Namespace: "addsvc", |
65 | 64 | Name: "integers_summed", |
66 | 65 | Help: "Total count of integers summed via the Sum method.", |
67 | 66 | }, []string{}) |
68 | chars = prometheus.NewCounter(stdprometheus.CounterOpts{ | |
67 | chars = prometheus.NewCounterFrom(stdprometheus.CounterOpts{ | |
69 | 68 | Namespace: "addsvc", |
70 | 69 | Name: "characters_concatenated", |
71 | 70 | Help: "Total count of characters concatenated via the Concat method.", |
72 | 71 | }, []string{}) |
73 | 72 | } |
74 | var duration metrics.TimeHistogram | |
73 | var duration metrics.Histogram | |
75 | 74 | { |
76 | 75 | // Transport level metrics. |
77 | duration = metrics.NewTimeHistogram(time.Nanosecond, prometheus.NewSummary(stdprometheus.SummaryOpts{ | |
76 | duration = prometheus.NewSummaryFrom(stdprometheus.SummaryOpts{ | |
78 | 77 | Namespace: "addsvc", |
79 | 78 | Name: "request_duration_ns", |
80 | 79 | Help: "Request duration in nanoseconds.", |
81 | }, []string{"method", "success"})) | |
80 | }, []string{"method", "success"}) | |
82 | 81 | } |
83 | 82 | |
84 | 83 | // Tracing domain. |
131 | 130 | // Endpoint domain. |
132 | 131 | var sumEndpoint endpoint.Endpoint |
133 | 132 | { |
134 | sumDuration := duration.With(metrics.Field{Key: "method", Value: "Sum"}) | |
133 | sumDuration := duration.With("method", "Sum") | |
135 | 134 | sumLogger := log.NewContext(logger).With("method", "Sum") |
136 | 135 | |
137 | 136 | sumEndpoint = addsvc.MakeSumEndpoint(service) |
141 | 140 | } |
142 | 141 | var concatEndpoint endpoint.Endpoint |
143 | 142 | { |
144 | concatDuration := duration.With(metrics.Field{Key: "method", Value: "Concat"}) | |
143 | concatDuration := duration.With("method", "Concat") | |
145 | 144 | concatLogger := log.NewContext(logger).With("method", "Concat") |
146 | 145 | |
147 | 146 | concatEndpoint = addsvc.MakeConcatEndpoint(service) |
87 | 87 | // the duration of each invocation to the passed histogram. The middleware adds |
88 | 88 | // a single field: "success", which is "true" if no error is returned, and |
89 | 89 | // "false" otherwise. |
90 | func EndpointInstrumentingMiddleware(duration metrics.TimeHistogram) endpoint.Middleware { | |
90 | func EndpointInstrumentingMiddleware(duration metrics.Histogram) endpoint.Middleware { | |
91 | 91 | return func(next endpoint.Endpoint) endpoint.Endpoint { |
92 | 92 | return func(ctx context.Context, request interface{}) (response interface{}, err error) { |
93 | 93 | |
94 | 94 | defer func(begin time.Time) { |
95 | f := metrics.Field{Key: "success", Value: fmt.Sprint(err == nil)} | |
96 | duration.With(f).Observe(time.Since(begin)) | |
95 | duration.With("success", fmt.Sprint(err == nil)).Observe(time.Since(begin).Seconds()) | |
97 | 96 | }(time.Now()) |
98 | 97 | return next(ctx, request) |
99 | 98 |
152 | 152 | |
153 | 153 | func (mw serviceInstrumentingMiddleware) Sum(ctx context.Context, a, b int) (int, error) { |
154 | 154 | v, err := mw.next.Sum(ctx, a, b) |
155 | mw.ints.Add(uint64(v)) | |
155 | mw.ints.Add(float64(v)) | |
156 | 156 | return v, err |
157 | 157 | } |
158 | 158 | |
159 | 159 | func (mw serviceInstrumentingMiddleware) Concat(ctx context.Context, a, b string) (string, error) { |
160 | 160 | v, err := mw.next.Concat(ctx, a, b) |
161 | mw.chars.Add(uint64(len(v))) | |
161 | mw.chars.Add(float64(len(v))) | |
162 | 162 | return v, err |
163 | 163 | } |
10 | 10 | |
11 | 11 | type instrumentingService struct { |
12 | 12 | requestCount metrics.Counter |
13 | requestLatency metrics.TimeHistogram | |
13 | requestLatency metrics.Histogram | |
14 | 14 | Service |
15 | 15 | } |
16 | 16 | |
17 | 17 | // NewInstrumentingService returns an instance of an instrumenting Service. |
18 | func NewInstrumentingService(requestCount metrics.Counter, requestLatency metrics.TimeHistogram, s Service) Service { | |
18 | func NewInstrumentingService(requestCount metrics.Counter, requestLatency metrics.Histogram, s Service) Service { | |
19 | 19 | return &instrumentingService{ |
20 | 20 | requestCount: requestCount, |
21 | 21 | requestLatency: requestLatency, |
25 | 25 | |
26 | 26 | func (s *instrumentingService) BookNewCargo(origin, destination location.UNLocode, arrivalDeadline time.Time) (cargo.TrackingID, error) { |
27 | 27 | defer func(begin time.Time) { |
28 | methodField := metrics.Field{Key: "method", Value: "book"} | |
29 | s.requestCount.With(methodField).Add(1) | |
30 | s.requestLatency.With(methodField).Observe(time.Since(begin)) | |
28 | s.requestCount.With("method", "book").Add(1) | |
29 | s.requestLatency.With("method", "book").Observe(time.Since(begin).Seconds()) | |
31 | 30 | }(time.Now()) |
32 | 31 | |
33 | 32 | return s.Service.BookNewCargo(origin, destination, arrivalDeadline) |
35 | 34 | |
36 | 35 | func (s *instrumentingService) LoadCargo(id cargo.TrackingID) (c Cargo, err error) { |
37 | 36 | defer func(begin time.Time) { |
38 | methodField := metrics.Field{Key: "method", Value: "load"} | |
39 | s.requestCount.With(methodField).Add(1) | |
40 | s.requestLatency.With(methodField).Observe(time.Since(begin)) | |
37 | s.requestCount.With("method", "load").Add(1) | |
38 | s.requestLatency.With("method", "load").Observe(time.Since(begin).Seconds()) | |
41 | 39 | }(time.Now()) |
42 | 40 | |
43 | 41 | return s.Service.LoadCargo(id) |
45 | 43 | |
46 | 44 | func (s *instrumentingService) RequestPossibleRoutesForCargo(id cargo.TrackingID) []cargo.Itinerary { |
47 | 45 | defer func(begin time.Time) { |
48 | methodField := metrics.Field{Key: "method", Value: "request_routes"} | |
49 | s.requestCount.With(methodField).Add(1) | |
50 | s.requestLatency.With(methodField).Observe(time.Since(begin)) | |
46 | s.requestCount.With("method", "request_routes").Add(1) | |
47 | s.requestLatency.With("method", "request_routes").Observe(time.Since(begin).Seconds()) | |
51 | 48 | }(time.Now()) |
52 | 49 | |
53 | 50 | return s.Service.RequestPossibleRoutesForCargo(id) |
55 | 52 | |
56 | 53 | func (s *instrumentingService) AssignCargoToRoute(id cargo.TrackingID, itinerary cargo.Itinerary) (err error) { |
57 | 54 | defer func(begin time.Time) { |
58 | methodField := metrics.Field{Key: "method", Value: "assign_to_route"} | |
59 | s.requestCount.With(methodField).Add(1) | |
60 | s.requestLatency.With(methodField).Observe(time.Since(begin)) | |
55 | s.requestCount.With("method", "assign_to_route").Add(1) | |
56 | s.requestLatency.With("method", "assign_to_route").Observe(time.Since(begin).Seconds()) | |
61 | 57 | }(time.Now()) |
62 | 58 | |
63 | 59 | return s.Service.AssignCargoToRoute(id, itinerary) |
65 | 61 | |
66 | 62 | func (s *instrumentingService) ChangeDestination(id cargo.TrackingID, l location.UNLocode) (err error) { |
67 | 63 | defer func(begin time.Time) { |
68 | methodField := metrics.Field{Key: "method", Value: "change_destination"} | |
69 | s.requestCount.With(methodField).Add(1) | |
70 | s.requestLatency.With(methodField).Observe(time.Since(begin)) | |
64 | s.requestCount.With("method", "change_destination").Add(1) | |
65 | s.requestLatency.With("method", "change_destination").Observe(time.Since(begin).Seconds()) | |
71 | 66 | }(time.Now()) |
72 | 67 | |
73 | 68 | return s.Service.ChangeDestination(id, l) |
75 | 70 | |
76 | 71 | func (s *instrumentingService) Cargos() []Cargo { |
77 | 72 | defer func(begin time.Time) { |
78 | methodField := metrics.Field{Key: "method", Value: "list_cargos"} | |
79 | s.requestCount.With(methodField).Add(1) | |
80 | s.requestLatency.With(methodField).Observe(time.Since(begin)) | |
73 | s.requestCount.With("method", "list_cargos").Add(1) | |
74 | s.requestLatency.With("method", "list_cargos").Observe(time.Since(begin).Seconds()) | |
81 | 75 | }(time.Now()) |
82 | 76 | |
83 | 77 | return s.Service.Cargos() |
85 | 79 | |
86 | 80 | func (s *instrumentingService) Locations() []Location { |
87 | 81 | defer func(begin time.Time) { |
88 | methodField := metrics.Field{Key: "method", Value: "list_locations"} | |
89 | s.requestCount.With(methodField).Add(1) | |
90 | s.requestLatency.With(methodField).Observe(time.Since(begin)) | |
82 | s.requestCount.With("method", "list_locations").Add(1) | |
83 | s.requestLatency.With("method", "list_locations").Observe(time.Since(begin).Seconds()) | |
91 | 84 | }(time.Now()) |
92 | 85 | |
93 | 86 | return s.Service.Locations() |
11 | 11 | |
12 | 12 | type instrumentingService struct { |
13 | 13 | requestCount metrics.Counter |
14 | requestLatency metrics.TimeHistogram | |
14 | requestLatency metrics.Histogram | |
15 | 15 | Service |
16 | 16 | } |
17 | 17 | |
18 | 18 | // NewInstrumentingService returns an instance of an instrumenting Service. |
19 | func NewInstrumentingService(requestCount metrics.Counter, requestLatency metrics.TimeHistogram, s Service) Service { | |
19 | func NewInstrumentingService(requestCount metrics.Counter, requestLatency metrics.Histogram, s Service) Service { | |
20 | 20 | return &instrumentingService{ |
21 | 21 | requestCount: requestCount, |
22 | 22 | requestLatency: requestLatency, |
28 | 28 | loc location.UNLocode, eventType cargo.HandlingEventType) error { |
29 | 29 | |
30 | 30 | defer func(begin time.Time) { |
31 | methodField := metrics.Field{Key: "method", Value: "register_incident"} | |
32 | s.requestCount.With(methodField).Add(1) | |
33 | s.requestLatency.With(methodField).Observe(time.Since(begin)) | |
31 | s.requestCount.With("method", "register_incident").Add(1) | |
32 | s.requestLatency.With("method", "register_incident").Observe(time.Since(begin).Seconds()) | |
34 | 33 | }(time.Now()) |
35 | 34 | |
36 | 35 | return s.Service.RegisterHandlingEvent(completionTime, trackingID, voyage, loc, eventType) |
13 | 13 | "golang.org/x/net/context" |
14 | 14 | |
15 | 15 | "github.com/go-kit/kit/log" |
16 | "github.com/go-kit/kit/metrics" | |
17 | 16 | kitprometheus "github.com/go-kit/kit/metrics/prometheus" |
18 | 17 | |
19 | 18 | "github.com/go-kit/kit/examples/shipping/booking" |
80 | 79 | bs = booking.NewService(cargos, locations, handlingEvents, rs) |
81 | 80 | bs = booking.NewLoggingService(log.NewContext(logger).With("component", "booking"), bs) |
82 | 81 | bs = booking.NewInstrumentingService( |
83 | kitprometheus.NewCounter(stdprometheus.CounterOpts{ | |
82 | kitprometheus.NewCounterFrom(stdprometheus.CounterOpts{ | |
84 | 83 | Namespace: "api", |
85 | 84 | Subsystem: "booking_service", |
86 | 85 | Name: "request_count", |
87 | 86 | Help: "Number of requests received.", |
88 | 87 | }, fieldKeys), |
89 | metrics.NewTimeHistogram(time.Microsecond, kitprometheus.NewSummary(stdprometheus.SummaryOpts{ | |
88 | kitprometheus.NewSummaryFrom(stdprometheus.SummaryOpts{ | |
90 | 89 | Namespace: "api", |
91 | 90 | Subsystem: "booking_service", |
92 | 91 | Name: "request_latency_microseconds", |
93 | 92 | Help: "Total duration of requests in microseconds.", |
94 | }, fieldKeys)), bs) | |
93 | }, fieldKeys), | |
94 | bs, | |
95 | ) | |
95 | 96 | |
96 | 97 | var ts tracking.Service |
97 | 98 | ts = tracking.NewService(cargos, handlingEvents) |
98 | 99 | ts = tracking.NewLoggingService(log.NewContext(logger).With("component", "tracking"), ts) |
99 | 100 | ts = tracking.NewInstrumentingService( |
100 | kitprometheus.NewCounter(stdprometheus.CounterOpts{ | |
101 | kitprometheus.NewCounterFrom(stdprometheus.CounterOpts{ | |
101 | 102 | Namespace: "api", |
102 | 103 | Subsystem: "tracking_service", |
103 | 104 | Name: "request_count", |
104 | 105 | Help: "Number of requests received.", |
105 | 106 | }, fieldKeys), |
106 | metrics.NewTimeHistogram(time.Microsecond, kitprometheus.NewSummary(stdprometheus.SummaryOpts{ | |
107 | kitprometheus.NewSummaryFrom(stdprometheus.SummaryOpts{ | |
107 | 108 | Namespace: "api", |
108 | 109 | Subsystem: "tracking_service", |
109 | 110 | Name: "request_latency_microseconds", |
110 | 111 | Help: "Total duration of requests in microseconds.", |
111 | }, fieldKeys)), ts) | |
112 | }, fieldKeys), | |
113 | ts, | |
114 | ) | |
112 | 115 | |
113 | 116 | var hs handling.Service |
114 | 117 | hs = handling.NewService(handlingEvents, handlingEventFactory, handlingEventHandler) |
115 | 118 | hs = handling.NewLoggingService(log.NewContext(logger).With("component", "handling"), hs) |
116 | 119 | hs = handling.NewInstrumentingService( |
117 | kitprometheus.NewCounter(stdprometheus.CounterOpts{ | |
120 | kitprometheus.NewCounterFrom(stdprometheus.CounterOpts{ | |
118 | 121 | Namespace: "api", |
119 | 122 | Subsystem: "handling_service", |
120 | 123 | Name: "request_count", |
121 | 124 | Help: "Number of requests received.", |
122 | 125 | }, fieldKeys), |
123 | metrics.NewTimeHistogram(time.Microsecond, kitprometheus.NewSummary(stdprometheus.SummaryOpts{ | |
126 | kitprometheus.NewSummaryFrom(stdprometheus.SummaryOpts{ | |
124 | 127 | Namespace: "api", |
125 | 128 | Subsystem: "handling_service", |
126 | 129 | Name: "request_latency_microseconds", |
127 | 130 | Help: "Total duration of requests in microseconds.", |
128 | }, fieldKeys)), hs) | |
131 | }, fieldKeys), | |
132 | hs, | |
133 | ) | |
129 | 134 | |
130 | 135 | httpLogger := log.NewContext(logger).With("component", "http") |
131 | 136 |
7 | 7 | |
8 | 8 | type instrumentingService struct { |
9 | 9 | requestCount metrics.Counter |
10 | requestLatency metrics.TimeHistogram | |
10 | requestLatency metrics.Histogram | |
11 | 11 | Service |
12 | 12 | } |
13 | 13 | |
14 | 14 | // NewInstrumentingService returns an instance of an instrumenting Service. |
15 | func NewInstrumentingService(requestCount metrics.Counter, requestLatency metrics.TimeHistogram, s Service) Service { | |
15 | func NewInstrumentingService(requestCount metrics.Counter, requestLatency metrics.Histogram, s Service) Service { | |
16 | 16 | return &instrumentingService{ |
17 | 17 | requestCount: requestCount, |
18 | 18 | requestLatency: requestLatency, |
22 | 22 | |
23 | 23 | func (s *instrumentingService) Track(id string) (Cargo, error) { |
24 | 24 | defer func(begin time.Time) { |
25 | methodField := metrics.Field{Key: "method", Value: "track"} | |
26 | s.requestCount.With(methodField).Add(1) | |
27 | s.requestLatency.With(methodField).Observe(time.Since(begin)) | |
25 | s.requestCount.With("method", "track").Add(1) | |
26 | s.requestLatency.With("method", "track").Observe(time.Since(begin).Seconds()) | |
28 | 27 | }(time.Now()) |
29 | 28 | |
30 | 29 | return s.Service.Track(id) |
8 | 8 | |
9 | 9 | type instrumentingMiddleware struct { |
10 | 10 | requestCount metrics.Counter |
11 | requestLatency metrics.TimeHistogram | |
11 | requestLatency metrics.Histogram | |
12 | 12 | countResult metrics.Histogram |
13 | 13 | next StringService |
14 | 14 | } |
15 | 15 | |
16 | 16 | func (mw instrumentingMiddleware) Uppercase(s string) (output string, err error) { |
17 | 17 | defer func(begin time.Time) { |
18 | methodField := metrics.Field{Key: "method", Value: "uppercase"} | |
19 | errorField := metrics.Field{Key: "error", Value: fmt.Sprintf("%v", err)} | |
20 | mw.requestCount.With(methodField).With(errorField).Add(1) | |
21 | mw.requestLatency.With(methodField).With(errorField).Observe(time.Since(begin)) | |
18 | lvs := []string{"method", "uppercase", "error", fmt.Sprint(err == nil)} | |
19 | mw.requestCount.With(lvs...).Add(1) | |
20 | mw.requestLatency.With(lvs...).Observe(time.Since(begin).Seconds()) | |
22 | 21 | }(time.Now()) |
23 | 22 | |
24 | 23 | output, err = mw.next.Uppercase(s) |
27 | 26 | |
28 | 27 | func (mw instrumentingMiddleware) Count(s string) (n int) { |
29 | 28 | defer func(begin time.Time) { |
30 | methodField := metrics.Field{Key: "method", Value: "count"} | |
31 | errorField := metrics.Field{Key: "error", Value: fmt.Sprintf("%v", error(nil))} | |
32 | mw.requestCount.With(methodField).With(errorField).Add(1) | |
33 | mw.requestLatency.With(methodField).With(errorField).Observe(time.Since(begin)) | |
34 | mw.countResult.Observe(int64(n)) | |
29 | lvs := []string{"method", "count"} | |
30 | mw.requestCount.With(lvs...).Add(1) | |
31 | mw.requestLatency.With(lvs...).Observe(time.Since(begin).Seconds()) | |
32 | mw.countResult.Observe(float64(n)) | |
35 | 33 | }(time.Now()) |
36 | 34 | |
37 | 35 | n = mw.next.Count(s) |
2 | 2 | import ( |
3 | 3 | "net/http" |
4 | 4 | "os" |
5 | "time" | |
6 | 5 | |
7 | 6 | stdprometheus "github.com/prometheus/client_golang/prometheus" |
8 | 7 | "golang.org/x/net/context" |
9 | 8 | |
10 | 9 | "github.com/go-kit/kit/log" |
11 | "github.com/go-kit/kit/metrics" | |
12 | 10 | kitprometheus "github.com/go-kit/kit/metrics/prometheus" |
13 | 11 | httptransport "github.com/go-kit/kit/transport/http" |
14 | 12 | ) |
18 | 16 | logger := log.NewLogfmtLogger(os.Stderr) |
19 | 17 | |
20 | 18 | fieldKeys := []string{"method", "error"} |
21 | requestCount := kitprometheus.NewCounter(stdprometheus.CounterOpts{ | |
19 | requestCount := kitprometheus.NewCounterFrom(stdprometheus.CounterOpts{ | |
22 | 20 | Namespace: "my_group", |
23 | 21 | Subsystem: "string_service", |
24 | 22 | Name: "request_count", |
25 | 23 | Help: "Number of requests received.", |
26 | 24 | }, fieldKeys) |
27 | requestLatency := metrics.NewTimeHistogram(time.Microsecond, kitprometheus.NewSummary(stdprometheus.SummaryOpts{ | |
25 | requestLatency := kitprometheus.NewSummaryFrom(stdprometheus.SummaryOpts{ | |
28 | 26 | Namespace: "my_group", |
29 | 27 | Subsystem: "string_service", |
30 | 28 | Name: "request_latency_microseconds", |
31 | 29 | Help: "Total duration of requests in microseconds.", |
32 | }, fieldKeys)) | |
33 | countResult := kitprometheus.NewSummary(stdprometheus.SummaryOpts{ | |
30 | }, fieldKeys) | |
31 | countResult := kitprometheus.NewSummaryFrom(stdprometheus.SummaryOpts{ | |
34 | 32 | Namespace: "my_group", |
35 | 33 | Subsystem: "string_service", |
36 | 34 | Name: "count_result", |
8 | 8 | |
9 | 9 | func instrumentingMiddleware( |
10 | 10 | requestCount metrics.Counter, |
11 | requestLatency metrics.TimeHistogram, | |
11 | requestLatency metrics.Histogram, | |
12 | 12 | countResult metrics.Histogram, |
13 | 13 | ) ServiceMiddleware { |
14 | 14 | return func(next StringService) StringService { |
18 | 18 | |
19 | 19 | type instrmw struct { |
20 | 20 | requestCount metrics.Counter |
21 | requestLatency metrics.TimeHistogram | |
21 | requestLatency metrics.Histogram | |
22 | 22 | countResult metrics.Histogram |
23 | 23 | StringService |
24 | 24 | } |
25 | 25 | |
26 | 26 | func (mw instrmw) Uppercase(s string) (output string, err error) { |
27 | 27 | defer func(begin time.Time) { |
28 | methodField := metrics.Field{Key: "method", Value: "uppercase"} | |
29 | errorField := metrics.Field{Key: "error", Value: fmt.Sprintf("%v", err)} | |
30 | mw.requestCount.With(methodField).With(errorField).Add(1) | |
31 | mw.requestLatency.With(methodField).With(errorField).Observe(time.Since(begin)) | |
28 | lvs := []string{"method", "uppercase", "error", fmt.Sprint(err == nil)} | |
29 | mw.requestCount.With(lvs...).Add(1) | |
30 | mw.requestLatency.With(lvs...).Observe(time.Since(begin).Seconds()) | |
32 | 31 | }(time.Now()) |
33 | 32 | |
34 | 33 | output, err = mw.StringService.Uppercase(s) |
37 | 36 | |
38 | 37 | func (mw instrmw) Count(s string) (n int) { |
39 | 38 | defer func(begin time.Time) { |
40 | methodField := metrics.Field{Key: "method", Value: "count"} | |
41 | errorField := metrics.Field{Key: "error", Value: fmt.Sprintf("%v", error(nil))} | |
42 | mw.requestCount.With(methodField).With(errorField).Add(1) | |
43 | mw.requestLatency.With(methodField).With(errorField).Observe(time.Since(begin)) | |
44 | mw.countResult.Observe(int64(n)) | |
39 | lvs := []string{"method", "uppercase"} | |
40 | mw.requestCount.With(lvs...).Add(1) | |
41 | mw.requestLatency.With(lvs...).Observe(time.Since(begin).Seconds()) | |
42 | mw.countResult.Observe(float64(n)) | |
45 | 43 | }(time.Now()) |
46 | 44 | |
47 | 45 | n = mw.StringService.Count(s) |
3 | 3 | "flag" |
4 | 4 | "net/http" |
5 | 5 | "os" |
6 | "time" | |
7 | 6 | |
8 | 7 | stdprometheus "github.com/prometheus/client_golang/prometheus" |
9 | 8 | "golang.org/x/net/context" |
10 | 9 | |
11 | 10 | "github.com/go-kit/kit/log" |
12 | "github.com/go-kit/kit/metrics" | |
13 | 11 | kitprometheus "github.com/go-kit/kit/metrics/prometheus" |
14 | 12 | httptransport "github.com/go-kit/kit/transport/http" |
15 | 13 | ) |
28 | 26 | ctx := context.Background() |
29 | 27 | |
30 | 28 | fieldKeys := []string{"method", "error"} |
31 | requestCount := kitprometheus.NewCounter(stdprometheus.CounterOpts{ | |
29 | requestCount := kitprometheus.NewCounterFrom(stdprometheus.CounterOpts{ | |
32 | 30 | Namespace: "my_group", |
33 | 31 | Subsystem: "string_service", |
34 | 32 | Name: "request_count", |
35 | 33 | Help: "Number of requests received.", |
36 | 34 | }, fieldKeys) |
37 | requestLatency := metrics.NewTimeHistogram(time.Microsecond, kitprometheus.NewSummary(stdprometheus.SummaryOpts{ | |
35 | requestLatency := kitprometheus.NewSummaryFrom(stdprometheus.SummaryOpts{ | |
38 | 36 | Namespace: "my_group", |
39 | 37 | Subsystem: "string_service", |
40 | 38 | Name: "request_latency_microseconds", |
41 | 39 | Help: "Total duration of requests in microseconds.", |
42 | }, fieldKeys)) | |
43 | countResult := kitprometheus.NewSummary(stdprometheus.SummaryOpts{ | |
40 | }, fieldKeys) | |
41 | countResult := kitprometheus.NewSummaryFrom(stdprometheus.SummaryOpts{ | |
44 | 42 | Namespace: "my_group", |
45 | 43 | Subsystem: "string_service", |
46 | 44 | Name: "count_result", |