diff --git a/.chloggen/unexport-metricstransformprocessor.yaml b/.chloggen/unexport-metricstransformprocessor.yaml new file mode 100644 index 000000000000..f63d5e8c261e --- /dev/null +++ b/.chloggen/unexport-metricstransformprocessor.yaml @@ -0,0 +1,27 @@ +# Use this changelog template to create an entry for release notes. + +# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix' +change_type: breaking + +# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver) +component: metricstransformprocessor + +# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`). +note: Unexport elements of the Go API of the processor + +# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists. +issues: [24846] + +# (Optional) One or more lines of additional information to render under the primary note. +# These lines will be padded with 2 spaces and then inserted directly into the document. +# Use pipe (|) for multiline entries. +subtext: + +# If your change doesn't affect end users or the exported elements of any package, +# you should instead start your pull request title with [chore] or use the "Skip Changelog" label. +# Optional: The change log or logs in which this entry should be included. +# e.g. '[user]' or '[user, api]' +# Include 'user' if the change is relevant to end users. +# Include 'api' if there is a change to a library API. +# Default: '[user]' +change_logs: [api] diff --git a/processor/metricstransformprocessor/config.go b/processor/metricstransformprocessor/config.go index 18983b2482cf..b462a54a2473 100644 --- a/processor/metricstransformprocessor/config.go +++ b/processor/metricstransformprocessor/config.go @@ -4,49 +4,49 @@ package metricstransformprocessor // import "github.com/open-telemetry/opentelemetry-collector-contrib/processor/metricstransformprocessor" const ( - // IncludeFieldName is the mapstructure field name for Include field - IncludeFieldName = "include" + // includeFieldName is the mapstructure field name for Include field + includeFieldName = "include" - // MatchTypeFieldName is the mapstructure field name for MatchType field - MatchTypeFieldName = "match_type" + // matchTypeFieldName is the mapstructure field name for matchType field + matchTypeFieldName = "match_type" - // ActionFieldName is the mapstructure field name for Action field - ActionFieldName = "action" + // actionFieldName is the mapstructure field name for Action field + actionFieldName = "action" - // NewNameFieldName is the mapstructure field name for NewName field - NewNameFieldName = "new_name" + // newNameFieldName is the mapstructure field name for NewName field + newNameFieldName = "new_name" - // GroupResourceLabelsFieldName is the mapstructure field name for GroupResouceLabels field - GroupResourceLabelsFieldName = "group_resource_labels" + // groupResourceLabelsFieldName is the mapstructure field name for GroupResouceLabels field + groupResourceLabelsFieldName = "group_resource_labels" - // AggregationTypeFieldName is the mapstructure field name for AggregationType field - AggregationTypeFieldName = "aggregation_type" + // aggregationTypeFieldName is the mapstructure field name for aggregationType field + aggregationTypeFieldName = "aggregation_type" - // LabelFieldName is the mapstructure field name for Label field - LabelFieldName = "label" + // labelFieldName is the mapstructure field name for Label field + labelFieldName = "label" - // NewLabelFieldName is the mapstructure field name for NewLabel field - NewLabelFieldName = "new_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" + // newValueFieldName is the mapstructure field name for NewValue field + newValueFieldName = "new_value" - // ScaleFieldName is the mapstructure field name for Scale field - ScaleFieldName = "experimental_scale" + // scaleFieldName is the mapstructure field name for Scale field + scaleFieldName = "experimental_scale" - // SubmatchCaseFieldName is the mapstructure field name for SubmatchCase field - SubmatchCaseFieldName = "submatch_case" + // submatchCaseFieldName is the mapstructure field name for submatchCase field + submatchCaseFieldName = "submatch_case" ) // Config defines configuration for Resource processor. type Config struct { - // Transform specifies a list of transforms on metrics with each transform focusing on one metric. - Transforms []Transform `mapstructure:"transforms"` + // 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 { +// transform defines the transformation applied to the specific metric +type transform struct { // --- SPECIFY WHICH METRIC(S) TO MATCH --- @@ -75,10 +75,10 @@ type Transform struct { // AggregationType specifies how to aggregate. // REQUIRED only if Action is COMBINE. - AggregationType AggregationType `mapstructure:"aggregation_type"` + AggregationType aggregationType `mapstructure:"aggregation_type"` // SubmatchCase specifies what case to use for label values created from regexp submatches. - SubmatchCase SubmatchCase `mapstructure:"submatch_case"` + SubmatchCase submatchCase `mapstructure:"submatch_case"` // Operations contains a list of operations that will be performed on the resulting metric(s). Operations []Operation `mapstructure:"operations"` @@ -89,7 +89,7 @@ type FilterConfig struct { Include string `mapstructure:"include"` // MatchType determines how the Include string is matched: . - MatchType MatchType `mapstructure:"match_type"` + MatchType matchType `mapstructure:"match_type"` // MatchLabels specifies the label set against which the metric filter will work. // This field is optional. @@ -100,7 +100,7 @@ type FilterConfig struct { type Operation struct { // Action specifies the action performed for this operation. // REQUIRED - Action OperationAction `mapstructure:"action"` + Action operationAction `mapstructure:"action"` // Label identifies the exact label to operate on. Label string `mapstructure:"label"` @@ -112,12 +112,12 @@ type Operation struct { LabelSet []string `mapstructure:"label_set"` // AggregationType specifies how to aggregate. - AggregationType AggregationType `mapstructure:"aggregation_type"` + 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 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. @@ -168,45 +168,45 @@ func (ca ConfigAction) isValid() bool { return false } -// OperationAction is the enum to capture the thress types of actions to perform for an operation. -type OperationAction string +// 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 adds a new label to an existing metric. // Metric has to match the FilterConfig with all its data points if used with Update ConfigAction, // otherwise the operation will be ignored. - AddLabel OperationAction = "add_label" + addLabel operationAction = "add_label" - // UpdateLabel applies name changes to label and/or label values. - UpdateLabel OperationAction = "update_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 deletes a label value by also removing all the points associated with this label value // Metric has to match the FilterConfig with all its data points if used with Update ConfigAction, // otherwise the operation will be ignored. - DeleteLabelValue OperationAction = "delete_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" + // toggleScalarDataType changes the data type from int64 to double, or vice-versa + toggleScalarDataType operationAction = "toggle_scalar_data_type" - // ScaleValue multiplies the value by a constant scalar - ScaleValue OperationAction = "experimental_scale_value" + // scaleValue multiplies the value by a constant scalar + scaleValue operationAction = "experimental_scale_value" - // AggregateLabels aggregates away all labels other than the ones in Operation.LabelSet + // aggregateLabels aggregates away all labels other than the ones in Operation.LabelSet // by the method indicated by Operation.AggregationType. // Metric has to match the FilterConfig with all its data points if used with Update ConfigAction, // otherwise the operation will be ignored. - AggregateLabels OperationAction = "aggregate_labels" + aggregateLabels operationAction = "aggregate_labels" - // AggregateLabelValues aggregates away the values in Operation.AggregatedValues + // aggregateLabelValues aggregates away the values in Operation.AggregatedValues // by the method indicated by Operation.AggregationType. // Metric has to match the FilterConfig with all its data points if used with Update ConfigAction, // otherwise the operation will be ignored. - AggregateLabelValues OperationAction = "aggregate_label_values" + aggregateLabelValues operationAction = "aggregate_label_values" ) -var operationActions = []OperationAction{AddLabel, UpdateLabel, DeleteLabelValue, ToggleScalarDataType, ScaleValue, AggregateLabels, AggregateLabelValues} +var operationActions = []operationAction{addLabel, updateLabel, deleteLabelValue, toggleScalarDataType, scaleValue, aggregateLabels, aggregateLabelValues} -func (oa OperationAction) isValid() bool { +func (oa operationAction) isValid() bool { for _, operationAction := range operationActions { if oa == operationAction { return true @@ -216,26 +216,26 @@ func (oa OperationAction) isValid() bool { return false } -// AggregationType is the enum to capture the three types of aggregation for the aggregation operation. -type AggregationType string +// 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" + // sum indicates taking the sum of the aggregated data. + sum aggregationType = "sum" - // Mean indicates taking the mean of the aggregated data. - Mean AggregationType = "mean" + // mean indicates taking the mean of the aggregated data. + mean aggregationType = "mean" - // Min indicates taking the minimum of the aggregated data. - Min AggregationType = "min" + // min indicates taking the minimum of the aggregated data. + min aggregationType = "min" - // Max indicates taking the max of the aggregated data. - Max AggregationType = "max" + // max indicates taking the max of the aggregated data. + max aggregationType = "max" ) -var aggregationTypes = []AggregationType{Sum, Mean, Min, Max} +var aggregationTypes = []aggregationType{sum, mean, min, max} -func (at AggregationType) isValid() bool { +func (at aggregationType) isValid() bool { for _, aggregationType := range aggregationTypes { if at == aggregationType { return true @@ -245,20 +245,20 @@ func (at AggregationType) isValid() bool { 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 +// 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" + // 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" + // regexpMatchType is the FilterType for filtering by regexp string matches. + regexpMatchType matchType = "regexp" ) -var matchTypes = []MatchType{StrictMatchType, RegexpMatchType} +var matchTypes = []matchType{strictMatchType, regexpMatchType} -func (mt MatchType) isValid() bool { +func (mt matchType) isValid() bool { for _, matchType := range matchTypes { if mt == matchType { return true @@ -268,20 +268,20 @@ func (mt MatchType) isValid() bool { return false } -// SubmatchCase is the enum to capture the two types of case changes to apply to submatches. -type SubmatchCase string +// submatchCase is the enum to capture the two types of case changes to apply to submatches. +type submatchCase string const ( - // Lower is the SubmatchCase for lower casing the submatch. - Lower SubmatchCase = "lower" + // lower is the submatchCase for lower casing the submatch. + lower submatchCase = "lower" - // Upper is the SubmatchCase for upper casing the submatch. - Upper SubmatchCase = "upper" + // upper is the submatchCase for upper casing the submatch. + upper submatchCase = "upper" ) -var submatchCases = []SubmatchCase{Lower, Upper} +var submatchCases = []submatchCase{lower, upper} -func (sc SubmatchCase) isValid() bool { +func (sc submatchCase) isValid() bool { for _, submatchCase := range submatchCases { if sc == submatchCase { return true diff --git a/processor/metricstransformprocessor/config_test.go b/processor/metricstransformprocessor/config_test.go index f17e6b67ab84..0433fd785037 100644 --- a/processor/metricstransformprocessor/config_test.go +++ b/processor/metricstransformprocessor/config_test.go @@ -25,7 +25,7 @@ func TestLoadConfig(t *testing.T) { configFile: "config_full.yaml", id: component.NewID(metadata.Type), expected: &Config{ - Transforms: []Transform{ + Transforms: []transform{ { MetricIncludeFilter: FilterConfig{ Include: "name", @@ -41,7 +41,7 @@ func TestLoadConfig(t *testing.T) { configFile: "config_full.yaml", id: component.NewIDWithName(metadata.Type, "multiple"), expected: &Config{ - Transforms: []Transform{ + Transforms: []transform{ { MetricIncludeFilter: FilterConfig{ Include: "name1", diff --git a/processor/metricstransformprocessor/factory.go b/processor/metricstransformprocessor/factory.go index dcd9e3d20c68..94c5681c1f3a 100644 --- a/processor/metricstransformprocessor/factory.go +++ b/processor/metricstransformprocessor/factory.go @@ -19,7 +19,7 @@ import ( var consumerCapabilities = consumer.Capabilities{MutatesData: true} -// NewFactory returns a new factory for the Metrics Transform processor. +// NewFactory returns a new factory for the Metrics transform processor. func NewFactory() processor.Factory { return processor.NewFactory( metadata.Type, @@ -62,60 +62,60 @@ func createMetricsProcessor( func validateConfiguration(config *Config) error { for _, transform := range config.Transforms { if transform.MetricIncludeFilter.Include == "" { - return fmt.Errorf("missing required field %q", IncludeFieldName) + return fmt.Errorf("missing required field %q", includeFieldName) } if transform.MetricIncludeFilter.MatchType != "" && !transform.MetricIncludeFilter.MatchType.isValid() { - return fmt.Errorf("%q must be in %q", MatchTypeFieldName, matchTypes) + return fmt.Errorf("%q must be in %q", matchTypeFieldName, matchTypes) } - if transform.MetricIncludeFilter.MatchType == RegexpMatchType { + if transform.MetricIncludeFilter.MatchType == regexpMatchType { _, err := regexp.Compile(transform.MetricIncludeFilter.Include) if err != nil { - return fmt.Errorf("%q, %w", IncludeFieldName, err) + return fmt.Errorf("%q, %w", includeFieldName, err) } } if !transform.Action.isValid() { - return fmt.Errorf("%q must be in %q", ActionFieldName, actions) + return fmt.Errorf("%q must be in %q", actionFieldName, actions) } if transform.Action == Insert && transform.NewName == "" { - return fmt.Errorf("missing required field %q while %q is %v", NewNameFieldName, ActionFieldName, Insert) + return fmt.Errorf("missing required field %q while %q is %v", newNameFieldName, actionFieldName, Insert) } if transform.Action == Group && transform.GroupResourceLabels == nil { - return fmt.Errorf("missing required field %q while %q is %v", GroupResourceLabelsFieldName, ActionFieldName, Group) + return fmt.Errorf("missing required field %q while %q is %v", groupResourceLabelsFieldName, actionFieldName, Group) } if transform.AggregationType != "" && !transform.AggregationType.isValid() { - return fmt.Errorf("%q must be in %q", AggregationTypeFieldName, aggregationTypes) + return fmt.Errorf("%q must be in %q", aggregationTypeFieldName, aggregationTypes) } if transform.SubmatchCase != "" && !transform.SubmatchCase.isValid() { - return fmt.Errorf("%q must be in %q", SubmatchCaseFieldName, submatchCases) + return fmt.Errorf("%q must be in %q", submatchCaseFieldName, submatchCases) } for i, op := range transform.Operations { if !op.Action.isValid() { - return fmt.Errorf("operation %v: %q must be in %q", i+1, ActionFieldName, operationActions) + return fmt.Errorf("operation %v: %q must be in %q", i+1, actionFieldName, operationActions) } - if op.Action == UpdateLabel && op.Label == "" { - return fmt.Errorf("operation %v: missing required field %q while %q is %v", i+1, LabelFieldName, ActionFieldName, UpdateLabel) + if op.Action == updateLabel && op.Label == "" { + return fmt.Errorf("operation %v: missing required field %q while %q is %v", i+1, labelFieldName, actionFieldName, updateLabel) } - if op.Action == AddLabel && op.NewLabel == "" { - return fmt.Errorf("operation %v: missing required field %q while %q is %v", i+1, NewLabelFieldName, ActionFieldName, AddLabel) + if op.Action == addLabel && op.NewLabel == "" { + return fmt.Errorf("operation %v: missing required field %q while %q is %v", i+1, newLabelFieldName, actionFieldName, addLabel) } - if op.Action == AddLabel && op.NewValue == "" { - return fmt.Errorf("operation %v: missing required field %q while %q is %v", i+1, NewValueFieldName, ActionFieldName, AddLabel) + if op.Action == addLabel && op.NewValue == "" { + return fmt.Errorf("operation %v: missing required field %q while %q is %v", i+1, newValueFieldName, actionFieldName, addLabel) } - if op.Action == ScaleValue && op.Scale == 0 { - return fmt.Errorf("operation %v: missing required field %q while %q is %v", i+1, ScaleFieldName, ActionFieldName, ScaleValue) + if op.Action == scaleValue && op.Scale == 0 { + return fmt.Errorf("operation %v: missing required field %q while %q is %v", i+1, scaleFieldName, actionFieldName, scaleValue) } if op.AggregationType != "" && !op.AggregationType.isValid() { - return fmt.Errorf("operation %v: %q must be in %q", i+1, AggregationTypeFieldName, aggregationTypes) + return fmt.Errorf("operation %v: %q must be in %q", i+1, aggregationTypeFieldName, aggregationTypes) } } } @@ -128,7 +128,7 @@ func buildHelperConfig(config *Config, version string) ([]internalTransform, err for i, t := range config.Transforms { if t.MetricIncludeFilter.MatchType == "" { - t.MetricIncludeFilter.MatchType = StrictMatchType + t.MetricIncludeFilter.MatchType = strictMatchType } filter, err := createFilter(t.MetricIncludeFilter) @@ -154,9 +154,9 @@ func buildHelperConfig(config *Config, version string) ([]internalTransform, err if len(op.ValueActions) > 0 { mtpOp.valueActionsMapping = createLabelValueMapping(op.ValueActions, version) } - if op.Action == AggregateLabels { + if op.Action == aggregateLabels { mtpOp.labelSetMap = sliceToSet(op.LabelSet) - } else if op.Action == AggregateLabelValues { + } else if op.Action == aggregateLabelValues { mtpOp.aggregatedValuesSet = sliceToSet(op.AggregatedValues) } helperT.Operations[j] = mtpOp @@ -168,13 +168,13 @@ func buildHelperConfig(config *Config, version string) ([]internalTransform, err func createFilter(filterConfig FilterConfig) (internalFilter, error) { switch filterConfig.MatchType { - case StrictMatchType: + case strictMatchType: matchers, err := getMatcherMap(filterConfig.MatchLabels, func(str string) (StringMatcher, error) { return strictMatcher(str), nil }) if err != nil { return nil, err } return internalFilterStrict{include: filterConfig.Include, attrMatchers: matchers}, nil - case RegexpMatchType: + case regexpMatchType: matchers, err := getMatcherMap(filterConfig.MatchLabels, func(str string) (StringMatcher, error) { return regexp.Compile(str) }) if err != nil { return nil, err diff --git a/processor/metricstransformprocessor/factory_test.go b/processor/metricstransformprocessor/factory_test.go index f7eda38a88a9..3408e97b0512 100644 --- a/processor/metricstransformprocessor/factory_test.go +++ b/processor/metricstransformprocessor/factory_test.go @@ -46,62 +46,62 @@ func TestCreateProcessors(t *testing.T) { { configName: "config_invalid_newname.yaml", succeed: false, - errorMessage: fmt.Sprintf("missing required field %q while %q is %v", NewNameFieldName, ActionFieldName, Insert), + errorMessage: fmt.Sprintf("missing required field %q while %q is %v", newNameFieldName, actionFieldName, Insert), }, { configName: "config_invalid_group.yaml", succeed: false, - errorMessage: fmt.Sprintf("missing required field %q while %q is %v", GroupResourceLabelsFieldName, ActionFieldName, Group), + errorMessage: fmt.Sprintf("missing required field %q while %q is %v", groupResourceLabelsFieldName, actionFieldName, Group), }, { configName: "config_invalid_action.yaml", succeed: false, - errorMessage: fmt.Sprintf("%q must be in %q", ActionFieldName, actions), + errorMessage: fmt.Sprintf("%q must be in %q", actionFieldName, actions), }, { configName: "config_invalid_include.yaml", succeed: false, - errorMessage: fmt.Sprintf("missing required field %q", IncludeFieldName), + errorMessage: fmt.Sprintf("missing required field %q", includeFieldName), }, { configName: "config_invalid_matchtype.yaml", succeed: false, - errorMessage: fmt.Sprintf("%q must be in %q", MatchTypeFieldName, matchTypes), + errorMessage: fmt.Sprintf("%q must be in %q", matchTypeFieldName, matchTypes), }, { configName: "config_invalid_label.yaml", succeed: false, - errorMessage: fmt.Sprintf("operation %v: missing required field %q while %q is %v", 1, LabelFieldName, ActionFieldName, UpdateLabel), + errorMessage: fmt.Sprintf("operation %v: missing required field %q while %q is %v", 1, labelFieldName, actionFieldName, updateLabel), }, { configName: "config_invalid_scale.yaml", succeed: false, - errorMessage: fmt.Sprintf("operation %v: missing required field %q while %q is %v", 1, ScaleFieldName, ActionFieldName, ScaleValue), + errorMessage: fmt.Sprintf("operation %v: missing required field %q while %q is %v", 1, scaleFieldName, actionFieldName, scaleValue), }, { configName: "config_invalid_regexp.yaml", succeed: false, - errorMessage: fmt.Sprintf("%q, error parsing regexp: missing closing ]: `[\\da`", IncludeFieldName), + errorMessage: fmt.Sprintf("%q, error parsing regexp: missing closing ]: `[\\da`", includeFieldName), }, { configName: "config_invalid_aggregationtype.yaml", succeed: false, - errorMessage: fmt.Sprintf("%q must be in %q", AggregationTypeFieldName, aggregationTypes), + errorMessage: fmt.Sprintf("%q must be in %q", aggregationTypeFieldName, aggregationTypes), }, { configName: "config_invalid_operation_action.yaml", succeed: false, - errorMessage: fmt.Sprintf("operation %v: %q must be in %q", 1, ActionFieldName, operationActions), + errorMessage: fmt.Sprintf("operation %v: %q must be in %q", 1, actionFieldName, operationActions), }, { configName: "config_invalid_operation_aggregationtype.yaml", succeed: false, - errorMessage: fmt.Sprintf("operation %v: %q must be in %q", 1, AggregationTypeFieldName, aggregationTypes), + errorMessage: fmt.Sprintf("operation %v: %q must be in %q", 1, aggregationTypeFieldName, aggregationTypes), }, { configName: "config_invalid_submatchcase.yaml", succeed: false, - errorMessage: fmt.Sprintf("%q must be in %q", SubmatchCaseFieldName, submatchCases), + errorMessage: fmt.Sprintf("%q must be in %q", submatchCaseFieldName, submatchCases), }, } @@ -146,16 +146,16 @@ func TestCreateProcessors(t *testing.T) { func TestFactory_validateConfiguration(t *testing.T) { v1 := Config{ - Transforms: []Transform{ + Transforms: []transform{ { MetricIncludeFilter: FilterConfig{ Include: "mymetric", - MatchType: StrictMatchType, + MatchType: strictMatchType, }, Action: Update, Operations: []Operation{ { - Action: AddLabel, + Action: addLabel, NewValue: "bar", }, }, @@ -166,16 +166,16 @@ func TestFactory_validateConfiguration(t *testing.T) { assert.Equal(t, "operation 1: missing required field \"new_label\" while \"action\" is add_label", err.Error()) v2 := Config{ - Transforms: []Transform{ + Transforms: []transform{ { MetricIncludeFilter: FilterConfig{ Include: "mymetric", - MatchType: StrictMatchType, + MatchType: strictMatchType, }, Action: Update, Operations: []Operation{ { - Action: AddLabel, + Action: addLabel, NewLabel: "foo", }, }, @@ -192,22 +192,22 @@ func TestCreateProcessorsFilledData(t *testing.T) { cfg := factory.CreateDefaultConfig() oCfg := cfg.(*Config) - oCfg.Transforms = []Transform{ + oCfg.Transforms = []transform{ { MetricIncludeFilter: FilterConfig{ Include: "name", - MatchType: StrictMatchType, + MatchType: strictMatchType, }, Action: Update, NewName: "new-name", Operations: []Operation{ { - Action: AddLabel, + Action: addLabel, NewLabel: "new-label", NewValue: "new-value {{version}}", }, { - Action: UpdateLabel, + Action: updateLabel, Label: "label", NewLabel: "new-label", ValueActions: []ValueAction{ @@ -218,16 +218,16 @@ func TestCreateProcessorsFilledData(t *testing.T) { }, }, { - Action: AggregateLabels, + Action: aggregateLabels, LabelSet: []string{"label1", "label2"}, - AggregationType: Sum, + AggregationType: sum, }, { - Action: AggregateLabelValues, + Action: aggregateLabelValues, Label: "label", AggregatedValues: []string{"value1", "value2"}, NewValue: "new-value", - AggregationType: Sum, + AggregationType: sum, }, }, }, @@ -241,14 +241,14 @@ func TestCreateProcessorsFilledData(t *testing.T) { Operations: []internalOperation{ { configOperation: Operation{ - Action: AddLabel, + Action: addLabel, NewLabel: "new-label", NewValue: "new-value v0.0.1", }, }, { configOperation: Operation{ - Action: UpdateLabel, + Action: updateLabel, Label: "label", NewLabel: "new-label", ValueActions: []ValueAction{ @@ -262,9 +262,9 @@ func TestCreateProcessorsFilledData(t *testing.T) { }, { configOperation: Operation{ - Action: AggregateLabels, + Action: aggregateLabels, LabelSet: []string{"label1", "label2"}, - AggregationType: Sum, + AggregationType: sum, }, labelSetMap: map[string]bool{ "label1": true, @@ -273,11 +273,11 @@ func TestCreateProcessorsFilledData(t *testing.T) { }, { configOperation: Operation{ - Action: AggregateLabelValues, + Action: aggregateLabelValues, Label: "label", AggregatedValues: []string{"value1", "value2"}, NewValue: "new-value", - AggregationType: Sum, + AggregationType: sum, }, aggregatedValuesSet: map[string]bool{ "value1": true, diff --git a/processor/metricstransformprocessor/metrics_transform_processor.go b/processor/metricstransformprocessor/metrics_transform_processor.go index a9efeecee984..d39042340fff 100644 --- a/processor/metricstransformprocessor/metrics_transform_processor.go +++ b/processor/metricstransformprocessor/metrics_transform_processor.go @@ -23,8 +23,8 @@ type internalTransform struct { Action ConfigAction NewName string GroupResourceLabels map[string]string - AggregationType AggregationType - SubmatchCase SubmatchCase + AggregationType aggregationType + SubmatchCase submatchCase Operations []internalOperation } @@ -79,11 +79,11 @@ func newMetricsTransformProcessor(logger *zap.Logger, internalTransforms []inter } } -func replaceCaseOfSubmatch(replacement SubmatchCase, submatch string) string { +func replaceCaseOfSubmatch(replacement submatchCase, submatch string) string { switch replacement { - case Lower: + case lower: return strings.ToLower(submatch) - case Upper: + case upper: return strings.ToUpper(submatch) } diff --git a/processor/metricstransformprocessor/metrics_transform_processor_otlp.go b/processor/metricstransformprocessor/metrics_transform_processor_otlp.go index cf93a5263f49..3a6e11166398 100644 --- a/processor/metricstransformprocessor/metrics_transform_processor_otlp.go +++ b/processor/metricstransformprocessor/metrics_transform_processor_otlp.go @@ -537,25 +537,25 @@ func transformMetric(metric pmetric.Metric, transform internalTransform) bool { for _, op := range transform.Operations { switch op.configOperation.Action { - case UpdateLabel: + case updateLabel: updateLabelOp(metric, op, transform.MetricIncludeFilter) - case AggregateLabels: + case aggregateLabels: if canChangeMetric { aggregateLabelsOp(metric, op) } - case AggregateLabelValues: + case aggregateLabelValues: if canChangeMetric { aggregateLabelValuesOp(metric, op) } - case ToggleScalarDataType: + case toggleScalarDataType: toggleScalarDataTypeOp(metric, transform.MetricIncludeFilter) - case ScaleValue: + case scaleValue: scaleValueOp(metric, op, transform.MetricIncludeFilter) - case AddLabel: + case addLabel: if canChangeMetric { addLabelOp(metric, op) } - case DeleteLabelValue: + case deleteLabelValue: if canChangeMetric { deleteLabelValueOp(metric, op) } diff --git a/processor/metricstransformprocessor/metrics_transform_processor_testcases_test.go b/processor/metricstransformprocessor/metrics_transform_processor_testcases_test.go index 15970488aa00..9363541420b9 100644 --- a/processor/metricstransformprocessor/metrics_transform_processor_testcases_test.go +++ b/processor/metricstransformprocessor/metrics_transform_processor_testcases_test.go @@ -109,7 +109,7 @@ var ( Operations: []internalOperation{ { configOperation: Operation{ - Action: UpdateLabel, + Action: updateLabel, Label: "label1", NewLabel: "new/label1", }, @@ -135,7 +135,7 @@ var ( Operations: []internalOperation{ { configOperation: Operation{ - Action: UpdateLabel, + Action: updateLabel, Label: "label1", }, valueActionsMapping: map[string]string{ @@ -165,7 +165,7 @@ var ( Operations: []internalOperation{ { configOperation: Operation{ - Action: UpdateLabel, + Action: updateLabel, Label: "label1", NewLabel: "new/label1", }, @@ -192,7 +192,7 @@ var ( Operations: []internalOperation{ { configOperation: Operation{ - Action: UpdateLabel, + Action: updateLabel, Label: "label1", }, valueActionsMapping: map[string]string{"label1-value1": "new/label1-value1"}, @@ -222,8 +222,8 @@ var ( Operations: []internalOperation{ { configOperation: Operation{ - Action: AggregateLabels, - AggregationType: Sum, + Action: aggregateLabels, + AggregationType: sum, LabelSet: []string{"label1"}, }, labelSetMap: map[string]bool{"label1": true}, @@ -250,8 +250,8 @@ var ( Operations: []internalOperation{ { configOperation: Operation{ - Action: AggregateLabels, - AggregationType: Mean, + Action: aggregateLabels, + AggregationType: mean, LabelSet: []string{"label1"}, }, labelSetMap: map[string]bool{"label1": true}, @@ -278,8 +278,8 @@ var ( Operations: []internalOperation{ { configOperation: Operation{ - Action: AggregateLabels, - AggregationType: Max, + Action: aggregateLabels, + AggregationType: max, LabelSet: []string{"label1"}, }, labelSetMap: map[string]bool{"label1": true}, @@ -307,8 +307,8 @@ var ( Operations: []internalOperation{ { configOperation: Operation{ - Action: AggregateLabels, - AggregationType: Min, + Action: aggregateLabels, + AggregationType: min, LabelSet: []string{"label1"}, }, labelSetMap: map[string]bool{"label1": true}, @@ -336,8 +336,8 @@ var ( Operations: []internalOperation{ { configOperation: Operation{ - Action: AggregateLabels, - AggregationType: Sum, + Action: aggregateLabels, + AggregationType: sum, LabelSet: []string{"label1"}, }, labelSetMap: map[string]bool{"label1": true}, @@ -364,8 +364,8 @@ var ( Operations: []internalOperation{ { configOperation: Operation{ - Action: AggregateLabels, - AggregationType: Mean, + Action: aggregateLabels, + AggregationType: mean, LabelSet: []string{"label1"}, }, labelSetMap: map[string]bool{"label1": true}, @@ -392,8 +392,8 @@ var ( Operations: []internalOperation{ { configOperation: Operation{ - Action: AggregateLabels, - AggregationType: Max, + Action: aggregateLabels, + AggregationType: max, LabelSet: []string{"label1"}, }, labelSetMap: map[string]bool{"label1": true}, @@ -420,8 +420,8 @@ var ( Operations: []internalOperation{ { configOperation: Operation{ - Action: AggregateLabels, - AggregationType: Min, + Action: aggregateLabels, + AggregationType: min, LabelSet: []string{"label1"}, }, labelSetMap: map[string]bool{"label1": true}, @@ -454,8 +454,8 @@ var ( Operations: []internalOperation{ { configOperation: Operation{ - Action: AggregateLabels, - AggregationType: Sum, + Action: aggregateLabels, + AggregationType: sum, LabelSet: []string{"label1", "label2"}, }, labelSetMap: map[string]bool{"label1": true, "label2": true}, @@ -489,9 +489,9 @@ var ( Operations: []internalOperation{ { configOperation: Operation{ - Action: AggregateLabelValues, + Action: aggregateLabelValues, NewValue: "new/label2-value", - AggregationType: Sum, + AggregationType: sum, Label: "label2", }, aggregatedValuesSet: map[string]bool{"label2-value1": true, "label2-value2": true}, @@ -525,8 +525,8 @@ var ( Operations: []internalOperation{ { configOperation: Operation{ - Action: AggregateLabels, - AggregationType: Sum, + Action: aggregateLabels, + AggregationType: sum, LabelSet: []string{"label1"}, }, labelSetMap: map[string]bool{"label1": true}, @@ -561,8 +561,8 @@ var ( Operations: []internalOperation{ { configOperation: Operation{ - Action: AggregateLabels, - AggregationType: Sum, + Action: aggregateLabels, + AggregationType: sum, LabelSet: []string{"label1"}, }, labelSetMap: map[string]bool{"label1": true}, @@ -592,8 +592,8 @@ var ( Operations: []internalOperation{ { configOperation: Operation{ - Action: AggregateLabels, - AggregationType: Mean, + Action: aggregateLabels, + AggregationType: mean, LabelSet: []string{"label1"}, }, labelSetMap: map[string]bool{"label1": true}, @@ -891,7 +891,7 @@ var ( Operations: []internalOperation{ { configOperation: Operation{ - Action: UpdateLabel, + Action: updateLabel, Label: "label1", NewLabel: "new/label1", }, @@ -920,7 +920,7 @@ var ( Operations: []internalOperation{ { configOperation: Operation{ - Action: UpdateLabel, + Action: updateLabel, Label: "label1", }, valueActionsMapping: map[string]string{"label1-value1": "new/label1-value1"}, @@ -951,8 +951,8 @@ var ( Operations: []internalOperation{ { configOperation: Operation{ - Action: AggregateLabels, - AggregationType: Sum, + Action: aggregateLabels, + AggregationType: sum, LabelSet: []string{"label1"}, }, labelSetMap: map[string]bool{"label1": true}, @@ -982,9 +982,9 @@ var ( Operations: []internalOperation{ { configOperation: Operation{ - Action: AggregateLabelValues, + Action: aggregateLabelValues, NewValue: "new/label2-value", - AggregationType: Sum, + AggregationType: sum, Label: "label2", }, aggregatedValuesSet: map[string]bool{"label2-value1": true, "label2-value2": true}, @@ -1014,8 +1014,8 @@ var ( Operations: []internalOperation{ { configOperation: Operation{ - Action: AggregateLabels, - AggregationType: Sum, + Action: aggregateLabels, + AggregationType: sum, LabelSet: []string{"label1"}, }, labelSetMap: map[string]bool{"label1": true}, @@ -1111,7 +1111,7 @@ var ( MetricIncludeFilter: internalFilterRegexp{include: regexp.MustCompile("^metric[12]$")}, Action: Combine, NewName: "new", - AggregationType: Sum, + AggregationType: sum, }, }, in: []pmetric.Metric{ @@ -1134,15 +1134,15 @@ var ( Operations: []internalOperation{ { configOperation: Operation{ - Action: AddLabel, + Action: addLabel, NewLabel: "new_label", NewValue: "new_label_value", }, }, { configOperation: Operation{ - Action: AggregateLabels, - AggregationType: Sum, + Action: aggregateLabels, + AggregationType: sum, LabelSet: []string{"$1", "new_label"}, }, labelSetMap: map[string]bool{"$1": true, "new_label": true}, @@ -1168,7 +1168,7 @@ var ( MetricIncludeFilter: internalFilterRegexp{include: regexp.MustCompile("^metric[12]$")}, Action: Combine, NewName: "new", - AggregationType: Sum, + AggregationType: sum, }, }, in: []pmetric.Metric{ @@ -1189,7 +1189,7 @@ var ( MetricIncludeFilter: internalFilterRegexp{include: regexp.MustCompile("^metric[12]$")}, Action: Combine, NewName: "new", - AggregationType: Sum, + AggregationType: sum, }, }, in: []pmetric.Metric{ @@ -1210,7 +1210,7 @@ var ( MetricIncludeFilter: internalFilterRegexp{include: regexp.MustCompile("^metric[12]$")}, Action: Combine, NewName: "new", - AggregationType: Sum, + AggregationType: sum, }, }, in: []pmetric.Metric{ @@ -1233,7 +1233,7 @@ var ( MetricIncludeFilter: internalFilterRegexp{include: regexp.MustCompile("^metric[12]$")}, Action: Combine, NewName: "new", - AggregationType: Sum, + AggregationType: sum, }, }, in: []pmetric.Metric{ @@ -1257,7 +1257,7 @@ var ( Operations: []internalOperation{ { configOperation: Operation{ - Action: ToggleScalarDataType, + Action: toggleScalarDataType, }, }, }, @@ -1268,7 +1268,7 @@ var ( Operations: []internalOperation{ { configOperation: Operation{ - Action: ToggleScalarDataType, + Action: toggleScalarDataType, }, }, }, @@ -1292,7 +1292,7 @@ var ( Operations: []internalOperation{ { configOperation: Operation{ - Action: ToggleScalarDataType, + Action: toggleScalarDataType, }, }, }, @@ -1303,7 +1303,7 @@ var ( Operations: []internalOperation{ { configOperation: Operation{ - Action: ToggleScalarDataType, + Action: toggleScalarDataType, }, }, }, @@ -1327,7 +1327,7 @@ var ( Operations: []internalOperation{ { configOperation: Operation{ - Action: ToggleScalarDataType, + Action: toggleScalarDataType, }, }, }, @@ -1352,7 +1352,7 @@ var ( Operations: []internalOperation{ { configOperation: Operation{ - Action: ScaleValue, + Action: scaleValue, Scale: 100, }, }, @@ -1364,7 +1364,7 @@ var ( Operations: []internalOperation{ { configOperation: Operation{ - Action: ScaleValue, + Action: scaleValue, Scale: 10, }, }, @@ -1389,7 +1389,7 @@ var ( Operations: []internalOperation{ { configOperation: Operation{ - Action: ScaleValue, + Action: scaleValue, Scale: 100, }, }, @@ -1401,7 +1401,7 @@ var ( Operations: []internalOperation{ { configOperation: Operation{ - Action: ScaleValue, + Action: scaleValue, Scale: .1, }, }, @@ -1426,7 +1426,7 @@ var ( Operations: []internalOperation{ { configOperation: Operation{ - Action: ScaleValue, + Action: scaleValue, Scale: 100, }, }, @@ -1438,7 +1438,7 @@ var ( Operations: []internalOperation{ { configOperation: Operation{ - Action: ScaleValue, + Action: scaleValue, Scale: .1, }, }, @@ -1467,7 +1467,7 @@ var ( Operations: []internalOperation{ { configOperation: Operation{ - Action: ScaleValue, + Action: scaleValue, Scale: 100, }, }, @@ -1479,7 +1479,7 @@ var ( Operations: []internalOperation{ { configOperation: Operation{ - Action: ScaleValue, + Action: scaleValue, Scale: .1, }, }, @@ -1509,7 +1509,7 @@ var ( Operations: []internalOperation{ { configOperation: Operation{ - Action: ScaleValue, + Action: scaleValue, Scale: 100, }, }, @@ -1522,7 +1522,7 @@ var ( Operations: []internalOperation{ { configOperation: Operation{ - Action: ScaleValue, + Action: scaleValue, Scale: 10, }, }, @@ -1535,7 +1535,7 @@ var ( Operations: []internalOperation{ { configOperation: Operation{ - Action: ScaleValue, + Action: scaleValue, Scale: 0.1, }, }, @@ -1575,7 +1575,7 @@ var ( Operations: []internalOperation{ { configOperation: Operation{ - Action: AddLabel, + Action: addLabel, NewLabel: "foo", NewValue: "bar", }, @@ -1599,7 +1599,7 @@ var ( Operations: []internalOperation{ { configOperation: Operation{ - Action: AddLabel, + Action: addLabel, NewLabel: "foo", NewValue: "bar", }, @@ -1625,7 +1625,7 @@ var ( Operations: []internalOperation{ { configOperation: Operation{ - Action: AddLabel, + Action: addLabel, NewLabel: "label1", NewValue: "value3", }, @@ -1651,7 +1651,7 @@ var ( Operations: []internalOperation{ { configOperation: Operation{ - Action: AddLabel, + Action: addLabel, NewLabel: "foo", NewValue: "bar", }, @@ -1678,7 +1678,7 @@ var ( Operations: []internalOperation{ { configOperation: Operation{ - Action: DeleteLabelValue, + Action: deleteLabelValue, Label: "label1", LabelValue: "label1value1", }, @@ -1705,7 +1705,7 @@ var ( Operations: []internalOperation{ { configOperation: Operation{ - Action: DeleteLabelValue, + Action: deleteLabelValue, Label: "label1", LabelValue: "label1value1", }, diff --git a/processor/metricstransformprocessor/operation_aggregate_labels.go b/processor/metricstransformprocessor/operation_aggregate_labels.go index 97f418795b72..dccc9ec869f3 100644 --- a/processor/metricstransformprocessor/operation_aggregate_labels.go +++ b/processor/metricstransformprocessor/operation_aggregate_labels.go @@ -31,7 +31,7 @@ func aggregateLabelsOp(metric pmetric.Metric, mtpOp internalOperation) { // groupMetrics groups all the provided timeseries that will be aggregated together based on all the label values. // Returns a map of grouped timeseries and the corresponding selected labels // canBeCombined must be callled before. -func groupMetrics(metrics pmetric.MetricSlice, aggType AggregationType, to pmetric.Metric) { +func groupMetrics(metrics pmetric.MetricSlice, aggType aggregationType, to pmetric.Metric) { var ag aggGroups for i := 0; i < metrics.Len(); i++ { ag = groupDataPoints(metrics.At(i), ag) @@ -68,7 +68,7 @@ func groupDataPoints(metric pmetric.Metric, ag aggGroups) aggGroups { return ag } -func mergeDataPoints(to pmetric.Metric, aggType AggregationType, ag aggGroups) { +func mergeDataPoints(to pmetric.Metric, aggType aggregationType, ag aggGroups) { switch to.Type() { case pmetric.MetricTypeGauge: mergeNumberDataPoints(ag.gauge, aggType, to.Gauge().DataPoints()) @@ -153,7 +153,7 @@ func dataPointHashKey(atts pcommon.Map, ts pcommon.Timestamp, other ...interface return string(jsonStr) } -func mergeNumberDataPoints(dpsMap map[string]pmetric.NumberDataPointSlice, agg AggregationType, to pmetric.NumberDataPointSlice) { +func mergeNumberDataPoints(dpsMap map[string]pmetric.NumberDataPointSlice, agg aggregationType, to pmetric.NumberDataPointSlice) { for _, dps := range dpsMap { dp := to.AppendEmpty() dps.At(0).MoveTo(dp) @@ -161,30 +161,30 @@ func mergeNumberDataPoints(dpsMap map[string]pmetric.NumberDataPointSlice, agg A case pmetric.NumberDataPointValueTypeDouble: for i := 1; i < dps.Len(); i++ { switch agg { - case Sum, Mean: + case sum, mean: dp.SetDoubleValue(dp.DoubleValue() + doubleVal(dps.At(i))) - case Max: + case max: dp.SetDoubleValue(math.Max(dp.DoubleValue(), doubleVal(dps.At(i)))) - case Min: + case min: dp.SetDoubleValue(math.Min(dp.DoubleValue(), doubleVal(dps.At(i)))) } if dps.At(i).StartTimestamp() < dp.StartTimestamp() { dp.SetStartTimestamp(dps.At(i).StartTimestamp()) } } - if agg == Mean { + if agg == mean { dp.SetDoubleValue(dp.DoubleValue() / float64(dps.Len())) } case pmetric.NumberDataPointValueTypeInt: for i := 1; i < dps.Len(); i++ { switch agg { - case Sum, Mean: + case sum, mean: dp.SetIntValue(dp.IntValue() + dps.At(i).IntValue()) - case Max: + case max: if dp.IntValue() < intVal(dps.At(i)) { dp.SetIntValue(intVal(dps.At(i))) } - case Min: + case min: if dp.IntValue() > intVal(dps.At(i)) { dp.SetIntValue(intVal(dps.At(i))) } @@ -193,7 +193,7 @@ func mergeNumberDataPoints(dpsMap map[string]pmetric.NumberDataPointSlice, agg A dp.SetStartTimestamp(dps.At(i).StartTimestamp()) } } - if agg == Mean { + if agg == mean { dp.SetIntValue(dp.IntValue() / int64(dps.Len())) } }