-
Notifications
You must be signed in to change notification settings - Fork 2.5k
/
Copy pathconfig.go
128 lines (99 loc) · 4.82 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
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0
package prometheusremotewriteexporter // import "github.com/open-telemetry/opentelemetry-collector-contrib/exporter/prometheusremotewriteexporter"
import (
"fmt"
"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/config/confighttp"
"go.opentelemetry.io/collector/config/configretry"
"go.opentelemetry.io/collector/exporter/exporterhelper"
"github.com/open-telemetry/opentelemetry-collector-contrib/pkg/resourcetotelemetry"
)
// Config defines configuration for Remote Write exporter.
type Config struct {
TimeoutSettings exporterhelper.TimeoutConfig `mapstructure:",squash"` // squash ensures fields are correctly decoded in embedded struct.
configretry.BackOffConfig `mapstructure:"retry_on_failure"`
// prefix attached to each exported metric name
// See: https://prometheus.io/docs/practices/naming/#metric-names
Namespace string `mapstructure:"namespace"`
// QueueConfig allows users to fine tune the queues
// that handle outgoing requests.
RemoteWriteQueue RemoteWriteQueue `mapstructure:"remote_write_queue"`
// ExternalLabels defines a map of label keys and values that are allowed to start with reserved prefix "__"
ExternalLabels map[string]string `mapstructure:"external_labels"`
ClientConfig confighttp.ClientConfig `mapstructure:",squash"` // squash ensures fields are correctly decoded in embedded struct.
// maximum size in bytes of time series batch sent to remote storage
MaxBatchSizeBytes int `mapstructure:"max_batch_size_bytes"`
// maximum amount of parallel requests to do when handling large batch request
MaxBatchRequestParallelism *int `mapstructure:"max_batch_request_parallelism"`
// ResourceToTelemetrySettings is the option for converting resource attributes to telemetry attributes.
// "Enabled" - A boolean field to enable/disable this option. Default is `false`.
// If enabled, all the resource attributes will be converted to metric labels by default.
ResourceToTelemetrySettings resourcetotelemetry.Settings `mapstructure:"resource_to_telemetry_conversion"`
WAL *WALConfig `mapstructure:"wal"`
// TargetInfo allows customizing the target_info metric
TargetInfo *TargetInfo `mapstructure:"target_info,omitempty"`
// CreatedMetric allows customizing creation of _created metrics
// Deprecated[0.114.0]: The feature doesn't provide the expected behavior. Use Prometheus remote-write v2 to enable sending Created Timestamps.
// This feature is planned to be removed in v0.116.0
CreatedMetric *CreatedMetric `mapstructure:"export_created_metric,omitempty"`
// AddMetricSuffixes controls whether unit and type suffixes are added to metrics on export
AddMetricSuffixes bool `mapstructure:"add_metric_suffixes"`
// SendMetadata controls whether prometheus metadata will be generated and sent
SendMetadata bool `mapstructure:"send_metadata"`
}
type CreatedMetric struct {
// Enabled if true the _created metrics could be exported
Enabled bool `mapstructure:"enabled"`
}
type TargetInfo struct {
// Enabled if false the target_info metric is not generated by the exporter
Enabled bool `mapstructure:"enabled"`
}
// RemoteWriteQueue allows to configure the remote write queue.
type RemoteWriteQueue struct {
// Enabled if false the queue is not enabled, the export requests
// are executed synchronously.
Enabled bool `mapstructure:"enabled"`
// QueueSize is the maximum number of OTLP metric batches allowed
// in the queue at a given time. Ignored if Enabled is false.
QueueSize int `mapstructure:"queue_size"`
// NumWorkers configures the number of workers used by
// the collector to fan out remote write requests.
NumConsumers int `mapstructure:"num_consumers"`
}
// TODO(jbd): Add capacity, max_samples_per_send to QueueConfig.
var _ component.Config = (*Config)(nil)
// Validate checks if the exporter configuration is valid
func (cfg *Config) Validate() error {
if cfg.MaxBatchRequestParallelism != nil && *cfg.MaxBatchRequestParallelism < 1 {
return fmt.Errorf("max_batch_request_parallelism can't be set to below 1")
}
if cfg.RemoteWriteQueue.QueueSize < 0 {
return fmt.Errorf("remote write queue size can't be negative")
}
if cfg.RemoteWriteQueue.Enabled && cfg.RemoteWriteQueue.QueueSize == 0 {
return fmt.Errorf("a 0 size queue will drop all the data")
}
if cfg.RemoteWriteQueue.NumConsumers < 0 {
return fmt.Errorf("remote write consumer number can't be negative")
}
if cfg.TargetInfo == nil {
cfg.TargetInfo = &TargetInfo{
Enabled: true,
}
}
if cfg.CreatedMetric == nil {
cfg.CreatedMetric = &CreatedMetric{
Enabled: false,
}
}
if cfg.MaxBatchSizeBytes < 0 {
return fmt.Errorf("max_batch_byte_size must be greater than 0")
}
if cfg.MaxBatchSizeBytes == 0 {
// Defaults to ~2.81MB
cfg.MaxBatchSizeBytes = 3000000
}
return nil
}