From 791cfa01af45475cf75ca87b12c8ab61ff530d56 Mon Sep 17 00:00:00 2001 From: Bogdan Drutu Date: Mon, 31 Aug 2020 10:27:37 -0700 Subject: [PATCH] Change goldendataset to use the new internal metrics structs Signed-off-by: Bogdan Drutu --- internal/goldendataset/metric_gen.go | 152 ++++++------ internal/goldendataset/metric_gen_test.go | 100 ++++---- internal/goldendataset/pict_metric_gen.go | 43 ++-- .../goldendataset/pict_metric_gen_test.go | 14 +- .../goldendataset/pict_metrics_input_defs.go | 18 +- .../testdata/generated_pict_pairs_metrics.txt | 38 +-- .../testdata/pict_input_metrics.txt | 2 +- testbed/correctness/metrics/metric_diff.go | 220 +++++++++--------- .../correctness/metrics/metric_diff_test.go | 31 +-- 9 files changed, 323 insertions(+), 295 deletions(-) diff --git a/internal/goldendataset/metric_gen.go b/internal/goldendataset/metric_gen.go index 307b8eeee21..24a36dd7104 100644 --- a/internal/goldendataset/metric_gen.go +++ b/internal/goldendataset/metric_gen.go @@ -18,7 +18,7 @@ import ( "fmt" "go.opentelemetry.io/collector/consumer/pdata" - "go.opentelemetry.io/collector/internal/dataold" + "go.opentelemetry.io/collector/internal/data" ) // Simple utilities for generating metrics for testing @@ -27,7 +27,9 @@ import ( // metrics with the corresponding number/type of attributes and pass into MetricDataFromCfg to generate metrics. type MetricCfg struct { // The type of metric to generate - MetricDescriptorType dataold.MetricType + MetricDescriptorType pdata.MetricDataType + // If MetricDescriptorType is one of the Sum, this describes if the sum is monotonic or not. + IsMonotonicSum bool // A prefix for every metric name MetricNamePrefix string // The number of instrumentation library metrics per resource @@ -54,7 +56,7 @@ type MetricCfg struct { // (but boring) metrics, and can be used as a starting point for making alterations. func DefaultCfg() MetricCfg { return MetricCfg{ - MetricDescriptorType: dataold.MetricTypeInt64, + MetricDescriptorType: pdata.MetricDataTypeDoubleGauge, MetricNamePrefix: "", NumILMPerResource: 1, NumMetricsPerILM: 1, @@ -69,12 +71,12 @@ func DefaultCfg() MetricCfg { } // DefaultMetricData produces MetricData with a default config. -func DefaultMetricData() dataold.MetricData { +func DefaultMetricData() data.MetricData { return MetricDataFromCfg(DefaultCfg()) } // MetricDataFromCfg produces MetricData with the passed-in config. -func MetricDataFromCfg(cfg MetricCfg) dataold.MetricData { +func MetricDataFromCfg(cfg MetricCfg) data.MetricData { return newMetricGenerator().genMetricDataFromCfg(cfg) } @@ -86,8 +88,8 @@ func newMetricGenerator() *metricGenerator { return &metricGenerator{} } -func (g *metricGenerator) genMetricDataFromCfg(cfg MetricCfg) dataold.MetricData { - md := dataold.NewMetricData() +func (g *metricGenerator) genMetricDataFromCfg(cfg MetricCfg) data.MetricData { + md := data.NewMetricData() rms := md.ResourceMetrics() rms.Resize(cfg.NumResourceMetrics) for i := 0; i < cfg.NumResourceMetrics; i++ { @@ -105,7 +107,7 @@ func (g *metricGenerator) genMetricDataFromCfg(cfg MetricCfg) dataold.MetricData return md } -func (g *metricGenerator) populateIlm(cfg MetricCfg, rm dataold.ResourceMetrics) { +func (g *metricGenerator) populateIlm(cfg MetricCfg, rm pdata.ResourceMetrics) { ilms := rm.InstrumentationLibraryMetrics() ilms.Resize(cfg.NumILMPerResource) for i := 0; i < cfg.NumILMPerResource; i++ { @@ -114,38 +116,60 @@ func (g *metricGenerator) populateIlm(cfg MetricCfg, rm dataold.ResourceMetrics) } } -func (g *metricGenerator) populateMetrics(cfg MetricCfg, ilm dataold.InstrumentationLibraryMetrics) { +func (g *metricGenerator) populateMetrics(cfg MetricCfg, ilm pdata.InstrumentationLibraryMetrics) { metrics := ilm.Metrics() metrics.Resize(cfg.NumMetricsPerILM) for i := 0; i < cfg.NumMetricsPerILM; i++ { metric := metrics.At(i) - metric.InitEmpty() g.populateMetricDesc(cfg, metric) switch cfg.MetricDescriptorType { - case dataold.MetricTypeInt64, dataold.MetricTypeMonotonicInt64: - populateIntPoints(cfg, metric) - case dataold.MetricTypeDouble, dataold.MetricTypeMonotonicDouble: - populateDblPoints(cfg, metric) - case dataold.MetricTypeHistogram: - populateHistogramPoints(cfg, metric) - case dataold.MetricTypeSummary: - populateSummaryPoints(cfg, metric) + case pdata.MetricDataTypeIntGauge: + metric.SetDataType(pdata.MetricDataTypeIntGauge) + metric.IntGauge().InitEmpty() + populateIntPoints(cfg, metric.IntGauge().DataPoints()) + case pdata.MetricDataTypeDoubleGauge: + metric.SetDataType(pdata.MetricDataTypeDoubleGauge) + metric.DoubleGauge().InitEmpty() + populateDoublePoints(cfg, metric.DoubleGauge().DataPoints()) + case pdata.MetricDataTypeIntSum: + metric.SetDataType(pdata.MetricDataTypeIntSum) + sum := metric.IntSum() + sum.InitEmpty() + sum.SetIsMonotonic(cfg.IsMonotonicSum) + sum.SetAggregationTemporality(pdata.AggregationTemporalityCumulative) + populateIntPoints(cfg, sum.DataPoints()) + case pdata.MetricDataTypeDoubleSum: + metric.SetDataType(pdata.MetricDataTypeDoubleSum) + sum := metric.DoubleSum() + sum.InitEmpty() + sum.SetIsMonotonic(cfg.IsMonotonicSum) + sum.SetAggregationTemporality(pdata.AggregationTemporalityCumulative) + populateDoublePoints(cfg, sum.DataPoints()) + case pdata.MetricDataTypeIntHistogram: + metric.SetDataType(pdata.MetricDataTypeDoubleHistogram) + histo := metric.IntHistogram() + histo.InitEmpty() + histo.SetAggregationTemporality(pdata.AggregationTemporalityCumulative) + populateIntHistogram(cfg, histo) + case pdata.MetricDataTypeDoubleHistogram: + metric.SetDataType(pdata.MetricDataTypeDoubleHistogram) + histo := metric.DoubleHistogram() + histo.InitEmpty() + histo.SetAggregationTemporality(pdata.AggregationTemporalityCumulative) + populateDoubleHistogram(cfg, histo) } } } -func (g *metricGenerator) populateMetricDesc(cfg MetricCfg, metric dataold.Metric) { - desc := metric.MetricDescriptor() - desc.InitEmpty() - desc.SetName(fmt.Sprintf("%smetric_%d", cfg.MetricNamePrefix, g.metricID)) +func (g *metricGenerator) populateMetricDesc(cfg MetricCfg, metric pdata.Metric) { + metric.InitEmpty() + metric.SetName(fmt.Sprintf("%smetric_%d", cfg.MetricNamePrefix, g.metricID)) g.metricID++ - desc.SetDescription("my-md-description") - desc.SetUnit("my-md-units") - desc.SetType(cfg.MetricDescriptorType) + metric.SetDescription("my-md-description") + metric.SetUnit("my-md-units") } -func populateIntPoints(cfg MetricCfg, metric dataold.Metric) { - pts := metric.Int64DataPoints() +func populateIntPoints(cfg MetricCfg, pts pdata.IntDataPointSlice) { pts.Resize(cfg.NumPtsPerMetric) for i := 0; i < cfg.NumPtsPerMetric; i++ { pt := pts.At(i) @@ -156,8 +180,7 @@ func populateIntPoints(cfg MetricCfg, metric dataold.Metric) { } } -func populateDblPoints(cfg MetricCfg, metric dataold.Metric) { - pts := metric.DoubleDataPoints() +func populateDoublePoints(cfg MetricCfg, pts pdata.DoubleDataPointSlice) { pts.Resize(cfg.NumPtsPerMetric) for i := 0; i < cfg.NumPtsPerMetric; i++ { pt := pts.At(i) @@ -168,8 +191,8 @@ func populateDblPoints(cfg MetricCfg, metric dataold.Metric) { } } -func populateHistogramPoints(cfg MetricCfg, metric dataold.Metric) { - pts := metric.HistogramDataPoints() +func populateDoubleHistogram(cfg MetricCfg, dh pdata.DoubleHistogram) { + pts := dh.DataPoints() pts.Resize(cfg.NumPtsPerMetric) for i := 0; i < cfg.NumPtsPerMetric; i++ { pt := pts.At(i) @@ -177,70 +200,69 @@ func populateHistogramPoints(cfg MetricCfg, metric dataold.Metric) { ts := getTimestamp(cfg.StartTime, cfg.StepSize, i) pt.SetTimestamp(ts) populatePtLabels(cfg, pt.LabelsMap()) - setHistogramBounds(pt, 1, 2, 3, 4, 5) - addHistogramVal(pt, 1, ts) + setDoubleHistogramBounds(pt, 1, 2, 3, 4, 5) + addDoubleHistogramVal(pt, 1) for i := 0; i < cfg.PtVal; i++ { - addHistogramVal(pt, 3, ts) + addDoubleHistogramVal(pt, 3) } - addHistogramVal(pt, 5, ts) + addDoubleHistogramVal(pt, 5) } } -func setHistogramBounds(hdp dataold.HistogramDataPoint, bounds ...float64) { - hdp.Buckets().Resize(len(bounds)) +func setDoubleHistogramBounds(hdp pdata.DoubleHistogramDataPoint, bounds ...float64) { + hdp.SetBucketCounts(make([]uint64, len(bounds))) hdp.SetExplicitBounds(bounds) } -func addHistogramVal(hdp dataold.HistogramDataPoint, val float64, ts pdata.TimestampUnixNano) { +func addDoubleHistogramVal(hdp pdata.DoubleHistogramDataPoint, val float64) { hdp.SetCount(hdp.Count() + 1) hdp.SetSum(hdp.Sum() + val) - buckets := hdp.Buckets() + buckets := hdp.BucketCounts() bounds := hdp.ExplicitBounds() for i := 0; i < len(bounds); i++ { bound := bounds[i] if val <= bound { - bucket := buckets.At(i) - bucket.SetCount(bucket.Count() + 1) - ex := bucket.Exemplar() - ex.InitEmpty() - ex.SetValue(val) - ex.SetTimestamp(ts) + buckets[i]++ break } } } -func populateSummaryPoints(cfg MetricCfg, metric dataold.Metric) { - pts := metric.SummaryDataPoints() +func populateIntHistogram(cfg MetricCfg, dh pdata.IntHistogram) { + pts := dh.DataPoints() pts.Resize(cfg.NumPtsPerMetric) for i := 0; i < cfg.NumPtsPerMetric; i++ { pt := pts.At(i) pt.SetStartTime(pdata.TimestampUnixNano(cfg.StartTime)) - pt.SetTimestamp(getTimestamp(cfg.StartTime, cfg.StepSize, i)) - setSummaryPercentiles(pt, 0, 50, 95) - addSummaryValue(pt, 55, 0) + ts := getTimestamp(cfg.StartTime, cfg.StepSize, i) + pt.SetTimestamp(ts) + populatePtLabels(cfg, pt.LabelsMap()) + setIntHistogramBounds(pt, 1, 2, 3, 4, 5) + addIntHistogramVal(pt, 1) for i := 0; i < cfg.PtVal; i++ { - addSummaryValue(pt, 70, 1) + addIntHistogramVal(pt, 3) } - addSummaryValue(pt, 90, 2) - populatePtLabels(cfg, pt.LabelsMap()) + addIntHistogramVal(pt, 5) } } -func setSummaryPercentiles(pt dataold.SummaryDataPoint, pctiles ...float64) { - vap := pt.ValueAtPercentiles() - l := len(pctiles) - vap.Resize(l) - for i := 0; i < l; i++ { - vap.At(i).SetPercentile(pctiles[i]) - } +func setIntHistogramBounds(hdp pdata.IntHistogramDataPoint, bounds ...float64) { + hdp.SetBucketCounts(make([]uint64, len(bounds))) + hdp.SetExplicitBounds(bounds) } -func addSummaryValue(pt dataold.SummaryDataPoint, value float64, pctileIndex int) { - pt.SetCount(pt.Count() + 1) - pt.SetSum(pt.Sum() + value) - vap := pt.ValueAtPercentiles().At(pctileIndex) - vap.SetValue(vap.Value() + 1) +func addIntHistogramVal(hdp pdata.IntHistogramDataPoint, val int64) { + hdp.SetCount(hdp.Count() + 1) + hdp.SetSum(hdp.Sum() + val) + buckets := hdp.BucketCounts() + bounds := hdp.ExplicitBounds() + for i := 0; i < len(bounds); i++ { + bound := bounds[i] + if float64(val) <= bound { + buckets[i]++ + break + } + } } func populatePtLabels(cfg MetricCfg, lm pdata.StringMap) { diff --git a/internal/goldendataset/metric_gen_test.go b/internal/goldendataset/metric_gen_test.go index 2235bb44a47..65ff5cd9b7d 100644 --- a/internal/goldendataset/metric_gen_test.go +++ b/internal/goldendataset/metric_gen_test.go @@ -19,7 +19,8 @@ import ( "github.com/stretchr/testify/require" - "go.opentelemetry.io/collector/internal/dataold" + "go.opentelemetry.io/collector/consumer/pdata" + "go.opentelemetry.io/collector/internal/data" ) func TestGenDefault(t *testing.T) { @@ -40,12 +41,12 @@ func TestGenDefault(t *testing.T) { ms := ilms.At(0).Metrics() require.Equal(t, 1, ms.Len()) pdm := ms.At(0) - desc := pdm.MetricDescriptor() - require.Equal(t, "metric_0", desc.Name()) - require.Equal(t, "my-md-description", desc.Description()) - require.Equal(t, "my-md-units", desc.Unit()) + require.Equal(t, "metric_0", pdm.Name()) + require.Equal(t, "my-md-description", pdm.Description()) + require.Equal(t, "my-md-units", pdm.Unit()) - pts := pdm.Int64DataPoints() + require.Equal(t, pdata.MetricDataTypeDoubleGauge, pdm.DataType()) + pts := pdm.DoubleGauge().DataPoints() require.Equal(t, 1, pts.Len()) pt := pts.At(0) @@ -58,82 +59,75 @@ func TestGenDefault(t *testing.T) { require.EqualValues(t, 1, pt.Value()) } -func TestHistogramFunctions(t *testing.T) { - pt := dataold.NewHistogramDataPoint() +func TestDoubleHistogramFunctions(t *testing.T) { + pt := pdata.NewDoubleHistogramDataPoint() pt.InitEmpty() - setHistogramBounds(pt, 1, 2, 3, 4, 5) + setDoubleHistogramBounds(pt, 1, 2, 3, 4, 5) require.Equal(t, 5, len(pt.ExplicitBounds())) - require.Equal(t, 5, pt.Buckets().Len()) + require.Equal(t, 5, len(pt.BucketCounts())) - addHistogramVal(pt, 1, 0) + addDoubleHistogramVal(pt, 1) require.EqualValues(t, 1, pt.Count()) require.EqualValues(t, 1, pt.Sum()) - require.EqualValues(t, 1, pt.Buckets().At(0).Count()) + require.EqualValues(t, 1, pt.BucketCounts()[0]) - addHistogramVal(pt, 2, 0) + addDoubleHistogramVal(pt, 2) require.EqualValues(t, 2, pt.Count()) require.EqualValues(t, 3, pt.Sum()) - require.EqualValues(t, 1, pt.Buckets().At(1).Count()) + require.EqualValues(t, 1, pt.BucketCounts()[1]) - addHistogramVal(pt, 2, 0) + addDoubleHistogramVal(pt, 2) require.EqualValues(t, 3, pt.Count()) require.EqualValues(t, 5, pt.Sum()) - require.EqualValues(t, 2, pt.Buckets().At(1).Count()) + require.EqualValues(t, 2, pt.BucketCounts()[1]) } -func TestGenHistogram(t *testing.T) { - cfg := DefaultCfg() - cfg.MetricDescriptorType = dataold.MetricTypeHistogram - cfg.PtVal = 2 - md := MetricDataFromCfg(cfg) - pts := getMetric(md).HistogramDataPoints() - pt := pts.At(0) - buckets := pt.Buckets() - require.Equal(t, 5, buckets.Len()) - middleBucket := buckets.At(2) - require.EqualValues(t, 2, middleBucket.Count()) - ex := pt.Buckets().At(0).Exemplar() - ex.Value() - require.EqualValues(t, 1, ex.Value()) -} - -func TestSummaryFunctions(t *testing.T) { - pt := dataold.NewSummaryDataPoint() +func TestIntHistogramFunctions(t *testing.T) { + pt := pdata.NewIntHistogramDataPoint() pt.InitEmpty() - setSummaryPercentiles(pt, 0, 50, 95) - addSummaryValue(pt, 55, 0) - addSummaryValue(pt, 70, 1) - addSummaryValue(pt, 90, 2) + setIntHistogramBounds(pt, 1, 2, 3, 4, 5) + require.Equal(t, 5, len(pt.ExplicitBounds())) + require.Equal(t, 5, len(pt.BucketCounts())) + + addIntHistogramVal(pt, 1) + require.EqualValues(t, 1, pt.Count()) + require.EqualValues(t, 1, pt.Sum()) + require.EqualValues(t, 1, pt.BucketCounts()[0]) + + addIntHistogramVal(pt, 2) + require.EqualValues(t, 2, pt.Count()) + require.EqualValues(t, 3, pt.Sum()) + require.EqualValues(t, 1, pt.BucketCounts()[1]) + + addIntHistogramVal(pt, 2) require.EqualValues(t, 3, pt.Count()) - v := pt.ValueAtPercentiles().At(2).Value() - require.EqualValues(t, 1, v) - pctile := pt.ValueAtPercentiles().At(2).Percentile() - require.EqualValues(t, 95, pctile) + require.EqualValues(t, 5, pt.Sum()) + require.EqualValues(t, 2, pt.BucketCounts()[1]) } -func TestGenSummary(t *testing.T) { +func TestGenDoubleHistogram(t *testing.T) { cfg := DefaultCfg() - cfg.MetricDescriptorType = dataold.MetricTypeSummary + cfg.MetricDescriptorType = pdata.MetricDataTypeDoubleHistogram + cfg.PtVal = 2 md := MetricDataFromCfg(cfg) - metric := getMetric(md) - pts := metric.SummaryDataPoints() - require.Equal(t, 1, pts.Len()) + pts := getMetric(md).DoubleHistogram().DataPoints() pt := pts.At(0) - require.EqualValues(t, 3, pt.Count()) - require.EqualValues(t, 215, pt.Sum()) + buckets := pt.BucketCounts() + require.Equal(t, 5, len(buckets)) + require.EqualValues(t, 2, buckets[2]) } -func TestGenDouble(t *testing.T) { +func TestGenDoubleGauge(t *testing.T) { cfg := DefaultCfg() - cfg.MetricDescriptorType = dataold.MetricTypeDouble + cfg.MetricDescriptorType = pdata.MetricDataTypeDoubleGauge md := MetricDataFromCfg(cfg) metric := getMetric(md) - pts := metric.DoubleDataPoints() + pts := metric.DoubleGauge().DataPoints() require.Equal(t, 1, pts.Len()) pt := pts.At(0) require.EqualValues(t, 1, pt.Value()) } -func getMetric(md dataold.MetricData) dataold.Metric { +func getMetric(md data.MetricData) pdata.Metric { return md.ResourceMetrics().At(0).InstrumentationLibraryMetrics().At(0).Metrics().At(0) } diff --git a/internal/goldendataset/pict_metric_gen.go b/internal/goldendataset/pict_metric_gen.go index 756ac196939..be83ff356da 100644 --- a/internal/goldendataset/pict_metric_gen.go +++ b/internal/goldendataset/pict_metric_gen.go @@ -17,24 +17,25 @@ package goldendataset import ( "fmt" - "go.opentelemetry.io/collector/internal/dataold" + "go.opentelemetry.io/collector/consumer/pdata" + "go.opentelemetry.io/collector/internal/data" ) // GenerateMetricDatas takes the filename of a PICT-generated file, walks through all of the rows in the PICT // file and for each row, generates a MetricData object, collecting them and returning them to the caller. -func GenerateMetricDatas(metricPairsFile string) ([]dataold.MetricData, error) { +func GenerateMetricDatas(metricPairsFile string) ([]data.MetricData, error) { pictData, err := loadPictOutputFile(metricPairsFile) if err != nil { return nil, err } - var out []dataold.MetricData + var out []data.MetricData for i, values := range pictData { if i == 0 { continue } metricInputs := PICTMetricInputs{ NumPtsPerMetric: PICTNumPtsPerMetric(values[0]), - MetricType: PICTMetricType(values[1]), + MetricType: PICTMetricDataType(values[1]), NumPtLabels: PICTNumPtLabels(values[2]), } cfg := pictToCfg(metricInputs) @@ -64,18 +65,28 @@ func pictToCfg(inputs PICTMetricInputs) MetricCfg { } switch inputs.MetricType { - case MetricTypeInt: - cfg.MetricDescriptorType = dataold.MetricTypeInt64 - case MetricTypeMonotonicInt: - cfg.MetricDescriptorType = dataold.MetricTypeMonotonicInt64 - case MetricTypeDouble: - cfg.MetricDescriptorType = dataold.MetricTypeDouble - case MetricTypeMonotonicDouble: - cfg.MetricDescriptorType = dataold.MetricTypeMonotonicDouble - case MetricTypeHistogram: - cfg.MetricDescriptorType = dataold.MetricTypeHistogram - case MetricTypeSummary: - cfg.MetricDescriptorType = dataold.MetricTypeSummary + case MetricTypeIntGauge: + cfg.MetricDescriptorType = pdata.MetricDataTypeIntGauge + case MetricTypeMonotonicIntSum: + cfg.MetricDescriptorType = pdata.MetricDataTypeIntSum + cfg.IsMonotonicSum = true + case MetricTypeNonMonotonicIntSum: + cfg.MetricDescriptorType = pdata.MetricDataTypeIntSum + cfg.IsMonotonicSum = false + case MetricTypeDoubleGauge: + cfg.MetricDescriptorType = pdata.MetricDataTypeDoubleGauge + case MetricTypeMonotonicDoubleSum: + cfg.MetricDescriptorType = pdata.MetricDataTypeDoubleSum + cfg.IsMonotonicSum = true + case MetricTypeNonMonotonicDoubleSum: + cfg.MetricDescriptorType = pdata.MetricDataTypeDoubleSum + cfg.IsMonotonicSum = false + case MetricTypeIntHistogram: + cfg.MetricDescriptorType = pdata.MetricDataTypeIntHistogram + case MetricTypeDoubleHistogram: + cfg.MetricDescriptorType = pdata.MetricDataTypeDoubleHistogram + default: + panic("Should not happen, unsupported type " + string(inputs.MetricType)) } switch inputs.NumPtLabels { diff --git a/internal/goldendataset/pict_metric_gen_test.go b/internal/goldendataset/pict_metric_gen_test.go index ee6924dd864..642cf5971ed 100644 --- a/internal/goldendataset/pict_metric_gen_test.go +++ b/internal/goldendataset/pict_metric_gen_test.go @@ -19,7 +19,7 @@ import ( "github.com/stretchr/testify/require" - "go.opentelemetry.io/collector/internal/dataold" + "go.opentelemetry.io/collector/consumer/pdata" ) func TestGenerateMetricDatas(t *testing.T) { @@ -39,13 +39,13 @@ func TestPICTtoCfg(t *testing.T) { inputs: PICTMetricInputs{ NumResourceAttrs: AttrsNone, NumPtsPerMetric: NumPtsPerMetricOne, - MetricType: MetricTypeInt, + MetricType: MetricTypeIntGauge, NumPtLabels: LabelsNone, }, cfg: MetricCfg{ NumResourceAttrs: 0, NumPtsPerMetric: 1, - MetricDescriptorType: dataold.MetricTypeInt64, + MetricDescriptorType: pdata.MetricDataTypeIntGauge, NumPtLabels: 0, }, }, @@ -54,13 +54,13 @@ func TestPICTtoCfg(t *testing.T) { inputs: PICTMetricInputs{ NumResourceAttrs: AttrsOne, NumPtsPerMetric: NumPtsPerMetricOne, - MetricType: MetricTypeDouble, + MetricType: MetricTypeDoubleGauge, NumPtLabels: LabelsOne, }, cfg: MetricCfg{ NumResourceAttrs: 1, NumPtsPerMetric: 1, - MetricDescriptorType: dataold.MetricTypeDouble, + MetricDescriptorType: pdata.MetricDataTypeDoubleGauge, NumPtLabels: 1, }, }, @@ -69,13 +69,13 @@ func TestPICTtoCfg(t *testing.T) { inputs: PICTMetricInputs{ NumResourceAttrs: AttrsTwo, NumPtsPerMetric: NumPtsPerMetricMany, - MetricType: MetricTypeSummary, + MetricType: MetricTypeDoubleHistogram, NumPtLabels: LabelsMany, }, cfg: MetricCfg{ NumResourceAttrs: 2, NumPtsPerMetric: 16, - MetricDescriptorType: dataold.MetricTypeSummary, + MetricDescriptorType: pdata.MetricDataTypeDoubleHistogram, NumPtLabels: 16, }, }, diff --git a/internal/goldendataset/pict_metrics_input_defs.go b/internal/goldendataset/pict_metrics_input_defs.go index 0c3b5544ef4..6a44cf821c2 100644 --- a/internal/goldendataset/pict_metrics_input_defs.go +++ b/internal/goldendataset/pict_metrics_input_defs.go @@ -21,7 +21,7 @@ type PICTMetricInputs struct { // Specifies the number of points on each metric. NumPtsPerMetric PICTNumPtsPerMetric // Specifies the types of metrics that can be generated. - MetricType PICTMetricType + MetricType PICTMetricDataType // Specifies the number of labels on each datapoint. NumPtLabels PICTNumPtLabels // Specifies the number of attributes on each resource. @@ -29,15 +29,17 @@ type PICTMetricInputs struct { } // Enumerates the types of metrics that can be generated. -type PICTMetricType string +type PICTMetricDataType string const ( - MetricTypeInt PICTMetricType = "Int" - MetricTypeMonotonicInt PICTMetricType = "MonotonicInt" - MetricTypeDouble PICTMetricType = "Double" - MetricTypeMonotonicDouble PICTMetricType = "MonotonicDouble" - MetricTypeHistogram PICTMetricType = "Histogram" - MetricTypeSummary PICTMetricType = "Summary" + MetricTypeIntGauge PICTMetricDataType = "IntGauge" + MetricTypeMonotonicIntSum PICTMetricDataType = "MonotonicIntSum" + MetricTypeNonMonotonicIntSum PICTMetricDataType = "NonMonotonicIntSum" + MetricTypeDoubleGauge PICTMetricDataType = "DoubleGauge" + MetricTypeMonotonicDoubleSum PICTMetricDataType = "MonotonicDoubleSum" + MetricTypeNonMonotonicDoubleSum PICTMetricDataType = "NonMonotonicDoubleSum" + MetricTypeIntHistogram PICTMetricDataType = "IntHistogram" + MetricTypeDoubleHistogram PICTMetricDataType = "DoubleHistogram" ) // Enumerates the number of labels on each datapoint. diff --git a/internal/goldendataset/testdata/generated_pict_pairs_metrics.txt b/internal/goldendataset/testdata/generated_pict_pairs_metrics.txt index 0afba82a525..2b2a5ddb22b 100644 --- a/internal/goldendataset/testdata/generated_pict_pairs_metrics.txt +++ b/internal/goldendataset/testdata/generated_pict_pairs_metrics.txt @@ -1,20 +1,20 @@ NumPtsPerMetric MetricType NumLabels NumResourceAttrs -OnePt MonotonicInt ManyLabels NoAttrs -ManyPts Histogram NoLabels TwoAttrs -ManyPts MonotonicInt OneLabel TwoAttrs -OnePt MonotonicDouble OneLabel OneAttr -ManyPts Summary OneLabel NoAttrs -ManyPts Histogram ManyLabels NoAttrs -OnePt MonotonicDouble NoLabels NoAttrs -ManyPts Int OneLabel OneAttr -OnePt MonotonicDouble ManyLabels TwoAttrs -ManyPts MonotonicInt NoLabels OneAttr -ManyPts Double OneLabel OneAttr -OnePt Int ManyLabels NoAttrs -OnePt Summary NoLabels TwoAttrs -ManyPts Int NoLabels TwoAttrs -ManyPts Summary ManyLabels OneAttr -ManyPts MonotonicDouble NoLabels OneAttr -OnePt Double NoLabels NoAttrs -OnePt Histogram OneLabel OneAttr -OnePt Double ManyLabels TwoAttrs +OnePt MonotonicIntSum ManyLabels NoAttrs +ManyPts DoubleHistogram NoLabels TwoAttrs +ManyPts IntHistogram NoLabels TwoAttrs +ManyPts MonotonicIntSum OneLabel TwoAttrs +OnePt MonotonicDoubleSum OneLabel OneAttr +ManyPts IntHistogram ManyLabels NoAttrs +ManyPts DoubleHistogram ManyLabels NoAttrs +OnePt MonotonicDoubleSum NoLabels NoAttrs +ManyPts IntGauge OneLabel OneAttr +OnePt MonotonicDoubleSum ManyLabels TwoAttrs +ManyPts MonotonicIntSum NoLabels OneAttr +ManyPts DoubleGauge OneLabel OneAttr +OnePt IntGauge ManyLabels NoAttrs +ManyPts IntGauge NoLabels TwoAttrs +ManyPts MonotonicDoubleSum NoLabels OneAttr +OnePt DoubleGauge NoLabels NoAttrs +OnePt DoubleHistogram OneLabel OneAttr +OnePt IntHistogram OneLabel OneAttr +OnePt DoubleGauge ManyLabels TwoAttrs diff --git a/internal/goldendataset/testdata/pict_input_metrics.txt b/internal/goldendataset/testdata/pict_input_metrics.txt index 23d0c1988f4..9351db55e01 100644 --- a/internal/goldendataset/testdata/pict_input_metrics.txt +++ b/internal/goldendataset/testdata/pict_input_metrics.txt @@ -1,4 +1,4 @@ NumPtsPerMetric: OnePt, ManyPts -MetricType: Double, MonotonicDouble, Int, MonotonicInt, Histogram, Summary +MetricType: DoubleGauge, MonotonicDoubleSum, NonMonotonicDoubleSum, IntGauge, MonotonicIntSum, NonMonotonicIntSum, IntHistogram, DoubleHistogram NumLabels: NoLabels, OneLabel, ManyLabels NumResourceAttrs: NoAttrs, OneAttr, TwoAttrs diff --git a/testbed/correctness/metrics/metric_diff.go b/testbed/correctness/metrics/metric_diff.go index cc1eba80229..819f398a666 100644 --- a/testbed/correctness/metrics/metric_diff.go +++ b/testbed/correctness/metrics/metric_diff.go @@ -20,7 +20,6 @@ import ( "go.opentelemetry.io/collector/consumer/pdata" "go.opentelemetry.io/collector/consumer/pdatautil" - "go.opentelemetry.io/collector/internal/dataold" ) // MetricDiff is intended to support producing human-readable diffs between two MetricData structs during @@ -36,9 +35,9 @@ func (mf MetricDiff) String() string { return fmt.Sprintf("{msg='%v' expected=[%v] actual=[%v]}\n", mf.Msg, mf.ExpectedValue, mf.ActualValue) } -func pdmToPDRM(pdm []pdata.Metrics) (out []dataold.ResourceMetrics) { +func pdmToPDRM(pdm []pdata.Metrics) (out []pdata.ResourceMetrics) { for _, m := range pdm { - md := pdatautil.MetricsToOldInternalMetrics(m) + md := pdatautil.MetricsToInternalMetrics(m) rms := md.ResourceMetrics() for i := 0; i < rms.Len(); i++ { rm := rms.At(i) @@ -48,7 +47,7 @@ func pdmToPDRM(pdm []pdata.Metrics) (out []dataold.ResourceMetrics) { return out } -func diffRMSlices(sent []dataold.ResourceMetrics, recd []dataold.ResourceMetrics) []*MetricDiff { +func diffRMSlices(sent []pdata.ResourceMetrics, recd []pdata.ResourceMetrics) []*MetricDiff { var diffs []*MetricDiff if len(sent) != len(recd) { return []*MetricDiff{{ @@ -65,7 +64,7 @@ func diffRMSlices(sent []dataold.ResourceMetrics, recd []dataold.ResourceMetrics return diffs } -func diffRMs(diffs []*MetricDiff, expected dataold.ResourceMetrics, actual dataold.ResourceMetrics) []*MetricDiff { +func diffRMs(diffs []*MetricDiff, expected pdata.ResourceMetrics, actual pdata.ResourceMetrics) []*MetricDiff { diffs = diffResource(diffs, expected.Resource(), actual.Resource()) diffs = diffILMSlice( diffs, @@ -77,8 +76,8 @@ func diffRMs(diffs []*MetricDiff, expected dataold.ResourceMetrics, actual datao func diffILMSlice( diffs []*MetricDiff, - expected dataold.InstrumentationLibraryMetricsSlice, - actual dataold.InstrumentationLibraryMetricsSlice, + expected pdata.InstrumentationLibraryMetricsSlice, + actual pdata.InstrumentationLibraryMetricsSlice, ) []*MetricDiff { var mismatch bool diffs, mismatch = diffValues(diffs, actual.Len(), expected.Len(), "InstrumentationLibraryMetricsSlice len") @@ -93,13 +92,13 @@ func diffILMSlice( func diffILM( diffs []*MetricDiff, - expected dataold.InstrumentationLibraryMetrics, - actual dataold.InstrumentationLibraryMetrics, + expected pdata.InstrumentationLibraryMetrics, + actual pdata.InstrumentationLibraryMetrics, ) []*MetricDiff { return diffMetrics(diffs, expected.Metrics(), actual.Metrics()) } -func diffMetrics(diffs []*MetricDiff, expected dataold.MetricSlice, actual dataold.MetricSlice) []*MetricDiff { +func diffMetrics(diffs []*MetricDiff, expected pdata.MetricSlice, actual pdata.MetricSlice) []*MetricDiff { var mismatch bool diffs, mismatch = diffValues(diffs, actual.Len(), expected.Len(), "MetricSlice len") if mismatch { @@ -111,192 +110,191 @@ func diffMetrics(diffs []*MetricDiff, expected dataold.MetricSlice, actual datao return diffs } -func DiffMetric(diffs []*MetricDiff, expected dataold.Metric, actual dataold.Metric) []*MetricDiff { - diffs = diffMetricDescriptor(diffs, expected.MetricDescriptor(), actual.MetricDescriptor()) - diffs = diffInt64Pts(diffs, expected.Int64DataPoints(), actual.Int64DataPoints()) - diffs = diffDoublePts(diffs, expected.DoubleDataPoints(), actual.DoubleDataPoints()) - diffs = diffHistogramPts(diffs, expected.HistogramDataPoints(), actual.HistogramDataPoints()) - diffs = diffSummaryPts(diffs, expected.SummaryDataPoints(), actual.SummaryDataPoints()) - return diffs -} - -func diffSummaryPts( - diffs []*MetricDiff, - expected dataold.SummaryDataPointSlice, - actual dataold.SummaryDataPointSlice, -) []*MetricDiff { +func DiffMetric(diffs []*MetricDiff, expected pdata.Metric, actual pdata.Metric) []*MetricDiff { var mismatch bool - diffs, mismatch = diffValues(diffs, actual.Len(), expected.Len(), "MetricSlice len") + diffs, mismatch = diffMetricDescriptor(diffs, expected, actual) if mismatch { return diffs } - for i := 0; i < expected.Len(); i++ { - diffs = diffSummaryPt(diffs, expected.At(i), actual.At(i)) + switch actual.DataType() { + case pdata.MetricDataTypeIntGauge: + diffs = diffIntPts(diffs, expected.IntGauge().DataPoints(), actual.IntGauge().DataPoints()) + case pdata.MetricDataTypeDoubleGauge: + diffs = diffDoublePts(diffs, expected.DoubleGauge().DataPoints(), actual.DoubleGauge().DataPoints()) + case pdata.MetricDataTypeIntSum: + diffs = diff(diffs, expected.IntSum().IsMonotonic(), actual.IntSum().IsMonotonic(), "IntSum IsMonotonic") + diffs = diff(diffs, expected.IntSum().AggregationTemporality(), actual.IntSum().AggregationTemporality(), "IntSum AggregationTemporality") + diffs = diffIntPts(diffs, expected.IntSum().DataPoints(), actual.IntSum().DataPoints()) + case pdata.MetricDataTypeDoubleSum: + diffs = diff(diffs, expected.DoubleSum().IsMonotonic(), actual.DoubleSum().IsMonotonic(), "DoubleSum IsMonotonic") + diffs = diff(diffs, expected.DoubleSum().AggregationTemporality(), actual.DoubleSum().AggregationTemporality(), "DoubleSum AggregationTemporality") + diffs = diffDoublePts(diffs, expected.DoubleSum().DataPoints(), actual.DoubleSum().DataPoints()) + case pdata.MetricDataTypeIntHistogram: + diffs = diff(diffs, expected.IntHistogram().AggregationTemporality(), actual.IntHistogram().AggregationTemporality(), "IntHistogram AggregationTemporality") + diffs = diffIntHistogramPts(diffs, expected.IntHistogram().DataPoints(), actual.IntHistogram().DataPoints()) + case pdata.MetricDataTypeDoubleHistogram: + diffs = diff(diffs, expected.DoubleHistogram().AggregationTemporality(), actual.DoubleHistogram().AggregationTemporality(), "DoubleHistogram AggregationTemporality") + diffs = diffDoubleHistogramPts(diffs, expected.DoubleHistogram().DataPoints(), actual.DoubleHistogram().DataPoints()) } return diffs } -func diffSummaryPt( +func diffMetricDescriptor( diffs []*MetricDiff, - expected dataold.SummaryDataPoint, - actual dataold.SummaryDataPoint, -) []*MetricDiff { - diffs = diff(diffs, expected.Count(), actual.Count(), "SummaryDataPoint Count") - diffs = diff(diffs, expected.Sum(), actual.Sum(), "SummaryDataPoint Sum") - diffs = diffPercentiles(diffs, expected.ValueAtPercentiles(), actual.ValueAtPercentiles()) - return diffs + expected pdata.Metric, + actual pdata.Metric, +) ([]*MetricDiff, bool) { + diffs = diff(diffs, expected.Name(), actual.Name(), "Metric Name") + diffs = diff(diffs, expected.Description(), actual.Description(), "Metric Description") + diffs = diff(diffs, expected.Unit(), actual.Unit(), "Metric Unit") + return diffValues(diffs, expected.DataType(), actual.DataType(), "Metric Type") } -func diffPercentiles( +func diffDoublePts( diffs []*MetricDiff, - expected dataold.SummaryValueAtPercentileSlice, - actual dataold.SummaryValueAtPercentileSlice, + expected pdata.DoubleDataPointSlice, + actual pdata.DoubleDataPointSlice, ) []*MetricDiff { var mismatch bool - diffs, mismatch = diffValues(diffs, expected.Len(), actual.Len(), "MetricSlice len") + diffs, mismatch = diffValues(diffs, expected.Len(), actual.Len(), "DoubleDataPointSlice len") if mismatch { return diffs } for i := 0; i < expected.Len(); i++ { - diffs = diffSummaryAtPct(diffs, expected.At(i), actual.At(i)) + diffs = diffDoublePt(diffs, expected.At(i), actual.At(i)) } return diffs } -func diffSummaryAtPct( - diffs []*MetricDiff, - expected dataold.SummaryValueAtPercentile, - actual dataold.SummaryValueAtPercentile, -) []*MetricDiff { - diffs = diff(diffs, expected.Value(), actual.Value(), "SummaryValueAtPercentile Value") - diffs = diff(diffs, expected.Percentile(), actual.Percentile(), "SummaryValueAtPercentile Percentile") - return diffs -} - -func diffMetricDescriptor( +func diffDoublePt( diffs []*MetricDiff, - expected dataold.MetricDescriptor, - actual dataold.MetricDescriptor, + expected pdata.DoubleDataPoint, + actual pdata.DoubleDataPoint, ) []*MetricDiff { - diffs = diff(diffs, expected.Type(), actual.Type(), "MetricDescriptor Type") - diffs = diff(diffs, expected.Name(), actual.Name(), "MetricDescriptor Name") - diffs = diff(diffs, expected.Description(), actual.Description(), "MetricDescriptor Description") - diffs = diff(diffs, expected.Unit(), actual.Unit(), "MetricDescriptor Unit") - return diffs + diffs = diff(diffs, expected.Value(), actual.Value(), "DoubleDataPoint value") + return diffDoubleExemplars(diffs, expected.Exemplars(), actual.Exemplars()) } -func diffDoublePts( +func diffDoubleHistogramPts( diffs []*MetricDiff, - expected dataold.DoubleDataPointSlice, - actual dataold.DoubleDataPointSlice, + expected pdata.DoubleHistogramDataPointSlice, + actual pdata.DoubleHistogramDataPointSlice, ) []*MetricDiff { var mismatch bool - diffs, mismatch = diffValues(diffs, expected.Len(), actual.Len(), "DoubleDataPointSlice len") + diffs, mismatch = diffValues(diffs, expected.Len(), actual.Len(), "HistogramDataPointSlice len") if mismatch { return diffs } for i := 0; i < expected.Len(); i++ { - diffs = diffDoublePt(diffs, expected.At(i), actual.At(i)) + diffs = diffDoubleHistogramPt(diffs, expected.At(i), actual.At(i)) } return diffs } -func diffDoublePt( +func diffDoubleHistogramPt( diffs []*MetricDiff, - expected dataold.DoubleDataPoint, - actual dataold.DoubleDataPoint, + expected pdata.DoubleHistogramDataPoint, + actual pdata.DoubleHistogramDataPoint, ) []*MetricDiff { - return diff(diffs, expected.Value(), actual.Value(), "DoubleDataPoint value") + diffs = diff(diffs, expected.Count(), actual.Count(), "DoubleHistogramDataPoint Count") + diffs = diff(diffs, expected.Sum(), actual.Sum(), "DoubleHistogramDataPoint Sum") + diffs = diff(diffs, expected.BucketCounts(), actual.BucketCounts(), "DoubleHistogramDataPoint BucketCounts") + diffs = diff(diffs, expected.ExplicitBounds(), actual.ExplicitBounds(), "DoubleHistogramDataPoint ExplicitBounds") + // todo LabelsMap() + return diffDoubleExemplars(diffs, expected.Exemplars(), actual.Exemplars()) } -func diffHistogramPts( +func diffDoubleExemplars( diffs []*MetricDiff, - expected dataold.HistogramDataPointSlice, - actual dataold.HistogramDataPointSlice, + expected pdata.DoubleExemplarSlice, + actual pdata.DoubleExemplarSlice, ) []*MetricDiff { var mismatch bool - diffs, mismatch = diffValues(diffs, expected.Len(), actual.Len(), "HistogramDataPointSlice len") + diffs, mismatch = diffValues(diffs, expected.Len(), actual.Len(), "DoubleExemplarSlice len") if mismatch { return diffs } for i := 0; i < expected.Len(); i++ { - diffs = diffHistogramPt(diffs, expected.At(i), actual.At(i)) + diffs, mismatch = diffValues(diffs, expected.At(i).IsNil(), actual.At(i).IsNil(), "DoubleExemplar IsNil") + if mismatch { + continue + } + diffs = diff(diffs, expected.At(i).Value(), actual.At(i).Value(), "DoubleExemplar Value") } return diffs } -func diffHistogramPt( +func diffIntHistogramPts( diffs []*MetricDiff, - expected dataold.HistogramDataPoint, - actual dataold.HistogramDataPoint, -) []*MetricDiff { - diffs = diff(diffs, expected.Count(), actual.Count(), "HistogramDataPoint Count") - diffs = diff(diffs, expected.Sum(), actual.Sum(), "HistogramDataPoint Sum") - // todo LabelsMap() - diffs = diffBuckets(diffs, expected.Buckets(), actual.Buckets()) - return diffs -} - -func diffBuckets( - diffs []*MetricDiff, - expected dataold.HistogramBucketSlice, - actual dataold.HistogramBucketSlice, + expected pdata.IntHistogramDataPointSlice, + actual pdata.IntHistogramDataPointSlice, ) []*MetricDiff { var mismatch bool - diffs, mismatch = diffValues(diffs, expected.Len(), actual.Len(), "HistogramBucketSlice len") + diffs, mismatch = diffValues(diffs, expected.Len(), actual.Len(), "HistogramDataPointSlice len") if mismatch { return diffs } for i := 0; i < expected.Len(); i++ { - diffs = diffBucket(diffs, expected.At(i), actual.At(i)) + diffs = diffIntHistogramPt(diffs, expected.At(i), actual.At(i)) } return diffs } -func diffBucket( +func diffIntHistogramPt( diffs []*MetricDiff, - expected dataold.HistogramBucket, - actual dataold.HistogramBucket, + expected pdata.IntHistogramDataPoint, + actual pdata.IntHistogramDataPoint, ) []*MetricDiff { - diffs = diff(diffs, expected.Count(), actual.Count(), "HistogramBucket Count") - diffs = diffExemplar(diffs, expected.Exemplar(), actual.Exemplar()) - return diffs + diffs = diff(diffs, expected.Count(), actual.Count(), "DoubleHistogramDataPoint Count") + diffs = diff(diffs, expected.Sum(), actual.Sum(), "DoubleHistogramDataPoint Sum") + diffs = diff(diffs, expected.BucketCounts(), actual.BucketCounts(), "DoubleHistogramDataPoint BucketCounts") + diffs = diff(diffs, expected.ExplicitBounds(), actual.ExplicitBounds(), "DoubleHistogramDataPoint ExplicitBounds") + // todo LabelsMap() + return diffIntExemplars(diffs, expected.Exemplars(), actual.Exemplars()) } -func diffExemplar( +func diffIntExemplars( diffs []*MetricDiff, - expected dataold.HistogramBucketExemplar, - actual dataold.HistogramBucketExemplar, + expected pdata.IntExemplarSlice, + actual pdata.IntExemplarSlice, ) []*MetricDiff { - diffs = diff(diffs, expected.IsNil(), actual.IsNil(), "HistogramBucketExemplar IsNil") - if expected.IsNil() || actual.IsNil() { + var mismatch bool + diffs, mismatch = diffValues(diffs, expected.Len(), actual.Len(), "DoubleExemplarSlice len") + if mismatch { return diffs } - return diff(diffs, expected.Value(), actual.Value(), "HistogramBucketExemplar Value") + for i := 0; i < expected.Len(); i++ { + diffs, mismatch = diffValues(diffs, expected.At(i).IsNil(), actual.At(i).IsNil(), "DoubleExemplar IsNil") + if mismatch { + continue + } + diffs = diff(diffs, expected.At(i).Value(), actual.At(i).Value(), "DoubleExemplar Value") + } + return diffs } -func diffInt64Pts( +func diffIntPts( diffs []*MetricDiff, - expected dataold.Int64DataPointSlice, - actual dataold.Int64DataPointSlice, + expected pdata.IntDataPointSlice, + actual pdata.IntDataPointSlice, ) []*MetricDiff { var mismatch bool - diffs, mismatch = diffValues(diffs, expected.Len(), actual.Len(), "Int64DataPointSlice len") + diffs, mismatch = diffValues(diffs, expected.Len(), actual.Len(), "IntDataPointSlice len") if mismatch { return diffs } for i := 0; i < expected.Len(); i++ { - diffs = diffInt64Pt(diffs, expected.At(i), actual.At(i)) + diffs = diffIntPt(diffs, expected.At(i), actual.At(i)) } return diffs } -func diffInt64Pt( +func diffIntPt( diffs []*MetricDiff, - expected dataold.Int64DataPoint, - actual dataold.Int64DataPoint, + expected pdata.IntDataPoint, + actual pdata.IntDataPoint, ) []*MetricDiff { - return diff(diffs, expected.Value(), actual.Value(), "Int64DataPoint value") + return diff(diffs, expected.Value(), actual.Value(), "IntDataPoint value") } func diffResource(diffs []*MetricDiff, expected pdata.Resource, actual pdata.Resource) []*MetricDiff { @@ -325,7 +323,7 @@ func diffValues( actual interface{}, msg string, ) ([]*MetricDiff, bool) { - if expected != actual { + if !reflect.DeepEqual(expected, actual) { return append(diffs, &MetricDiff{ Msg: msg, ExpectedValue: expected, diff --git a/testbed/correctness/metrics/metric_diff_test.go b/testbed/correctness/metrics/metric_diff_test.go index 2e4b68ff720..0b04d10aaa8 100644 --- a/testbed/correctness/metrics/metric_diff_test.go +++ b/testbed/correctness/metrics/metric_diff_test.go @@ -22,6 +22,7 @@ import ( "go.opentelemetry.io/collector/consumer/pdata" "go.opentelemetry.io/collector/consumer/pdatautil" + "go.opentelemetry.io/collector/internal/data" "go.opentelemetry.io/collector/internal/dataold" "go.opentelemetry.io/collector/internal/goldendataset" ) @@ -33,13 +34,13 @@ func TestSameMetrics(t *testing.T) { assert.Nil(t, diffs) } -func diffMetricData(expected dataold.MetricData, actual dataold.MetricData) []*MetricDiff { +func diffMetricData(expected data.MetricData, actual data.MetricData) []*MetricDiff { expectedRMSlice := expected.ResourceMetrics() actualRMSlice := actual.ResourceMetrics() return diffRMSlices(toSlice(expectedRMSlice), toSlice(actualRMSlice)) } -func toSlice(s dataold.ResourceMetricsSlice) (out []dataold.ResourceMetrics) { +func toSlice(s pdata.ResourceMetricsSlice) (out []pdata.ResourceMetrics) { for i := 0; i < s.Len(); i++ { out = append(out, s.At(i)) } @@ -52,7 +53,7 @@ func TestDifferentValues(t *testing.T) { cfg.PtVal = 2 actual := goldendataset.MetricDataFromCfg(cfg) diffs := diffMetricData(expected, actual) - assert.Equal(t, 1, len(diffs)) + assert.Len(t, diffs, 1) } func TestDifferentNumPts(t *testing.T) { @@ -61,45 +62,45 @@ func TestDifferentNumPts(t *testing.T) { cfg.NumPtsPerMetric = 2 actual := goldendataset.MetricDataFromCfg(cfg) diffs := diffMetricData(expected, actual) - assert.Equal(t, 1, len(diffs)) + assert.Len(t, diffs, 1) } func TestDifferentPtTypes(t *testing.T) { expected := goldendataset.DefaultMetricData() cfg := goldendataset.DefaultCfg() - cfg.MetricDescriptorType = dataold.MetricTypeDouble + cfg.MetricDescriptorType = pdata.MetricDataTypeDoubleGauge actual := goldendataset.MetricDataFromCfg(cfg) diffs := diffMetricData(expected, actual) - assert.Equal(t, 3, len(diffs)) + assert.Len(t, diffs, 3) } -func TestHistogram(t *testing.T) { +func TestDoubleHistogram(t *testing.T) { cfg1 := goldendataset.DefaultCfg() - cfg1.MetricDescriptorType = dataold.MetricTypeHistogram + cfg1.MetricDescriptorType = pdata.MetricDataTypeDoubleHistogram expected := goldendataset.MetricDataFromCfg(cfg1) cfg2 := goldendataset.DefaultCfg() - cfg2.MetricDescriptorType = dataold.MetricTypeHistogram + cfg2.MetricDescriptorType = pdata.MetricDataTypeDoubleHistogram cfg2.PtVal = 2 actual := goldendataset.MetricDataFromCfg(cfg2) diffs := diffMetricData(expected, actual) - assert.Equal(t, 3, len(diffs)) + assert.Len(t, diffs, 3) } -func TestSummary(t *testing.T) { +func TestIntHistogram(t *testing.T) { cfg1 := goldendataset.DefaultCfg() - cfg1.MetricDescriptorType = dataold.MetricTypeSummary + cfg1.MetricDescriptorType = pdata.MetricDataTypeIntHistogram expected := goldendataset.MetricDataFromCfg(cfg1) cfg2 := goldendataset.DefaultCfg() - cfg2.MetricDescriptorType = dataold.MetricTypeSummary + cfg2.MetricDescriptorType = pdata.MetricDataTypeIntHistogram cfg2.PtVal = 2 actual := goldendataset.MetricDataFromCfg(cfg2) diffs := diffMetricData(expected, actual) - assert.Equal(t, 3, len(diffs)) + assert.Len(t, diffs, 3) } func TestPDMToPDRM(t *testing.T) { md := dataold.NewMetricData() md.ResourceMetrics().Resize(1) rm := pdmToPDRM([]pdata.Metrics{pdatautil.MetricsFromOldInternalMetrics(md)}) - require.Equal(t, 1, len(rm)) + require.Len(t, rm, 1) }