-
Notifications
You must be signed in to change notification settings - Fork 17
/
batch.go
38 lines (31 loc) · 924 Bytes
/
batch.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
package cloudwatch
import "time"
// CloudwatchMessage is a simple JSON input to Cloudwatch.
type CloudwatchMessage struct {
Message string `json:"message"`
Group string `json:"group"`
Stream string `json:"stream"`
Time time.Time `json:"time"`
Container string `json:"container"`
}
type CloudwatchBatch struct {
Msgs []CloudwatchMessage
Size int64
}
// Rules for creating Cloudwatch Log batches, from https://goo.gl/TrIN8c
const MAX_BATCH_COUNT = 10000 // messages
const MAX_BATCH_SIZE = 1048576 // bytes
const MSG_OVERHEAD = 26 // bytes
func msgSize(msg CloudwatchMessage) int64 {
return int64((len(msg.Message) * 8) + MSG_OVERHEAD)
}
func NewCloudwatchBatch() *CloudwatchBatch {
return &CloudwatchBatch{
Msgs: []CloudwatchMessage{},
Size: 0,
}
}
func (b *CloudwatchBatch) Append(msg CloudwatchMessage) {
b.Msgs = append(b.Msgs, msg)
b.Size = b.Size + msgSize(msg)
}