Skip to content

Commit

Permalink
unit test and changelog follow up to batch processor descriptor fix (o…
Browse files Browse the repository at this point in the history
  • Loading branch information
dashpole authored Nov 11, 2021
1 parent 1faf505 commit a9df2ae
Show file tree
Hide file tree
Showing 2 changed files with 91 additions and 0 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 🛑
Expand Down
87 changes: 87 additions & 0 deletions processor/batchprocessor/splitmetrics_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit a9df2ae

Please sign in to comment.