-
Notifications
You must be signed in to change notification settings - Fork 13
/
config.go
78 lines (59 loc) · 1.62 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
73
74
75
76
77
78
package kinesis
import (
"time"
"github.com/apex/log"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/session"
k "github.com/aws/aws-sdk-go/service/kinesis"
"github.com/aws/aws-sdk-go/service/kinesis/kinesisiface"
"github.com/jpillora/backoff"
)
const (
maxRecordsPerRequest = 500
)
type Config struct {
// StreamName is the Kinesis stream.
StreamName string
// FlushInterval is a regular interval for flushing the buffer. Defaults to 1s.
FlushInterval time.Duration
// BufferSize determines the batch request size. Must not exceed 500. Defaults to 500.
BufferSize int
// BacklogSize determines the channel capacity before Put() will begin blocking. Defaults to 500.
BacklogSize int
// Backoff determines the backoff strategy for record failures.
Backoff backoff.Backoff
// Logger is the logger used. Defaults to log.Log.
Logger log.Interface
// Client is the Kinesis API implementation.
Client kinesisiface.KinesisAPI
}
// defaults for configuration.
func (c *Config) defaults() {
if c.Client == nil {
c.Client = k.New(session.New(aws.NewConfig()))
}
if c.Logger == nil {
c.Logger = log.Log
}
c.Logger = c.Logger.WithFields(log.Fields{
"package": "kinesis",
})
if c.StreamName == "" {
c.Logger.Fatal("StreamName required")
}
c.Logger = c.Logger.WithFields(log.Fields{
"stream": c.StreamName,
})
if c.BufferSize == 0 {
c.BufferSize = maxRecordsPerRequest
}
if c.BufferSize > maxRecordsPerRequest {
c.Logger.Fatal("BufferSize exceeds 500")
}
if c.BacklogSize == 0 {
c.BacklogSize = maxRecordsPerRequest
}
if c.FlushInterval == 0 {
c.FlushInterval = time.Second
}
}