Skip to content

Commit bc88695

Browse files
crobert-1zeck-ops
authored andcommitted
[processor/metricsgeneration] Add config validation for generated metric names (open-telemetry#37599)
<!--Ex. Fixing a bug - Describe the bug and how this fixes the issue. Ex. Adding a feature - Explain what this achieves.--> #### Description If a generated metric name matched the metric being scaled an infinite loop is hit. Since this action is not supported by this processor, and is supported by the metrics transform processor, the fix here is to add config validation to enforce metric names are different. <!-- Issue number (e.g. open-telemetry#1234) or full URL to issue, if applicable. --> #### Link to tracking issue Fixes open-telemetry#37474 <!--Describe what testing was performed and which tests were added.--> #### Testing Added a test to ensure enforcement is done properly.
1 parent fb8ecc9 commit bc88695

File tree

4 files changed

+57
-0
lines changed

4 files changed

+57
-0
lines changed

.chloggen/metricsgeneration_loop.yaml

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Use this changelog template to create an entry for release notes.
2+
3+
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
4+
change_type: bug_fix
5+
6+
# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver)
7+
component: metricsgenerationprocessor
8+
9+
# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
10+
note: Generated metric name may not match metric being scaled
11+
12+
# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists.
13+
issues: [37474]
14+
15+
# (Optional) One or more lines of additional information to render under the primary note.
16+
# These lines will be padded with 2 spaces and then inserted directly into the document.
17+
# Use pipe (|) for multiline entries.
18+
subtext:
19+
20+
# If your change doesn't affect end users or the exported elements of any package,
21+
# you should instead start your pull request title with [chore] or use the "Skip Changelog" label.
22+
# Optional: The change log or logs in which this entry should be included.
23+
# e.g. '[user]' or '[user, api]'
24+
# Include 'user' if the change is relevant to end users.
25+
# Include 'api' if there is a change to a library API.
26+
# Default: '[user]'
27+
change_logs: []

processor/metricsgenerationprocessor/config.go

+6
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,12 @@ func (config *Config) Validate() error {
161161
if rule.Operation != "" && !rule.Operation.isValid() {
162162
return fmt.Errorf("%q must be in %q", operationFieldName, operationTypeKeys())
163163
}
164+
165+
if rule.Name == rule.Metric1 {
166+
return fmt.Errorf("value of field %q may not match value of field %q", nameFieldName, metric1FieldName)
167+
} else if rule.Name == rule.Metric2 {
168+
return fmt.Errorf("value of field %q may not match value of field %q", nameFieldName, metric2FieldName)
169+
}
164170
}
165171
return nil
166172
}

processor/metricsgenerationprocessor/config_test.go

+8
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,14 @@ func TestLoadConfig(t *testing.T) {
7575
id: component.NewIDWithName(metadata.Type, "invalid_operation"),
7676
errorMessage: fmt.Sprintf("%q must be in %q", operationFieldName, operationTypeKeys()),
7777
},
78+
{
79+
id: component.NewIDWithName(metadata.Type, "matching_metric1"),
80+
errorMessage: fmt.Sprintf("value of field %q may not match value of field %q", nameFieldName, metric1FieldName),
81+
},
82+
{
83+
id: component.NewIDWithName(metadata.Type, "matching_metric2"),
84+
errorMessage: fmt.Sprintf("value of field %q may not match value of field %q", nameFieldName, metric2FieldName),
85+
},
7886
}
7987

8088
for _, tt := range tests {

processor/metricsgenerationprocessor/testdata/config.yaml

+16
Original file line numberDiff line numberDiff line change
@@ -68,3 +68,19 @@ metricsgeneration/missing_type:
6868
metric1: metric1
6969
metric2: metric2
7070
operation: percent
71+
72+
metricsgeneration/matching_metric1:
73+
rules:
74+
- name: new_metric
75+
type: scale
76+
metric1: new_metric
77+
operation: multiply
78+
scale_by: 100
79+
80+
metricsgeneration/matching_metric2:
81+
rules:
82+
- name: new_metric
83+
type: calculate
84+
metric1: original
85+
metric2: new_metric
86+
operation: multiply

0 commit comments

Comments
 (0)