From 5459e31a41e1ecf46a9102c93dd8c72a904ab24c Mon Sep 17 00:00:00 2001 From: Bogdan Drutu Date: Mon, 1 Mar 2021 08:06:26 -0800 Subject: [PATCH] Fix comments and func names in goldendataset metrics (#2562) Signed-off-by: Bogdan Drutu --- internal/goldendataset/metric_gen.go | 20 +++++++--------- internal/goldendataset/metric_gen_test.go | 6 ++--- internal/goldendataset/pict_metric_gen.go | 2 +- processor/filterprocessor/expr_test.go | 2 +- .../filterprocessor/filter_processor_test.go | 2 +- .../correctness/metrics/metric_diff_test.go | 24 +++++++++---------- 6 files changed, 26 insertions(+), 30 deletions(-) diff --git a/internal/goldendataset/metric_gen.go b/internal/goldendataset/metric_gen.go index 68ee094e1cde..df71b4e213e7 100644 --- a/internal/goldendataset/metric_gen.go +++ b/internal/goldendataset/metric_gen.go @@ -23,7 +23,7 @@ import ( // Simple utilities for generating metrics for testing // MetricCfg holds parameters for generating dummy metrics for testing. Set values on this struct to generate -// metrics with the corresponding number/type of attributes and pass into MetricDataFromCfg to generate metrics. +// metrics with the corresponding number/type of attributes and pass into MetricsFromCfg to generate metrics. type MetricCfg struct { // The type of metric to generate MetricDescriptorType pdata.MetricDataType @@ -69,25 +69,21 @@ func DefaultCfg() MetricCfg { } } -// DefaultMetricData produces MetricData with a default config. -func DefaultMetricData() pdata.Metrics { - return MetricDataFromCfg(DefaultCfg()) -} - -// MetricDataFromCfg produces MetricData with the passed-in config. -func MetricDataFromCfg(cfg MetricCfg) pdata.Metrics { - return newMetricGenerator().genMetricDataFromCfg(cfg) +// MetricsFromCfg produces pdata.Metrics with the passed-in config. +func MetricsFromCfg(cfg MetricCfg) pdata.Metrics { + mg := newMetricGenerator() + return mg.genMetricFromCfg(cfg) } type metricGenerator struct { metricID int } -func newMetricGenerator() *metricGenerator { - return &metricGenerator{} +func newMetricGenerator() metricGenerator { + return metricGenerator{} } -func (g *metricGenerator) genMetricDataFromCfg(cfg MetricCfg) pdata.Metrics { +func (g *metricGenerator) genMetricFromCfg(cfg MetricCfg) pdata.Metrics { md := pdata.NewMetrics() rms := md.ResourceMetrics() rms.Resize(cfg.NumResourceMetrics) diff --git a/internal/goldendataset/metric_gen_test.go b/internal/goldendataset/metric_gen_test.go index 360f9e50a086..4d26e1b4ae67 100644 --- a/internal/goldendataset/metric_gen_test.go +++ b/internal/goldendataset/metric_gen_test.go @@ -23,7 +23,7 @@ import ( ) func TestGenDefault(t *testing.T) { - md := DefaultMetricData() + md := MetricsFromCfg(DefaultCfg()) mCount, ptCount := md.MetricAndDataPointCount() require.Equal(t, 1, mCount) require.Equal(t, 1, ptCount) @@ -106,7 +106,7 @@ func TestGenDoubleHistogram(t *testing.T) { cfg := DefaultCfg() cfg.MetricDescriptorType = pdata.MetricDataTypeDoubleHistogram cfg.PtVal = 2 - md := MetricDataFromCfg(cfg) + md := MetricsFromCfg(cfg) pts := getMetric(md).DoubleHistogram().DataPoints() pt := pts.At(0) buckets := pt.BucketCounts() @@ -117,7 +117,7 @@ func TestGenDoubleHistogram(t *testing.T) { func TestGenDoubleGauge(t *testing.T) { cfg := DefaultCfg() cfg.MetricDescriptorType = pdata.MetricDataTypeDoubleGauge - md := MetricDataFromCfg(cfg) + md := MetricsFromCfg(cfg) metric := getMetric(md) pts := metric.DoubleGauge().DataPoints() require.Equal(t, 1, pts.Len()) diff --git a/internal/goldendataset/pict_metric_gen.go b/internal/goldendataset/pict_metric_gen.go index 53b8e8535636..5592a01b27b3 100644 --- a/internal/goldendataset/pict_metric_gen.go +++ b/internal/goldendataset/pict_metric_gen.go @@ -39,7 +39,7 @@ func GenerateMetricDatas(metricPairsFile string) ([]pdata.Metrics, error) { } cfg := pictToCfg(metricInputs) cfg.MetricNamePrefix = fmt.Sprintf("pict_%d_", i) - md := MetricDataFromCfg(cfg) + md := MetricsFromCfg(cfg) out = append(out, md) } return out, nil diff --git a/processor/filterprocessor/expr_test.go b/processor/filterprocessor/expr_test.go index 2f7f99c6092b..c9e4c64c0771 100644 --- a/processor/filterprocessor/expr_test.go +++ b/processor/filterprocessor/expr_test.go @@ -203,5 +203,5 @@ func testData(prefix string, size int, mdType pdata.MetricDataType) pdata.Metric NumResourceAttrs: size, NumResourceMetrics: size, } - return goldendataset.MetricDataFromCfg(c) + return goldendataset.MetricsFromCfg(c) } diff --git a/processor/filterprocessor/filter_processor_test.go b/processor/filterprocessor/filter_processor_test.go index 3834c37a1cfa..f9542b00e387 100644 --- a/processor/filterprocessor/filter_processor_test.go +++ b/processor/filterprocessor/filter_processor_test.go @@ -488,7 +488,7 @@ func pdm(prefix string, size int) pdata.Metrics { NumResourceAttrs: size, NumResourceMetrics: size, } - return goldendataset.MetricDataFromCfg(c) + return goldendataset.MetricsFromCfg(c) } func TestMetricIndexSingle(t *testing.T) { diff --git a/testbed/correctness/metrics/metric_diff_test.go b/testbed/correctness/metrics/metric_diff_test.go index 13931054d19c..a16224822d98 100644 --- a/testbed/correctness/metrics/metric_diff_test.go +++ b/testbed/correctness/metrics/metric_diff_test.go @@ -24,8 +24,8 @@ import ( ) func TestSameMetrics(t *testing.T) { - expected := goldendataset.DefaultMetricData() - actual := goldendataset.DefaultMetricData() + expected := goldendataset.MetricsFromCfg(goldendataset.DefaultCfg()) + actual := goldendataset.MetricsFromCfg(goldendataset.DefaultCfg()) diffs := diffMetricData(expected, actual) assert.Nil(t, diffs) } @@ -44,28 +44,28 @@ func toSlice(s pdata.ResourceMetricsSlice) (out []pdata.ResourceMetrics) { } func TestDifferentValues(t *testing.T) { - expected := goldendataset.DefaultMetricData() + expected := goldendataset.MetricsFromCfg(goldendataset.DefaultCfg()) cfg := goldendataset.DefaultCfg() cfg.PtVal = 2 - actual := goldendataset.MetricDataFromCfg(cfg) + actual := goldendataset.MetricsFromCfg(cfg) diffs := diffMetricData(expected, actual) assert.Len(t, diffs, 1) } func TestDifferentNumPts(t *testing.T) { - expected := goldendataset.DefaultMetricData() + expected := goldendataset.MetricsFromCfg(goldendataset.DefaultCfg()) cfg := goldendataset.DefaultCfg() cfg.NumPtsPerMetric = 2 - actual := goldendataset.MetricDataFromCfg(cfg) + actual := goldendataset.MetricsFromCfg(cfg) diffs := diffMetricData(expected, actual) assert.Len(t, diffs, 1) } func TestDifferentPtTypes(t *testing.T) { - expected := goldendataset.DefaultMetricData() + expected := goldendataset.MetricsFromCfg(goldendataset.DefaultCfg()) cfg := goldendataset.DefaultCfg() cfg.MetricDescriptorType = pdata.MetricDataTypeDoubleGauge - actual := goldendataset.MetricDataFromCfg(cfg) + actual := goldendataset.MetricsFromCfg(cfg) diffs := diffMetricData(expected, actual) assert.Len(t, diffs, 1) } @@ -73,11 +73,11 @@ func TestDifferentPtTypes(t *testing.T) { func TestDoubleHistogram(t *testing.T) { cfg1 := goldendataset.DefaultCfg() cfg1.MetricDescriptorType = pdata.MetricDataTypeDoubleHistogram - expected := goldendataset.MetricDataFromCfg(cfg1) + expected := goldendataset.MetricsFromCfg(cfg1) cfg2 := goldendataset.DefaultCfg() cfg2.MetricDescriptorType = pdata.MetricDataTypeDoubleHistogram cfg2.PtVal = 2 - actual := goldendataset.MetricDataFromCfg(cfg2) + actual := goldendataset.MetricsFromCfg(cfg2) diffs := diffMetricData(expected, actual) assert.Len(t, diffs, 3) } @@ -85,11 +85,11 @@ func TestDoubleHistogram(t *testing.T) { func TestIntHistogram(t *testing.T) { cfg1 := goldendataset.DefaultCfg() cfg1.MetricDescriptorType = pdata.MetricDataTypeIntHistogram - expected := goldendataset.MetricDataFromCfg(cfg1) + expected := goldendataset.MetricsFromCfg(cfg1) cfg2 := goldendataset.DefaultCfg() cfg2.MetricDescriptorType = pdata.MetricDataTypeIntHistogram cfg2.PtVal = 2 - actual := goldendataset.MetricDataFromCfg(cfg2) + actual := goldendataset.MetricsFromCfg(cfg2) diffs := diffMetricData(expected, actual) assert.Len(t, diffs, 3) }