diff --git a/clients/cmd/docker-driver/config.go b/clients/cmd/docker-driver/config.go index c204618a6c..27488be9e3 100644 --- a/clients/cmd/docker-driver/config.go +++ b/clients/cmd/docker-driver/config.go @@ -10,10 +10,10 @@ import ( "strings" "time" - "github.com/cortexproject/cortex/pkg/util/flagext" "github.com/docker/docker/daemon/logger" "github.com/docker/docker/daemon/logger/templates" "github.com/grafana/dskit/backoff" + "github.com/grafana/dskit/flagext" "github.com/pkg/errors" "github.com/prometheus/common/model" "github.com/prometheus/prometheus/pkg/labels" diff --git a/clients/cmd/fluent-bit/config.go b/clients/cmd/fluent-bit/config.go index 1207c42ee6..143afb686e 100644 --- a/clients/cmd/fluent-bit/config.go +++ b/clients/cmd/fluent-bit/config.go @@ -9,7 +9,7 @@ import ( "strings" "time" - "github.com/cortexproject/cortex/pkg/util/flagext" + "github.com/grafana/dskit/flagext" "github.com/prometheus/common/model" "github.com/weaveworks/common/logging" diff --git a/clients/cmd/fluent-bit/config_test.go b/clients/cmd/fluent-bit/config_test.go index 27fc1be6ac..e4bedf1f4d 100644 --- a/clients/cmd/fluent-bit/config_test.go +++ b/clients/cmd/fluent-bit/config_test.go @@ -8,8 +8,8 @@ import ( "testing" "time" - "github.com/cortexproject/cortex/pkg/util/flagext" "github.com/grafana/dskit/backoff" + "github.com/grafana/dskit/flagext" "github.com/prometheus/common/model" "github.com/weaveworks/common/logging" diff --git a/clients/cmd/promtail/main.go b/clients/cmd/promtail/main.go index 5d894d1665..e4e1ac298b 100644 --- a/clients/cmd/promtail/main.go +++ b/clients/cmd/promtail/main.go @@ -11,9 +11,9 @@ import ( "k8s.io/klog" - "github.com/cortexproject/cortex/pkg/util/flagext" util_log "github.com/cortexproject/cortex/pkg/util/log" "github.com/go-kit/kit/log/level" + "github.com/grafana/dskit/flagext" "github.com/prometheus/client_golang/prometheus" "github.com/prometheus/common/version" "github.com/weaveworks/common/logging" diff --git a/clients/pkg/promtail/client/client.go b/clients/pkg/promtail/client/client.go index a3e3a57a71..bf14be0f06 100644 --- a/clients/pkg/promtail/client/client.go +++ b/clients/pkg/promtail/client/client.go @@ -12,21 +12,19 @@ import ( "sync" "time" - "github.com/prometheus/prometheus/promql/parser" - - "github.com/grafana/dskit/backoff" - "github.com/grafana/loki/clients/pkg/logentry/metric" - "github.com/grafana/loki/clients/pkg/promtail/api" - - lokiutil "github.com/grafana/loki/pkg/util" - "github.com/go-kit/kit/log" "github.com/go-kit/kit/log/level" - + "github.com/grafana/dskit/backoff" "github.com/prometheus/client_golang/prometheus" "github.com/prometheus/common/config" "github.com/prometheus/common/model" "github.com/prometheus/common/version" + "github.com/prometheus/prometheus/promql/parser" + + "github.com/grafana/loki/clients/pkg/logentry/metric" + "github.com/grafana/loki/clients/pkg/promtail/api" + + lokiutil "github.com/grafana/loki/pkg/util" ) const ( diff --git a/clients/pkg/promtail/client/client_test.go b/clients/pkg/promtail/client/client_test.go index bcfacb2aca..1e9ba79e5f 100644 --- a/clients/pkg/promtail/client/client_test.go +++ b/clients/pkg/promtail/client/client_test.go @@ -10,17 +10,16 @@ import ( "testing" "time" - "github.com/go-kit/kit/log" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" - "github.com/cortexproject/cortex/pkg/util" - "github.com/cortexproject/cortex/pkg/util/flagext" + "github.com/go-kit/kit/log" "github.com/grafana/dskit/backoff" + "github.com/grafana/dskit/flagext" "github.com/prometheus/client_golang/prometheus" "github.com/prometheus/client_golang/prometheus/testutil" "github.com/prometheus/common/config" "github.com/prometheus/common/model" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/grafana/loki/clients/pkg/promtail/api" diff --git a/clients/pkg/promtail/client/config.go b/clients/pkg/promtail/client/config.go index c8d364f3b2..1507e04eb1 100644 --- a/clients/pkg/promtail/client/config.go +++ b/clients/pkg/promtail/client/config.go @@ -4,8 +4,8 @@ import ( "flag" "time" - "github.com/cortexproject/cortex/pkg/util/flagext" "github.com/grafana/dskit/backoff" + "github.com/grafana/dskit/flagext" "github.com/prometheus/common/config" lokiflag "github.com/grafana/loki/pkg/util/flagext" diff --git a/clients/pkg/promtail/client/config_test.go b/clients/pkg/promtail/client/config_test.go index 94b98c6d2d..f5ee8aad3c 100644 --- a/clients/pkg/promtail/client/config_test.go +++ b/clients/pkg/promtail/client/config_test.go @@ -6,8 +6,8 @@ import ( "testing" "time" - "github.com/cortexproject/cortex/pkg/util/flagext" "github.com/grafana/dskit/backoff" + "github.com/grafana/dskit/flagext" "github.com/stretchr/testify/require" "gopkg.in/yaml.v2" diff --git a/clients/pkg/promtail/client/logger_test.go b/clients/pkg/promtail/client/logger_test.go index 7b7f2f3a44..6ebfd46484 100644 --- a/clients/pkg/promtail/client/logger_test.go +++ b/clients/pkg/promtail/client/logger_test.go @@ -5,8 +5,8 @@ import ( "testing" "time" - cortexflag "github.com/cortexproject/cortex/pkg/util/flagext" util_log "github.com/cortexproject/cortex/pkg/util/log" + cortexflag "github.com/grafana/dskit/flagext" "github.com/prometheus/common/model" "github.com/stretchr/testify/require" diff --git a/clients/pkg/promtail/client/multi_test.go b/clients/pkg/promtail/client/multi_test.go index 6cbad18c5a..77790ba942 100644 --- a/clients/pkg/promtail/client/multi_test.go +++ b/clients/pkg/promtail/client/multi_test.go @@ -6,19 +6,18 @@ import ( "testing" "time" - "github.com/cortexproject/cortex/pkg/util/flagext" util_log "github.com/cortexproject/cortex/pkg/util/log" "github.com/go-kit/kit/log" + "github.com/grafana/dskit/backoff" + "github.com/grafana/dskit/flagext" "github.com/prometheus/client_golang/prometheus" "github.com/prometheus/common/model" "github.com/stretchr/testify/require" - "github.com/grafana/dskit/backoff" - "github.com/grafana/loki/clients/pkg/promtail/api" - "github.com/grafana/loki/pkg/logproto" lokiflag "github.com/grafana/loki/pkg/util/flagext" + "github.com/grafana/loki/clients/pkg/promtail/api" "github.com/grafana/loki/clients/pkg/promtail/client/fake" ) diff --git a/clients/pkg/promtail/config/config.go b/clients/pkg/promtail/config/config.go index bcf6bfdc1b..6fbcae9119 100644 --- a/clients/pkg/promtail/config/config.go +++ b/clients/pkg/promtail/config/config.go @@ -4,12 +4,13 @@ import ( "flag" "fmt" + yaml "gopkg.in/yaml.v2" + "github.com/grafana/loki/clients/pkg/promtail/client" "github.com/grafana/loki/clients/pkg/promtail/positions" "github.com/grafana/loki/clients/pkg/promtail/scrapeconfig" "github.com/grafana/loki/clients/pkg/promtail/server" "github.com/grafana/loki/clients/pkg/promtail/targets/file" - yaml "gopkg.in/yaml.v2" ) // Config for promtail, describing what files to watch. diff --git a/clients/pkg/promtail/promtail_test.go b/clients/pkg/promtail/promtail_test.go index 47749afdaf..0da7c90f84 100644 --- a/clients/pkg/promtail/promtail_test.go +++ b/clients/pkg/promtail/promtail_test.go @@ -16,10 +16,10 @@ import ( "time" "github.com/cortexproject/cortex/pkg/util" - "github.com/cortexproject/cortex/pkg/util/flagext" util_log "github.com/cortexproject/cortex/pkg/util/log" "github.com/go-kit/kit/log" "github.com/go-kit/kit/log/level" + "github.com/grafana/dskit/flagext" "github.com/pkg/errors" "github.com/prometheus/client_golang/prometheus" "github.com/prometheus/common/model" diff --git a/clients/pkg/promtail/targets/lokipush/pushtarget_test.go b/clients/pkg/promtail/targets/lokipush/pushtarget_test.go index 4cd27e62c6..6b86ebca05 100644 --- a/clients/pkg/promtail/targets/lokipush/pushtarget_test.go +++ b/clients/pkg/promtail/targets/lokipush/pushtarget_test.go @@ -8,8 +8,8 @@ import ( "testing" "time" - "github.com/cortexproject/cortex/pkg/util/flagext" "github.com/go-kit/kit/log" + "github.com/grafana/dskit/flagext" "github.com/prometheus/client_golang/prometheus" "github.com/prometheus/common/model" "github.com/prometheus/prometheus/pkg/relabel" diff --git a/cmd/loki/main.go b/cmd/loki/main.go index bb68b99488..10f4806046 100644 --- a/cmd/loki/main.go +++ b/cmd/loki/main.go @@ -6,8 +6,8 @@ import ( "os" "reflect" - "github.com/cortexproject/cortex/pkg/util/flagext" "github.com/go-kit/kit/log/level" + "github.com/grafana/dskit/flagext" "github.com/prometheus/client_golang/prometheus" "github.com/prometheus/common/version" "github.com/weaveworks/common/logging" diff --git a/go.mod b/go.mod index 6ed0b1f2fc..cdc4fe4160 100644 --- a/go.mod +++ b/go.mod @@ -44,7 +44,7 @@ require ( github.com/google/go-cmp v0.5.6 github.com/gorilla/mux v1.8.0 github.com/gorilla/websocket v1.4.2 - github.com/grafana/dskit v0.0.0-20210819132858-471020752967 + github.com/grafana/dskit v0.0.0-20210827060659-9daca2f00327 github.com/grpc-ecosystem/go-grpc-middleware v1.3.0 github.com/grpc-ecosystem/go-grpc-prometheus v1.2.1-0.20191002090509-6af20e3a5340 // indirect github.com/grpc-ecosystem/grpc-opentracing v0.0.0-20180507213350-8e809c8a8645 diff --git a/go.sum b/go.sum index ddc67d9d8b..1486fc3e19 100644 --- a/go.sum +++ b/go.sum @@ -1077,8 +1077,8 @@ github.com/gorilla/websocket v1.4.2 h1:+/TMaTYc4QFitKJxsQ7Yye35DkWvkdLcvGKqM+x0U github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= github.com/gotestyourself/gotestyourself v2.2.0+incompatible/go.mod h1:zZKM6oeNM8k+FRljX1mnzVYeS8wiGgQyvST1/GafPbY= github.com/grafana/dskit v0.0.0-20210818123532-6645f87e9e12/go.mod h1:QaNAQaCSFOtG/NHf6Jd/zh67H25kkrVCq36U61Y2Mhw= -github.com/grafana/dskit v0.0.0-20210819132858-471020752967 h1:1Z8LpFZzzpqEK1pq1PU8UGbeUQubO1Idh+jt1XXwB8M= -github.com/grafana/dskit v0.0.0-20210819132858-471020752967/go.mod h1:uF46UNN1/feB1egpq8UGbBBKvJjGgZauW7pcVbeFLLM= +github.com/grafana/dskit v0.0.0-20210827060659-9daca2f00327 h1:THdW9RnugPdLwW8RmHB/xOcKf267QunSH1mDuaJkhWk= +github.com/grafana/dskit v0.0.0-20210827060659-9daca2f00327/go.mod h1:+T2iuDOzx/BSQJSvli9FUvLM5HnV8aDPmXM8KWuVj3M= github.com/grafana/gocql v0.0.0-20200605141915-ba5dc39ece85 h1:xLuzPoOzdfNb/RF/IENCw+oLVdZB4G21VPhkHBgwSHY= github.com/grafana/gocql v0.0.0-20200605141915-ba5dc39ece85/go.mod h1:crI9WX6p0IhrqB+DqIUHulRW853PaNFf7o4UprV//3I= github.com/grafana/tail v0.0.0-20201004203643-7aa4e4a91f03 h1:fGgFrAraMB0BaPfYumu+iulfDXwHm+GFyHA4xEtBqI8= diff --git a/pkg/distributor/distributor_test.go b/pkg/distributor/distributor_test.go index 296e2b5b6b..0d5e092552 100644 --- a/pkg/distributor/distributor_test.go +++ b/pkg/distributor/distributor_test.go @@ -16,8 +16,8 @@ import ( ring_client "github.com/cortexproject/cortex/pkg/ring/client" "github.com/cortexproject/cortex/pkg/ring/kv" "github.com/cortexproject/cortex/pkg/ring/kv/consul" - "github.com/cortexproject/cortex/pkg/util/flagext" "github.com/cortexproject/cortex/pkg/util/test" + "github.com/grafana/dskit/flagext" "github.com/grafana/dskit/services" "github.com/prometheus/client_golang/prometheus" "github.com/prometheus/common/model" diff --git a/pkg/distributor/validator_test.go b/pkg/distributor/validator_test.go index 9bb064f85f..e789e929bc 100644 --- a/pkg/distributor/validator_test.go +++ b/pkg/distributor/validator_test.go @@ -5,7 +5,7 @@ import ( "testing" "time" - "github.com/cortexproject/cortex/pkg/util/flagext" + "github.com/grafana/dskit/flagext" "github.com/prometheus/common/model" "github.com/prometheus/prometheus/pkg/labels" "github.com/stretchr/testify/assert" diff --git a/pkg/ingester/flush_test.go b/pkg/ingester/flush_test.go index e054cfc1ee..f016a784da 100644 --- a/pkg/ingester/flush_test.go +++ b/pkg/ingester/flush_test.go @@ -13,7 +13,7 @@ import ( "github.com/cortexproject/cortex/pkg/ring" "github.com/cortexproject/cortex/pkg/ring/kv" "github.com/cortexproject/cortex/pkg/tenant" - "github.com/cortexproject/cortex/pkg/util/flagext" + "github.com/grafana/dskit/flagext" "github.com/grafana/dskit/services" "github.com/prometheus/common/model" "github.com/prometheus/prometheus/pkg/labels" diff --git a/pkg/ingester/ingester_test.go b/pkg/ingester/ingester_test.go index 15939a368a..8f8a57f745 100644 --- a/pkg/ingester/ingester_test.go +++ b/pkg/ingester/ingester_test.go @@ -8,7 +8,7 @@ import ( "time" "github.com/cortexproject/cortex/pkg/tenant" - "github.com/cortexproject/cortex/pkg/util/flagext" + "github.com/grafana/dskit/flagext" "github.com/grafana/dskit/services" "github.com/prometheus/common/model" "github.com/prometheus/prometheus/pkg/labels" diff --git a/pkg/ingester/transfer_test.go b/pkg/ingester/transfer_test.go index 077656fd83..5521cc77df 100644 --- a/pkg/ingester/transfer_test.go +++ b/pkg/ingester/transfer_test.go @@ -11,7 +11,6 @@ import ( "github.com/cortexproject/cortex/pkg/ring" "github.com/cortexproject/cortex/pkg/ring/kv" util_log "github.com/cortexproject/cortex/pkg/util/log" - "github.com/go-kit/kit/log/level" "github.com/grafana/dskit/services" "github.com/stretchr/testify/assert" diff --git a/pkg/loki/loki.go b/pkg/loki/loki.go index 3a35643932..f3cdcbb2d4 100644 --- a/pkg/loki/loki.go +++ b/pkg/loki/loki.go @@ -16,12 +16,12 @@ import ( "github.com/cortexproject/cortex/pkg/scheduler" "github.com/cortexproject/cortex/pkg/util" "github.com/cortexproject/cortex/pkg/util/fakeauth" - "github.com/cortexproject/cortex/pkg/util/flagext" "github.com/cortexproject/cortex/pkg/util/grpc/healthcheck" util_log "github.com/cortexproject/cortex/pkg/util/log" "github.com/cortexproject/cortex/pkg/util/runtimeconfig" "github.com/felixge/fgprof" "github.com/go-kit/kit/log/level" + "github.com/grafana/dskit/flagext" "github.com/grafana/dskit/modules" "github.com/grafana/dskit/services" "github.com/pkg/errors" diff --git a/pkg/querier/querier_test.go b/pkg/querier/querier_test.go index f2d48dde48..f72562ae4b 100644 --- a/pkg/querier/querier_test.go +++ b/pkg/querier/querier_test.go @@ -10,7 +10,7 @@ import ( "github.com/cortexproject/cortex/pkg/ring" ring_client "github.com/cortexproject/cortex/pkg/ring/client" - "github.com/cortexproject/cortex/pkg/util/flagext" + "github.com/grafana/dskit/flagext" "github.com/prometheus/common/model" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/mock" diff --git a/pkg/storage/chunk/aws/dynamodb_storage_client.go b/pkg/storage/chunk/aws/dynamodb_storage_client.go index 449bd1669d..1f4964be3f 100644 --- a/pkg/storage/chunk/aws/dynamodb_storage_client.go +++ b/pkg/storage/chunk/aws/dynamodb_storage_client.go @@ -17,8 +17,13 @@ import ( "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/dynamodb" "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/cortexproject/cortex/pkg/util/spanlogger" "github.com/go-kit/kit/log/level" "github.com/grafana/dskit/backoff" + "github.com/grafana/dskit/flagext" ot "github.com/opentracing/opentracing-go" otlog "github.com/opentracing/opentracing-go/log" "github.com/pkg/errors" @@ -27,12 +32,6 @@ import ( "github.com/weaveworks/common/instrument" "golang.org/x/time/rate" - "github.com/cortexproject/cortex/pkg/util" - "github.com/cortexproject/cortex/pkg/util/flagext" - "github.com/cortexproject/cortex/pkg/util/log" - "github.com/cortexproject/cortex/pkg/util/math" - "github.com/cortexproject/cortex/pkg/util/spanlogger" - "github.com/grafana/loki/pkg/storage/chunk" chunk_util "github.com/grafana/loki/pkg/storage/chunk/util" ) diff --git a/pkg/storage/chunk/aws/s3_storage_client.go b/pkg/storage/chunk/aws/s3_storage_client.go index cb4d1ebf3f..d65e4829f7 100644 --- a/pkg/storage/chunk/aws/s3_storage_client.go +++ b/pkg/storage/chunk/aws/s3_storage_client.go @@ -30,7 +30,7 @@ import ( cortex_s3 "github.com/cortexproject/cortex/pkg/storage/bucket/s3" "github.com/cortexproject/cortex/pkg/util" - "github.com/cortexproject/cortex/pkg/util/flagext" + "github.com/grafana/dskit/flagext" "github.com/grafana/loki/pkg/storage/chunk" ) diff --git a/pkg/storage/chunk/azure/blob_storage_client.go b/pkg/storage/chunk/azure/blob_storage_client.go index ef18b29c69..c40299d7d0 100644 --- a/pkg/storage/chunk/azure/blob_storage_client.go +++ b/pkg/storage/chunk/azure/blob_storage_client.go @@ -14,8 +14,8 @@ import ( "github.com/Azure/azure-storage-blob-go/azblob" "github.com/cortexproject/cortex/pkg/util" - "github.com/cortexproject/cortex/pkg/util/flagext" "github.com/cortexproject/cortex/pkg/util/log" + "github.com/grafana/dskit/flagext" "github.com/grafana/loki/pkg/storage/chunk" chunk_util "github.com/grafana/loki/pkg/storage/chunk/util" diff --git a/pkg/storage/chunk/cache/fifo_cache.go b/pkg/storage/chunk/cache/fifo_cache.go index 1215a6cff1..539beef3fc 100644 --- a/pkg/storage/chunk/cache/fifo_cache.go +++ b/pkg/storage/chunk/cache/fifo_cache.go @@ -8,15 +8,14 @@ import ( "time" "unsafe" + util_log "github.com/cortexproject/cortex/pkg/util/log" "github.com/dustin/go-humanize" "github.com/go-kit/kit/log" "github.com/go-kit/kit/log/level" + "github.com/grafana/dskit/flagext" "github.com/pkg/errors" "github.com/prometheus/client_golang/prometheus" "github.com/prometheus/client_golang/prometheus/promauto" - - "github.com/cortexproject/cortex/pkg/util/flagext" - util_log "github.com/cortexproject/cortex/pkg/util/log" ) const ( diff --git a/pkg/storage/chunk/cache/redis_client.go b/pkg/storage/chunk/cache/redis_client.go index acb2162ec6..1c1bd8f184 100644 --- a/pkg/storage/chunk/cache/redis_client.go +++ b/pkg/storage/chunk/cache/redis_client.go @@ -9,7 +9,7 @@ import ( "time" "unsafe" - "github.com/cortexproject/cortex/pkg/util/flagext" + "github.com/grafana/dskit/flagext" "github.com/go-redis/redis/v8" ) diff --git a/pkg/storage/chunk/cassandra/fixtures.go b/pkg/storage/chunk/cassandra/fixtures.go index 609ded4b7b..c7d567e355 100644 --- a/pkg/storage/chunk/cassandra/fixtures.go +++ b/pkg/storage/chunk/cassandra/fixtures.go @@ -5,7 +5,7 @@ import ( "io" "os" - "github.com/cortexproject/cortex/pkg/util/flagext" + "github.com/grafana/dskit/flagext" "github.com/grafana/loki/pkg/storage/chunk" "github.com/grafana/loki/pkg/storage/chunk/testutils" diff --git a/pkg/storage/chunk/cassandra/storage_client.go b/pkg/storage/chunk/cassandra/storage_client.go index ca8f1c606c..12423734c8 100644 --- a/pkg/storage/chunk/cassandra/storage_client.go +++ b/pkg/storage/chunk/cassandra/storage_client.go @@ -17,8 +17,8 @@ import ( "github.com/prometheus/client_golang/prometheus" "golang.org/x/sync/semaphore" - "github.com/cortexproject/cortex/pkg/util/flagext" util_log "github.com/cortexproject/cortex/pkg/util/log" + "github.com/grafana/dskit/flagext" "github.com/grafana/loki/pkg/storage/chunk" "github.com/grafana/loki/pkg/storage/chunk/util" diff --git a/pkg/storage/chunk/cassandra/storage_client_test.go b/pkg/storage/chunk/cassandra/storage_client_test.go index 8c7a3438c2..5d493ee633 100644 --- a/pkg/storage/chunk/cassandra/storage_client_test.go +++ b/pkg/storage/chunk/cassandra/storage_client_test.go @@ -7,7 +7,7 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "github.com/cortexproject/cortex/pkg/util/flagext" + "github.com/grafana/dskit/flagext" ) func TestConfig_setClusterConfig_noAuth(t *testing.T) { diff --git a/pkg/storage/chunk/chunk_store_test.go b/pkg/storage/chunk/chunk_store_test.go index 8a9da84da7..2279d9d7a4 100644 --- a/pkg/storage/chunk/chunk_store_test.go +++ b/pkg/storage/chunk/chunk_store_test.go @@ -18,8 +18,8 @@ import ( "github.com/stretchr/testify/require" "github.com/weaveworks/common/test" - "github.com/cortexproject/cortex/pkg/util/flagext" "github.com/cortexproject/cortex/pkg/util/validation" + "github.com/grafana/dskit/flagext" "github.com/grafana/loki/pkg/storage/chunk/cache" "github.com/grafana/loki/pkg/storage/chunk/encoding" diff --git a/pkg/storage/chunk/purger/purger_test.go b/pkg/storage/chunk/purger/purger_test.go index e54e5dbe62..4dbc6a8da5 100644 --- a/pkg/storage/chunk/purger/purger_test.go +++ b/pkg/storage/chunk/purger/purger_test.go @@ -8,13 +8,12 @@ import ( "testing" "time" - "github.com/prometheus/client_golang/prometheus/testutil" - - "github.com/cortexproject/cortex/pkg/util/flagext" util_log "github.com/cortexproject/cortex/pkg/util/log" "github.com/cortexproject/cortex/pkg/util/test" + "github.com/grafana/dskit/flagext" "github.com/grafana/dskit/services" "github.com/prometheus/client_golang/prometheus" + "github.com/prometheus/client_golang/prometheus/testutil" "github.com/prometheus/common/model" "github.com/prometheus/prometheus/promql/parser" "github.com/stretchr/testify/require" diff --git a/pkg/storage/chunk/storage/caching_fixtures.go b/pkg/storage/chunk/storage/caching_fixtures.go index 775549d1d8..7a77111929 100644 --- a/pkg/storage/chunk/storage/caching_fixtures.go +++ b/pkg/storage/chunk/storage/caching_fixtures.go @@ -7,13 +7,12 @@ import ( "github.com/go-kit/kit/log" "github.com/prometheus/client_golang/prometheus" - "github.com/cortexproject/cortex/pkg/util/flagext" "github.com/cortexproject/cortex/pkg/util/validation" + "github.com/grafana/dskit/flagext" + "github.com/grafana/loki/pkg/storage/chunk" "github.com/grafana/loki/pkg/storage/chunk/cache" "github.com/grafana/loki/pkg/storage/chunk/gcp" - - "github.com/grafana/loki/pkg/storage/chunk" "github.com/grafana/loki/pkg/storage/chunk/testutils" ) diff --git a/pkg/storage/chunk/storage/factory_test.go b/pkg/storage/chunk/storage/factory_test.go index 045be79827..f3ca3cb5bf 100644 --- a/pkg/storage/chunk/storage/factory_test.go +++ b/pkg/storage/chunk/storage/factory_test.go @@ -7,13 +7,12 @@ import ( "testing" "time" + "github.com/cortexproject/cortex/pkg/util/validation" "github.com/go-kit/kit/log" + "github.com/grafana/dskit/flagext" "github.com/prometheus/common/model" "github.com/stretchr/testify/require" - "github.com/cortexproject/cortex/pkg/util/flagext" - "github.com/cortexproject/cortex/pkg/util/validation" - "github.com/grafana/loki/pkg/storage/chunk" "github.com/grafana/loki/pkg/storage/chunk/cassandra" "github.com/grafana/loki/pkg/storage/chunk/local" diff --git a/pkg/storage/chunk/testutils/testutils.go b/pkg/storage/chunk/testutils/testutils.go index 99019ff77a..e432a3d293 100644 --- a/pkg/storage/chunk/testutils/testutils.go +++ b/pkg/storage/chunk/testutils/testutils.go @@ -6,12 +6,11 @@ import ( "strconv" "time" - "github.com/prometheus/common/model" - "github.com/prometheus/prometheus/pkg/labels" - "github.com/cortexproject/cortex/pkg/ingester/client" - "github.com/cortexproject/cortex/pkg/util/flagext" "github.com/cortexproject/cortex/pkg/util/validation" + "github.com/grafana/dskit/flagext" + "github.com/prometheus/common/model" + "github.com/prometheus/prometheus/pkg/labels" "github.com/grafana/loki/pkg/storage/chunk" "github.com/grafana/loki/pkg/storage/chunk/cache" diff --git a/pkg/storage/store.go b/pkg/storage/store.go index 1cd487c95c..e95b1ef102 100644 --- a/pkg/storage/store.go +++ b/pkg/storage/store.go @@ -9,9 +9,9 @@ import ( "github.com/cortexproject/cortex/pkg/querier/astmapper" "github.com/cortexproject/cortex/pkg/tenant" - "github.com/cortexproject/cortex/pkg/util/flagext" "github.com/go-kit/kit/log" "github.com/go-kit/kit/log/level" + "github.com/grafana/dskit/flagext" "github.com/prometheus/client_golang/prometheus" "github.com/prometheus/common/model" "github.com/prometheus/prometheus/pkg/labels" diff --git a/pkg/storage/store_test.go b/pkg/storage/store_test.go index 612518a56a..71d09d852e 100644 --- a/pkg/storage/store_test.go +++ b/pkg/storage/store_test.go @@ -23,7 +23,7 @@ import ( "github.com/weaveworks/common/user" "github.com/cortexproject/cortex/pkg/querier/astmapper" - "github.com/cortexproject/cortex/pkg/util/flagext" + "github.com/grafana/dskit/flagext" "github.com/grafana/loki/pkg/iter" "github.com/grafana/loki/pkg/logproto" diff --git a/pkg/storage/stores/shipper/compactor/compactor_test.go b/pkg/storage/stores/shipper/compactor/compactor_test.go index d00b6a24e4..e0cffec23a 100644 --- a/pkg/storage/stores/shipper/compactor/compactor_test.go +++ b/pkg/storage/stores/shipper/compactor/compactor_test.go @@ -10,7 +10,7 @@ import ( "testing" "time" - "github.com/cortexproject/cortex/pkg/util/flagext" + "github.com/grafana/dskit/flagext" "github.com/stretchr/testify/require" diff --git a/pkg/storage/stores/shipper/gateway_client_test.go b/pkg/storage/stores/shipper/gateway_client_test.go index 5f33261923..988d1e903c 100644 --- a/pkg/storage/stores/shipper/gateway_client_test.go +++ b/pkg/storage/stores/shipper/gateway_client_test.go @@ -8,7 +8,7 @@ import ( "net" "testing" - "github.com/cortexproject/cortex/pkg/util/flagext" + "github.com/grafana/dskit/flagext" "github.com/stretchr/testify/require" "github.com/weaveworks/common/user" diff --git a/pkg/util/cfg/cfg.go b/pkg/util/cfg/cfg.go index 0cdc5ac7e3..31ac5d9df7 100644 --- a/pkg/util/cfg/cfg.go +++ b/pkg/util/cfg/cfg.go @@ -5,7 +5,7 @@ import ( "os" "reflect" - "github.com/cortexproject/cortex/pkg/util/flagext" + "github.com/grafana/dskit/flagext" "github.com/pkg/errors" ) diff --git a/pkg/util/cfg/data_test.go b/pkg/util/cfg/data_test.go index 037cd54722..6596e20d1d 100644 --- a/pkg/util/cfg/data_test.go +++ b/pkg/util/cfg/data_test.go @@ -4,7 +4,7 @@ import ( "flag" "time" - "github.com/cortexproject/cortex/pkg/util/flagext" + "github.com/grafana/dskit/flagext" ) // Data is a test Data structure diff --git a/pkg/util/cfg/files_test.go b/pkg/util/cfg/files_test.go index f697857ee2..64c47b1324 100644 --- a/pkg/util/cfg/files_test.go +++ b/pkg/util/cfg/files_test.go @@ -4,7 +4,7 @@ import ( "flag" "testing" - "github.com/cortexproject/cortex/pkg/util/flagext" + "github.com/grafana/dskit/flagext" "github.com/stretchr/testify/require" ) diff --git a/pkg/util/cfg/flag.go b/pkg/util/cfg/flag.go index 1813941fe2..29520ba635 100644 --- a/pkg/util/cfg/flag.go +++ b/pkg/util/cfg/flag.go @@ -7,7 +7,7 @@ import ( "sort" "strings" - "github.com/cortexproject/cortex/pkg/util/flagext" + "github.com/grafana/dskit/flagext" "github.com/pkg/errors" ) diff --git a/vendor/github.com/grafana/dskit/flagext/cidr.go b/vendor/github.com/grafana/dskit/flagext/cidr.go new file mode 100644 index 0000000000..72b93b680c --- /dev/null +++ b/vendor/github.com/grafana/dskit/flagext/cidr.go @@ -0,0 +1,82 @@ +package flagext + +import ( + "net" + "strings" + + "github.com/pkg/errors" +) + +// CIDR is a network CIDR. +type CIDR struct { + Value *net.IPNet +} + +// String implements flag.Value. +func (c CIDR) String() string { + if c.Value == nil { + return "" + } + return c.Value.String() +} + +// Set implements flag.Value. +func (c *CIDR) Set(s string) error { + _, value, err := net.ParseCIDR(s) + if err != nil { + return err + } + c.Value = value + return nil +} + +// CIDRSliceCSV is a slice of CIDRs that is parsed from a comma-separated string. +// It implements flag.Value and yaml Marshalers. +type CIDRSliceCSV []CIDR + +// String implements flag.Value +func (c CIDRSliceCSV) String() string { + values := make([]string, 0, len(c)) + for _, cidr := range c { + values = append(values, cidr.String()) + } + + return strings.Join(values, ",") +} + +// Set implements flag.Value +func (c *CIDRSliceCSV) Set(s string) error { + parts := strings.Split(s, ",") + + for _, part := range parts { + cidr := &CIDR{} + if err := cidr.Set(part); err != nil { + return errors.Wrapf(err, "cidr: %s", part) + } + + *c = append(*c, *cidr) + } + + return nil +} + +// UnmarshalYAML implements yaml.Unmarshaler. +func (c *CIDRSliceCSV) UnmarshalYAML(unmarshal func(interface{}) error) error { + var s string + if err := unmarshal(&s); err != nil { + return err + } + + // An empty string means no CIDRs has been configured. + if s == "" { + *c = nil + return nil + } + + return c.Set(s) +} + +// MarshalYAML implements yaml.Marshaler. +func (c CIDRSliceCSV) MarshalYAML() (interface{}, error) { + return c.String(), nil +} diff --git a/vendor/github.com/grafana/dskit/flagext/day.go b/vendor/github.com/grafana/dskit/flagext/day.go new file mode 100644 index 0000000000..8370ac0d57 --- /dev/null +++ b/vendor/github.com/grafana/dskit/flagext/day.go @@ -0,0 +1,59 @@ +package flagext + +import ( + "time" + + "github.com/prometheus/common/model" +) + +const secondsInDay = 24 * 60 * 60 + +// DayValue is a model.Time that can be used as a flag. +// NB it only parses days! +type DayValue struct { + model.Time + set bool +} + +// NewDayValue makes a new DayValue; will round t down to the nearest midnight. +func NewDayValue(t model.Time) DayValue { + return DayValue{ + Time: model.TimeFromUnix((t.Unix() / secondsInDay) * secondsInDay), + set: true, + } +} + +// String implements flag.Value +func (v DayValue) String() string { + return v.Time.Time().Format(time.RFC3339) +} + +// Set implements flag.Value +func (v *DayValue) Set(s string) error { + t, err := time.Parse("2006-01-02", s) + if err != nil { + return err + } + v.Time = model.TimeFromUnix(t.Unix()) + v.set = true + return nil +} + +// IsSet returns true is the DayValue has been set. +func (v *DayValue) IsSet() bool { + return v.set +} + +// UnmarshalYAML implements yaml.Unmarshaler. +func (v *DayValue) UnmarshalYAML(unmarshal func(interface{}) error) error { + var s string + if err := unmarshal(&s); err != nil { + return err + } + return v.Set(s) +} + +// MarshalYAML implements yaml.Marshaler. +func (v DayValue) MarshalYAML() (interface{}, error) { + return v.Time.Time().Format("2006-01-02"), nil +} diff --git a/vendor/github.com/grafana/dskit/flagext/deprecated.go b/vendor/github.com/grafana/dskit/flagext/deprecated.go new file mode 100644 index 0000000000..0a6913ab69 --- /dev/null +++ b/vendor/github.com/grafana/dskit/flagext/deprecated.go @@ -0,0 +1,37 @@ +package flagext + +import ( + "flag" + + "github.com/go-kit/kit/log" + "github.com/go-kit/kit/log/level" + "github.com/prometheus/client_golang/prometheus" + "github.com/prometheus/client_golang/prometheus/promauto" +) + +// DeprecatedFlagsUsed is the metric that counts deprecated flags set. +var DeprecatedFlagsUsed = promauto.NewCounter( + prometheus.CounterOpts{ + Name: "deprecated_flags_inuse_total", + Help: "The number of deprecated flags currently set.", + }) + +type deprecatedFlag struct { + name string + logger log.Logger +} + +func (deprecatedFlag) String() string { + return "deprecated" +} + +func (d deprecatedFlag) Set(string) error { + level.Warn(d.logger).Log("msg", "flag disabled", "flag", d.name) + DeprecatedFlagsUsed.Inc() + return nil +} + +// DeprecatedFlag logs a warning when you try to use it. +func DeprecatedFlag(f *flag.FlagSet, name, message string, logger log.Logger) { + f.Var(deprecatedFlag{name: name, logger: logger}, name, message) +} diff --git a/vendor/github.com/grafana/dskit/flagext/ignored.go b/vendor/github.com/grafana/dskit/flagext/ignored.go new file mode 100644 index 0000000000..2dd49a87eb --- /dev/null +++ b/vendor/github.com/grafana/dskit/flagext/ignored.go @@ -0,0 +1,22 @@ +package flagext + +import ( + "flag" +) + +type ignoredFlag struct { + name string +} + +func (ignoredFlag) String() string { + return "ignored" +} + +func (d ignoredFlag) Set(string) error { + return nil +} + +// IgnoredFlag ignores set value, without any warning +func IgnoredFlag(f *flag.FlagSet, name, message string) { + f.Var(ignoredFlag{name}, name, message) +} diff --git a/vendor/github.com/grafana/dskit/flagext/register.go b/vendor/github.com/grafana/dskit/flagext/register.go new file mode 100644 index 0000000000..1140843e04 --- /dev/null +++ b/vendor/github.com/grafana/dskit/flagext/register.go @@ -0,0 +1,24 @@ +package flagext + +import "flag" + +// Registerer is a thing that can RegisterFlags +type Registerer interface { + RegisterFlags(*flag.FlagSet) +} + +// RegisterFlags registers flags with the provided Registerers +func RegisterFlags(rs ...Registerer) { + for _, r := range rs { + r.RegisterFlags(flag.CommandLine) + } +} + +// DefaultValues initiates a set of configs (Registerers) with their defaults. +func DefaultValues(rs ...Registerer) { + fs := flag.NewFlagSet("", flag.PanicOnError) + for _, r := range rs { + r.RegisterFlags(fs) + } + _ = fs.Parse([]string{}) +} diff --git a/vendor/github.com/grafana/dskit/flagext/secret.go b/vendor/github.com/grafana/dskit/flagext/secret.go new file mode 100644 index 0000000000..aa7101b149 --- /dev/null +++ b/vendor/github.com/grafana/dskit/flagext/secret.go @@ -0,0 +1,34 @@ +package flagext + +type Secret struct { + Value string +} + +// String implements flag.Value +func (v Secret) String() string { + return v.Value +} + +// Set implements flag.Value +func (v *Secret) Set(s string) error { + v.Value = s + return nil +} + +// UnmarshalYAML implements yaml.Unmarshaler. +func (v *Secret) UnmarshalYAML(unmarshal func(interface{}) error) error { + var s string + if err := unmarshal(&s); err != nil { + return err + } + + return v.Set(s) +} + +// MarshalYAML implements yaml.Marshaler. +func (v Secret) MarshalYAML() (interface{}, error) { + if len(v.Value) == 0 { + return "", nil + } + return "********", nil +} diff --git a/vendor/github.com/grafana/dskit/flagext/stringslice.go b/vendor/github.com/grafana/dskit/flagext/stringslice.go new file mode 100644 index 0000000000..7c4fd45cff --- /dev/null +++ b/vendor/github.com/grafana/dskit/flagext/stringslice.go @@ -0,0 +1,17 @@ +package flagext + +import "fmt" + +// StringSlice is a slice of strings that implements flag.Value +type StringSlice []string + +// String implements flag.Value +func (v StringSlice) String() string { + return fmt.Sprintf("%s", []string(v)) +} + +// Set implements flag.Value +func (v *StringSlice) Set(s string) error { + *v = append(*v, s) + return nil +} diff --git a/vendor/github.com/grafana/dskit/flagext/stringslicecsv.go b/vendor/github.com/grafana/dskit/flagext/stringslicecsv.go new file mode 100644 index 0000000000..47ccd54ca0 --- /dev/null +++ b/vendor/github.com/grafana/dskit/flagext/stringslicecsv.go @@ -0,0 +1,33 @@ +package flagext + +import "strings" + +// StringSliceCSV is a slice of strings that is parsed from a comma-separated string +// It implements flag.Value and yaml Marshalers +type StringSliceCSV []string + +// String implements flag.Value +func (v StringSliceCSV) String() string { + return strings.Join(v, ",") +} + +// Set implements flag.Value +func (v *StringSliceCSV) Set(s string) error { + *v = strings.Split(s, ",") + return nil +} + +// UnmarshalYAML implements yaml.Unmarshaler. +func (v *StringSliceCSV) UnmarshalYAML(unmarshal func(interface{}) error) error { + var s string + if err := unmarshal(&s); err != nil { + return err + } + + return v.Set(s) +} + +// MarshalYAML implements yaml.Marshaler. +func (v StringSliceCSV) MarshalYAML() (interface{}, error) { + return v.String(), nil +} diff --git a/vendor/github.com/grafana/dskit/flagext/time.go b/vendor/github.com/grafana/dskit/flagext/time.go new file mode 100644 index 0000000000..452857e9de --- /dev/null +++ b/vendor/github.com/grafana/dskit/flagext/time.go @@ -0,0 +1,60 @@ +package flagext + +import ( + "fmt" + "time" +) + +// Time usable as flag or in YAML config. +type Time time.Time + +// String implements flag.Value +func (t Time) String() string { + if time.Time(t).IsZero() { + return "0" + } + + return time.Time(t).Format(time.RFC3339) +} + +// Set implements flag.Value +func (t *Time) Set(s string) error { + if s == "0" { + *t = Time(time.Time{}) + return nil + } + + p, err := time.Parse("2006-01-02", s) + if err == nil { + *t = Time(p) + return nil + } + + p, err = time.Parse("2006-01-02T15:04", s) + if err == nil { + *t = Time(p) + return nil + } + + p, err = time.Parse("2006-01-02T15:04:05Z07:00", s) + if err == nil { + *t = Time(p) + return nil + } + + return fmt.Errorf("failed to parse time: %q", s) +} + +// UnmarshalYAML implements yaml.Unmarshaler. +func (t *Time) UnmarshalYAML(unmarshal func(interface{}) error) error { + var s string + if err := unmarshal(&s); err != nil { + return err + } + return t.Set(s) +} + +// MarshalYAML implements yaml.Marshaler. +func (t Time) MarshalYAML() (interface{}, error) { + return t.String(), nil +} diff --git a/vendor/github.com/grafana/dskit/flagext/url.go b/vendor/github.com/grafana/dskit/flagext/url.go new file mode 100644 index 0000000000..3b3b8303be --- /dev/null +++ b/vendor/github.com/grafana/dskit/flagext/url.go @@ -0,0 +1,59 @@ +package flagext + +import "net/url" + +// URLValue is a url.URL that can be used as a flag. +type URLValue struct { + *url.URL +} + +// String implements flag.Value +func (v URLValue) String() string { + if v.URL == nil { + return "" + } + return v.URL.String() +} + +// Set implements flag.Value +func (v *URLValue) Set(s string) error { + u, err := url.Parse(s) + if err != nil { + return err + } + v.URL = u + return nil +} + +// UnmarshalYAML implements yaml.Unmarshaler. +func (v *URLValue) UnmarshalYAML(unmarshal func(interface{}) error) error { + var s string + if err := unmarshal(&s); err != nil { + return err + } + + // An empty string means no URL has been configured. + if s == "" { + v.URL = nil + return nil + } + + return v.Set(s) +} + +// MarshalYAML implements yaml.Marshaler. +func (v URLValue) MarshalYAML() (interface{}, error) { + if v.URL == nil { + return "", nil + } + + // Mask out passwords when marshalling URLs back to YAML. + u := *v.URL + if u.User != nil { + if _, set := u.User.Password(); set { + u.User = url.UserPassword(u.User.Username(), "********") + } + } + + return u.String(), nil +} diff --git a/vendor/github.com/grafana/dskit/services/basic_service.go b/vendor/github.com/grafana/dskit/services/basic_service.go index cb43eaa380..ead611a3f9 100644 --- a/vendor/github.com/grafana/dskit/services/basic_service.go +++ b/vendor/github.com/grafana/dskit/services/basic_service.go @@ -77,7 +77,7 @@ func invalidServiceStateWithFailureError(state, expected State, failure error) e return fmt.Errorf("invalid service state: %v, expected: %v, failure: %w", state, expected, failure) } -// Returns service built from three functions (using BasicService). +// NewBasicService returns service built from three functions (using BasicService). func NewBasicService(start StartingFn, run RunningFn, stop StoppingFn) *BasicService { return &BasicService{ startFn: start, @@ -246,7 +246,7 @@ func (b *BasicService) StopAsync() { } } -// Returns context that this service uses internally for controlling its lifecycle. It is the same context that +// ServiceContext returns context that this service uses internally for controlling its lifecycle. It is the same context that // is passed to Starting and Running functions, and is based on context passed to the service via StartAsync. // // Before service enters Starting state, there is no context. This context is stopped when service enters Stopping state. diff --git a/vendor/github.com/grafana/dskit/services/failure_watcher.go b/vendor/github.com/grafana/dskit/services/failure_watcher.go index 62cbe4561e..a44fd4495e 100644 --- a/vendor/github.com/grafana/dskit/services/failure_watcher.go +++ b/vendor/github.com/grafana/dskit/services/failure_watcher.go @@ -13,7 +13,7 @@ func NewFailureWatcher() *FailureWatcher { return &FailureWatcher{ch: make(chan error)} } -// Returns channel for this watcher. If watcher is nil, returns nil channel. +// Chan returns channel for this watcher. If watcher is nil, returns nil channel. // Errors returned on the channel include failure case and service description. func (w *FailureWatcher) Chan() <-chan error { if w == nil { diff --git a/vendor/github.com/grafana/dskit/services/manager.go b/vendor/github.com/grafana/dskit/services/manager.go index 6a556b1a78..4da481ec5e 100644 --- a/vendor/github.com/grafana/dskit/services/manager.go +++ b/vendor/github.com/grafana/dskit/services/manager.go @@ -17,18 +17,18 @@ const ( // ManagerListener listens for events from Manager. type ManagerListener interface { - // Called when Manager reaches Healthy state (all services Running) + // Healthy is called when Manager reaches Healthy state (all services Running) Healthy() - // Called when Manager reaches Stopped state (all services are either Terminated or Failed) + // Stopped is called when Manager reaches Stopped state (all services are either Terminated or Failed) Stopped() - // Called when service fails. + // Failure is called when service fails. Failure(service Service) } -// Service Manager is initialized with a collection of services. They all must be in New state. -// Service manager can start them, and observe their state as a group. +// Manager is initialized with a collection of services. They all must be in New state. +// Manager can start them, and observe their state as a group. // Once all services are running, Manager is said to be Healthy. It is possible for manager to never reach the Healthy state, if some services fail to start. // When all services are stopped (Terminated or Failed), manager is Stopped. type Manager struct { @@ -72,7 +72,7 @@ func NewManager(services ...Service) (*Manager, error) { return m, nil } -// Initiates service startup on all the services being managed. +// StartAsync initiates service startup on all the services being managed. // It is only valid to call this method if all of the services are New. func (m *Manager) StartAsync(ctx context.Context) error { for _, s := range m.services { @@ -84,7 +84,7 @@ func (m *Manager) StartAsync(ctx context.Context) error { return nil } -// Initiates service shutdown if necessary on all the services being managed. +// StopAsync initiates service shutdown if necessary on all the services being managed. func (m *Manager) StopAsync() { if m == nil { return @@ -95,7 +95,7 @@ func (m *Manager) StopAsync() { } } -// Returns true if all services are currently in the Running state. +// IsHealthy returns true if all services are currently in the Running state. func (m *Manager) IsHealthy() bool { m.mu.Lock() defer m.mu.Unlock() @@ -103,7 +103,7 @@ func (m *Manager) IsHealthy() bool { return m.state == healthy } -// Waits for the ServiceManager to become healthy. Returns nil, if manager is healthy, error otherwise (eg. manager +// AwaitHealthy waits for the ServiceManager to become healthy. Returns nil, if manager is healthy, error otherwise (eg. manager // is in a state in which it cannot get healthy anymore). func (m *Manager) AwaitHealthy(ctx context.Context) error { select { @@ -132,7 +132,7 @@ func (m *Manager) AwaitHealthy(ctx context.Context) error { return nil } -// Returns true if all services are in terminal state (Terminated or Failed) +// IsStopped returns true if all services are in terminal state (Terminated or Failed) func (m *Manager) IsStopped() bool { m.mu.Lock() defer m.mu.Unlock() @@ -140,7 +140,7 @@ func (m *Manager) IsStopped() bool { return m.state == stopped } -// Waits for the ServiceManager to become stopped. Returns nil, if manager is stopped, error when context finishes earlier. +// AwaitStopped waits for the ServiceManager to become stopped. Returns nil, if manager is stopped, error when context finishes earlier. func (m *Manager) AwaitStopped(ctx context.Context) error { select { case <-ctx.Done(): @@ -150,7 +150,7 @@ func (m *Manager) AwaitStopped(ctx context.Context) error { } } -// Provides a snapshot of the current state of all the services under management. +// ServicesByState provides a snapshot of the current state of all the services under management. func (m *Manager) ServicesByState() map[State][]Service { m.mu.Lock() defer m.mu.Unlock() @@ -219,7 +219,7 @@ func (m *Manager) serviceStateChanged(s Service, from State, to State) { } } -// Registers a ManagerListener to be run when this Manager changes state. +// AddListener registers a ManagerListener to be run when this Manager changes state. // The listener will not have previous state changes replayed, so it is suggested that listeners are added before any of the managed services are started. // // AddListener guarantees execution ordering across calls to a given listener but not across calls to multiple listeners. diff --git a/vendor/github.com/grafana/dskit/services/service.go b/vendor/github.com/grafana/dskit/services/service.go index 490cbcad8b..c559ef96a3 100644 --- a/vendor/github.com/grafana/dskit/services/service.go +++ b/vendor/github.com/grafana/dskit/services/service.go @@ -8,13 +8,14 @@ import ( // State of the service. See Service interface for full state diagram. type State int +// Possible states to represent the service State. const ( - New State = iota // Service is new, not running yet. Initial state. - Starting // Service is starting. If starting succeeds, service enters Running state. - Running // Service is fully running now. When service stops running, it enters Stopping state. - Stopping // Service is shutting down - Terminated // Service has stopped successfully. Terminal state. - Failed // Service has failed in Starting, Running or Stopping state. Terminal state. + New State = iota // New: Service is new, not running yet. Initial State. + Starting // Starting: Service is starting. If starting succeeds, service enters Running state. + Running // Running: Service is fully running now. When service stops running, it enters Stopping state. + Stopping // Stopping: Service is shutting down + Terminated // Terminated: Service has stopped successfully. Terminal state. + Failed // Failed: Service has failed in Starting, Running or Stopping state. Terminal state. ) func (s State) String() string { @@ -104,18 +105,18 @@ type NamedService interface { // Listener receives notifications about Service state changes. type Listener interface { - // Called when the service transitions from NEW to STARTING. + // Starting is called when the service transitions from NEW to STARTING. Starting() - // Called when the service transitions from STARTING to RUNNING. + // Running is called when the service transitions from STARTING to RUNNING. Running() - // Called when the service transitions to the STOPPING state. + // Stopping is called when the service transitions to the STOPPING state. Stopping(from State) - // Called when the service transitions to the TERMINATED state. + // Terminated is called when the service transitions to the TERMINATED state. Terminated(from State) - // Called when the service transitions to the FAILED state. + // Failed is called when the service transitions to the FAILED state. Failed(from State, failure error) } diff --git a/vendor/github.com/grafana/dskit/services/services.go b/vendor/github.com/grafana/dskit/services/services.go index f7a668789f..7bb91ae84b 100644 --- a/vendor/github.com/grafana/dskit/services/services.go +++ b/vendor/github.com/grafana/dskit/services/services.go @@ -6,7 +6,7 @@ import ( "time" ) -// Initializes basic service as an "idle" service -- it doesn't do anything in its Running state, +// NewIdleService initializes basic service as an "idle" service -- it doesn't do anything in its Running state, // but still supports all state transitions. func NewIdleService(up StartingFn, down StoppingFn) *BasicService { run := func(ctx context.Context) error { @@ -17,11 +17,11 @@ func NewIdleService(up StartingFn, down StoppingFn) *BasicService { return NewBasicService(up, run, down) } -// One iteration of the timer service. Called repeatedly until service is stopped, or this function returns error +// OneIteration is one iteration of the timer service. Called repeatedly until service is stopped, or this function returns error // in which case, service will fail. type OneIteration func(ctx context.Context) error -// Runs iteration function on every interval tick. When iteration returns error, service fails. +// NewTimerService runs iteration function on every interval tick. When iteration returns error, service fails. func NewTimerService(interval time.Duration, start StartingFn, iter OneIteration, stop StoppingFn) *BasicService { run := func(ctx context.Context) error { t := time.NewTicker(interval) diff --git a/vendor/modules.txt b/vendor/modules.txt index 1bba488aea..3e8c9fc179 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -567,9 +567,10 @@ github.com/gorilla/mux # github.com/gorilla/websocket v1.4.2 ## explicit github.com/gorilla/websocket -# github.com/grafana/dskit v0.0.0-20210819132858-471020752967 +# github.com/grafana/dskit v0.0.0-20210827060659-9daca2f00327 ## explicit github.com/grafana/dskit/backoff +github.com/grafana/dskit/flagext github.com/grafana/dskit/modules github.com/grafana/dskit/services # github.com/grpc-ecosystem/go-grpc-middleware v1.3.0