diff --git a/CHANGELOG.md b/CHANGELOG.md index 026d9c461157..30db69bf036c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -28,6 +28,10 @@ ## 💡 Enhancements 💡 - Supports more compression methods(`snappy` and `zstd`) for configgrpc, in addition to current `gzip` (#4088) +## 🧰 Bug fixes 🧰 + +- Fix AggregationTemporality and IsMonotonic when metric descriptors are split in the batch processor (#4389) + ## v0.38.0 Beta ## 🛑 Breaking changes 🛑 diff --git a/processor/batchprocessor/splitmetrics_test.go b/processor/batchprocessor/splitmetrics_test.go index 66746e22942c..243ccccbb50c 100644 --- a/processor/batchprocessor/splitmetrics_test.go +++ b/processor/batchprocessor/splitmetrics_test.go @@ -163,6 +163,93 @@ func TestSplitMetricsUneven(t *testing.T) { assert.Equal(t, "test-metric-int-0-9", split.ResourceMetrics().At(0).InstrumentationLibraryMetrics().At(0).Metrics().At(0).Name()) } +func TestSplitMetricsAllTypes(t *testing.T) { + md := testdata.GeneratMetricsAllTypesWithSampleDatapoints() + dataPointCount := 2 + metrics := md.ResourceMetrics().At(0).InstrumentationLibraryMetrics().At(0).Metrics() + for i := 0; i < metrics.Len(); i++ { + metrics.At(i).SetName(getTestMetricName(0, i)) + assert.Equal(t, dataPointCount, metricDPC(metrics.At(i))) + } + + splitSize := 2 + // Start with 6 metric types, and 2 points per-metric. Split out the first, + // and then split by 2 for the rest so that each metric is split in half. + // Verify that descriptors are preserved for all data types across splits. + + split := splitMetrics(1, md) + assert.Equal(t, 1, split.MetricCount()) + assert.Equal(t, 6, md.MetricCount()) + gaugeInt := split.ResourceMetrics().At(0).InstrumentationLibraryMetrics().At(0).Metrics().At(0) + assert.Equal(t, 1, gaugeInt.Gauge().DataPoints().Len()) + assert.Equal(t, "test-metric-int-0-0", gaugeInt.Name()) + + split = splitMetrics(splitSize, md) + assert.Equal(t, 2, split.MetricCount()) + assert.Equal(t, 5, md.MetricCount()) + gaugeInt = split.ResourceMetrics().At(0).InstrumentationLibraryMetrics().At(0).Metrics().At(0) + gaugeDouble := split.ResourceMetrics().At(0).InstrumentationLibraryMetrics().At(0).Metrics().At(1) + assert.Equal(t, 1, gaugeInt.Gauge().DataPoints().Len()) + assert.Equal(t, "test-metric-int-0-0", gaugeInt.Name()) + assert.Equal(t, 1, gaugeDouble.Gauge().DataPoints().Len()) + assert.Equal(t, "test-metric-int-0-1", gaugeDouble.Name()) + + split = splitMetrics(splitSize, md) + assert.Equal(t, 2, split.MetricCount()) + assert.Equal(t, 4, md.MetricCount()) + gaugeDouble = split.ResourceMetrics().At(0).InstrumentationLibraryMetrics().At(0).Metrics().At(0) + sumInt := split.ResourceMetrics().At(0).InstrumentationLibraryMetrics().At(0).Metrics().At(1) + 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, pdata.MetricAggregationTemporalityCumulative, sumInt.Sum().AggregationTemporality()) + assert.Equal(t, true, sumInt.Sum().IsMonotonic()) + assert.Equal(t, "test-metric-int-0-2", sumInt.Name()) + + split = splitMetrics(splitSize, md) + assert.Equal(t, 2, split.MetricCount()) + assert.Equal(t, 3, md.MetricCount()) + sumInt = split.ResourceMetrics().At(0).InstrumentationLibraryMetrics().At(0).Metrics().At(0) + sumDouble := split.ResourceMetrics().At(0).InstrumentationLibraryMetrics().At(0).Metrics().At(1) + assert.Equal(t, 1, sumInt.Sum().DataPoints().Len()) + assert.Equal(t, pdata.MetricAggregationTemporalityCumulative, 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, pdata.MetricAggregationTemporalityCumulative, sumDouble.Sum().AggregationTemporality()) + assert.Equal(t, true, sumDouble.Sum().IsMonotonic()) + assert.Equal(t, "test-metric-int-0-3", sumDouble.Name()) + + split = splitMetrics(splitSize, md) + assert.Equal(t, 2, split.MetricCount()) + assert.Equal(t, 2, md.MetricCount()) + sumDouble = split.ResourceMetrics().At(0).InstrumentationLibraryMetrics().At(0).Metrics().At(0) + doubleHistogram := split.ResourceMetrics().At(0).InstrumentationLibraryMetrics().At(0).Metrics().At(1) + assert.Equal(t, 1, sumDouble.Sum().DataPoints().Len()) + assert.Equal(t, pdata.MetricAggregationTemporalityCumulative, sumDouble.Sum().AggregationTemporality()) + assert.Equal(t, true, sumDouble.Sum().IsMonotonic()) + assert.Equal(t, "test-metric-int-0-3", sumDouble.Name()) + assert.Equal(t, 1, doubleHistogram.Histogram().DataPoints().Len()) + assert.Equal(t, pdata.MetricAggregationTemporalityCumulative, doubleHistogram.Histogram().AggregationTemporality()) + assert.Equal(t, "test-metric-int-0-4", doubleHistogram.Name()) + + split = splitMetrics(splitSize, md) + assert.Equal(t, 2, split.MetricCount()) + assert.Equal(t, 1, md.MetricCount()) + doubleHistogram = split.ResourceMetrics().At(0).InstrumentationLibraryMetrics().At(0).Metrics().At(0) + doubleSummary := split.ResourceMetrics().At(0).InstrumentationLibraryMetrics().At(0).Metrics().At(1) + assert.Equal(t, 1, doubleHistogram.Histogram().DataPoints().Len()) + assert.Equal(t, pdata.MetricAggregationTemporalityCumulative, doubleHistogram.Histogram().AggregationTemporality()) + assert.Equal(t, "test-metric-int-0-4", doubleHistogram.Name()) + assert.Equal(t, 1, doubleSummary.Summary().DataPoints().Len()) + assert.Equal(t, "test-metric-int-0-5", doubleSummary.Name()) + + split = splitMetrics(splitSize, md) + doubleSummary = split.ResourceMetrics().At(0).InstrumentationLibraryMetrics().At(0).Metrics().At(0) + assert.Equal(t, 1, doubleSummary.Summary().DataPoints().Len()) + assert.Equal(t, "test-metric-int-0-5", doubleSummary.Name()) +} + func TestSplitMetricsBatchSizeSmallerThanDataPointCount(t *testing.T) { md := testdata.GenerateMetricsManyMetricsSameResource(2) metrics := md.ResourceMetrics().At(0).InstrumentationLibraryMetrics().At(0).Metrics()