From 15b32609072b19c470b94283185de3edecffbdf6 Mon Sep 17 00:00:00 2001 From: dmathieu <42@dmathieu.com> Date: Mon, 3 Feb 2025 16:47:26 +0100 Subject: [PATCH 1/3] add pprofile aggregation temporality constants --- pdata/pprofile/aggregation_temporality.go | 35 +++++++++++++++++++ .../pprofile/aggregation_temporality_test.go | 17 +++++++++ 2 files changed, 52 insertions(+) create mode 100644 pdata/pprofile/aggregation_temporality.go create mode 100644 pdata/pprofile/aggregation_temporality_test.go diff --git a/pdata/pprofile/aggregation_temporality.go b/pdata/pprofile/aggregation_temporality.go new file mode 100644 index 00000000000..b79f8b04097 --- /dev/null +++ b/pdata/pprofile/aggregation_temporality.go @@ -0,0 +1,35 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +package pprofile // import "go.opentelemetry.io/collector/pdata/pprofile" + +import ( + otlpprofiles "go.opentelemetry.io/collector/pdata/internal/data/protogen/profiles/v1development" +) + +// AggregationTemporality specifies the method of aggregating metric values, +// either DELTA (change since last report) or CUMULATIVE (total since a fixed +// start time). +type AggregationTemporality int32 + +const ( + // AggregationTemporalityUnspecified is the default AggregationTemporality, it MUST NOT be used. + AggregationTemporalityUnspecified = AggregationTemporality(otlpprofiles.AggregationTemporality_AGGREGATION_TEMPORALITY_UNSPECIFIED) + // AggregationTemporalityDelta is a AggregationTemporality for a metric aggregator which reports changes since last report time. + AggregationTemporalityDelta = AggregationTemporality(otlpprofiles.AggregationTemporality_AGGREGATION_TEMPORALITY_DELTA) + // AggregationTemporalityCumulative is a AggregationTemporality for a metric aggregator which reports changes since a fixed start time. + AggregationTemporalityCumulative = AggregationTemporality(otlpprofiles.AggregationTemporality_AGGREGATION_TEMPORALITY_CUMULATIVE) +) + +// String returns the string representation of the AggregationTemporality. +func (at AggregationTemporality) String() string { + switch at { + case AggregationTemporalityUnspecified: + return "Unspecified" + case AggregationTemporalityDelta: + return "Delta" + case AggregationTemporalityCumulative: + return "Cumulative" + } + return "" +} diff --git a/pdata/pprofile/aggregation_temporality_test.go b/pdata/pprofile/aggregation_temporality_test.go new file mode 100644 index 00000000000..eefe2c89e8f --- /dev/null +++ b/pdata/pprofile/aggregation_temporality_test.go @@ -0,0 +1,17 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +package pprofile + +import ( + "testing" + + "github.com/stretchr/testify/assert" +) + +func TestAggregationTemporalityString(t *testing.T) { + assert.Equal(t, "Unspecified", AggregationTemporalityUnspecified.String()) + assert.Equal(t, "Delta", AggregationTemporalityDelta.String()) + assert.Equal(t, "Cumulative", AggregationTemporalityCumulative.String()) + assert.Equal(t, "", (AggregationTemporalityCumulative + 1).String()) +} From e6f2275482b2e4aab51873519583a94aac958b9d Mon Sep 17 00:00:00 2001 From: dmathieu <42@dmathieu.com> Date: Mon, 3 Feb 2025 16:49:14 +0100 Subject: [PATCH 2/3] add changelog entry --- .chloggen/pprofile-aggregation-constants.yaml | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 .chloggen/pprofile-aggregation-constants.yaml diff --git a/.chloggen/pprofile-aggregation-constants.yaml b/.chloggen/pprofile-aggregation-constants.yaml new file mode 100644 index 00000000000..3620f40f2d3 --- /dev/null +++ b/.chloggen/pprofile-aggregation-constants.yaml @@ -0,0 +1,25 @@ +# Use this changelog template to create an entry for release notes. + +# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix' +change_type: enhancement + +# The name of the component, or a single word describing the area of concern, (e.g. otlpreceiver) +component: pdata/pprofile + +# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`). +note: Introduce aggregation temporality constants + +# One or more tracking issues or pull requests related to the change +issues: [12253] + +# (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: + +# 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] From 582e27c85402be6f9245fdcebb0c002e9e8524ae Mon Sep 17 00:00:00 2001 From: dmathieu <42@dmathieu.com> Date: Tue, 4 Feb 2025 09:41:38 +0100 Subject: [PATCH 3/3] use pprofile AggregationTemporality in generated code --- .../cmd/pdatagen/internal/pprofile_package.go | 13 ++++++++----- pdata/pprofile/generated_valuetype.go | 8 ++++---- pdata/pprofile/generated_valuetype_test.go | 11 ++++------- 3 files changed, 16 insertions(+), 16 deletions(-) diff --git a/pdata/internal/cmd/pdatagen/internal/pprofile_package.go b/pdata/internal/cmd/pdatagen/internal/pprofile_package.go index cc15b783642..146743f7935 100644 --- a/pdata/internal/cmd/pdatagen/internal/pprofile_package.go +++ b/pdata/internal/cmd/pdatagen/internal/pprofile_package.go @@ -283,11 +283,14 @@ var valueType = &messageValueStruct{ defaultVal: "int32(0)", testVal: "int32(1)", }, - &primitiveField{ - fieldName: "AggregationTemporality", - returnType: "otlpprofiles.AggregationTemporality", - defaultVal: "otlpprofiles.AggregationTemporality(0)", - testVal: "otlpprofiles.AggregationTemporality(1)", + &primitiveTypedField{ + fieldName: "AggregationTemporality", + returnType: &primitiveType{ + structName: "AggregationTemporality", + rawType: "otlpprofiles.AggregationTemporality", + defaultVal: "otlpprofiles.AggregationTemporality(0)", + testVal: "otlpprofiles.AggregationTemporality(1)", + }, }, }, } diff --git a/pdata/pprofile/generated_valuetype.go b/pdata/pprofile/generated_valuetype.go index 2afc8614048..4f8b4e11e6a 100644 --- a/pdata/pprofile/generated_valuetype.go +++ b/pdata/pprofile/generated_valuetype.go @@ -68,14 +68,14 @@ func (ms ValueType) SetUnitStrindex(v int32) { } // AggregationTemporality returns the aggregationtemporality associated with this ValueType. -func (ms ValueType) AggregationTemporality() otlpprofiles.AggregationTemporality { - return ms.orig.AggregationTemporality +func (ms ValueType) AggregationTemporality() AggregationTemporality { + return AggregationTemporality(ms.orig.AggregationTemporality) } // SetAggregationTemporality replaces the aggregationtemporality associated with this ValueType. -func (ms ValueType) SetAggregationTemporality(v otlpprofiles.AggregationTemporality) { +func (ms ValueType) SetAggregationTemporality(v AggregationTemporality) { ms.state.AssertMutable() - ms.orig.AggregationTemporality = v + ms.orig.AggregationTemporality = otlpprofiles.AggregationTemporality(v) } // CopyTo copies all properties from the current struct overriding the destination. diff --git a/pdata/pprofile/generated_valuetype_test.go b/pdata/pprofile/generated_valuetype_test.go index 8e535a15086..8c1b537875f 100644 --- a/pdata/pprofile/generated_valuetype_test.go +++ b/pdata/pprofile/generated_valuetype_test.go @@ -58,13 +58,10 @@ func TestValueType_UnitStrindex(t *testing.T) { func TestValueType_AggregationTemporality(t *testing.T) { ms := NewValueType() - assert.Equal(t, otlpprofiles.AggregationTemporality(0), ms.AggregationTemporality()) - ms.SetAggregationTemporality(otlpprofiles.AggregationTemporality(1)) - assert.Equal(t, otlpprofiles.AggregationTemporality(1), ms.AggregationTemporality()) - sharedState := internal.StateReadOnly - assert.Panics(t, func() { - newValueType(&otlpprofiles.ValueType{}, &sharedState).SetAggregationTemporality(otlpprofiles.AggregationTemporality(1)) - }) + assert.Equal(t, AggregationTemporality(otlpprofiles.AggregationTemporality(0)), ms.AggregationTemporality()) + testValAggregationTemporality := AggregationTemporality(otlpprofiles.AggregationTemporality(1)) + ms.SetAggregationTemporality(testValAggregationTemporality) + assert.Equal(t, testValAggregationTemporality, ms.AggregationTemporality()) } func generateTestValueType() ValueType {