From 3f822249e17d087c33f95a1a0c75312c27c22e4c Mon Sep 17 00:00:00 2001 From: FlamingSaint <78465537+FlamingSaint@users.noreply.github.com> Date: Mon, 3 Jun 2024 21:08:55 +0530 Subject: [PATCH] Enable Lint Rule: dot-imports (#5513) ## Which problem is this PR solving? - Partial Fix for #5506 ## Description of the changes - Enabled dot-imports in revive linter. - Removed dot imports in a few and added qualifiers for the rest. ## How was this change tested? - `make lint` `make test` ## Checklist - [x] I have read https://github.com/jaegertracing/jaeger/blob/master/CONTRIBUTING_GUIDELINES.md - [x] I have signed all commits - [ ] I have added unit tests for the new functionality - [x] I have run lint and test steps successfully - for `jaeger`: `make lint test` - for `jaeger-ui`: `yarn lint` and `yarn test` Signed-off-by: FlamingSaint --- .golangci.yml | 3 -- internal/metrics/prometheus/factory_test.go | 30 +++++++++---------- pkg/healthcheck/handler_test.go | 24 +++++++-------- .../metricsstore/metrics/decorator_test.go | 6 ++-- storage/spanstore/composite_test.go | 8 ++--- storage/spanstore/metrics/decorator_test.go | 6 ++-- 6 files changed, 37 insertions(+), 40 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index 9370dd45b30..0030a986836 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -219,9 +219,6 @@ linters-settings: # enable after cleanup - name: confusing-results disabled: true - # we do use dot imports, but not a bad idea to make it explicit - - name: dot-imports - disabled: true # enable after cleanup: "tag on not-exported field" - name: struct-tag disabled: true diff --git a/internal/metrics/prometheus/factory_test.go b/internal/metrics/prometheus/factory_test.go index de5aaf2b91f..5aa2eaa3409 100644 --- a/internal/metrics/prometheus/factory_test.go +++ b/internal/metrics/prometheus/factory_test.go @@ -23,19 +23,19 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - . "github.com/jaegertracing/jaeger/internal/metrics/prometheus" + promMetrics "github.com/jaegertracing/jaeger/internal/metrics/prometheus" "github.com/jaegertracing/jaeger/pkg/metrics" "github.com/jaegertracing/jaeger/pkg/testutils" ) func TestOptions(t *testing.T) { - f1 := New() + f1 := promMetrics.New() assert.NotNil(t, f1) } func TestSeparator(t *testing.T) { registry := prometheus.NewPedanticRegistry() - f1 := New(WithRegisterer(registry), WithSeparator(SeparatorColon)) + f1 := promMetrics.New(promMetrics.WithRegisterer(registry), promMetrics.WithSeparator(promMetrics.SeparatorColon)) c1 := f1.Namespace(metrics.NSOptions{ Name: "bender", }).Counter(metrics.Options{ @@ -52,7 +52,7 @@ func TestSeparator(t *testing.T) { func TestCounter(t *testing.T) { registry := prometheus.NewPedanticRegistry() - f1 := New(WithRegisterer(registry)) + f1 := promMetrics.New(promMetrics.WithRegisterer(registry)) fDummy := f1.Namespace(metrics.NSOptions{}) f2 := fDummy.Namespace(metrics.NSOptions{ Name: "bender", @@ -94,7 +94,7 @@ func TestCounter(t *testing.T) { func TestCounterDefaultHelp(t *testing.T) { registry := prometheus.NewPedanticRegistry() - f1 := New(WithRegisterer(registry)) + f1 := promMetrics.New(promMetrics.WithRegisterer(registry)) c1 := f1.Counter(metrics.Options{ Name: "rodriguez", Tags: map[string]string{"x": "y"}, @@ -109,7 +109,7 @@ func TestCounterDefaultHelp(t *testing.T) { func TestGauge(t *testing.T) { registry := prometheus.NewPedanticRegistry() - f1 := New(WithRegisterer(registry)) + f1 := promMetrics.New(promMetrics.WithRegisterer(registry)) f2 := f1.Namespace(metrics.NSOptions{ Name: "bender", Tags: map[string]string{"a": "b"}, @@ -151,7 +151,7 @@ func TestGauge(t *testing.T) { func TestGaugeDefaultHelp(t *testing.T) { registry := prometheus.NewPedanticRegistry() - f1 := New(WithRegisterer(registry)) + f1 := promMetrics.New(promMetrics.WithRegisterer(registry)) g1 := f1.Gauge(metrics.Options{ Name: "rodriguez", Tags: map[string]string{"x": "y"}, @@ -166,7 +166,7 @@ func TestGaugeDefaultHelp(t *testing.T) { func TestTimer(t *testing.T) { registry := prometheus.NewPedanticRegistry() - f1 := New(WithRegisterer(registry)) + f1 := promMetrics.New(promMetrics.WithRegisterer(registry)) f2 := f1.Namespace(metrics.NSOptions{ Name: "bender", Tags: map[string]string{"a": "b"}, @@ -230,7 +230,7 @@ func TestTimer(t *testing.T) { func TestTimerDefaultHelp(t *testing.T) { registry := prometheus.NewPedanticRegistry() - f1 := New(WithRegisterer(registry)) + f1 := promMetrics.New(promMetrics.WithRegisterer(registry)) t1 := f1.Timer(metrics.TimerOptions{ Name: "rodriguez", Tags: map[string]string{"x": "y"}, @@ -245,7 +245,7 @@ func TestTimerDefaultHelp(t *testing.T) { func TestTimerCustomBuckets(t *testing.T) { registry := prometheus.NewPedanticRegistry() - f1 := New(WithRegisterer(registry), WithBuckets([]float64{1.5})) + f1 := promMetrics.New(promMetrics.WithRegisterer(registry), promMetrics.WithBuckets([]float64{1.5})) // dot and dash in the metric name will be replaced with underscore t1 := f1.Timer(metrics.TimerOptions{ Name: "bender.bending-rodriguez", @@ -266,7 +266,7 @@ func TestTimerCustomBuckets(t *testing.T) { func TestTimerDefaultBuckets(t *testing.T) { registry := prometheus.NewPedanticRegistry() - f1 := New(WithRegisterer(registry), WithBuckets([]float64{1.5, 2})) + f1 := promMetrics.New(promMetrics.WithRegisterer(registry), promMetrics.WithBuckets([]float64{1.5, 2})) // dot and dash in the metric name will be replaced with underscore t1 := f1.Timer(metrics.TimerOptions{ Name: "bender.bending-rodriguez", @@ -287,7 +287,7 @@ func TestTimerDefaultBuckets(t *testing.T) { func TestHistogram(t *testing.T) { registry := prometheus.NewPedanticRegistry() - f1 := New(WithRegisterer(registry)) + f1 := promMetrics.New(promMetrics.WithRegisterer(registry)) f2 := f1.Namespace(metrics.NSOptions{ Name: "bender", Tags: map[string]string{"a": "b"}, @@ -351,7 +351,7 @@ func TestHistogram(t *testing.T) { func TestHistogramDefaultHelp(t *testing.T) { registry := prometheus.NewPedanticRegistry() - f1 := New(WithRegisterer(registry)) + f1 := promMetrics.New(promMetrics.WithRegisterer(registry)) t1 := f1.Histogram(metrics.HistogramOptions{ Name: "rodriguez", Tags: map[string]string{"x": "y"}, @@ -366,7 +366,7 @@ func TestHistogramDefaultHelp(t *testing.T) { func TestHistogramCustomBuckets(t *testing.T) { registry := prometheus.NewPedanticRegistry() - f1 := New(WithRegisterer(registry)) + f1 := promMetrics.New(promMetrics.WithRegisterer(registry)) // dot and dash in the metric name will be replaced with underscore t1 := f1.Histogram(metrics.HistogramOptions{ Name: "bender.bending-rodriguez", @@ -387,7 +387,7 @@ func TestHistogramCustomBuckets(t *testing.T) { func TestHistogramDefaultBuckets(t *testing.T) { registry := prometheus.NewPedanticRegistry() - f1 := New(WithRegisterer(registry), WithBuckets([]float64{1.5})) + f1 := promMetrics.New(promMetrics.WithRegisterer(registry), promMetrics.WithBuckets([]float64{1.5})) // dot and dash in the metric name will be replaced with underscore t1 := f1.Histogram(metrics.HistogramOptions{ Name: "bender.bending-rodriguez", diff --git a/pkg/healthcheck/handler_test.go b/pkg/healthcheck/handler_test.go index ab64e688a72..dc26fd98433 100644 --- a/pkg/healthcheck/handler_test.go +++ b/pkg/healthcheck/handler_test.go @@ -22,16 +22,16 @@ import ( "github.com/stretchr/testify/assert" - . "github.com/jaegertracing/jaeger/pkg/healthcheck" + "github.com/jaegertracing/jaeger/pkg/healthcheck" "github.com/jaegertracing/jaeger/pkg/testutils" ) func TestStatusString(t *testing.T) { - tests := map[Status]string{ - Unavailable: "unavailable", - Ready: "ready", - Broken: "broken", - Status(-1): "unknown", + tests := map[healthcheck.Status]string{ + healthcheck.Unavailable: "unavailable", + healthcheck.Ready: "ready", + healthcheck.Broken: "broken", + healthcheck.Status(-1): "unknown", } for k, v := range tests { assert.Equal(t, v, k.String()) @@ -39,22 +39,22 @@ func TestStatusString(t *testing.T) { } func TestStatusSetGet(t *testing.T) { - hc := New() - assert.Equal(t, Unavailable, hc.Get()) + hc := healthcheck.New() + assert.Equal(t, healthcheck.Unavailable, hc.Get()) logger, logBuf := testutils.NewLogger() - hc = New() + hc = healthcheck.New() hc.SetLogger(logger) - assert.Equal(t, Unavailable, hc.Get()) + assert.Equal(t, healthcheck.Unavailable, hc.Get()) hc.Ready() - assert.Equal(t, Ready, hc.Get()) + assert.Equal(t, healthcheck.Ready, hc.Get()) assert.Equal(t, map[string]string{"level": "info", "msg": "Health Check state change", "status": "ready"}, logBuf.JSONLine(0)) } func TestHealthCheck_Handler_ContentType(t *testing.T) { rec := httptest.NewRecorder() - New().Handler().ServeHTTP(rec, httptest.NewRequest(http.MethodGet, "/", nil)) + healthcheck.New().Handler().ServeHTTP(rec, httptest.NewRequest(http.MethodGet, "/", nil)) resp := rec.Result() assert.Equal(t, "application/json", resp.Header.Get("Content-Type")) diff --git a/storage/metricsstore/metrics/decorator_test.go b/storage/metricsstore/metrics/decorator_test.go index e005b85f4d2..55710f97894 100644 --- a/storage/metricsstore/metrics/decorator_test.go +++ b/storage/metricsstore/metrics/decorator_test.go @@ -26,7 +26,7 @@ import ( "github.com/jaegertracing/jaeger/pkg/testutils" protometrics "github.com/jaegertracing/jaeger/proto-gen/api_v2/metrics" "github.com/jaegertracing/jaeger/storage/metricsstore" - . "github.com/jaegertracing/jaeger/storage/metricsstore/metrics" + "github.com/jaegertracing/jaeger/storage/metricsstore/metrics" "github.com/jaegertracing/jaeger/storage/metricsstore/mocks" ) @@ -34,7 +34,7 @@ func TestSuccessfulUnderlyingCalls(t *testing.T) { mf := metricstest.NewFactory(0) mockReader := mocks.Reader{} - mrs := NewReadMetricsDecorator(&mockReader, mf) + mrs := metrics.NewReadMetricsDecorator(&mockReader, mf) glParams := &metricsstore.LatenciesQueryParameters{} mockReader.On("GetLatencies", context.Background(), glParams). Return(&protometrics.MetricFamily{}, nil) @@ -107,7 +107,7 @@ func TestFailingUnderlyingCalls(t *testing.T) { mf := metricstest.NewFactory(0) mockReader := mocks.Reader{} - mrs := NewReadMetricsDecorator(&mockReader, mf) + mrs := metrics.NewReadMetricsDecorator(&mockReader, mf) glParams := &metricsstore.LatenciesQueryParameters{} mockReader.On("GetLatencies", context.Background(), glParams). Return(&protometrics.MetricFamily{}, errors.New("failure")) diff --git a/storage/spanstore/composite_test.go b/storage/spanstore/composite_test.go index 08b7d7f7ad2..d10b1deda1a 100644 --- a/storage/spanstore/composite_test.go +++ b/storage/spanstore/composite_test.go @@ -24,7 +24,7 @@ import ( "github.com/stretchr/testify/require" "github.com/jaegertracing/jaeger/model" - . "github.com/jaegertracing/jaeger/storage/spanstore" + "github.com/jaegertracing/jaeger/storage/spanstore" ) var errIWillAlwaysFail = errors.New("ErrProneWriteSpanStore will always fail") @@ -42,16 +42,16 @@ func (n *noopWriteSpanStore) WriteSpan(ctx context.Context, span *model.Span) er } func TestCompositeWriteSpanStoreSuccess(t *testing.T) { - c := NewCompositeWriter(&noopWriteSpanStore{}, &noopWriteSpanStore{}) + c := spanstore.NewCompositeWriter(&noopWriteSpanStore{}, &noopWriteSpanStore{}) require.NoError(t, c.WriteSpan(context.Background(), nil)) } func TestCompositeWriteSpanStoreSecondFailure(t *testing.T) { - c := NewCompositeWriter(&errProneWriteSpanStore{}, &errProneWriteSpanStore{}) + c := spanstore.NewCompositeWriter(&errProneWriteSpanStore{}, &errProneWriteSpanStore{}) require.EqualError(t, c.WriteSpan(context.Background(), nil), fmt.Sprintf("%s\n%s", errIWillAlwaysFail, errIWillAlwaysFail)) } func TestCompositeWriteSpanStoreFirstFailure(t *testing.T) { - c := NewCompositeWriter(&errProneWriteSpanStore{}, &noopWriteSpanStore{}) + c := spanstore.NewCompositeWriter(&errProneWriteSpanStore{}, &noopWriteSpanStore{}) require.EqualError(t, c.WriteSpan(context.Background(), nil), errIWillAlwaysFail.Error()) } diff --git a/storage/spanstore/metrics/decorator_test.go b/storage/spanstore/metrics/decorator_test.go index 13f61d20204..8afc6a921a9 100644 --- a/storage/spanstore/metrics/decorator_test.go +++ b/storage/spanstore/metrics/decorator_test.go @@ -25,7 +25,7 @@ import ( "github.com/jaegertracing/jaeger/internal/metricstest" "github.com/jaegertracing/jaeger/model" "github.com/jaegertracing/jaeger/storage/spanstore" - . "github.com/jaegertracing/jaeger/storage/spanstore/metrics" + "github.com/jaegertracing/jaeger/storage/spanstore/metrics" "github.com/jaegertracing/jaeger/storage/spanstore/mocks" ) @@ -33,7 +33,7 @@ func TestSuccessfulUnderlyingCalls(t *testing.T) { mf := metricstest.NewFactory(0) mockReader := mocks.Reader{} - mrs := NewReadMetricsDecorator(&mockReader, mf) + mrs := metrics.NewReadMetricsDecorator(&mockReader, mf) mockReader.On("GetServices", context.Background()).Return([]string{}, nil) mrs.GetServices(context.Background()) operationQuery := spanstore.OperationQueryParameters{ServiceName: "something"} @@ -100,7 +100,7 @@ func TestFailingUnderlyingCalls(t *testing.T) { mf := metricstest.NewFactory(0) mockReader := mocks.Reader{} - mrs := NewReadMetricsDecorator(&mockReader, mf) + mrs := metrics.NewReadMetricsDecorator(&mockReader, mf) mockReader.On("GetServices", context.Background()). Return(nil, errors.New("Failure")) mrs.GetServices(context.Background())