-
Notifications
You must be signed in to change notification settings - Fork 4
/
config.go
76 lines (58 loc) · 2.51 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
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0
package fluentforwardexporter // import "github.com/r0mdau/fluentforwardexporter"
import (
"fmt"
"net"
"time"
"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/config/configretry"
"go.opentelemetry.io/collector/config/configtls"
"go.opentelemetry.io/collector/exporter/exporterhelper"
)
// TCPClientSettings defines common settings for a TCP client.
type TCPClientSettings struct {
// Endpoint to send logs to.
Endpoint `mapstructure:"endpoint"`
// Connection Timeout parameter configures `net.Dialer`.
ConnectionTimeout time.Duration `mapstructure:"connection_timeout"`
// ClientConfig struct exposes TLS client configuration.
ClientConfig configtls.ClientConfig `mapstructure:"tls"`
// SharedKey is used for authorization with the server that knows it.
SharedKey string `mapstructure:"shared_key"`
}
// Config defines configuration for fluentforward exporter.
type Config struct {
TCPClientSettings `mapstructure:",squash"` // squash ensures fields are correctly decoded in embedded struct.
// RequireAck enables the acknowledgement feature.
RequireAck bool `mapstructure:"require_ack"`
// The Fluent tag parameter used for routing
Tag string `mapstructure:"tag"`
// CompressGzip enables gzip compression for the payload.
CompressGzip bool `mapstructure:"compress_gzip"`
// DefaultLabelsEnabled is a map of default attributes to be added to each log record.
DefaultLabelsEnabled map[string]bool `mapstructure:"default_labels_enabled"`
exporterhelper.QueueConfig `mapstructure:"sending_queue"`
configretry.BackOffConfig `mapstructure:"retry_on_failure"`
}
type Endpoint struct {
// TCPAddr is the address of the server to connect to.
TCPAddr string `mapstructure:"tcp_addr"`
// Controls whether to validate the tcp address.
ValidateTCPResolution bool `mapstructure:"validate_tcp_resolution"`
}
var _ component.Config = (*Config)(nil)
// Validate checks if the configuration is valid
func (config *Config) Validate() error {
if err := config.QueueConfig.Validate(); err != nil {
return fmt.Errorf("queue settings has invalid configuration: %w", err)
}
if config.TCPClientSettings.Endpoint.ValidateTCPResolution {
// Resolve TCP address just to ensure that it is a valid one. It is better
// to fail here than at when the exporter is started.
if _, err := net.ResolveTCPAddr("tcp", config.Endpoint.TCPAddr); err != nil {
return fmt.Errorf("exporter has an invalid TCP endpoint: %w", err)
}
}
return nil
}