Skip to content

Commit

Permalink
Enable Lint Rule: dot-imports (#5513)
Browse files Browse the repository at this point in the history
## 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 <[email protected]>
  • Loading branch information
FlamingSaint authored Jun 3, 2024
1 parent bd33dc2 commit 3f82224
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 40 deletions.
3 changes: 0 additions & 3 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
30 changes: 15 additions & 15 deletions internal/metrics/prometheus/factory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand All @@ -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",
Expand Down Expand Up @@ -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"},
Expand All @@ -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"},
Expand Down Expand Up @@ -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"},
Expand All @@ -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"},
Expand Down Expand Up @@ -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"},
Expand All @@ -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",
Expand All @@ -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",
Expand All @@ -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"},
Expand Down Expand Up @@ -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"},
Expand All @@ -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",
Expand All @@ -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",
Expand Down
24 changes: 12 additions & 12 deletions pkg/healthcheck/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,39 +22,39 @@ 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())
}
}

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"))
Expand Down
6 changes: 3 additions & 3 deletions storage/metricsstore/metrics/decorator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,15 @@ 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"
)

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)
Expand Down Expand Up @@ -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"))
Expand Down
8 changes: 4 additions & 4 deletions storage/spanstore/composite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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())
}
6 changes: 3 additions & 3 deletions storage/spanstore/metrics/decorator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,15 @@ 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"
)

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"}
Expand Down Expand Up @@ -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())
Expand Down

0 comments on commit 3f82224

Please sign in to comment.