forked from open-telemetry/opentelemetry-collector-contrib
-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.go
245 lines (182 loc) · 7.75 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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
// 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 metricstransformprocessor
import (
"go.opentelemetry.io/collector/config/configmodels"
)
const (
// IncludeFieldName is the mapstructure field name for Include field
IncludeFieldName = "include"
// MatchTypeFieldName is the mapstructure field name for MatchType field
MatchTypeFieldName = "match_type"
// MetricNameFieldName is the mapstructure field name for MetricName field
MetricNameFieldName = "metric_name"
// ActionFieldName is the mapstructure field name for Action field
ActionFieldName = "action"
// NewNameFieldName is the mapstructure field name for NewName field
NewNameFieldName = "new_name"
// AggregationTypeFieldName is the mapstructure field name for AggregationType field
AggregationTypeFieldName = "aggregation_type"
// LabelFieldName is the mapstructure field name for Label field
LabelFieldName = "label"
// NewLabelFieldName is the mapstructure field name for NewLabel field
NewLabelFieldName = "new_label"
// NewValueFieldName is the mapstructure field name for NewValue field
NewValueFieldName = "new_value"
)
// Config defines configuration for Resource processor.
type Config struct {
configmodels.ProcessorSettings `mapstructure:",squash"`
// Transform specifies a list of transforms on metrics with each transform focusing on one metric.
Transforms []Transform `mapstructure:"transforms"`
}
// Transform defines the transformation applied to the specific metric
type Transform struct {
// MetricIncludeFilter is used to select the metric(s) to operate on.
// REQUIRED
MetricIncludeFilter FilterConfig `mapstructure:",squash"`
// MetricName is used to select the metric to operate on.
// DEPRECATED. Use MetricIncludeFilter instead.
MetricName string `mapstructure:"metric_name"`
// Action specifies the action performed on the matched metric.
// REQUIRED
Action ConfigAction `mapstructure:"action"`
// NewName specifies the name of the new metric when inserting or updating.
// REQUIRED only if Action is INSERT.
NewName string `mapstructure:"new_name"`
// AggregationType specifies how to aggregate.
// REQUIRED only if Action is COMBINE.
AggregationType AggregationType `mapstructure:"aggregation_type"`
// Operations contains a list of operations that will be performed on the selected metric.
Operations []Operation `mapstructure:"operations"`
}
type FilterConfig struct {
// Include specifies the metric(s) to operate on.
Include string `mapstructure:"include"`
// MatchType determines how the Include string is matched: <strict|regexp>.
MatchType MatchType `mapstructure:"match_type"`
}
// Operation defines the specific operation performed on the selected metrics.
type Operation struct {
// Action specifies the action performed for this operation.
// REQUIRED
Action OperationAction `mapstructure:"action"`
// Label identifies the exact label to operate on.
Label string `mapstructure:"label"`
// NewLabel determines the name to rename the identified label to.
NewLabel string `mapstructure:"new_label"`
// LabelSet is a list of labels to keep. All other labels are aggregated based on the AggregationType.
LabelSet []string `mapstructure:"label_set"`
// AggregationType specifies how to aggregate.
AggregationType AggregationType `mapstructure:"aggregation_type"`
// AggregatedValues is a list of label values to aggregate away.
AggregatedValues []string `mapstructure:"aggregated_values"`
// NewValue is used to set a new label value either when the operation is `AggregatedValues` or `AddLabel`.
NewValue string `mapstructure:"new_value"`
// ValueActions is a list of renaming actions for label values.
ValueActions []ValueAction `mapstructure:"value_actions"`
// LabelValue identifies the exact label value to operate on
LabelValue string `mapstructure:"label_value"`
}
// ValueAction renames label values.
type ValueAction struct {
// Value specifies the current label value.
Value string `mapstructure:"value"`
// NewValue specifies the label value to rename to.
NewValue string `mapstructure:"new_value"`
}
// ConfigAction is the enum to capture the two types of actions to perform on a metric.
type ConfigAction string
const (
// Insert adds a new metric to the batch with a new name.
Insert ConfigAction = "insert"
// Update updates an existing metric.
Update ConfigAction = "update"
// Combine combines multiple metrics into a single metric.
Combine ConfigAction = "combine"
)
var Actions = []ConfigAction{Insert, Update, Combine}
func (ca ConfigAction) isValid() bool {
for _, configAction := range Actions {
if ca == configAction {
return true
}
}
return false
}
// OperationAction is the enum to capture the thress types of actions to perform for an operation.
type OperationAction string
const (
// AddLabel adds a new label to an existing metric.
AddLabel OperationAction = "add_label"
// UpdateLabel applies name changes to label and/or label values.
UpdateLabel OperationAction = "update_label"
// DeleteLabelValue deletes a label value by also removing all the points associated with this label value
DeleteLabelValue OperationAction = "delete_label_value"
// ToggleScalarDataType changes the data type from int64 to double, or vice-versa
ToggleScalarDataType OperationAction = "toggle_scalar_data_type"
// AggregateLabels aggregates away all labels other than the ones in Operation.LabelSet
// by the method indicated by Operation.AggregationType.
AggregateLabels OperationAction = "aggregate_labels"
// AggregateLabelValues aggregates away the values in Operation.AggregatedValues
// by the method indicated by Operation.AggregationType.
AggregateLabelValues OperationAction = "aggregate_label_values"
)
var OperationActions = []OperationAction{AddLabel, UpdateLabel, DeleteLabelValue, ToggleScalarDataType, AggregateLabels, AggregateLabelValues}
func (oa OperationAction) isValid() bool {
for _, operationAction := range OperationActions {
if oa == operationAction {
return true
}
}
return false
}
// AggregationType is the enum to capture the three types of aggregation for the aggregation operation.
type AggregationType string
const (
// Sum indicates taking the sum of the aggregated data.
Sum AggregationType = "sum"
// Mean indicates taking the mean of the aggregated data.
Mean AggregationType = "mean"
// Min indicates taking the minimum of the aggregated data.
Min AggregationType = "min"
// Max indicates taking the max of the aggregated data.
Max AggregationType = "max"
)
var AggregationTypes = []AggregationType{Sum, Mean, Min, Max}
func (at AggregationType) isValid() bool {
for _, aggregationType := range AggregationTypes {
if at == aggregationType {
return true
}
}
return false
}
// MatchType is the enum to capture the two types of matching metric(s) that should have operations applied to them.
type MatchType string
const (
// StrictMatchType is the FilterType for filtering by exact string matches.
StrictMatchType MatchType = "strict"
// RegexpMatchType is the FilterType for filtering by regexp string matches.
RegexpMatchType MatchType = "regexp"
)
var MatchTypes = []MatchType{StrictMatchType, RegexpMatchType}
func (mt MatchType) isValid() bool {
for _, matchType := range MatchTypes {
if mt == matchType {
return true
}
}
return false
}