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

chore: pkg import only once #5644

Merged
merged 2 commits into from
Nov 10, 2023
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
3 changes: 1 addition & 2 deletions pkg/configs/db/postgres/postgres.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ import (
"github.com/golang-migrate/migrate/v4"
_ "github.com/golang-migrate/migrate/v4/database/postgres" // Import the postgres migrations driver
_ "github.com/golang-migrate/migrate/v4/source/file" // Import the postgres migrations driver
"github.com/lib/pq"
_ "github.com/lib/pq" // Import the postgres sql driver
"github.com/lib/pq" // Import the postgres sql driver
"github.com/pkg/errors"
)

Expand Down
3 changes: 1 addition & 2 deletions pkg/cortexpb/compat_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package cortexpb

import (
"encoding/json"
stdlibjson "encoding/json"
"math"
"testing"
"unsafe"
Expand All @@ -21,7 +20,7 @@ func TestJsoniterMarshalForSample(t *testing.T) {
}

func TestStdlibJsonMarshalForSample(t *testing.T) {
testMarshalling(t, stdlibjson.Marshal, "json: error calling MarshalJSON for type cortexpb.Sample: test sample")
testMarshalling(t, json.Marshal, "json: error calling MarshalJSON for type cortexpb.Sample: test sample")
}

func testMarshalling(t *testing.T, marshalFn func(v interface{}) ([]byte, error), expectedError string) {
Expand Down
9 changes: 4 additions & 5 deletions pkg/querier/batch/batch.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package batch
import (
"github.com/cortexproject/cortex/pkg/chunk"
"github.com/cortexproject/cortex/pkg/chunk/encoding"
promchunk "github.com/cortexproject/cortex/pkg/chunk/encoding"
"github.com/cortexproject/cortex/pkg/querier/iterators"

"github.com/prometheus/common/model"
Expand Down Expand Up @@ -48,7 +47,7 @@ type iterator interface {

// Batch returns the current batch. Must only be called after Seek or Next
// have returned true.
Batch() promchunk.Batch
Batch() encoding.Batch

Err() error
}
Expand All @@ -74,7 +73,7 @@ func NewGenericChunkMergeIterator(chunks []GenericChunk) chunkenc.Iterator {
// call to Next; on calls to Seek, resets batch size to 1.
type iteratorAdapter struct {
batchSize int
curr promchunk.Batch
curr encoding.Batch
underlying iterator
}

Expand Down Expand Up @@ -130,8 +129,8 @@ func (a *iteratorAdapter) Next() bool {
for a.curr.Index >= a.curr.Length && a.underlying.Next(a.batchSize) {
a.curr = a.underlying.Batch()
a.batchSize = a.batchSize * 2
if a.batchSize > promchunk.BatchSize {
a.batchSize = promchunk.BatchSize
if a.batchSize > encoding.BatchSize {
a.batchSize = encoding.BatchSize
}
}
return a.curr.Index < a.curr.Length
Expand Down
5 changes: 2 additions & 3 deletions pkg/querier/worker/frontend_processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import (
"google.golang.org/grpc"

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

func (fp *frontendProcessor) runRequest(ctx context.Context, request *httpgrpc.HTTPRequest, statsEnabled bool, sendHTTPResponse func(response *httpgrpc.HTTPResponse, stats *stats.QueryStats) error) {
func (fp *frontendProcessor) runRequest(ctx context.Context, request *httpgrpc.HTTPRequest, statsEnabled bool, sendHTTPResponse func(response *httpgrpc.HTTPResponse, stats *querier_stats.QueryStats) error) {
var stats *querier_stats.QueryStats
if statsEnabled {
stats, ctx = querier_stats.ContextWithEmptyStats(ctx)
Expand Down
9 changes: 4 additions & 5 deletions pkg/ring/lifecycler.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (
"github.com/go-kit/log"
"github.com/go-kit/log/level"
"github.com/pkg/errors"
perrors "github.com/pkg/errors"
"github.com/prometheus/client_golang/prometheus"
"go.uber.org/atomic"

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

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

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

if i.ShouldUnregisterOnShutdown() {
if err := i.unregister(context.Background()); err != nil {
return perrors.Wrapf(err, "failed to unregister from the KV store, ring: %s", i.RingName)
return errors.Wrapf(err, "failed to unregister from the KV store, ring: %s", i.RingName)
}
level.Info(i.logger).Log("msg", "instance removed from the KV store", "ring", i.RingName)
}
Expand Down
3 changes: 1 addition & 2 deletions pkg/util/log/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"os"

"github.com/go-kit/log"
kitlog "github.com/go-kit/log"
"github.com/go-kit/log/level"
"github.com/prometheus/client_golang/prometheus"
"github.com/weaveworks/common/logging"
Expand All @@ -27,7 +26,7 @@ var (
// Logger is a shared go-kit logger.
// TODO: Change all components to take a non-global logger via their constructors.
// Prefer accepting a non-global logger as an argument.
Logger = kitlog.NewNopLogger()
Logger = log.NewNopLogger()

logMessages = prometheus.NewCounterVec(prometheus.CounterOpts{
Name: "log_messages_total",
Expand Down
13 changes: 6 additions & 7 deletions pkg/util/log/wrappers.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,23 @@ import (
"context"

"github.com/go-kit/log"
kitlog "github.com/go-kit/log"
"github.com/weaveworks/common/tracing"

"github.com/cortexproject/cortex/pkg/tenant"
)

// WithUserID returns a Logger that has information about the current user in
// its details.
func WithUserID(userID string, l kitlog.Logger) kitlog.Logger {
func WithUserID(userID string, l log.Logger) log.Logger {
// See note in WithContext.
return kitlog.With(l, "org_id", userID)
return log.With(l, "org_id", userID)
}

// WithTraceID returns a Logger that has information about the traceID in
// its details.
func WithTraceID(traceID string, l kitlog.Logger) kitlog.Logger {
func WithTraceID(traceID string, l log.Logger) log.Logger {
// See note in WithContext.
return kitlog.With(l, "traceID", traceID)
return log.With(l, "traceID", traceID)
}

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

// Weaveworks uses "orgs" and "orgID" to represent Cortex users,
Expand Down Expand Up @@ -59,7 +58,7 @@ func WithSourceIPs(sourceIPs string, l log.Logger) log.Logger {
func headersFromContext(ctx context.Context, l log.Logger) log.Logger {
headerContentsMap := HeaderMapFromContext(ctx)
for header, contents := range headerContentsMap {
l = kitlog.With(l, header, contents)
l = log.With(l, header, contents)
}
return l
}
Loading