forked from open-telemetry/opentelemetry-collector-contrib
-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.go
136 lines (123 loc) · 6.52 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
// Copyright 2020, OpenTelemetry Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http:https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package awsemfexporter
import (
"go.opentelemetry.io/collector/config"
"go.opentelemetry.io/collector/exporter/exporterhelper"
"go.uber.org/zap"
)
var (
// EMFSupportedUnits contains the unit collection supported by CloudWatch backend service.
// https://docs.aws.amazon.com/AmazonCloudWatch/latest/APIReference/API_MetricDatum.html
EMFSupportedUnits = newEMFSupportedUnits()
)
// Config defines configuration for AWS EMF exporter.
type Config struct {
*config.ExporterSettings `mapstructure:"-"`
// LogGroupName is the name of CloudWatch log group which defines group of log streams
// that share the same retention, monitoring, and access control settings.
LogGroupName string `mapstructure:"log_group_name"`
// LogStreamName is the name of CloudWatch log stream which is a sequence of log events
// that share the same source.
LogStreamName string `mapstructure:"log_stream_name"`
// Namespace is a container for CloudWatch metrics.
// Metrics in different namespaces are isolated from each other.
Namespace string `mapstructure:"namespace"`
// Endpoint is the CloudWatch Logs service endpoint which the requests
// are forwarded to. https://docs.aws.amazon.com/general/latest/gr/cwl_region.html
// e.g. logs.us-east-1.amazonaws.com and logs-fips.us-east-1.amazonaws.com
Endpoint string `mapstructure:"endpoint"`
// RequestTimeoutSeconds is number of seconds before a request times out.
RequestTimeoutSeconds int `mapstructure:"request_timeout_seconds"`
// ProxyAddress defines the proxy address that the local TCP server
// forwards HTTP requests to AWS CloudWatch Logs backend through.
ProxyAddress string `mapstructure:"proxy_address"`
// Region is the AWS region where the metric logs are sent to.
Region string `mapstructure:"region"`
// RoleARN is the IAM role used by the collector when communicating
// with the CloudWatch Logs service
RoleARN string `mapstructure:"role_arn"`
// NoVerifySSL is the option to disable TLS certificate verification.
NoVerifySSL bool `mapstructure:"no_verify_ssl"`
// MaxRetries is the maximum number of retries before abandoning an attempt to post data.
MaxRetries int `mapstructure:"max_retries"`
// DimensionRollupOption is the option for metrics dimension rollup. Three options are available, default option is "ZeroAndSingleDimensionRollup".
// "ZeroAndSingleDimensionRollup" - Enable both zero dimension rollup and single dimension rollup
// "SingleDimensionRollupOnly" - Enable single dimension rollup
// "NoDimensionRollup" - No dimension rollup (only keep original metrics which contain all dimensions)
DimensionRollupOption string `mapstructure:"dimension_rollup_option"`
// ParseJSONEncodedAttributeValues is an array of attribute keys whose corresponding values are JSON-encoded as strings.
// Those strings will be decoded to its original json structure.
ParseJSONEncodedAttributeValues []string `mapstructure:"parse_json_encoded_attr_values"`
// MetricDeclarations is the list of rules to be used to set dimensions for exported metrics.
MetricDeclarations []*MetricDeclaration `mapstructure:"metric_declarations"`
// MetricDescriptors is the list of override metric descriptors that are sent to the CloudWatch
MetricDescriptors []MetricDescriptor `mapstructure:"metric_descriptors"`
// OutputDestination is an option to specify the EMFExporter output. Default option is "cloudwatch"
// "cloudwatch" - direct the exporter output to CloudWatch backend
// "stdout" - direct the exporter output to stdout
// TODO: we can support directing output to a file (in the future) while customer specifies a file path here.
OutputDestination string `mapstructure:"output_destination"`
// ResourceToTelemetrySettings is the option for converting resource attrihutes 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.
exporterhelper.ResourceToTelemetrySettings `mapstructure:"resource_to_telemetry_conversion"`
// logger is the Logger used for writing error/warning logs
logger *zap.Logger
}
type MetricDescriptor struct {
// metricName is the name of the metric
metricName string `mapstructure:"metric_name"`
// unit defines the override value of metric descriptor `unit`
unit string `mapstructure:"unit"`
// overwrite set to true means the existing metric descriptor will be overwritten or a new metric descriptor will be created; false means
// the descriptor will only be configured if empty.
overwrite bool `mapstructure:"overwrite"`
}
// Validate filters out invalid metricDeclarations and metricDescriptors
func (config *Config) Validate() {
validDeclarations := []*MetricDeclaration{}
for _, declaration := range config.MetricDeclarations {
err := declaration.Init(config.logger)
if err != nil {
config.logger.Warn("Dropped metric declaration.", zap.Error(err))
} else {
validDeclarations = append(validDeclarations, declaration)
}
}
config.MetricDeclarations = validDeclarations
validDescriptors := []MetricDescriptor{}
for _, descriptor := range config.MetricDescriptors {
if descriptor.metricName == "" {
continue
}
if _, ok := EMFSupportedUnits[descriptor.unit]; ok {
validDescriptors = append(validDescriptors, descriptor)
} else {
config.logger.Warn("Dropped unsupported metric desctriptor.", zap.String("unit", descriptor.unit))
}
}
config.MetricDescriptors = validDescriptors
}
func newEMFSupportedUnits() map[string]interface{} {
unitIndexer := map[string]interface{}{}
for _, unit := range []string{"Seconds", "Microseconds", "Milliseconds", "Bytes", "Kilobytes", "Megabytes",
"Gigabytes", "Terabytes", "Bits", "Kilobits", "Megabits", "Gigabits", "Terabits",
"Percent", "Count", "Bytes/Second", "Kilobytes/Second", "Megabytes/Second",
"Gigabytes/Second", "Terabytes/Second", "Bits/Second", "Kilobits/Second",
"Megabits/Second", "Gigabits/Second", "Terabits/Second", "Count/Second", "None"} {
unitIndexer[unit] = nil
}
return unitIndexer
}