This repository has been archived by the owner on Aug 18, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 31
/
protocol.go
105 lines (88 loc) · 2.67 KB
/
protocol.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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
package protocol
import (
"io"
"context"
"github.com/signalfx/golib/datapoint/dpsink"
"github.com/signalfx/golib/event"
"github.com/signalfx/golib/sfxclient"
"github.com/signalfx/golib/trace"
"net/http"
)
// DatapointForwarder can send datapoints and not events
type DatapointForwarder interface {
sfxclient.Collector
io.Closer
dpsink.DSink
}
// DebugEndpointer gives an object a chance to expose http endpoints
type DebugEndpointer interface {
DebugEndpoints() map[string]http.Handler
}
// Forwarder is the basic interface endpoints must support for the gateway to forward to them
type Forwarder interface {
dpsink.Sink
trace.Sink
Pipeline
sfxclient.Collector
io.Closer
StartupHook
DebugEndpointer
}
// Listener is the basic interface anything that listens for new metrics must implement
type Listener interface {
sfxclient.Collector
io.Closer
HealthChecker
}
// HealthChecker interface is anything that exports a healthcheck that would need to be invalidated on graceful shutdown
type HealthChecker interface {
CloseHealthCheck()
}
// StartupHook interface allows a forwarder to present a callback after startup if it needs to do something that requires a fully running gateway
type StartupHook interface {
StartupFinished() error
}
// Pipeline returns the number of items still in flight that need to be drained
type Pipeline interface {
Pipeline() int64
}
// UneventfulForwarder converts a datapoint only forwarder into a datapoint/event forwarder
type UneventfulForwarder struct {
DatapointForwarder
}
// DebugEndpoints does nothing
func (u *UneventfulForwarder) DebugEndpoints() map[string]http.Handler {
return map[string]http.Handler{}
}
// StartupFinished is to be called after startup is finished
func (u *UneventfulForwarder) StartupFinished() error {
return nil
}
// AddEvents does nothing and returns nil
func (u *UneventfulForwarder) AddEvents(ctx context.Context, events []*event.Event) error {
return nil
}
// AddSpans does nothing and returns nil
func (u *UneventfulForwarder) AddSpans(ctx context.Context, events []*trace.Span) error {
return nil
}
// Pipeline returns zero since UneventfulForwarder doesn't have it's own buffer
func (u *UneventfulForwarder) Pipeline() int64 {
return 0
}
// ListenerDims are the common stat dimensions we expect on listener protocols
func ListenerDims(name string, typ string) map[string]string {
return map[string]string{
"location": "listener",
"name": name,
"type": typ,
}
}
// ForwarderDims are the common stat dimensions we expect on forwarder protocols
func ForwarderDims(name string, typ string) map[string]string {
return map[string]string{
"location": "forwarder",
"name": name,
"type": typ,
}
}