-
Notifications
You must be signed in to change notification settings - Fork 75
/
Copy pathmetrics.go
51 lines (43 loc) · 1.68 KB
/
metrics.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package metrics
import (
"context"
"time"
)
// HTTPReqProperties are the metric properties for the metrics based
// on client request.
type HTTPReqProperties struct {
// Service is the service that has served the request.
Service string
// ID is the id of the request handler.
ID string
// Method is the method of the request.
Method string
// Code is the response of the request.
Code string
}
// HTTPProperties are the metric properties for the global server metrics.
type HTTPProperties struct {
// Service is the service that has served the request.
Service string
// ID is the id of the request handler.
ID string
}
// Recorder knows how to record and measure the metrics. This
// Interface has the required methods to be used with the HTTP
// middlewares.
type Recorder interface {
// ObserveHTTPRequestDuration measures the duration of an HTTP request.
ObserveHTTPRequestDuration(ctx context.Context, props HTTPReqProperties, duration time.Duration)
// ObserveHTTPResponseSize measures the size of an HTTP response in bytes.
ObserveHTTPResponseSize(ctx context.Context, props HTTPReqProperties, sizeBytes int64)
// AddInflightRequests increments and decrements the number of inflight request being
// processed.
AddInflightRequests(ctx context.Context, props HTTPProperties, quantity int)
}
// Dummy is a dummy recorder.
const Dummy = dummy(0)
type dummy int
func (dummy) ObserveHTTPRequestDuration(_ context.Context, _ HTTPReqProperties, _ time.Duration) {}
func (dummy) ObserveHTTPResponseSize(_ context.Context, _ HTTPReqProperties, _ int64) {}
func (dummy) AddInflightRequests(_ context.Context, _ HTTPProperties, _ int) {}
var _ Recorder = Dummy