-
Notifications
You must be signed in to change notification settings - Fork 2.8k
/
option.go
118 lines (104 loc) · 3.16 KB
/
option.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
106
107
108
109
110
111
112
113
114
115
116
117
118
// SPDX-License-Identifier: Apache-2.0
// Copyright Authors of Cilium
package pool
import (
"time"
"github.com/sirupsen/logrus"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials/insecure"
"github.com/cilium/cilium/pkg/backoff"
peerTypes "github.com/cilium/cilium/pkg/hubble/peer/types"
"github.com/cilium/cilium/pkg/hubble/relay/defaults"
poolTypes "github.com/cilium/cilium/pkg/hubble/relay/pool/types"
"github.com/cilium/cilium/pkg/logging"
"github.com/cilium/cilium/pkg/logging/logfields"
)
// defaultOptions is the reference point for default values.
var defaultOptions = options{
peerServiceAddress: defaults.PeerTarget,
peerClientBuilder: peerTypes.LocalClientBuilder{
DialTimeout: defaults.DialTimeout,
},
clientConnBuilder: GRPCClientConnBuilder{
DialTimeout: defaults.DialTimeout,
Options: []grpc.DialOption{
grpc.WithTransportCredentials(insecure.NewCredentials()),
grpc.WithBlock(),
grpc.FailOnNonTempDialError(true),
grpc.WithReturnConnectionError(),
},
},
backoff: &backoff.Exponential{
Min: 10 * time.Second,
Max: 90 * time.Minute,
Factor: 2.0,
},
connCheckInterval: 2 * time.Minute,
retryTimeout: defaults.RetryTimeout,
log: logging.DefaultLogger.WithField(logfields.LogSubsys, "hubble-relay"),
}
// Option customizes the configuration of the Manager.
type Option func(o *options) error
// options stores all the configuration values for peer manager.
type options struct {
peerServiceAddress string
peerClientBuilder peerTypes.ClientBuilder
clientConnBuilder poolTypes.ClientConnBuilder
backoff BackoffDuration
connCheckInterval time.Duration
retryTimeout time.Duration
log logrus.FieldLogger
}
// WithPeerServiceAddress sets the address of the peer gRPC service.
func WithPeerServiceAddress(a string) Option {
return func(o *options) error {
o.peerServiceAddress = a
return nil
}
}
// WithPeerClientBuilder sets the ClientBuilder that is used to create new Peer
// service clients.
func WithPeerClientBuilder(b peerTypes.ClientBuilder) Option {
return func(o *options) error {
o.peerClientBuilder = b
return nil
}
}
// WithClientConnBuilder sets the GRPCClientConnBuilder that is used to create
// new gRPC connections to peers.
func WithClientConnBuilder(b poolTypes.ClientConnBuilder) Option {
return func(o *options) error {
o.clientConnBuilder = b
return nil
}
}
// WithBackoff sets the backoff between after a failed connection attempt.
func WithBackoff(b BackoffDuration) Option {
return func(o *options) error {
o.backoff = b
return nil
}
}
// WithConnCheckInterval sets the time interval between peer connections health
// checks.
func WithConnCheckInterval(i time.Duration) Option {
return func(o *options) error {
o.connCheckInterval = i
return nil
}
}
// WithRetryTimeout sets the duration to wait before attempting to re-connect
// to the peer gRPC service.
func WithRetryTimeout(t time.Duration) Option {
return func(o *options) error {
o.retryTimeout = t
return nil
}
}
// WithLogger sets the logger to use for logging.
func WithLogger(l logrus.FieldLogger) Option {
return func(o *options) error {
o.log = l
return nil
}
}