forked from r0mdau/fluentforwardexporter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.go
104 lines (84 loc) · 3.26 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
// 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"`
// KubernetesMetadata includes kubernetes metadata as a nested object.
// It leverages resources attributes provided by k8sattributesprocessor
//
// Configuration example
// ```
// kubernetes_metadata:
// key: kubernetes
// include_pod_labels: true
// ```
//
// Resulting record structure:
// ```
// kubernetes:
// namespace_name: default
// container_name: nginx
// pod_name: nginx-59f678c4b-p6lk6
// labels:
// app.kubernetes.io/name: nginx
// host: gke-dev-node-pool-8-cf541dd4-98ro
// ```
//
KubernetesMetadata *KubernetesMetadata `mapstructure:"kubernetes_metadata,omitempty"`
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"`
}
type KubernetesMetadata struct {
Key string `mapstructure:"key"`
IncludePodLabels bool `mapstructure:"include_pod_labels"`
}
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
}