Skip to content

Commit 200fa9e

Browse files
pichlermarcTylerHelmuth
authored andcommitted
[processor/transform] use default unit in extract_count_metric() (open-telemetry#31636)
**Description:** The `transformprocessor` offers a function `extract_count_metric()`. Currently this function copies over the `unit` from the original metric to a new `count` metric. However, this unit is not applicable as the value is a count of how many values were recorded in a Explicit Bucket/Exponential Histogram or Summary. Therefore this PR changes that function so that it adds the default unit (`1`) to the extracted count metric instead. **Link to tracking Issue:** open-telemetry#31575 **Testing:** Unit tests (updated) **Documentation:** Added a changelog entry as the change is user-facing (the unit of the emitted telemetry is changed) --------- Co-authored-by: Tyler Helmuth <[email protected]>
1 parent ca1fdc2 commit 200fa9e

File tree

4 files changed

+38
-2
lines changed

4 files changed

+38
-2
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
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: transformprocessor
8+
9+
# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
10+
note: Change metric unit for metrics extracted with `extract_count_metric()` to be the default unit (`1`)
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: [31575]
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+
The original metric `unit` does not apply to extracted `count` metrics the same way it does to `sum`, `min` or `max`.
20+
Metrics extracted using `extract_count_metric()` now use the more appropriate default unit (`1`) instead.
21+
22+
# If your change doesn't affect end users or the exported elements of any package,
23+
# you should instead start your pull request title with [chore] or use the "Skip Changelog" label.
24+
# Optional: The change log or logs in which this entry should be included.
25+
# e.g. '[user]' or '[user, api]'
26+
# Include 'user' if the change is relevant to end users.
27+
# Include 'api' if there is a change to a library API.
28+
# Default: '[user]'
29+
change_logs: [user]

processor/transformprocessor/internal/metrics/func_extract_count_metric.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ func extractCountMetric(monotonic bool) (ottl.ExprFunc[ottlmetric.TransformConte
4444
countMetric := pmetric.NewMetric()
4545
countMetric.SetDescription(metric.Description())
4646
countMetric.SetName(metric.Name() + "_count")
47-
countMetric.SetUnit(metric.Unit())
47+
// Use the default unit as the original metric unit does not apply to the 'count' field
48+
countMetric.SetUnit("1")
4849
countMetric.SetEmptySum().SetAggregationTemporality(aggTemp)
4950
countMetric.Sum().SetIsMonotonic(monotonic)
5051

processor/transformprocessor/internal/metrics/func_extract_count_metric_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ func Test_extractCountMetric(t *testing.T) {
2424
histogramMetric := getTestHistogramMetric()
2525
histogramMetric.CopyTo(metrics.AppendEmpty())
2626
countMetric := metrics.AppendEmpty()
27+
countMetric.SetUnit("1")
2728
countMetric.SetEmptySum()
2829
countMetric.Sum().SetAggregationTemporality(histogramMetric.Histogram().AggregationTemporality())
2930
countMetric.Sum().SetIsMonotonic(false)
@@ -44,6 +45,7 @@ func Test_extractCountMetric(t *testing.T) {
4445
histogramMetric := getTestHistogramMetric()
4546
histogramMetric.CopyTo(metrics.AppendEmpty())
4647
countMetric := metrics.AppendEmpty()
48+
countMetric.SetUnit("1")
4749
countMetric.SetEmptySum()
4850
countMetric.Sum().SetAggregationTemporality(histogramMetric.Histogram().AggregationTemporality())
4951
countMetric.Sum().SetIsMonotonic(true)
@@ -64,6 +66,7 @@ func Test_extractCountMetric(t *testing.T) {
6466
expHistogramMetric := getTestExponentialHistogramMetric()
6567
expHistogramMetric.CopyTo(metrics.AppendEmpty())
6668
countMetric := metrics.AppendEmpty()
69+
countMetric.SetUnit("1")
6770
countMetric.SetEmptySum()
6871
countMetric.Sum().SetAggregationTemporality(expHistogramMetric.ExponentialHistogram().AggregationTemporality())
6972
countMetric.Sum().SetIsMonotonic(false)
@@ -85,6 +88,7 @@ func Test_extractCountMetric(t *testing.T) {
8588
expHistogramMetric.CopyTo(metrics.AppendEmpty())
8689
countMetric := metrics.AppendEmpty()
8790
countMetric.SetEmptySum()
91+
countMetric.SetUnit("1")
8892
countMetric.Sum().SetAggregationTemporality(expHistogramMetric.ExponentialHistogram().AggregationTemporality())
8993
countMetric.Sum().SetIsMonotonic(true)
9094

@@ -105,6 +109,7 @@ func Test_extractCountMetric(t *testing.T) {
105109
summaryMetric.CopyTo(metrics.AppendEmpty())
106110
countMetric := metrics.AppendEmpty()
107111
countMetric.SetEmptySum()
112+
countMetric.SetUnit("1")
108113
countMetric.Sum().SetAggregationTemporality(pmetric.AggregationTemporalityCumulative)
109114
countMetric.Sum().SetIsMonotonic(false)
110115

@@ -125,6 +130,7 @@ func Test_extractCountMetric(t *testing.T) {
125130
summaryMetric.CopyTo(metrics.AppendEmpty())
126131
countMetric := metrics.AppendEmpty()
127132
countMetric.SetEmptySum()
133+
countMetric.SetUnit("1")
128134
countMetric.Sum().SetAggregationTemporality(pmetric.AggregationTemporalityCumulative)
129135
countMetric.Sum().SetIsMonotonic(true)
130136

processor/transformprocessor/internal/metrics/processor_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ func Test_ProcessMetrics_MetricContext(t *testing.T) {
163163
countMetric.SetName(histogramMetric.Name() + "_count")
164164
countMetric.Sum().SetAggregationTemporality(pmetric.AggregationTemporalityDelta)
165165
countMetric.Sum().SetIsMonotonic(true)
166-
countMetric.SetUnit(histogramMetric.Unit())
166+
countMetric.SetUnit("1")
167167

168168
histogramDp0 := histogramMetric.Histogram().DataPoints().At(0)
169169
countDp0 := countMetric.Sum().DataPoints().AppendEmpty()

0 commit comments

Comments
 (0)