Use flagext from dskit (#4225)

Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com>
pull/4231/head
Arve Knudsen 4 years ago committed by GitHub
parent 034e2a63cf
commit cfb4fc1f55
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      clients/cmd/docker-driver/config.go
  2. 2
      clients/cmd/fluent-bit/config.go
  3. 2
      clients/cmd/fluent-bit/config_test.go
  4. 2
      clients/cmd/promtail/main.go
  5. 16
      clients/pkg/promtail/client/client.go
  6. 9
      clients/pkg/promtail/client/client_test.go
  7. 2
      clients/pkg/promtail/client/config.go
  8. 2
      clients/pkg/promtail/client/config_test.go
  9. 2
      clients/pkg/promtail/client/logger_test.go
  10. 7
      clients/pkg/promtail/client/multi_test.go
  11. 3
      clients/pkg/promtail/config/config.go
  12. 2
      clients/pkg/promtail/promtail_test.go
  13. 2
      clients/pkg/promtail/targets/lokipush/pushtarget_test.go
  14. 2
      cmd/loki/main.go
  15. 2
      go.mod
  16. 4
      go.sum
  17. 2
      pkg/distributor/distributor_test.go
  18. 2
      pkg/distributor/validator_test.go
  19. 2
      pkg/ingester/flush_test.go
  20. 2
      pkg/ingester/ingester_test.go
  21. 1
      pkg/ingester/transfer_test.go
  22. 2
      pkg/loki/loki.go
  23. 2
      pkg/querier/querier_test.go
  24. 11
      pkg/storage/chunk/aws/dynamodb_storage_client.go
  25. 2
      pkg/storage/chunk/aws/s3_storage_client.go
  26. 2
      pkg/storage/chunk/azure/blob_storage_client.go
  27. 5
      pkg/storage/chunk/cache/fifo_cache.go
  28. 2
      pkg/storage/chunk/cache/redis_client.go
  29. 2
      pkg/storage/chunk/cassandra/fixtures.go
  30. 2
      pkg/storage/chunk/cassandra/storage_client.go
  31. 2
      pkg/storage/chunk/cassandra/storage_client_test.go
  32. 2
      pkg/storage/chunk/chunk_store_test.go
  33. 5
      pkg/storage/chunk/purger/purger_test.go
  34. 5
      pkg/storage/chunk/storage/caching_fixtures.go
  35. 5
      pkg/storage/chunk/storage/factory_test.go
  36. 7
      pkg/storage/chunk/testutils/testutils.go
  37. 2
      pkg/storage/store.go
  38. 2
      pkg/storage/store_test.go
  39. 2
      pkg/storage/stores/shipper/compactor/compactor_test.go
  40. 2
      pkg/storage/stores/shipper/gateway_client_test.go
  41. 2
      pkg/util/cfg/cfg.go
  42. 2
      pkg/util/cfg/data_test.go
  43. 2
      pkg/util/cfg/files_test.go
  44. 2
      pkg/util/cfg/flag.go
  45. 82
      vendor/github.com/grafana/dskit/flagext/cidr.go
  46. 59
      vendor/github.com/grafana/dskit/flagext/day.go
  47. 37
      vendor/github.com/grafana/dskit/flagext/deprecated.go
  48. 22
      vendor/github.com/grafana/dskit/flagext/ignored.go
  49. 24
      vendor/github.com/grafana/dskit/flagext/register.go
  50. 34
      vendor/github.com/grafana/dskit/flagext/secret.go
  51. 17
      vendor/github.com/grafana/dskit/flagext/stringslice.go
  52. 33
      vendor/github.com/grafana/dskit/flagext/stringslicecsv.go
  53. 60
      vendor/github.com/grafana/dskit/flagext/time.go
  54. 59
      vendor/github.com/grafana/dskit/flagext/url.go
  55. 4
      vendor/github.com/grafana/dskit/services/basic_service.go
  56. 2
      vendor/github.com/grafana/dskit/services/failure_watcher.go
  57. 26
      vendor/github.com/grafana/dskit/services/manager.go
  58. 23
      vendor/github.com/grafana/dskit/services/service.go
  59. 6
      vendor/github.com/grafana/dskit/services/services.go
  60. 3
      vendor/modules.txt

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

@ -10,7 +10,7 @@ import (
"testing"
"time"
"github.com/cortexproject/cortex/pkg/util/flagext"
"github.com/grafana/dskit/flagext"
"github.com/stretchr/testify/require"

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

@ -5,7 +5,7 @@ import (
"os"
"reflect"
"github.com/cortexproject/cortex/pkg/util/flagext"
"github.com/grafana/dskit/flagext"
"github.com/pkg/errors"
)

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

@ -4,7 +4,7 @@ import (
"flag"
"testing"
"github.com/cortexproject/cortex/pkg/util/flagext"
"github.com/grafana/dskit/flagext"
"github.com/stretchr/testify/require"
)

@ -7,7 +7,7 @@ import (
"sort"
"strings"
"github.com/cortexproject/cortex/pkg/util/flagext"
"github.com/grafana/dskit/flagext"
"github.com/pkg/errors"
)

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Loading…
Cancel
Save