/
config.go
148 lines (126 loc) · 4.53 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
package traceability
import (
"net/url"
"time"
"github.com/Axway/agent-sdk/pkg/agent"
"github.com/Axway/agent-sdk/pkg/traceability/redaction"
"github.com/Axway/agent-sdk/pkg/traceability/sampling"
"github.com/Axway/agent-sdk/pkg/util/log"
"github.com/elastic/beats/v7/libbeat/beat"
"github.com/elastic/beats/v7/libbeat/common"
"github.com/elastic/beats/v7/libbeat/common/cfgwarn"
"github.com/elastic/beats/v7/libbeat/common/transport/tlscommon"
)
// Config -
type Config struct {
Index string `config:"index"`
LoadBalance bool `config:"loadbalance"`
BulkMaxSize int `config:"bulk_max_size"`
SlowStart bool `config:"slow_start"`
Timeout time.Duration `config:"client_timeout" validate:"min=0"`
TTL time.Duration `config:"ttl" validate:"min=0"`
Pipelining int `config:"pipelining" validate:"min=0"`
CompressionLevel int `config:"compression_level" validate:"min=0, max=9"`
MaxRetries int `config:"max_retries" validate:"min=-1"`
TLS *tlscommon.Config `config:"ssl"`
Proxy ProxyConfig `config:",inline"`
Backoff Backoff `config:"backoff"`
EscapeHTML bool `config:"escape_html"`
Protocol string `config:"protocol"`
Hosts []string `config:"hosts"`
Redaction redaction.Config `config:"redaction" yaml:"redaction"`
Sampling sampling.Sampling `config:"sampling" yaml:"sampling"`
APIExceptionsList []string `config:"apiExceptionsList"`
}
// ProxyConfig holds the configuration information required to proxy
// connections through a SOCKS5 proxy server.
type ProxyConfig struct {
// URL of the SOCKS proxy. Scheme must be socks5. Username and password can be
// embedded in the URL.
URL string `config:"proxy_url"`
// Resolve names locally instead of on the SOCKS server.
LocalResolve bool `config:"proxy_use_local_resolver"`
}
// Backoff -
type Backoff struct {
Init time.Duration
Max time.Duration
}
var outputConfig *Config
// DefaultConfig -
func DefaultConfig() *Config {
return &Config{
LoadBalance: false,
Pipelining: 0,
BulkMaxSize: 512,
SlowStart: false,
CompressionLevel: 3,
Timeout: 60 * time.Second,
MaxRetries: 3,
TTL: 0 * time.Second,
Backoff: Backoff{
Init: 1 * time.Second,
Max: 60 * time.Second,
},
EscapeHTML: false,
Protocol: "tcp",
Redaction: redaction.DefaultConfig(),
Sampling: sampling.DefaultConfig(),
}
}
func readConfig(cfg *common.Config, info beat.Info) (*Config, error) {
outputConfig = DefaultConfig()
err := cfgwarn.CheckRemoved6xSettings(cfg, "port")
if err != nil {
return nil, err
}
if err := cfg.Unpack(outputConfig); err != nil {
return nil, err
}
if outputConfig.Index == "" {
outputConfig.Index = info.IndexPrefix
}
// Setup the redaction regular expressions
redaction.SetupGlobalRedaction(outputConfig.Redaction)
// Setup the sampling config, if central config can not be found assume online mode
if agent.GetCentralConfig() != nil && agent.GetCentralConfig().GetUsageReportingConfig() != nil {
err = sampling.SetupSampling(outputConfig.Sampling, agent.GetCentralConfig().GetUsageReportingConfig().IsOfflineMode())
} else {
err = sampling.SetupSampling(outputConfig.Sampling, false)
}
if err != nil {
log.Warn(err.Error())
}
// Force piplining to 0
if outputConfig.Pipelining > 0 {
log.Warn("Pipelining is not supported by Amplify Visibility yet, forcing to synchronous")
outputConfig.Pipelining = 0
}
// if set, check for valid proxyURL
if outputConfig.Proxy.URL != "" {
if _, err := url.ParseRequestURI(outputConfig.Proxy.URL); err != nil {
return nil, ErrInvalidConfig.FormatError("traceability.proxyURL")
}
}
// set up the api exceptions list for logging events
exception, err := setUpAPIExceptionList(outputConfig.APIExceptionsList)
if err != nil {
err = ErrInvalidRegex.FormatError("apiExceptionValue", exception, err)
log.Error(err)
}
return outputConfig, nil
}
// IsHTTPTransport - Returns true if the protocol is set to http/https
func IsHTTPTransport() bool {
if outputConfig == nil {
return false
}
return (outputConfig.Protocol == "https" || outputConfig.Protocol == "http")
}
// GetMaxRetries - Returns the max retries configured for transport
func GetMaxRetries() int {
if outputConfig == nil {
return 3
}
return outputConfig.MaxRetries
}