Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix comments and func names in goldendataset metrics #2562

Merged
merged 1 commit into from
Mar 1, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 8 additions & 12 deletions internal/goldendataset/metric_gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions internal/goldendataset/metric_gen_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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()
Expand All @@ -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())
Expand Down
2 changes: 1 addition & 1 deletion internal/goldendataset/pict_metric_gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion processor/filterprocessor/expr_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
2 changes: 1 addition & 1 deletion processor/filterprocessor/filter_processor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
24 changes: 12 additions & 12 deletions testbed/correctness/metrics/metric_diff_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,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)
}
Expand All @@ -45,52 +45,52 @@ 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)
}

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)
}

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)
}
Expand Down