From 6d90d2313ee858125ed9e0cfd95ea4bc6ce12058 Mon Sep 17 00:00:00 2001 From: oleiade Date: Mon, 14 Mar 2022 14:15:08 +0100 Subject: [PATCH] Remove usage of `stats.New` in testing code --- .../workflows/xk6-tests/xk6-js-test/jstest.go | 4 +- api/v1/metric_routes_test.go | 8 +++- api/v1/metric_test.go | 6 ++- core/engine_test.go | 29 ++++++++++---- core/local/local_test.go | 4 +- js/summary_test.go | 39 +++++++++++++++---- lib/metrics/registry.go | 30 +++++++------- output/csv/output_test.go | 25 ++++++++---- output/helpers_test.go | 14 ++++++- output/influxdb/bench_test.go | 8 +++- output/influxdb/output_test.go | 13 ++++++- output/json/json_test.go | 8 +++- output/statsd/test_helper.go | 17 +++++--- stats/stats_test.go | 23 ----------- 14 files changed, 153 insertions(+), 75 deletions(-) diff --git a/.github/workflows/xk6-tests/xk6-js-test/jstest.go b/.github/workflows/xk6-tests/xk6-js-test/jstest.go index f13e1df7da5..cf46475049c 100644 --- a/.github/workflows/xk6-tests/xk6-js-test/jstest.go +++ b/.github/workflows/xk6-tests/xk6-js-test/jstest.go @@ -25,6 +25,7 @@ import ( "time" "go.k6.io/k6/lib" + "go.k6.io/k6/lib/metrics" "go.k6.io/k6/stats" "go.k6.io/k6/js/modules" @@ -44,7 +45,8 @@ func (j JSTest) Foo(ctx context.Context, arg float64) (bool, error) { return false, fmt.Errorf("called in init context") } - allTheFoos := stats.New("foos", stats.Counter) + registry := metrics.NewRegistry() + allTheFoos := registry.MustNewMetric("foos", stats.Counter) tags := state.CloneTags() tags["foo"] = "bar" stats.PushIfNotDone(ctx, state.Samples, stats.Sample{ diff --git a/api/v1/metric_routes_test.go b/api/v1/metric_routes_test.go index a32e307f9a2..3a4e1f89cd4 100644 --- a/api/v1/metric_routes_test.go +++ b/api/v1/metric_routes_test.go @@ -52,8 +52,10 @@ func TestGetMetrics(t *testing.T) { engine, err := core.NewEngine(execScheduler, lib.Options{}, lib.RuntimeOptions{}, nil, logger, builtinMetrics) require.NoError(t, err) + m, err := registry.NewMetric("my_metric", stats.Trend, stats.Time) + require.NoError(t, err) engine.Metrics = map[string]*stats.Metric{ - "my_metric": stats.New("my_metric", stats.Trend, stats.Time), + "my_metric": m, } engine.Metrics["my_metric"].Tainted = null.BoolFrom(true) @@ -112,8 +114,10 @@ func TestGetMetric(t *testing.T) { engine, err := core.NewEngine(execScheduler, lib.Options{}, lib.RuntimeOptions{}, nil, logger, builtinMetrics) require.NoError(t, err) + m, err := registry.NewMetric("my_metric", stats.Trend, stats.Time) + require.NoError(t, err) engine.Metrics = map[string]*stats.Metric{ - "my_metric": stats.New("my_metric", stats.Trend, stats.Time), + "my_metric": m, } engine.Metrics["my_metric"].Tainted = null.BoolFrom(true) diff --git a/api/v1/metric_test.go b/api/v1/metric_test.go index 787c2f6e9a6..5cfb3f63bb8 100644 --- a/api/v1/metric_test.go +++ b/api/v1/metric_test.go @@ -25,8 +25,10 @@ import ( "testing" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "gopkg.in/guregu/null.v3" + "go.k6.io/k6/lib/metrics" "go.k6.io/k6/stats" ) @@ -107,7 +109,9 @@ func TestNullValueTypeJSON(t *testing.T) { func TestNewMetric(t *testing.T) { t.Parallel() - old := stats.New("name", stats.Trend, stats.Time) + registry := metrics.NewRegistry() + old, err := registry.NewMetric("name", stats.Trend, stats.Time) + require.NoError(t, err) old.Tainted = null.BoolFrom(true) m := NewMetric(old, 0) assert.Equal(t, "name", m.Name) diff --git a/core/engine_test.go b/core/engine_test.go index 685faa94d18..bc1a8efb9b4 100644 --- a/core/engine_test.go +++ b/core/engine_test.go @@ -103,6 +103,8 @@ func TestNewEngine(t *testing.T) { func TestEngineRun(t *testing.T) { t.Parallel() logrus.SetLevel(logrus.DebugLevel) + registry := metrics.NewRegistry() + t.Run("exits with context", func(t *testing.T) { t.Parallel() done := make(chan struct{}) @@ -139,7 +141,8 @@ func TestEngineRun(t *testing.T) { // Make sure samples are discarded after context close (using "cutoff" timestamp in local.go) t.Run("collects samples", func(t *testing.T) { t.Parallel() - testMetric := stats.New("test_metric", stats.Trend) + testMetric, err := registry.NewMetric("test_metric", stats.Trend) + require.NoError(t, err) signalChan := make(chan interface{}) @@ -211,7 +214,9 @@ func TestEngineStopped(t *testing.T) { func TestEngineOutput(t *testing.T) { t.Parallel() - testMetric := stats.New("test_metric", stats.Trend) + registry := metrics.NewRegistry() + testMetric, err := registry.NewMetric("test_metric", stats.Trend) + require.NoError(t, err) runner := &minirunner.MiniRunner{ Fn: func(ctx context.Context, _ *lib.State, out chan<- stats.SampleContainer) error { @@ -248,7 +253,9 @@ func TestEngineOutput(t *testing.T) { func TestEngine_processSamples(t *testing.T) { t.Parallel() - metric := stats.New("my_metric", stats.Gauge) + registry := metrics.NewRegistry() + metric, err := registry.NewMetric("my_metric", stats.Gauge) + require.NoError(t, err) t.Run("metric", func(t *testing.T) { t.Parallel() @@ -290,7 +297,9 @@ func TestEngine_processSamples(t *testing.T) { func TestEngineThresholdsWillAbort(t *testing.T) { t.Parallel() - metric := stats.New("my_metric", stats.Gauge) + registry := metrics.NewRegistry() + metric, err := registry.NewMetric("my_metric", stats.Gauge) + require.NoError(t, err) // The incoming samples for the metric set it to 1.25. Considering // the metric is of type Gauge, value > 1.25 should always fail, and @@ -313,7 +322,9 @@ func TestEngineThresholdsWillAbort(t *testing.T) { func TestEngineAbortedByThresholds(t *testing.T) { t.Parallel() - metric := stats.New("my_metric", stats.Gauge) + registry := metrics.NewRegistry() + metric, err := registry.NewMetric("my_metric", stats.Gauge) + require.NoError(t, err) // The MiniRunner sets the value of the metric to 1.25. Considering // the metric is of type Gauge, value > 1.25 should always fail, and @@ -353,7 +364,9 @@ func TestEngineAbortedByThresholds(t *testing.T) { func TestEngine_processThresholds(t *testing.T) { t.Parallel() - metric := stats.New("my_metric", stats.Gauge) + registry := metrics.NewRegistry() + metric, err := registry.NewMetric("my_metric", stats.Gauge) + require.NoError(t, err) testdata := map[string]struct { pass bool @@ -1128,7 +1141,9 @@ func TestMinIterationDurationInSetupTeardownStage(t *testing.T) { func TestEngineRunsTeardownEvenAfterTestRunIsAborted(t *testing.T) { t.Parallel() - testMetric := stats.New("teardown_metric", stats.Counter) + registry := metrics.NewRegistry() + testMetric, err := registry.NewMetric("teardown_metric", stats.Counter) + require.NoError(t, err) ctx, cancel := context.WithCancel(context.Background()) diff --git a/core/local/local_test.go b/core/local/local_test.go index 33c04a72382..620ad67da98 100644 --- a/core/local/local_test.go +++ b/core/local/local_test.go @@ -1228,7 +1228,9 @@ func TestRealTimeAndSetupTeardownMetrics(t *testing.T) { } return stats.IntoSampleTags(&tags) } - testCounter := stats.New("test_counter", stats.Counter) + + testCounter, err := registry.NewMetric("test_counter", stats.Counter) + require.NoError(t, err) getSample := func(expValue float64, expMetric *stats.Metric, expTags ...string) stats.SampleContainer { return stats.Sample{ Metric: expMetric, diff --git a/js/summary_test.go b/js/summary_test.go index 23d38b2dbdb..c932421d17a 100644 --- a/js/summary_test.go +++ b/js/summary_test.go @@ -34,6 +34,7 @@ import ( "gopkg.in/guregu/null.v3" "go.k6.io/k6/lib" + "go.k6.io/k6/lib/metrics" "go.k6.io/k6/lib/testutils" "go.k6.io/k6/stats" ) @@ -98,14 +99,33 @@ func TestTextSummary(t *testing.T) { func TestTextSummaryWithSubMetrics(t *testing.T) { t.Parallel() - parentMetric := stats.New("my_parent", stats.Counter) + registry := metrics.NewRegistry() + parentMetric, err := registry.NewMetric("my_parent", stats.Counter) + require.NoError(t, err) parentMetric.Sink.Add(stats.Sample{Value: 11}) - parentMetricPost := stats.New("my_parent_post", stats.Counter) + + parentMetricPost, err := registry.NewMetric("my_parent_post", stats.Counter) + require.NoError(t, err) parentMetricPost.Sink.Add(stats.Sample{Value: 22}) - subMetric := stats.New("my_parent{sub:1}", stats.Counter) + // We instantiate Metric directly as Registry.NewMetric uses + // `checkName`, which does not handle the tag syntax. + subMetric := &stats.Metric{ + Name: "my_parent{sub:1}", + Type: stats.Counter, + Contains: stats.Default, + Sink: &stats.CounterSink{}, + } subMetric.Sink.Add(stats.Sample{Value: 1}) - subMetricPost := stats.New("my_parent_post{sub:2}", stats.Counter) + + // We instantiate Metric directly as Registry.NewMetric uses + // `checkName`, which does not handle the tag syntax. + subMetricPost := &stats.Metric{ + Name: "my_parent_post{sub:2}", + Type: stats.Counter, + Contains: stats.Default, + Sink: &stats.CounterSink{}, + } subMetricPost.Sink.Add(stats.Sample{Value: 2}) metrics := map[string]*stats.Metric{ @@ -147,15 +167,20 @@ func TestTextSummaryWithSubMetrics(t *testing.T) { } func createTestMetrics(t *testing.T) (map[string]*stats.Metric, *lib.Group) { + registry := metrics.NewRegistry() + metrics := make(map[string]*stats.Metric) - gaugeMetric := stats.New("vus", stats.Gauge) + gaugeMetric, err := registry.NewMetric("vus", stats.Gauge) + require.NoError(t, err) gaugeMetric.Sink.Add(stats.Sample{Value: 1}) - countMetric := stats.New("http_reqs", stats.Counter) + countMetric, err := registry.NewMetric("http_reqs", stats.Counter) + require.NoError(t, err) countMetric.Tainted = null.BoolFrom(true) countMetric.Thresholds = stats.Thresholds{Thresholds: []*stats.Threshold{{Source: "rate<100", LastFailed: true}}} - checksMetric := stats.New("checks", stats.Rate) + checksMetric, err := registry.NewMetric("checks", stats.Rate) + require.NoError(t, err) checksMetric.Tainted = null.BoolFrom(false) checksMetric.Thresholds = stats.Thresholds{Thresholds: []*stats.Threshold{{Source: "rate>70", LastFailed: false}}} sink := &stats.TrendSink{} diff --git a/lib/metrics/registry.go b/lib/metrics/registry.go index 81f78a28ea1..77a66e3cdd7 100644 --- a/lib/metrics/registry.go +++ b/lib/metrics/registry.go @@ -51,7 +51,7 @@ func checkName(name string) bool { // NewMetric returns new metric registered to this registry // TODO have multiple versions returning specific metric types when we have such things -func (r *Registry) NewMetric(name string, typ stats.MetricType, t ...stats.ValueType) (*stats.Metric, error) { +func (r *Registry) NewMetric(name string, mt stats.MetricType, vt ...stats.ValueType) (*stats.Metric, error) { r.l.Lock() defer r.l.Unlock() @@ -61,12 +61,13 @@ func (r *Registry) NewMetric(name string, typ stats.MetricType, t ...stats.Value oldMetric, ok := r.metrics[name] if !ok { - vt := stats.Default - if len(t) > 0 { - vt = t[0] + valueType := stats.Default + if len(vt) > 0 { + valueType = vt[0] } + var sink stats.Sink - switch typ { + switch mt { case stats.Counter: sink = &stats.CounterSink{} case stats.Gauge: @@ -76,22 +77,23 @@ func (r *Registry) NewMetric(name string, typ stats.MetricType, t ...stats.Value case stats.Rate: sink = &stats.RateSink{} default: - return nil, fmt.Errorf("unable to create metric of type %q; reason: unknown metric type", typ.String()) + return nil, fmt.Errorf("unable to create metric of type %q; reason: unknown metric type", mt.String()) } - m := &stats.Metric{Name: name, Type: typ, Contains: vt, Sink: sink} + m := &stats.Metric{Name: name, Type: mt, Contains: valueType, Sink: sink} r.metrics[name] = m return m, nil } - if oldMetric.Type != typ { - return nil, fmt.Errorf("metric '%s' already exists but with type %s, instead of %s", name, oldMetric.Type, typ) + + if oldMetric.Type != mt { + return nil, fmt.Errorf("metric '%s' already exists but with type %s, instead of %s", name, oldMetric.Type, mt) } - if len(t) > 0 { - if t[0] != oldMetric.Contains { - return nil, fmt.Errorf("metric '%s' already exists but with a value type %s, instead of %s", - name, oldMetric.Contains, t[0]) - } + + if len(vt) > 0 && vt[0] != oldMetric.Contains { + return nil, fmt.Errorf("metric '%s' already exists but with a value type %s, instead of %s", + name, oldMetric.Contains, vt[0]) } + return oldMetric, nil } diff --git a/output/csv/output_test.go b/output/csv/output_test.go index 4c3e7ff88ba..7ea5e11996a 100644 --- a/output/csv/output_test.go +++ b/output/csv/output_test.go @@ -36,6 +36,7 @@ import ( "github.com/stretchr/testify/require" "go.k6.io/k6/lib" + "go.k6.io/k6/lib/metrics" "go.k6.io/k6/lib/testutils" "go.k6.io/k6/output" "go.k6.io/k6/stats" @@ -65,6 +66,12 @@ func TestMakeHeader(t *testing.T) { } func TestSampleToRow(t *testing.T) { + t.Parallel() + + testRegistry := metrics.NewRegistry() + testMetric, err := testRegistry.NewMetric("my_metric", stats.Gauge) + require.NoError(t, err) + testData := []struct { testname string sample *stats.Sample @@ -75,7 +82,7 @@ func TestSampleToRow(t *testing.T) { testname: "One res tag, one ignored tag, one extra tag", sample: &stats.Sample{ Time: time.Unix(1562324644, 0), - Metric: stats.New("my_metric", stats.Gauge), + Metric: testMetric, Value: 1, Tags: stats.NewSampleTags(map[string]string{ "tag1": "val1", @@ -90,7 +97,7 @@ func TestSampleToRow(t *testing.T) { testname: "Two res tags, three extra tags", sample: &stats.Sample{ Time: time.Unix(1562324644, 0), - Metric: stats.New("my_metric", stats.Gauge), + Metric: testMetric, Value: 1, Tags: stats.NewSampleTags(map[string]string{ "tag1": "val1", @@ -107,7 +114,7 @@ func TestSampleToRow(t *testing.T) { testname: "Two res tags, two ignored", sample: &stats.Sample{ Time: time.Unix(1562324644, 0), - Metric: stats.New("my_metric", stats.Gauge), + Metric: testMetric, Value: 1, Tags: stats.NewSampleTags(map[string]string{ "tag1": "val1", @@ -214,6 +221,10 @@ func readCompressedFile(fileName string, fs afero.Fs) string { func TestRun(t *testing.T) { t.Parallel() + + testRegistry := metrics.NewRegistry() + testMetric, err := testRegistry.NewMetric("my_metric", stats.Gauge) + require.NoError(t, err) testData := []struct { samples []stats.SampleContainer fileName string @@ -224,7 +235,7 @@ func TestRun(t *testing.T) { samples: []stats.SampleContainer{ stats.Sample{ Time: time.Unix(1562324643, 0), - Metric: stats.New("my_metric", stats.Gauge), + Metric: testMetric, Value: 1, Tags: stats.NewSampleTags(map[string]string{ "check": "val1", @@ -234,7 +245,7 @@ func TestRun(t *testing.T) { }, stats.Sample{ Time: time.Unix(1562324644, 0), - Metric: stats.New("my_metric", stats.Gauge), + Metric: testMetric, Value: 1, Tags: stats.NewSampleTags(map[string]string{ "check": "val1", @@ -252,7 +263,7 @@ func TestRun(t *testing.T) { samples: []stats.SampleContainer{ stats.Sample{ Time: time.Unix(1562324643, 0), - Metric: stats.New("my_metric", stats.Gauge), + Metric: testMetric, Value: 1, Tags: stats.NewSampleTags(map[string]string{ "check": "val1", @@ -262,7 +273,7 @@ func TestRun(t *testing.T) { }, stats.Sample{ Time: time.Unix(1562324644, 0), - Metric: stats.New("my_metric", stats.Gauge), + Metric: testMetric, Value: 1, Tags: stats.NewSampleTags(map[string]string{ "check": "val1", diff --git a/output/helpers_test.go b/output/helpers_test.go index a4baac2228b..42749031083 100644 --- a/output/helpers_test.go +++ b/output/helpers_test.go @@ -29,14 +29,20 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + "go.k6.io/k6/lib/metrics" "go.k6.io/k6/stats" ) func TestSampleBufferBasics(t *testing.T) { t.Parallel() + + registry := metrics.NewRegistry() + m, err := registry.NewMetric("my_metric", stats.Rate) + require.NoError(t, err) + single := stats.Sample{ Time: time.Now(), - Metric: stats.New("my_metric", stats.Rate), + Metric: m, Value: float64(123), Tags: stats.NewSampleTags(map[string]string{"tag1": "val1"}), } @@ -70,6 +76,10 @@ func TestSampleBufferConcurrently(t *testing.T) { r := rand.New(rand.NewSource(seed)) //nolint:gosec t.Logf("Random source seeded with %d\n", seed) + registry := metrics.NewRegistry() + metric, err := registry.NewMetric("my_metric", stats.Gauge) + require.NoError(t, err) + producersCount := 50 + r.Intn(50) sampleCount := 10 + r.Intn(10) sleepModifier := 10 + r.Intn(10) @@ -80,7 +90,7 @@ func TestSampleBufferConcurrently(t *testing.T) { for i := 0; i < sampleCount; i++ { buffer.AddMetricSamples([]stats.SampleContainer{stats.Sample{ Time: time.Unix(1562324644, 0), - Metric: stats.New("my_metric", stats.Gauge), + Metric: metric, Value: float64(i), Tags: stats.NewSampleTags(map[string]string{"tag1": "val1"}), }}) diff --git a/output/influxdb/bench_test.go b/output/influxdb/bench_test.go index 4251dcd9912..2b79a9ef76a 100644 --- a/output/influxdb/bench_test.go +++ b/output/influxdb/bench_test.go @@ -27,10 +27,16 @@ import ( "testing" "time" + "github.com/stretchr/testify/require" + "go.k6.io/k6/lib/metrics" "go.k6.io/k6/stats" ) func benchmarkInfluxdb(b *testing.B, t time.Duration) { + registry := metrics.NewRegistry() + metric, err := registry.NewMetric("test_gauge", stats.Gauge) + require.NoError(b, err) + testOutputCycle(b, func(rw http.ResponseWriter, r *http.Request) { for { time.Sleep(t) @@ -47,7 +53,7 @@ func benchmarkInfluxdb(b *testing.B, t time.Duration) { samples := make(stats.Samples, 10) for i := 0; i < len(samples); i++ { samples[i] = stats.Sample{ - Metric: stats.New("testGauge", stats.Gauge), + Metric: metric, Time: time.Now(), Tags: stats.NewSampleTags(map[string]string{ "something": "else", diff --git a/output/influxdb/output_test.go b/output/influxdb/output_test.go index 48244b2b61f..2605b3464e1 100644 --- a/output/influxdb/output_test.go +++ b/output/influxdb/output_test.go @@ -35,6 +35,7 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + "go.k6.io/k6/lib/metrics" "go.k6.io/k6/lib/testutils" "go.k6.io/k6/output" "go.k6.io/k6/stats" @@ -108,6 +109,10 @@ func testOutputCycle(t testing.TB, handler http.HandlerFunc, body func(testing.T func TestOutput(t *testing.T) { t.Parallel() + registry := metrics.NewRegistry() + metric, err := registry.NewMetric("test_gauge", stats.Gauge) + require.NoError(t, err) + var samplesRead int defer func() { require.Equal(t, samplesRead, 20) @@ -130,7 +135,7 @@ func TestOutput(t *testing.T) { samples := make(stats.Samples, 10) for i := 0; i < len(samples); i++ { samples[i] = stats.Sample{ - Metric: stats.New("testGauge", stats.Gauge), + Metric: metric, Time: time.Now(), Tags: stats.NewSampleTags(map[string]string{ "something": "else", @@ -148,6 +153,10 @@ func TestOutput(t *testing.T) { func TestOutputFlushMetricsConcurrency(t *testing.T) { t.Parallel() + registry := metrics.NewRegistry() + metric, err := registry.NewMetric("test_gauge", stats.Gauge) + require.NoError(t, err) + var ( requests = int32(0) block = make(chan struct{}) @@ -183,7 +192,7 @@ func TestOutputFlushMetricsConcurrency(t *testing.T) { wg.Add(1) o.AddMetricSamples([]stats.SampleContainer{stats.Samples{ stats.Sample{ - Metric: stats.New("gauge", stats.Gauge), + Metric: metric, Value: 2.0, }, }}) diff --git a/output/json/json_test.go b/output/json/json_test.go index e38a3ebe47b..7397eed28e4 100644 --- a/output/json/json_test.go +++ b/output/json/json_test.go @@ -32,6 +32,7 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + "go.k6.io/k6/lib/metrics" "go.k6.io/k6/lib/testutils" "go.k6.io/k6/output" "go.k6.io/k6/stats" @@ -55,8 +56,11 @@ func getValidator(t *testing.T, expected []string) func(io.Reader) { } func generateTestMetricSamples(t *testing.T) ([]stats.SampleContainer, func(io.Reader)) { - metric1 := stats.New("my_metric1", stats.Gauge) - metric2 := stats.New("my_metric2", stats.Counter, stats.Data) + registry := metrics.NewRegistry() + metric1, err := registry.NewMetric("my_metric1", stats.Gauge) + require.NoError(t, err) + metric2, err := registry.NewMetric("my_metric2", stats.Counter, stats.Data) + require.NoError(t, err) time1 := time.Date(2021, time.February, 24, 13, 37, 10, 0, time.UTC) time2 := time1.Add(10 * time.Second) time3 := time2.Add(10 * time.Second) diff --git a/output/statsd/test_helper.go b/output/statsd/test_helper.go index 1ab6f83a965..f43074c5d7d 100644 --- a/output/statsd/test_helper.go +++ b/output/statsd/test_helper.go @@ -29,6 +29,7 @@ import ( "github.com/stretchr/testify/require" "gopkg.in/guregu/null.v3" + "go.k6.io/k6/lib/metrics" "go.k6.io/k6/lib/testutils" "go.k6.io/k6/lib/types" "go.k6.io/k6/stats" @@ -92,11 +93,17 @@ func baseTest(t *testing.T, } } - myCounter := stats.New("my_counter", stats.Counter) - myGauge := stats.New("my_gauge", stats.Gauge) - myTrend := stats.New("my_trend", stats.Trend) - myRate := stats.New("my_rate", stats.Rate) - myCheck := stats.New("my_check", stats.Rate) + registry := metrics.NewRegistry() + myCounter, err := registry.NewMetric("my_counter", stats.Counter) + require.NoError(t, err) + myGauge, err := registry.NewMetric("my_gauge", stats.Gauge) + require.NoError(t, err) + myTrend, err := registry.NewMetric("my_trend", stats.Trend) + require.NoError(t, err) + myRate, err := registry.NewMetric("my_rate", stats.Rate) + require.NoError(t, err) + myCheck, err := registry.NewMetric("my_check", stats.Rate) + require.NoError(t, err) testMatrix := []struct { input []stats.SampleContainer output string diff --git a/stats/stats_test.go b/stats/stats_test.go index dcc1333b4d6..e2edbf2e498 100644 --- a/stats/stats_test.go +++ b/stats/stats_test.go @@ -29,29 +29,6 @@ import ( "github.com/stretchr/testify/assert" ) -func TestNew(t *testing.T) { - t.Parallel() - testdata := map[string]struct { - Type MetricType - SinkType Sink - }{ - "Counter": {Counter, &CounterSink{}}, - "Gauge": {Gauge, &GaugeSink{}}, - "Trend": {Trend, &TrendSink{}}, - "Rate": {Rate, &RateSink{}}, - } - - for name, data := range testdata { - name, data := name, data - t.Run(name, func(t *testing.T) { - t.Parallel() - m := New("my_metric", data.Type) - assert.Equal(t, "my_metric", m.Name) - assert.IsType(t, data.SinkType, m.Sink) - }) - } -} - func TestNewSubmetric(t *testing.T) { t.Parallel() testdata := map[string]struct {