-
Notifications
You must be signed in to change notification settings - Fork 23
/
config.go
150 lines (136 loc) · 4.4 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
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
package shuttle
import (
"fmt"
"log"
"time"
)
// Input format constants.
// TODO: ensure these are really used properly
const (
InputFormatRaw = iota // default, just text
InputFormatRFC5424 // newline termined RFC5424 formated lines
InputFormatLengthPrefixedRFC5424 // length prefixed RFC5424 formatted lines
)
// Default option values
const (
DefaultMaxLineLength = 10000 // Logplex max is 10000 bytes, so default to that
DefaultInputFormat = InputFormatRaw
DefaultBackBuff = 50
DefaultTimeout = 5 * time.Second
DefaultWaitDuration = 250 * time.Millisecond
DefaultMaxAttempts = 3
DefaultStatsInterval = 0 * time.Second
DefaultStatsSource = ""
DefaultVerbose = false
DefaultSkipVerify = false
DefaultPriVal = "190"
DefaultVersion = "1"
DefaultProcID = "shuttle"
DefaultAppName = "token"
DefaultHostname = "shuttle"
DefaultMsgID = "- -"
DefaultLogsURL = ""
DefaultNumOutlets = 4
DefaultBatchSize = 500
DefaultID = ""
DefaultDrop = true
DefaultUseGzip = false
DefaultKinesisShards = 1
)
const (
errDrop errType = iota
errLost
)
// Defaults that can't be constants
var (
DefaultFormatterFunc = NewLogplexBatchFormatter
)
type errType int
type errData struct {
count int
since time.Time
eType errType
}
// Config holds the various config options for a shuttle
type Config struct {
MaxLineLength int
BackBuff int
BatchSize int
NumOutlets int
InputFormat int
MaxAttempts int
KinesisShards int
LogsURL string
Prival string
Version string
Procid string
Hostname string
Appname string
Msgid string
StatsSource string
SkipVerify bool
Verbose bool
UseGzip bool
Drop bool
WaitDuration time.Duration
Timeout time.Duration
StatsInterval time.Duration
lengthPrefixedSyslogFrameHeaderSize int
syslogFrameHeaderFormat string
ID string
FormatterFunc NewHTTPFormatterFunc
// Loggers
Logger *log.Logger
ErrLogger *log.Logger
}
// NewConfig returns a newly created Config, filled in with defaults
func NewConfig() Config {
shuttleConfig := Config{
MaxLineLength: DefaultMaxLineLength,
Verbose: DefaultVerbose,
SkipVerify: DefaultSkipVerify,
Prival: DefaultPriVal,
Version: DefaultVersion,
Procid: DefaultProcID,
Appname: DefaultAppName,
Hostname: DefaultHostname,
Msgid: DefaultMsgID,
LogsURL: DefaultLogsURL,
StatsSource: DefaultStatsSource,
StatsInterval: time.Duration(DefaultStatsInterval),
MaxAttempts: DefaultMaxAttempts,
InputFormat: DefaultInputFormat,
NumOutlets: DefaultNumOutlets,
WaitDuration: time.Duration(DefaultWaitDuration),
BatchSize: DefaultBatchSize,
BackBuff: DefaultBackBuff,
Timeout: time.Duration(DefaultTimeout),
ID: DefaultID,
Logger: discardLogger,
ErrLogger: discardLogger,
FormatterFunc: DefaultFormatterFunc,
Drop: DefaultDrop,
UseGzip: DefaultUseGzip,
KinesisShards: DefaultKinesisShards,
}
shuttleConfig.ComputeHeader()
return shuttleConfig
}
// ComputeHeader computes the syslogFrameHeaderFormat once so we don't have to
// do that for every formatter itteration
// Should be called after setting up the rest of the config or if the config
// changes
func (c *Config) ComputeHeader() {
// This is here to pre-compute this so other's don't have to later
c.lengthPrefixedSyslogFrameHeaderSize = len(c.Prival) + len(c.Version) + len(LogplexBatchTimeFormat) +
len(c.Hostname) + len(c.Appname) + len(c.Procid) + len(c.Msgid) + 8 // spaces, < & >
c.syslogFrameHeaderFormat = fmt.Sprintf("%s <%s>%s %s %s %s %s %s ",
"%d",
c.Prival,
c.Version,
"%s", // The time should be put here
c.Hostname,
c.Appname,
c.Procid,
c.Msgid)
}