diff --git a/pkg/ingester/instance.go b/pkg/ingester/instance.go index 9972670086..4d10d67042 100644 --- a/pkg/ingester/instance.go +++ b/pkg/ingester/instance.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 } diff --git a/pkg/storage/chunk/aws/dynamodb_storage_client.go b/pkg/storage/chunk/aws/dynamodb_storage_client.go index 5b3c6b17c8..0e50a335ee 100644 --- a/pkg/storage/chunk/aws/dynamodb_storage_client.go +++ b/pkg/storage/chunk/aws/dynamodb_storage_client.go @@ -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 ( diff --git a/pkg/storage/chunk/cache/memcached.go b/pkg/storage/chunk/cache/memcached.go index ab573cc80f..d4b01fe1f3 100644 --- a/pkg/storage/chunk/cache/memcached.go +++ b/pkg/storage/chunk/cache/memcached.go @@ -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 diff --git a/pkg/storage/chunk/gcp/bigtable_index_client.go b/pkg/storage/chunk/gcp/bigtable_index_client.go index 5e43218466..6a7861d3bf 100644 --- a/pkg/storage/chunk/gcp/bigtable_index_client.go +++ b/pkg/storage/chunk/gcp/bigtable_index_client.go @@ -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 ( diff --git a/pkg/storage/chunk/gcp/bigtable_object_client.go b/pkg/storage/chunk/gcp/bigtable_object_client.go index fa59005929..b18843d7c3 100644 --- a/pkg/storage/chunk/gcp/bigtable_object_client.go +++ b/pkg/storage/chunk/gcp/bigtable_object_client.go @@ -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 { diff --git a/pkg/storage/chunk/schema_config.go b/pkg/storage/chunk/schema_config.go index b23ee87f49..2922789fe4 100644 --- a/pkg/storage/chunk/schema_config.go +++ b/pkg/storage/chunk/schema_config.go @@ -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 ( diff --git a/pkg/storage/chunk/util/util.go b/pkg/storage/chunk/util/util.go index 64a250e010..7e19393dd0 100644 --- a/pkg/storage/chunk/util/util.go +++ b/pkg/storage/chunk/util/util.go @@ -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. diff --git a/pkg/storage/stores/shipper/compactor/table.go b/pkg/storage/stores/shipper/compactor/table.go index bb43cfc0d7..160cd75ad9 100644 --- a/pkg/storage/stores/shipper/compactor/table.go +++ b/pkg/storage/stores/shipper/compactor/table.go @@ -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 ( diff --git a/pkg/storage/stores/shipper/downloads/table.go b/pkg/storage/stores/shipper/downloads/table.go index c2179f1249..9db571a5cc 100644 --- a/pkg/storage/stores/shipper/downloads/table.go +++ b/pkg/storage/stores/shipper/downloads/table.go @@ -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. diff --git a/pkg/storage/stores/shipper/gateway_client.go b/pkg/storage/stores/shipper/gateway_client.go index 7ac61dd87f..4dec8b92b5 100644 --- a/pkg/storage/stores/shipper/gateway_client.go +++ b/pkg/storage/stores/shipper/gateway_client.go @@ -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 diff --git a/pkg/storage/stores/shipper/indexgateway/gateway_test.go b/pkg/storage/stores/shipper/indexgateway/gateway_test.go index 1e4e4b8061..1675abf57d 100644 --- a/pkg/storage/stores/shipper/indexgateway/gateway_test.go +++ b/pkg/storage/stores/shipper/indexgateway/gateway_test.go @@ -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 ( diff --git a/pkg/storage/stores/shipper/util/queries.go b/pkg/storage/stores/shipper/util/queries.go index f2b20d6b6d..561a338a1b 100644 --- a/pkg/storage/stores/shipper/util/queries.go +++ b/pkg/storage/stores/shipper/util/queries.go @@ -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 diff --git a/pkg/util/math.go b/pkg/util/math.go deleted file mode 100644 index b80dfcaf09..0000000000 --- a/pkg/util/math.go +++ /dev/null @@ -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 -} diff --git a/pkg/util/math/math.go b/pkg/util/math/math.go new file mode 100644 index 0000000000..b14e6f4f23 --- /dev/null +++ b/pkg/util/math/math.go @@ -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 +}