Chore: Copy `cortex/util/math` into Loki (#5036)

* Copy `cortex/pkg/util/math` into Loki.

Signed-off-by: Kaviraj <kavirajkanagaraj@gmail.com>

* Fix linter

Signed-off-by: Kaviraj <kavirajkanagaraj@gmail.com>

* Move `MinUint32` from `util` package into `util/math` package

Signed-off-by: Kaviraj <kavirajkanagaraj@gmail.com>

* Remove NewEWMARate and related helpers

Signed-off-by: Kaviraj <kavirajkanagaraj@gmail.com>

* Remove unwanted spaces

Signed-off-by: Kaviraj <kavirajkanagaraj@gmail.com>

* Fix spaces in import paths

Signed-off-by: Kaviraj <kavirajkanagaraj@gmail.com>
pull/5034/head
Kaviraj 3 years ago committed by GitHub
parent 57a8a878c1
commit 14afb13d36
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 4
      pkg/ingester/instance.go
  2. 5
      pkg/storage/chunk/aws/dynamodb_storage_client.go
  3. 3
      pkg/storage/chunk/cache/memcached.go
  4. 5
      pkg/storage/chunk/gcp/bigtable_index_client.go
  5. 3
      pkg/storage/chunk/gcp/bigtable_object_client.go
  6. 3
      pkg/storage/chunk/schema_config.go
  7. 3
      pkg/storage/chunk/util/util.go
  8. 2
      pkg/storage/stores/shipper/compactor/table.go
  9. 5
      pkg/storage/stores/shipper/downloads/table.go
  10. 2
      pkg/storage/stores/shipper/gateway_client.go
  11. 3
      pkg/storage/stores/shipper/indexgateway/gateway_test.go
  12. 3
      pkg/storage/stores/shipper/util/queries.go
  13. 9
      pkg/util/math.go
  14. 41
      pkg/util/math/math.go

@ -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"
)
@ -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
}

@ -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"
@ -31,10 +30,10 @@ import (
"github.com/weaveworks/common/instrument"
"golang.org/x/time/rate"
"github.com/grafana/loki/pkg/util/spanlogger"
"github.com/grafana/loki/pkg/storage/chunk"
chunk_util "github.com/grafana/loki/pkg/storage/chunk/util"
"github.com/grafana/loki/pkg/util/math"
"github.com/grafana/loki/pkg/util/spanlogger"
)
const (

@ -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

@ -11,16 +11,15 @@ 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/spanlogger"
"github.com/grafana/loki/pkg/storage/chunk"
chunk_util "github.com/grafana/loki/pkg/storage/chunk/util"
"github.com/grafana/loki/pkg/util/math"
"github.com/grafana/loki/pkg/util/spanlogger"
)
const (

@ -9,9 +9,8 @@ import (
otlog "github.com/opentracing/opentracing-go/log"
"github.com/pkg/errors"
"github.com/cortexproject/cortex/pkg/util/math"
"github.com/grafana/loki/pkg/storage/chunk"
"github.com/grafana/loki/pkg/util/math"
)
type bigtableObjectClient struct {

@ -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 (

@ -9,9 +9,8 @@ import (
ot "github.com/opentracing/opentracing-go"
"github.com/cortexproject/cortex/pkg/util/math"
"github.com/grafana/loki/pkg/storage/chunk"
"github.com/grafana/loki/pkg/util/math"
)
// Callback from an IndexQuery.

@ -10,7 +10,6 @@ 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"
@ -19,6 +18,7 @@ import (
"github.com/grafana/loki/pkg/storage/stores/shipper/compactor/retention"
"github.com/grafana/loki/pkg/storage/stores/shipper/storage"
shipper_util "github.com/grafana/loki/pkg/storage/stores/shipper/util"
util_math "github.com/grafana/loki/pkg/util/math"
)
const (

@ -12,17 +12,16 @@ 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"
"github.com/grafana/loki/pkg/util/spanlogger"
"github.com/grafana/loki/pkg/storage/chunk"
chunk_util "github.com/grafana/loki/pkg/storage/chunk/util"
"github.com/grafana/loki/pkg/storage/stores/shipper/storage"
shipper_util "github.com/grafana/loki/pkg/storage/stores/shipper/util"
util_math "github.com/grafana/loki/pkg/util/math"
"github.com/grafana/loki/pkg/util/spanlogger"
)
// timeout for downloading initial files for a table to avoid leaking resources by allowing it to take all the time.

@ -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"
@ -20,6 +19,7 @@ import (
"github.com/grafana/loki/pkg/storage/chunk/util"
"github.com/grafana/loki/pkg/storage/stores/shipper/indexgateway/indexgatewaypb"
shipper_util "github.com/grafana/loki/pkg/storage/stores/shipper/util"
util_math "github.com/grafana/loki/pkg/util/math"
)
const maxQueriesPerGoroutine = 100

@ -7,11 +7,10 @@ import (
"github.com/stretchr/testify/require"
"google.golang.org/grpc"
util_math "github.com/cortexproject/cortex/pkg/util/math"
"github.com/grafana/loki/pkg/storage/chunk"
"github.com/grafana/loki/pkg/storage/stores/shipper/indexgateway/indexgatewaypb"
"github.com/grafana/loki/pkg/storage/stores/shipper/util"
util_math "github.com/grafana/loki/pkg/util/math"
)
const (

@ -5,10 +5,9 @@ import (
"sync"
"unsafe"
util_math "github.com/cortexproject/cortex/pkg/util/math"
"github.com/grafana/loki/pkg/storage/chunk"
chunk_util "github.com/grafana/loki/pkg/storage/chunk/util"
util_math "github.com/grafana/loki/pkg/util/math"
)
const maxQueriesPerGoroutine = 100

@ -1,9 +0,0 @@
package util
// MinUint32 return the min of a and b.
func MinUint32(a, b uint32) uint32 {
if a < b {
return a
}
return b
}

@ -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
}
Loading…
Cancel
Save