Skip to content

Commit 6a3a571

Browse files
authored
chore: pkg import only once (#5644)
* chore: pkg import only once Signed-off-by: guoguangwu <[email protected]> * fix: lint Signed-off-by: guoguangwu <[email protected]> --------- Signed-off-by: guoguangwu <[email protected]>
1 parent e09002d commit 6a3a571

File tree

7 files changed

+19
-26
lines changed

7 files changed

+19
-26
lines changed

pkg/configs/db/postgres/postgres.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@ import (
1616
"github.com/golang-migrate/migrate/v4"
1717
_ "github.com/golang-migrate/migrate/v4/database/postgres" // Import the postgres migrations driver
1818
_ "github.com/golang-migrate/migrate/v4/source/file" // Import the postgres migrations driver
19-
"github.com/lib/pq"
20-
_ "github.com/lib/pq" // Import the postgres sql driver
19+
"github.com/lib/pq" // Import the postgres sql driver
2120
"github.com/pkg/errors"
2221
)
2322

pkg/cortexpb/compat_test.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package cortexpb
22

33
import (
44
"encoding/json"
5-
stdlibjson "encoding/json"
65
"math"
76
"testing"
87
"unsafe"
@@ -21,7 +20,7 @@ func TestJsoniterMarshalForSample(t *testing.T) {
2120
}
2221

2322
func TestStdlibJsonMarshalForSample(t *testing.T) {
24-
testMarshalling(t, stdlibjson.Marshal, "json: error calling MarshalJSON for type cortexpb.Sample: test sample")
23+
testMarshalling(t, json.Marshal, "json: error calling MarshalJSON for type cortexpb.Sample: test sample")
2524
}
2625

2726
func testMarshalling(t *testing.T, marshalFn func(v interface{}) ([]byte, error), expectedError string) {

pkg/querier/batch/batch.go

+4-5
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package batch
33
import (
44
"github.com/cortexproject/cortex/pkg/chunk"
55
"github.com/cortexproject/cortex/pkg/chunk/encoding"
6-
promchunk "github.com/cortexproject/cortex/pkg/chunk/encoding"
76
"github.com/cortexproject/cortex/pkg/querier/iterators"
87

98
"github.com/prometheus/common/model"
@@ -48,7 +47,7 @@ type iterator interface {
4847

4948
// Batch returns the current batch. Must only be called after Seek or Next
5049
// have returned true.
51-
Batch() promchunk.Batch
50+
Batch() encoding.Batch
5251

5352
Err() error
5453
}
@@ -74,7 +73,7 @@ func NewGenericChunkMergeIterator(chunks []GenericChunk) chunkenc.Iterator {
7473
// call to Next; on calls to Seek, resets batch size to 1.
7574
type iteratorAdapter struct {
7675
batchSize int
77-
curr promchunk.Batch
76+
curr encoding.Batch
7877
underlying iterator
7978
}
8079

@@ -130,8 +129,8 @@ func (a *iteratorAdapter) Next() bool {
130129
for a.curr.Index >= a.curr.Length && a.underlying.Next(a.batchSize) {
131130
a.curr = a.underlying.Batch()
132131
a.batchSize = a.batchSize * 2
133-
if a.batchSize > promchunk.BatchSize {
134-
a.batchSize = promchunk.BatchSize
132+
if a.batchSize > encoding.BatchSize {
133+
a.batchSize = encoding.BatchSize
135134
}
136135
}
137136
return a.curr.Index < a.curr.Length

pkg/querier/worker/frontend_processor.go

+2-3
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import (
1414
"google.golang.org/grpc"
1515

1616
"github.com/cortexproject/cortex/pkg/frontend/v1/frontendv1pb"
17-
"github.com/cortexproject/cortex/pkg/querier/stats"
1817
querier_stats "github.com/cortexproject/cortex/pkg/querier/stats"
1918
"github.com/cortexproject/cortex/pkg/util/backoff"
2019
util_log "github.com/cortexproject/cortex/pkg/util/log"
@@ -101,7 +100,7 @@ func (fp *frontendProcessor) process(c frontendv1pb.Frontend_ProcessClient) erro
101100
// and cancel the query. We don't actually handle queries in parallel
102101
// here, as we're running in lock step with the server - each Recv is
103102
// paired with a Send.
104-
go fp.runRequest(ctx, request.HttpRequest, request.StatsEnabled, func(response *httpgrpc.HTTPResponse, stats *stats.QueryStats) error {
103+
go fp.runRequest(ctx, request.HttpRequest, request.StatsEnabled, func(response *httpgrpc.HTTPResponse, stats *querier_stats.QueryStats) error {
105104
return c.Send(&frontendv1pb.ClientToFrontend{
106105
HttpResponse: response,
107106
Stats: stats,
@@ -120,7 +119,7 @@ func (fp *frontendProcessor) process(c frontendv1pb.Frontend_ProcessClient) erro
120119
}
121120
}
122121

123-
func (fp *frontendProcessor) runRequest(ctx context.Context, request *httpgrpc.HTTPRequest, statsEnabled bool, sendHTTPResponse func(response *httpgrpc.HTTPResponse, stats *stats.QueryStats) error) {
122+
func (fp *frontendProcessor) runRequest(ctx context.Context, request *httpgrpc.HTTPRequest, statsEnabled bool, sendHTTPResponse func(response *httpgrpc.HTTPResponse, stats *querier_stats.QueryStats) error) {
124123
var stats *querier_stats.QueryStats
125124
if statsEnabled {
126125
stats, ctx = querier_stats.ContextWithEmptyStats(ctx)

pkg/ring/lifecycler.go

+4-5
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import (
1313
"github.com/go-kit/log"
1414
"github.com/go-kit/log/level"
1515
"github.com/pkg/errors"
16-
perrors "github.com/pkg/errors"
1716
"github.com/prometheus/client_golang/prometheus"
1817
"go.uber.org/atomic"
1918

@@ -419,7 +418,7 @@ func (i *Lifecycler) loop(ctx context.Context) error {
419418
// First, see if we exist in the cluster, update our state to match if we do,
420419
// and add ourselves (without tokens) if we don't.
421420
if err := i.initRing(context.Background()); err != nil {
422-
return perrors.Wrapf(err, "failed to join the ring %s", i.RingName)
421+
return errors.Wrapf(err, "failed to join the ring %s", i.RingName)
423422
}
424423

425424
// We do various period tasks
@@ -464,14 +463,14 @@ func (i *Lifecycler) loop(ctx context.Context) error {
464463
// let's observe the ring. By using JOINING state, this ingester will be ignored by LEAVING
465464
// ingesters, but we also signal that it is not fully functional yet.
466465
if err := i.autoJoin(context.Background(), JOINING); err != nil {
467-
return perrors.Wrapf(err, "failed to pick tokens in the KV store, ring: %s", i.RingName)
466+
return errors.Wrapf(err, "failed to pick tokens in the KV store, ring: %s", i.RingName)
468467
}
469468

470469
level.Info(i.logger).Log("msg", "observing tokens before going ACTIVE", "ring", i.RingName)
471470
observeChan = time.After(i.cfg.ObservePeriod)
472471
} else {
473472
if err := i.autoJoin(context.Background(), ACTIVE); err != nil {
474-
return perrors.Wrapf(err, "failed to pick tokens in the KV store, ring: %s", i.RingName)
473+
return errors.Wrapf(err, "failed to pick tokens in the KV store, ring: %s", i.RingName)
475474
}
476475
}
477476
}
@@ -561,7 +560,7 @@ heartbeatLoop:
561560

562561
if i.ShouldUnregisterOnShutdown() {
563562
if err := i.unregister(context.Background()); err != nil {
564-
return perrors.Wrapf(err, "failed to unregister from the KV store, ring: %s", i.RingName)
563+
return errors.Wrapf(err, "failed to unregister from the KV store, ring: %s", i.RingName)
565564
}
566565
level.Info(i.logger).Log("msg", "instance removed from the KV store", "ring", i.RingName)
567566
}

pkg/util/log/log.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import (
77
"os"
88

99
"github.com/go-kit/log"
10-
kitlog "github.com/go-kit/log"
1110
"github.com/go-kit/log/level"
1211
"github.com/prometheus/client_golang/prometheus"
1312
"github.com/weaveworks/common/logging"
@@ -27,7 +26,7 @@ var (
2726
// Logger is a shared go-kit logger.
2827
// TODO: Change all components to take a non-global logger via their constructors.
2928
// Prefer accepting a non-global logger as an argument.
30-
Logger = kitlog.NewNopLogger()
29+
Logger = log.NewNopLogger()
3130

3231
logMessages = prometheus.NewCounterVec(prometheus.CounterOpts{
3332
Name: "log_messages_total",

pkg/util/log/wrappers.go

+6-7
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,23 @@ import (
44
"context"
55

66
"github.com/go-kit/log"
7-
kitlog "github.com/go-kit/log"
87
"github.com/weaveworks/common/tracing"
98

109
"github.com/cortexproject/cortex/pkg/tenant"
1110
)
1211

1312
// WithUserID returns a Logger that has information about the current user in
1413
// its details.
15-
func WithUserID(userID string, l kitlog.Logger) kitlog.Logger {
14+
func WithUserID(userID string, l log.Logger) log.Logger {
1615
// See note in WithContext.
17-
return kitlog.With(l, "org_id", userID)
16+
return log.With(l, "org_id", userID)
1817
}
1918

2019
// WithTraceID returns a Logger that has information about the traceID in
2120
// its details.
22-
func WithTraceID(traceID string, l kitlog.Logger) kitlog.Logger {
21+
func WithTraceID(traceID string, l log.Logger) log.Logger {
2322
// See note in WithContext.
24-
return kitlog.With(l, "traceID", traceID)
23+
return log.With(l, "traceID", traceID)
2524
}
2625

2726
// WithContext returns a Logger that has information about the current user in
@@ -31,7 +30,7 @@ func WithTraceID(traceID string, l kitlog.Logger) kitlog.Logger {
3130
//
3231
// log := util.WithContext(ctx)
3332
// log.Errorf("Could not chunk chunks: %v", err)
34-
func WithContext(ctx context.Context, l kitlog.Logger) kitlog.Logger {
33+
func WithContext(ctx context.Context, l log.Logger) log.Logger {
3534
l = headersFromContext(ctx, l)
3635

3736
// Weaveworks uses "orgs" and "orgID" to represent Cortex users,
@@ -59,7 +58,7 @@ func WithSourceIPs(sourceIPs string, l log.Logger) log.Logger {
5958
func headersFromContext(ctx context.Context, l log.Logger) log.Logger {
6059
headerContentsMap := HeaderMapFromContext(ctx)
6160
for header, contents := range headerContentsMap {
62-
l = kitlog.With(l, header, contents)
61+
l = log.With(l, header, contents)
6362
}
6463
return l
6564
}

0 commit comments

Comments
 (0)