-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwrapperOptions.go
86 lines (73 loc) · 2.11 KB
/
wrapperOptions.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
package wrappercloudwatchlogs
import (
"fmt"
"time"
)
const (
MaxBatchSize = 1_048_576
MaxLogEventsPerBatch = 10_000
)
type WrapperOptions struct {
logGroup string
logStream string
retentionDays RetentionPolicy
logsPerBatch uint
batchSize uint
sendAfter time.Duration
}
func NewWrapperOptions(
logGroup string,
logStream string,
retentionDays RetentionPolicy,
logsPerBatch uint,
batchSize uint,
sendAfter time.Duration) (*WrapperOptions, error) {
options := WrapperOptions{
logGroup: logGroup,
logStream: logStream,
retentionDays: retentionDays,
logsPerBatch: logsPerBatch,
batchSize: batchSize,
sendAfter: sendAfter,
}
err := options.validate()
if err != nil {
return nil, err
}
return &options, nil
}
var ErrTooManyLogsPerBatch = fmt.Errorf("to many logs per batch, maxValue: %d", MaxLogEventsPerBatch)
var ErrBatchSizeTooBig = fmt.Errorf("batch size too big, maxValue: %d", MaxBatchSize)
var ErrInvalidSendAfter = fmt.Errorf("AWS restrictions: a batch of log events in a single request cannot span more than 24 hours")
func (options WrapperOptions) validate() error {
if options.logsPerBatch > MaxLogEventsPerBatch {
return ErrTooManyLogsPerBatch
}
if options.batchSize > MaxBatchSize {
return ErrBatchSizeTooBig
}
if options.sendAfter >= time.Hour*24 {
return ErrInvalidSendAfter
}
return nil
}
type RetentionPolicy int32
const (
OneDay RetentionPolicy = 1
ThreeDays RetentionPolicy = 3
FiveDays RetentionPolicy = 5
OneWeek RetentionPolicy = 7
TwoWeeks RetentionPolicy = 14
OneMonth RetentionPolicy = 30
TwoMonths RetentionPolicy = 60
ThreeMonths RetentionPolicy = 90
FourMonths RetentionPolicy = 120
FiveMonths RetentionPolicy = 150
SixMonths RetentionPolicy = 180
OneYear RetentionPolicy = 365
OneYearAndOneMonth RetentionPolicy = 400
OneYearAndSixMonths RetentionPolicy = 545
TwoYears RetentionPolicy = 731
FiveYears RetentionPolicy = 1827
TenYears RetentionPolicy = 3653
)