-
Notifications
You must be signed in to change notification settings - Fork 217
/
observability.go
86 lines (73 loc) · 1.91 KB
/
observability.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
package http
import (
"fmt"
"github.com/cloudevents/sdk-go/pkg/cloudevents/observability"
"go.opencensus.io/stats"
"go.opencensus.io/stats/view"
)
var (
// LatencyMs measures the latency in milliseconds for the http transport
// methods for CloudEvents.
LatencyMs = stats.Float64(
"cloudevents.io/sdk-go/transport/http/latency",
"The latency in milliseconds for the http transport methods for CloudEvents.",
"ms")
)
var (
// LatencyView is an OpenCensus view that shows http transport method latency.
LatencyView = &view.View{
Name: "transport/http/latency",
Measure: LatencyMs,
Description: "The distribution of latency inside of http transport for CloudEvents.",
Aggregation: view.Distribution(0, .01, .1, 1, 10, 100, 1000, 10000),
TagKeys: observability.LatencyTags(),
}
)
type observed int32
// Adheres to Observable
var _ observability.Observable = observed(0)
const (
reportSend observed = iota
reportReceive
reportServeHTTP
reportEncode
reportDecode
)
// MethodName implements Observable.MethodName
func (o observed) MethodName() string {
switch o {
case reportSend:
return "send"
case reportReceive:
return "receive"
case reportServeHTTP:
return "servehttp"
case reportEncode:
return "encode"
case reportDecode:
return "decode"
default:
return "unknown"
}
}
// LatencyMs implements Observable.LatencyMs
func (o observed) LatencyMs() *stats.Float64Measure {
return LatencyMs
}
// CodecObserved is a wrapper to append version to observed.
type CodecObserved struct {
// Method
o observed
// Codec
c string
}
// Adheres to Observable
var _ observability.Observable = (*CodecObserved)(nil)
// MethodName implements Observable.MethodName
func (c CodecObserved) MethodName() string {
return fmt.Sprintf("%s/%s", c.o.MethodName(), c.c)
}
// LatencyMs implements Observable.LatencyMs
func (c CodecObserved) LatencyMs() *stats.Float64Measure {
return c.o.LatencyMs()
}