-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.go
72 lines (61 loc) · 1.6 KB
/
config.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
package sumologrus
import (
"github.com/segmentio/backo-go"
"github.com/sirupsen/logrus"
"time"
)
type Config struct {
EndPointURL string
Tags []string
Host string
Level logrus.Level
Interval time.Duration
BatchSize int
Verbose bool
GZip bool
// The maximum number of goroutines that will be spawned by a client to send
// requests to the backend API.
// This field is not exported and only exposed internally to let unit tests
// mock the current time.
maxConcurrentRequests int
// The retry policy used by the client to resend requests that have failed.
// The function is called with how many times the operation has been retried
// and is expected to return how long the client should wait before trying
// again.
// If not set the client will fallback to use a default retry policy.
RetryAfter func(int) time.Duration
}
const DefaultInterval = 5 * time.Second
const DefaultBatchSize = 250
func (c *Config) validate() error {
if c.Interval <= 0 {
return ConfigError{
Reason: "negative or 0 time intervals are not supported",
Field: "Interval",
Value: c.Interval,
}
}
if c.BatchSize <= 0 {
return ConfigError{
Reason: "negative or 0 batch sizes are not supported",
Field: "BatchSize",
Value: c.BatchSize,
}
}
return nil
}
func makeConfig(c Config) Config {
if c.Interval == 0 {
c.Interval = DefaultInterval
}
if c.BatchSize == 0 {
c.BatchSize = DefaultBatchSize
}
if c.maxConcurrentRequests == 0 {
c.maxConcurrentRequests = 1000
}
if c.RetryAfter == nil {
c.RetryAfter = backo.DefaultBacko().Duration
}
return c
}