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: Copy cortex/util/math into Loki #5036

Merged
merged 6 commits into from
Jan 5, 2022
Merged
Show file tree
Hide file tree
Changes from 4 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
4 changes: 2 additions & 2 deletions pkg/ingester/instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import (
"github.com/grafana/loki/pkg/querier/astmapper"
"github.com/grafana/loki/pkg/runtime"
"github.com/grafana/loki/pkg/storage"
"github.com/grafana/loki/pkg/util"
"github.com/grafana/loki/pkg/util/math"
"github.com/grafana/loki/pkg/validation"
)

Expand Down Expand Up @@ -668,7 +668,7 @@ func sendBatches(ctx context.Context, i iter.EntryIterator, queryServer QuerierQ
// send until the limit is reached.
sent := uint32(0)
for sent < limit && !isDone(queryServer.Context()) {
batch, batchSize, err := iter.ReadBatch(i, util.MinUint32(queryBatchSize, limit-sent))
batch, batchSize, err := iter.ReadBatch(i, math.MinUint32(queryBatchSize, limit-sent))
if err != nil {
return err
}
Expand Down
3 changes: 2 additions & 1 deletion pkg/storage/chunk/aws/dynamodb_storage_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import (
"github.com/aws/aws-sdk-go/service/dynamodb/dynamodbiface"
"github.com/cortexproject/cortex/pkg/util"
"github.com/cortexproject/cortex/pkg/util/log"
"github.com/cortexproject/cortex/pkg/util/math"
"github.com/go-kit/log/level"
"github.com/grafana/dskit/backoff"
"github.com/grafana/dskit/flagext"
Expand All @@ -31,6 +30,8 @@ import (
"github.com/weaveworks/common/instrument"
"golang.org/x/time/rate"

"github.com/grafana/loki/pkg/util/math"

"github.com/grafana/loki/pkg/util/spanlogger"

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please remove unwanted spaces here?
Same for some of the other files updated in this PR.

"github.com/grafana/loki/pkg/storage/chunk"
Expand Down
3 changes: 2 additions & 1 deletion pkg/storage/chunk/cache/memcached.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ import (
instr "github.com/weaveworks/common/instrument"

util_log "github.com/cortexproject/cortex/pkg/util/log"
"github.com/cortexproject/cortex/pkg/util/math"

"github.com/grafana/loki/pkg/util/math"
)

// MemcachedConfig is config to make a Memcached
Expand Down
3 changes: 2 additions & 1 deletion pkg/storage/chunk/gcp/bigtable_index_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,13 @@ import (
"time"

"cloud.google.com/go/bigtable"
"github.com/cortexproject/cortex/pkg/util/math"
"github.com/go-kit/log"
"github.com/grafana/dskit/grpcclient"
ot "github.com/opentracing/opentracing-go"
"github.com/pkg/errors"

"github.com/grafana/loki/pkg/util/math"

"github.com/grafana/loki/pkg/util/spanlogger"

"github.com/grafana/loki/pkg/storage/chunk"
Expand Down
2 changes: 1 addition & 1 deletion pkg/storage/chunk/gcp/bigtable_object_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
otlog "github.com/opentracing/opentracing-go/log"
"github.com/pkg/errors"

"github.com/cortexproject/cortex/pkg/util/math"
"github.com/grafana/loki/pkg/util/math"

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One more here. Sorry for being picky, we would miss fixing it until we start working on it again.

"github.com/grafana/loki/pkg/storage/chunk"
)
Expand Down
3 changes: 2 additions & 1 deletion pkg/storage/chunk/schema_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ import (
yaml "gopkg.in/yaml.v2"

"github.com/cortexproject/cortex/pkg/util/log"
"github.com/cortexproject/cortex/pkg/util/math"

"github.com/grafana/loki/pkg/util/math"
)

const (
Expand Down
2 changes: 1 addition & 1 deletion pkg/storage/chunk/util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (

ot "github.com/opentracing/opentracing-go"

"github.com/cortexproject/cortex/pkg/util/math"
"github.com/grafana/loki/pkg/util/math"

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here

"github.com/grafana/loki/pkg/storage/chunk"
)
Expand Down
3 changes: 2 additions & 1 deletion pkg/storage/stores/shipper/compactor/table.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@ import (
"time"

util_log "github.com/cortexproject/cortex/pkg/util/log"
util_math "github.com/cortexproject/cortex/pkg/util/math"
"github.com/go-kit/log"
"github.com/go-kit/log/level"
"go.etcd.io/bbolt"

util_math "github.com/grafana/loki/pkg/util/math"

chunk_util "github.com/grafana/loki/pkg/storage/chunk/util"
"github.com/grafana/loki/pkg/storage/stores/shipper/compactor/retention"
"github.com/grafana/loki/pkg/storage/stores/shipper/storage"
Expand Down
3 changes: 2 additions & 1 deletion pkg/storage/stores/shipper/downloads/table.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,12 @@ import (
"time"

util_log "github.com/cortexproject/cortex/pkg/util/log"
util_math "github.com/cortexproject/cortex/pkg/util/math"
"github.com/go-kit/log"
"github.com/go-kit/log/level"
"go.etcd.io/bbolt"

util_math "github.com/grafana/loki/pkg/util/math"

"github.com/grafana/loki/pkg/util/spanlogger"

"github.com/grafana/loki/pkg/storage/chunk"
Expand Down
3 changes: 2 additions & 1 deletion pkg/storage/stores/shipper/gateway_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"io"

util_log "github.com/cortexproject/cortex/pkg/util/log"
util_math "github.com/cortexproject/cortex/pkg/util/math"
"github.com/go-kit/log/level"
"github.com/grafana/dskit/grpcclient"
"github.com/pkg/errors"
Expand All @@ -16,6 +15,8 @@ import (
"github.com/weaveworks/common/instrument"
"google.golang.org/grpc"

util_math "github.com/grafana/loki/pkg/util/math"

"github.com/grafana/loki/pkg/storage/chunk"
"github.com/grafana/loki/pkg/storage/chunk/util"
"github.com/grafana/loki/pkg/storage/stores/shipper/indexgateway/indexgatewaypb"
Expand Down
2 changes: 1 addition & 1 deletion pkg/storage/stores/shipper/indexgateway/gateway_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"github.com/stretchr/testify/require"
"google.golang.org/grpc"

util_math "github.com/cortexproject/cortex/pkg/util/math"
util_math "github.com/grafana/loki/pkg/util/math"

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here

"github.com/grafana/loki/pkg/storage/chunk"
"github.com/grafana/loki/pkg/storage/stores/shipper/indexgateway/indexgatewaypb"
Expand Down
2 changes: 1 addition & 1 deletion pkg/storage/stores/shipper/util/queries.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"sync"
"unsafe"

util_math "github.com/cortexproject/cortex/pkg/util/math"
util_math "github.com/grafana/loki/pkg/util/math"

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here

"github.com/grafana/loki/pkg/storage/chunk"
chunk_util "github.com/grafana/loki/pkg/storage/chunk/util"
Expand Down
9 changes: 0 additions & 9 deletions pkg/util/math.go

This file was deleted.

41 changes: 41 additions & 0 deletions pkg/util/math/math.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package math

// Max returns the maximum of two ints
func Max(a, b int) int {
if a > b {
return a
}
return b
}

// Min returns the minimum of two ints
func Min(a, b int) int {
if a < b {
return a
}
return b
}

// Max64 returns the maximum of two int64s
func Max64(a, b int64) int64 {
if a > b {
return a
}
return b
}

// Min64 returns the minimum of two int64s
func Min64(a, b int64) int64 {
if a < b {
return a
}
return b
}

// MinUint32 return the min of a and b.
func MinUint32(a, b uint32) uint32 {
if a < b {
return a
}
return b
}