-
Notifications
You must be signed in to change notification settings - Fork 3
/
config.go
66 lines (50 loc) · 2.25 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
// 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 {
// The target endpoint URI to send data to (e.g.: some.url:24224).
Endpoint string `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.QueueSettings `mapstructure:"sending_queue"`
configretry.BackOffConfig `mapstructure:"retry_on_failure"`
}
var _ component.Config = (*Config)(nil)
// Validate checks if the configuration is valid
func (config *Config) Validate() error {
if err := config.QueueSettings.Validate(); err != nil {
return fmt.Errorf("queue settings has invalid configuration: %w", err)
}
// 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); err != nil {
return fmt.Errorf("exporter has an invalid TCP endpoint: %w", err)
}
return nil
}