From e4cfde47582df7bc20106fc0713d0a19b889f2a3 Mon Sep 17 00:00:00 2001 From: Dmitrii Anoshin Date: Fri, 7 Oct 2022 09:37:47 -0700 Subject: [PATCH] [pdata] Rename MetricAggregationTemporality to AggregationTemporality (#6253) As a new rule we want to rename all the structs for proto messages defined at the package level to not have the owner prefix in its name. --- CHANGELOG.md | 1 + internal/testdata/metric.go | 6 +-- .../cmd/pdatagen/internal/metrics_structs.go | 2 +- pdata/pmetric/generated_metrics.go | 18 ++++----- pdata/pmetric/generated_metrics_test.go | 12 +++--- pdata/pmetric/json_test.go | 6 +-- pdata/pmetric/metrics.go | 40 +++++++++++++------ pdata/pmetric/metrics_test.go | 20 +++++----- processor/batchprocessor/splitmetrics_test.go | 16 ++++---- 9 files changed, 68 insertions(+), 53 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 99ae7d77dbd..9ad79ac480b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -34,6 +34,7 @@ - Deprecate `p[metric|log|trace]otlp.RegiserServer` in favor of `p[metric|log|trace]otlp.RegiserGRPCServer` (#6180) - Deprecate `pcommon.Map.PutString` in favor of `pcommon.Map.PutStr` (#6210) - Deprecate `pcommon.NewValueString` in favor of `pcommon.NewValueStr` (#6209) +- Deprecate `pmetric.MetricAggregationTemporality` enum type in favor of `pmetric.AggregationTemporality` (#6249) ### 💡 Enhancements 💡 diff --git a/internal/testdata/metric.go b/internal/testdata/metric.go index eaec3478700..85a9464b014 100644 --- a/internal/testdata/metric.go +++ b/internal/testdata/metric.go @@ -291,13 +291,13 @@ func initMetric(m pmetric.Metric, name string, ty pmetric.MetricType) { case pmetric.MetricTypeSum: sum := m.SetEmptySum() sum.SetIsMonotonic(true) - sum.SetAggregationTemporality(pmetric.MetricAggregationTemporalityCumulative) + sum.SetAggregationTemporality(pmetric.AggregationTemporalityCumulative) case pmetric.MetricTypeHistogram: histo := m.SetEmptyHistogram() - histo.SetAggregationTemporality(pmetric.MetricAggregationTemporalityCumulative) + histo.SetAggregationTemporality(pmetric.AggregationTemporalityCumulative) case pmetric.MetricTypeExponentialHistogram: histo := m.SetEmptyExponentialHistogram() - histo.SetAggregationTemporality(pmetric.MetricAggregationTemporalityDelta) + histo.SetAggregationTemporality(pmetric.AggregationTemporalityDelta) case pmetric.MetricTypeSummary: m.SetEmptySummary() } diff --git a/pdata/internal/cmd/pdatagen/internal/metrics_structs.go b/pdata/internal/cmd/pdatagen/internal/metrics_structs.go index c9a07ec9cad..ea137a79ae6 100644 --- a/pdata/internal/cmd/pdatagen/internal/metrics_structs.go +++ b/pdata/internal/cmd/pdatagen/internal/metrics_structs.go @@ -568,7 +568,7 @@ var aggregationTemporalityField = &primitiveTypedField{ fieldName: "AggregationTemporality", originFieldName: "AggregationTemporality", returnType: &primitiveType{ - structName: "MetricAggregationTemporality", + structName: "AggregationTemporality", rawType: "otlpmetrics.AggregationTemporality", defaultVal: "otlpmetrics.AggregationTemporality(0)", testVal: "otlpmetrics.AggregationTemporality(1)", diff --git a/pdata/pmetric/generated_metrics.go b/pdata/pmetric/generated_metrics.go index d2df193b7b8..20a9c7dab26 100644 --- a/pdata/pmetric/generated_metrics.go +++ b/pdata/pmetric/generated_metrics.go @@ -870,12 +870,12 @@ func (ms Sum) MoveTo(dest Sum) { } // AggregationTemporality returns the aggregationtemporality associated with this Sum. -func (ms Sum) AggregationTemporality() MetricAggregationTemporality { - return MetricAggregationTemporality(ms.getOrig().AggregationTemporality) +func (ms Sum) AggregationTemporality() AggregationTemporality { + return AggregationTemporality(ms.getOrig().AggregationTemporality) } // SetAggregationTemporality replaces the aggregationtemporality associated with this Sum. -func (ms Sum) SetAggregationTemporality(v MetricAggregationTemporality) { +func (ms Sum) SetAggregationTemporality(v AggregationTemporality) { ms.getOrig().AggregationTemporality = otlpmetrics.AggregationTemporality(v) } @@ -935,12 +935,12 @@ func (ms Histogram) MoveTo(dest Histogram) { } // AggregationTemporality returns the aggregationtemporality associated with this Histogram. -func (ms Histogram) AggregationTemporality() MetricAggregationTemporality { - return MetricAggregationTemporality(ms.getOrig().AggregationTemporality) +func (ms Histogram) AggregationTemporality() AggregationTemporality { + return AggregationTemporality(ms.getOrig().AggregationTemporality) } // SetAggregationTemporality replaces the aggregationtemporality associated with this Histogram. -func (ms Histogram) SetAggregationTemporality(v MetricAggregationTemporality) { +func (ms Histogram) SetAggregationTemporality(v AggregationTemporality) { ms.getOrig().AggregationTemporality = otlpmetrics.AggregationTemporality(v) } @@ -990,12 +990,12 @@ func (ms ExponentialHistogram) MoveTo(dest ExponentialHistogram) { } // AggregationTemporality returns the aggregationtemporality associated with this ExponentialHistogram. -func (ms ExponentialHistogram) AggregationTemporality() MetricAggregationTemporality { - return MetricAggregationTemporality(ms.getOrig().AggregationTemporality) +func (ms ExponentialHistogram) AggregationTemporality() AggregationTemporality { + return AggregationTemporality(ms.getOrig().AggregationTemporality) } // SetAggregationTemporality replaces the aggregationtemporality associated with this ExponentialHistogram. -func (ms ExponentialHistogram) SetAggregationTemporality(v MetricAggregationTemporality) { +func (ms ExponentialHistogram) SetAggregationTemporality(v AggregationTemporality) { ms.getOrig().AggregationTemporality = otlpmetrics.AggregationTemporality(v) } diff --git a/pdata/pmetric/generated_metrics_test.go b/pdata/pmetric/generated_metrics_test.go index ab25934440b..ada350b96a8 100644 --- a/pdata/pmetric/generated_metrics_test.go +++ b/pdata/pmetric/generated_metrics_test.go @@ -598,8 +598,8 @@ func TestSum_CopyTo(t *testing.T) { func TestSum_AggregationTemporality(t *testing.T) { ms := NewSum() - assert.Equal(t, MetricAggregationTemporality(otlpmetrics.AggregationTemporality(0)), ms.AggregationTemporality()) - testValAggregationTemporality := MetricAggregationTemporality(otlpmetrics.AggregationTemporality(1)) + assert.Equal(t, AggregationTemporality(otlpmetrics.AggregationTemporality(0)), ms.AggregationTemporality()) + testValAggregationTemporality := AggregationTemporality(otlpmetrics.AggregationTemporality(1)) ms.SetAggregationTemporality(testValAggregationTemporality) assert.Equal(t, testValAggregationTemporality, ms.AggregationTemporality()) } @@ -638,8 +638,8 @@ func TestHistogram_CopyTo(t *testing.T) { func TestHistogram_AggregationTemporality(t *testing.T) { ms := NewHistogram() - assert.Equal(t, MetricAggregationTemporality(otlpmetrics.AggregationTemporality(0)), ms.AggregationTemporality()) - testValAggregationTemporality := MetricAggregationTemporality(otlpmetrics.AggregationTemporality(1)) + assert.Equal(t, AggregationTemporality(otlpmetrics.AggregationTemporality(0)), ms.AggregationTemporality()) + testValAggregationTemporality := AggregationTemporality(otlpmetrics.AggregationTemporality(1)) ms.SetAggregationTemporality(testValAggregationTemporality) assert.Equal(t, testValAggregationTemporality, ms.AggregationTemporality()) } @@ -671,8 +671,8 @@ func TestExponentialHistogram_CopyTo(t *testing.T) { func TestExponentialHistogram_AggregationTemporality(t *testing.T) { ms := NewExponentialHistogram() - assert.Equal(t, MetricAggregationTemporality(otlpmetrics.AggregationTemporality(0)), ms.AggregationTemporality()) - testValAggregationTemporality := MetricAggregationTemporality(otlpmetrics.AggregationTemporality(1)) + assert.Equal(t, AggregationTemporality(otlpmetrics.AggregationTemporality(0)), ms.AggregationTemporality()) + testValAggregationTemporality := AggregationTemporality(otlpmetrics.AggregationTemporality(1)) ms.SetAggregationTemporality(testValAggregationTemporality) assert.Equal(t, testValAggregationTemporality, ms.AggregationTemporality()) } diff --git a/pdata/pmetric/json_test.go b/pdata/pmetric/json_test.go index ea4cf384807..f4d05ca593f 100644 --- a/pdata/pmetric/json_test.go +++ b/pdata/pmetric/json_test.go @@ -77,7 +77,7 @@ var metricsSumOTLPFull = func() Metrics { sumMetric.SetDescription("test sum") sumMetric.SetUnit("unit") sum := sumMetric.SetEmptySum() - sum.SetAggregationTemporality(MetricAggregationTemporalityCumulative) + sum.SetAggregationTemporality(AggregationTemporalityCumulative) sum.SetIsMonotonic(true) datapoint := sum.DataPoints().AppendEmpty() datapoint.SetStartTimestamp(pcommon.NewTimestampFromTime(time.Now())) @@ -157,7 +157,7 @@ var metricsHistogramOTLPFull = func() Metrics { histogramMetric.SetDescription("test Histogram") histogramMetric.SetUnit("unit") histogram := histogramMetric.SetEmptyHistogram() - histogram.SetAggregationTemporality(MetricAggregationTemporalityCumulative) + histogram.SetAggregationTemporality(AggregationTemporalityCumulative) datapoint := histogram.DataPoints().AppendEmpty() datapoint.SetStartTimestamp(pcommon.NewTimestampFromTime(time.Now())) datapoint.Attributes().PutStr("string", "value") @@ -202,7 +202,7 @@ var metricsExponentialHistogramOTLPFull = func() Metrics { histogramMetric.SetDescription("test ExponentialHistogram") histogramMetric.SetUnit("unit") histogram := histogramMetric.SetEmptyExponentialHistogram() - histogram.SetAggregationTemporality(MetricAggregationTemporalityCumulative) + histogram.SetAggregationTemporality(AggregationTemporalityCumulative) datapoint := histogram.DataPoints().AppendEmpty() datapoint.SetScale(1) datapoint.SetStartTimestamp(pcommon.NewTimestampFromTime(time.Now())) diff --git a/pdata/pmetric/metrics.go b/pdata/pmetric/metrics.go index 11b968789f3..998ef8e417e 100644 --- a/pdata/pmetric/metrics.go +++ b/pdata/pmetric/metrics.go @@ -129,32 +129,46 @@ func (mdt MetricType) String() string { return "" } -// MetricAggregationTemporality defines how a metric aggregator reports aggregated values. +// AggregationTemporality defines how a metric aggregator reports aggregated values. // It describes how those values relate to the time interval over which they are aggregated. -type MetricAggregationTemporality int32 +type AggregationTemporality int32 const ( - // MetricAggregationTemporalityUnspecified is the default MetricAggregationTemporality, it MUST NOT be used. - MetricAggregationTemporalityUnspecified = MetricAggregationTemporality(otlpmetrics.AggregationTemporality_AGGREGATION_TEMPORALITY_UNSPECIFIED) - // MetricAggregationTemporalityDelta is a MetricAggregationTemporality for a metric aggregator which reports changes since last report time. - MetricAggregationTemporalityDelta = MetricAggregationTemporality(otlpmetrics.AggregationTemporality_AGGREGATION_TEMPORALITY_DELTA) - // MetricAggregationTemporalityCumulative is a MetricAggregationTemporality for a metric aggregator which reports changes since a fixed start time. - MetricAggregationTemporalityCumulative = MetricAggregationTemporality(otlpmetrics.AggregationTemporality_AGGREGATION_TEMPORALITY_CUMULATIVE) + // AggregationTemporalityUnspecified is the default AggregationTemporality, it MUST NOT be used. + AggregationTemporalityUnspecified = AggregationTemporality(otlpmetrics.AggregationTemporality_AGGREGATION_TEMPORALITY_UNSPECIFIED) + // AggregationTemporalityDelta is a AggregationTemporality for a metric aggregator which reports changes since last report time. + AggregationTemporalityDelta = AggregationTemporality(otlpmetrics.AggregationTemporality_AGGREGATION_TEMPORALITY_DELTA) + // AggregationTemporalityCumulative is a AggregationTemporality for a metric aggregator which reports changes since a fixed start time. + AggregationTemporalityCumulative = AggregationTemporality(otlpmetrics.AggregationTemporality_AGGREGATION_TEMPORALITY_CUMULATIVE) ) -// String returns the string representation of the MetricAggregationTemporality. -func (at MetricAggregationTemporality) String() string { +// String returns the string representation of the AggregationTemporality. +func (at AggregationTemporality) String() string { switch at { - case MetricAggregationTemporalityUnspecified: + case AggregationTemporalityUnspecified: return "Unspecified" - case MetricAggregationTemporalityDelta: + case AggregationTemporalityDelta: return "Delta" - case MetricAggregationTemporalityCumulative: + case AggregationTemporalityCumulative: return "Cumulative" } return "" } +// Deprecated: [0.62.0] Use AggregationTemporality instead. +type MetricAggregationTemporality = AggregationTemporality + +const ( + // Deprecated: [0.62.0] Use AggregationTemporalityUnspecified instead. + MetricAggregationTemporalityUnspecified = AggregationTemporalityUnspecified + + // Deprecated: [0.62.0] Use AggregationTemporalityDelta instead. + MetricAggregationTemporalityDelta = AggregationTemporalityDelta + + // Deprecated: [0.62.0] Use AggregationTemporalityCumulative instead. + MetricAggregationTemporalityCumulative = AggregationTemporalityCumulative +) + // NumberDataPointValueType specifies the type of NumberDataPoint value. type NumberDataPointValueType int32 diff --git a/pdata/pmetric/metrics_test.go b/pdata/pmetric/metrics_test.go index 4579412d6b9..1e3ad284e22 100644 --- a/pdata/pmetric/metrics_test.go +++ b/pdata/pmetric/metrics_test.go @@ -45,11 +45,11 @@ func TestMetricTypeString(t *testing.T) { assert.Equal(t, "", (MetricTypeSummary + 1).String()) } -func TestMetricAggregationTemporalityString(t *testing.T) { - assert.Equal(t, "Unspecified", MetricAggregationTemporalityUnspecified.String()) - assert.Equal(t, "Delta", MetricAggregationTemporalityDelta.String()) - assert.Equal(t, "Cumulative", MetricAggregationTemporalityCumulative.String()) - assert.Equal(t, "", (MetricAggregationTemporalityCumulative + 1).String()) +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()) } func TestNumberDataPointValueTypeString(t *testing.T) { @@ -284,7 +284,7 @@ func TestOtlpToInternalReadOnly(t *testing.T) { assert.EqualValues(t, "ms", metricDouble.Unit()) assert.EqualValues(t, MetricTypeSum, metricDouble.Type()) dsd := metricDouble.Sum() - assert.EqualValues(t, MetricAggregationTemporalityCumulative, dsd.AggregationTemporality()) + assert.EqualValues(t, AggregationTemporalityCumulative, dsd.AggregationTemporality()) sumDataPoints := dsd.DataPoints() assert.EqualValues(t, 2, sumDataPoints.Len()) // First point @@ -305,7 +305,7 @@ func TestOtlpToInternalReadOnly(t *testing.T) { assert.EqualValues(t, "ms", metricHistogram.Unit()) assert.EqualValues(t, MetricTypeHistogram, metricHistogram.Type()) dhd := metricHistogram.Histogram() - assert.EqualValues(t, MetricAggregationTemporalityDelta, dhd.AggregationTemporality()) + assert.EqualValues(t, AggregationTemporalityDelta, dhd.AggregationTemporality()) histogramDataPoints := dhd.DataPoints() assert.EqualValues(t, 2, histogramDataPoints.Len()) // First point @@ -462,7 +462,7 @@ func TestOtlpToFromInternalSumMutating(t *testing.T) { // Mutate DataPoints dsd := metric.Sum() assert.EqualValues(t, 2, dsd.DataPoints().Len()) - metric.SetEmptySum().SetAggregationTemporality(MetricAggregationTemporalityCumulative) + metric.SetEmptySum().SetAggregationTemporality(AggregationTemporalityCumulative) doubleDataPoints := metric.Sum().DataPoints() doubleDataPoints.AppendEmpty() assert.EqualValues(t, 1, doubleDataPoints.Len()) @@ -546,7 +546,7 @@ func TestOtlpToFromInternalHistogramMutating(t *testing.T) { // Mutate DataPoints dhd := metric.Histogram() assert.EqualValues(t, 2, dhd.DataPoints().Len()) - metric.SetEmptyHistogram().SetAggregationTemporality(MetricAggregationTemporalityDelta) + metric.SetEmptyHistogram().SetAggregationTemporality(AggregationTemporalityDelta) histogramDataPoints := metric.Histogram().DataPoints() histogramDataPoints.AppendEmpty() assert.EqualValues(t, 1, histogramDataPoints.Len()) @@ -629,7 +629,7 @@ func TestOtlpToFromInternalExponentialHistogramMutating(t *testing.T) { // Mutate DataPoints dhd := metric.Histogram() assert.EqualValues(t, 2, dhd.DataPoints().Len()) - metric.SetEmptyExponentialHistogram().SetAggregationTemporality(MetricAggregationTemporalityDelta) + metric.SetEmptyExponentialHistogram().SetAggregationTemporality(AggregationTemporalityDelta) histogramDataPoints := metric.ExponentialHistogram().DataPoints() histogramDataPoints.AppendEmpty() assert.EqualValues(t, 1, histogramDataPoints.Len()) diff --git a/processor/batchprocessor/splitmetrics_test.go b/processor/batchprocessor/splitmetrics_test.go index 12262c6f71c..f19f0d7c20b 100644 --- a/processor/batchprocessor/splitmetrics_test.go +++ b/processor/batchprocessor/splitmetrics_test.go @@ -202,7 +202,7 @@ func TestSplitMetricsAllTypes(t *testing.T) { assert.Equal(t, 1, gaugeDouble.Gauge().DataPoints().Len()) assert.Equal(t, "test-metric-int-0-1", gaugeDouble.Name()) assert.Equal(t, 1, sumInt.Sum().DataPoints().Len()) - assert.Equal(t, pmetric.MetricAggregationTemporalityCumulative, sumInt.Sum().AggregationTemporality()) + assert.Equal(t, pmetric.AggregationTemporalityCumulative, sumInt.Sum().AggregationTemporality()) assert.Equal(t, true, sumInt.Sum().IsMonotonic()) assert.Equal(t, "test-metric-int-0-2", sumInt.Name()) @@ -212,11 +212,11 @@ func TestSplitMetricsAllTypes(t *testing.T) { sumInt = split.ResourceMetrics().At(0).ScopeMetrics().At(0).Metrics().At(0) sumDouble := split.ResourceMetrics().At(0).ScopeMetrics().At(0).Metrics().At(1) assert.Equal(t, 1, sumInt.Sum().DataPoints().Len()) - assert.Equal(t, pmetric.MetricAggregationTemporalityCumulative, sumInt.Sum().AggregationTemporality()) + assert.Equal(t, pmetric.AggregationTemporalityCumulative, sumInt.Sum().AggregationTemporality()) assert.Equal(t, true, sumInt.Sum().IsMonotonic()) assert.Equal(t, "test-metric-int-0-2", sumInt.Name()) assert.Equal(t, 1, sumDouble.Sum().DataPoints().Len()) - assert.Equal(t, pmetric.MetricAggregationTemporalityCumulative, sumDouble.Sum().AggregationTemporality()) + assert.Equal(t, pmetric.AggregationTemporalityCumulative, sumDouble.Sum().AggregationTemporality()) assert.Equal(t, true, sumDouble.Sum().IsMonotonic()) assert.Equal(t, "test-metric-int-0-3", sumDouble.Name()) @@ -226,11 +226,11 @@ func TestSplitMetricsAllTypes(t *testing.T) { sumDouble = split.ResourceMetrics().At(0).ScopeMetrics().At(0).Metrics().At(0) histogram := split.ResourceMetrics().At(0).ScopeMetrics().At(0).Metrics().At(1) assert.Equal(t, 1, sumDouble.Sum().DataPoints().Len()) - assert.Equal(t, pmetric.MetricAggregationTemporalityCumulative, sumDouble.Sum().AggregationTemporality()) + assert.Equal(t, pmetric.AggregationTemporalityCumulative, sumDouble.Sum().AggregationTemporality()) assert.Equal(t, true, sumDouble.Sum().IsMonotonic()) assert.Equal(t, "test-metric-int-0-3", sumDouble.Name()) assert.Equal(t, 1, histogram.Histogram().DataPoints().Len()) - assert.Equal(t, pmetric.MetricAggregationTemporalityCumulative, histogram.Histogram().AggregationTemporality()) + assert.Equal(t, pmetric.AggregationTemporalityCumulative, histogram.Histogram().AggregationTemporality()) assert.Equal(t, "test-metric-int-0-4", histogram.Name()) split = splitMetrics(splitSize, md) @@ -239,10 +239,10 @@ func TestSplitMetricsAllTypes(t *testing.T) { histogram = split.ResourceMetrics().At(0).ScopeMetrics().At(0).Metrics().At(0) exponentialHistogram := split.ResourceMetrics().At(0).ScopeMetrics().At(0).Metrics().At(1) assert.Equal(t, 1, histogram.Histogram().DataPoints().Len()) - assert.Equal(t, pmetric.MetricAggregationTemporalityCumulative, histogram.Histogram().AggregationTemporality()) + assert.Equal(t, pmetric.AggregationTemporalityCumulative, histogram.Histogram().AggregationTemporality()) assert.Equal(t, "test-metric-int-0-4", histogram.Name()) assert.Equal(t, 1, exponentialHistogram.ExponentialHistogram().DataPoints().Len()) - assert.Equal(t, pmetric.MetricAggregationTemporalityDelta, exponentialHistogram.ExponentialHistogram().AggregationTemporality()) + assert.Equal(t, pmetric.AggregationTemporalityDelta, exponentialHistogram.ExponentialHistogram().AggregationTemporality()) assert.Equal(t, "test-metric-int-0-5", exponentialHistogram.Name()) split = splitMetrics(splitSize, md) @@ -251,7 +251,7 @@ func TestSplitMetricsAllTypes(t *testing.T) { exponentialHistogram = split.ResourceMetrics().At(0).ScopeMetrics().At(0).Metrics().At(0) summary := split.ResourceMetrics().At(0).ScopeMetrics().At(0).Metrics().At(1) assert.Equal(t, 1, exponentialHistogram.ExponentialHistogram().DataPoints().Len()) - assert.Equal(t, pmetric.MetricAggregationTemporalityDelta, exponentialHistogram.ExponentialHistogram().AggregationTemporality()) + assert.Equal(t, pmetric.AggregationTemporalityDelta, exponentialHistogram.ExponentialHistogram().AggregationTemporality()) assert.Equal(t, "test-metric-int-0-5", exponentialHistogram.Name()) assert.Equal(t, 1, summary.Summary().DataPoints().Len()) assert.Equal(t, "test-metric-int-0-6", summary.Name())