/
option.go
176 lines (159 loc) · 4.07 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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
//
// Copyright (C) 2019-2022 vdaas.org vald team <vald@vdaas.org>
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// Package jaeger provides a jaeger exporter.
package jaeger
import (
"net"
"net/http"
"time"
"github.com/vdaas/vald/internal/errors"
"go.opentelemetry.io/otel/sdk/trace"
)
type Option func(*export) error
var jaegerDefaultOpts = []Option{
WithAgentMaxPacketSize(65000),
WithAgentReconnectInterval("30s"),
WithServiceName("vald"),
WithHTTPClient(http.DefaultClient),
WithBatchTimeout("5s"),
WithExportTimeout("30s"),
WithMaxExportBatchSize(trace.DefaultMaxExportBatchSize),
WithMaxQueueSize(trace.DefaultMaxQueueSize),
}
func WithAgentEndpoint(aep string) Option {
return func(exp *export) error {
if len(aep) == 0 {
return errors.NewErrInvalidOption("agentEndpoint", aep)
}
host, port, err := net.SplitHostPort(aep)
if err != nil {
return errors.NewErrCriticalOption("agentEndpoint", aep, err)
}
exp.agentHost = host
exp.agentPort = port
return nil
}
}
func WithAgentReconnectInterval(dur string) Option {
return func(e *export) error {
if len(dur) == 0 {
return errors.NewErrInvalidOption("agentReconnectInterval", dur)
}
d, err := time.ParseDuration(dur)
if err != nil {
return errors.NewErrInvalidOption("agentReconnectInterval", dur, err)
}
e.agentReconnInterval = d
return nil
}
}
func WithAgentMaxPacketSize(cnt int) Option {
return func(exp *export) error {
if cnt <= 0 {
return errors.NewErrInvalidOption("agentMaxPacketSize", cnt)
}
exp.agentMaxPacketSize = cnt
return nil
}
}
func WithCollectorEndpoint(cep string) Option {
return func(exp *export) error {
if len(cep) == 0 {
return errors.NewErrInvalidOption("collectorEndpoint", cep)
}
exp.collectorEndpoint = cep
return nil
}
}
func WithHTTPClient(c *http.Client) Option {
return func(exp *export) error {
if c == nil {
return errors.NewErrInvalidOption("httpClient", c)
}
exp.client = c
return nil
}
}
func WithUsername(username string) Option {
return func(exp *export) error {
if username != "" {
exp.collectorUserName = username
}
return nil
}
}
func WithPassword(password string) Option {
return func(exp *export) error {
if len(password) == 0 {
return errors.NewErrInvalidOption("password", password)
}
exp.collectorPassword = password
return nil
}
}
func WithServiceName(serviceName string) Option {
return func(exp *export) error {
if len(serviceName) == 0 {
return errors.NewErrInvalidOption("serviceName", serviceName)
}
exp.serviceName = serviceName
return nil
}
}
func WithBatchTimeout(dur string) Option {
return func(e *export) error {
if len(dur) == 0 {
return errors.NewErrInvalidOption("batchTimeout", dur)
}
d, err := time.ParseDuration(dur)
if err != nil {
return errors.NewErrInvalidOption("batchTimeout", dur, err)
}
e.batchTimeout = d
return nil
}
}
func WithExportTimeout(dur string) Option {
return func(e *export) error {
if len(dur) == 0 {
return errors.NewErrInvalidOption("exportTimeout", dur)
}
d, err := time.ParseDuration(dur)
if err != nil {
return errors.NewErrInvalidOption("exportTimeout", dur, err)
}
e.exportTimeout = d
return nil
}
}
func WithMaxExportBatchSize(size int) Option {
return func(e *export) error {
if size <= 0 {
return errors.NewErrInvalidOption("maxExportBatchSize", size)
}
e.maxExportBatchSize = size
return nil
}
}
func WithMaxQueueSize(size int) Option {
return func(e *export) error {
if size <= 0 {
return errors.NewErrInvalidOption("maxQueueSize", size)
}
e.maxQueueSize = size
return nil
}
}