forked from StephanU/beats
-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.go
91 lines (79 loc) · 3.59 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
package harvester
import (
"fmt"
"time"
cfg "github.com/elastic/beats/filebeat/config"
"github.com/elastic/beats/filebeat/harvester/reader"
"github.com/elastic/beats/libbeat/common"
"github.com/elastic/beats/libbeat/common/match"
"github.com/dustin/go-humanize"
"github.com/elastic/beats/libbeat/logp"
)
var (
defaultConfig = harvesterConfig{
BufferSize: 16 * humanize.KiByte,
DocumentType: "log",
InputType: cfg.DefaultInputType,
Backoff: 1 * time.Second,
BackoffFactor: 2,
MaxBackoff: 10 * time.Second,
CloseInactive: 5 * time.Minute,
MaxBytes: 10 * humanize.MiByte,
CloseRemoved: true,
CloseRenamed: false,
CloseEOF: false,
CloseTimeout: 0,
ForceCloseFiles: false,
}
)
type harvesterConfig struct {
common.EventMetadata `config:",inline"` // Fields and tags to add to events.
BufferSize int `config:"harvester_buffer_size"`
DocumentType string `config:"document_type"`
Encoding string `config:"encoding"`
InputType string `config:"input_type"`
Backoff time.Duration `config:"backoff" validate:"min=0,nonzero"`
BackoffFactor int `config:"backoff_factor" validate:"min=1"`
MaxBackoff time.Duration `config:"max_backoff" validate:"min=0,nonzero"`
CloseInactive time.Duration `config:"close_inactive"`
CloseOlder time.Duration `config:"close_older"`
CloseRemoved bool `config:"close_removed"`
CloseRenamed bool `config:"close_renamed"`
CloseEOF bool `config:"close_eof"`
CloseTimeout time.Duration `config:"close_timeout" validate:"min=0"`
ForceCloseFiles bool `config:"force_close_files"`
ExcludeLines []match.Matcher `config:"exclude_lines"`
IncludeLines []match.Matcher `config:"include_lines"`
MaxBytes int `config:"max_bytes" validate:"min=0,nonzero"`
Multiline *reader.MultilineConfig `config:"multiline"`
JSON *reader.JSONConfig `config:"json"`
Pipeline string `config:"pipeline"`
Module string `config:"_module_name"` // hidden option to set the module name
Fileset string `config:"_fileset_name"` // hidden option to set the fileset name
}
func (config *harvesterConfig) Validate() error {
// DEPRECATED: remove in 6.0
if config.ForceCloseFiles {
config.CloseRemoved = true
config.CloseRenamed = true
logp.Warn("DEPRECATED: force_close_files was set to true. Use close_removed + close_rename")
}
// DEPRECATED: remove in 6.0
if config.CloseOlder > 0 {
config.CloseInactive = config.CloseOlder
logp.Warn("DEPRECATED: close_older is deprecated. Use close_inactive")
}
// Check input type
if _, ok := cfg.ValidInputType[config.InputType]; !ok {
return fmt.Errorf("Invalid input type: %v", config.InputType)
}
if config.JSON != nil && len(config.JSON.MessageKey) == 0 &&
config.Multiline != nil {
return fmt.Errorf("When using the JSON decoder and multiline together, you need to specify a message_key value")
}
if config.JSON != nil && len(config.JSON.MessageKey) == 0 &&
(len(config.IncludeLines) > 0 || len(config.ExcludeLines) > 0) {
return fmt.Errorf("When using the JSON decoder and line filtering together, you need to specify a message_key value")
}
return nil
}