Use dskit/tenant intead of loki/pkg/tenant. (#5724)

pull/5728/head
Karsten Jeschkies 3 years ago committed by GitHub
parent 9d62f051b8
commit 46956d0bf6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 3
      clients/cmd/fluent-bit/out_grafana_loki.go
  2. 1
      clients/pkg/promtail/server/ui/assets_vfsdata.go
  3. 2
      clients/pkg/promtail/targets/lokipush/pushtarget.go
  4. 3
      cmd/migrate/main.go
  5. 2
      go.mod
  6. 4
      go.sum
  7. 3
      pkg/distributor/distributor.go
  8. 3
      pkg/distributor/http.go
  9. 3
      pkg/ingester/flush.go
  10. 3
      pkg/ingester/flush_test.go
  11. 3
      pkg/ingester/ingester.go
  12. 3
      pkg/ingester/ingester_test.go
  13. 3
      pkg/logql/engine.go
  14. 3
      pkg/loki/modules.go
  15. 3
      pkg/lokifrontend/frontend/transport/handler.go
  16. 3
      pkg/lokifrontend/frontend/v1/frontend.go
  17. 3
      pkg/lokifrontend/frontend/v2/frontend.go
  18. 3
      pkg/querier/http.go
  19. 3
      pkg/querier/multi_tenant_querier.go
  20. 7
      pkg/querier/multi_tenant_querier_test.go
  21. 3
      pkg/querier/querier.go
  22. 3
      pkg/querier/queryrange/limits.go
  23. 3
      pkg/querier/queryrange/log_result_cache.go
  24. 3
      pkg/querier/queryrange/queryrangebase/results_cache.go
  25. 3
      pkg/querier/queryrange/queryrangebase/util.go
  26. 3
      pkg/querier/queryrange/querysharding.go
  27. 3
      pkg/querier/queryrange/roundtrip.go
  28. 3
      pkg/querier/queryrange/split_by_interval.go
  29. 3
      pkg/querier/worker/scheduler_processor.go
  30. 3
      pkg/ruler/base/api.go
  31. 3
      pkg/ruler/base/ruler.go
  32. 3
      pkg/ruler/base/ruler_test.go
  33. 3
      pkg/scheduler/scheduler.go
  34. 3
      pkg/storage/chunk/storage/caching_index_client.go
  35. 3
      pkg/storage/store.go
  36. 3
      pkg/storage/stores/shipper/compactor/deletion/request_handler.go
  37. 3
      pkg/storage/stores/shipper/downloads/index_set.go
  38. 3
      pkg/storage/stores/shipper/downloads/table.go
  39. 3
      pkg/storage/stores/shipper/uploads/table.go
  40. 2
      pkg/util/log/wrappers.go
  41. 20
      pkg/util/spanlogger/spanlogger.go
  42. 33
      vendor/github.com/grafana/dskit/modules/modules.go
  43. 14
      vendor/github.com/grafana/dskit/tenant/resolver.go
  44. 2
      vendor/github.com/grafana/dskit/tenant/tenant.go
  45. 3
      vendor/modules.txt

@ -16,8 +16,9 @@ import (
_ "github.com/grafana/loki/pkg/util/build"
)
import (
"github.com/grafana/loki/clients/pkg/promtail/client"
"github.com/prometheus/client_golang/prometheus"
"github.com/grafana/loki/clients/pkg/promtail/client"
)
var (

@ -1,5 +1,6 @@
// Code generated by vfsgen; DO NOT EDIT.
//go:build !dev
// +build !dev
package ui

@ -19,7 +19,7 @@ import (
promql_parser "github.com/prometheus/prometheus/promql/parser"
"github.com/weaveworks/common/server"
"github.com/grafana/loki/pkg/tenant"
"github.com/grafana/dskit/tenant"
"github.com/grafana/loki/clients/pkg/promtail/api"
"github.com/grafana/loki/clients/pkg/promtail/scrapeconfig"

@ -15,8 +15,9 @@ import (
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/common/model"
"github.com/grafana/dskit/tenant"
"github.com/grafana/loki/pkg/logql/syntax"
"github.com/grafana/loki/pkg/tenant"
"github.com/prometheus/prometheus/model/labels"
"github.com/weaveworks/common/user"

@ -47,7 +47,7 @@ require (
github.com/google/uuid v1.2.0
github.com/gorilla/mux v1.8.0
github.com/gorilla/websocket v1.4.2
github.com/grafana/dskit v0.0.0-20220211095946-19921f863583
github.com/grafana/dskit v0.0.0-20220329084310-1c453c3bd57a
github.com/grafana/regexp v0.0.0-20220304100321-149c8afcd6cb
github.com/grpc-ecosystem/go-grpc-middleware v1.3.0
github.com/grpc-ecosystem/grpc-opentracing v0.0.0-20180507213350-8e809c8a8645

@ -1035,8 +1035,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-20211021180445-3bd016e9d7f1/go.mod h1:uPG2nyK4CtgNDmWv7qyzYcdI+S90kHHRWvHnBtEMBXM=
github.com/grafana/dskit v0.0.0-20220211095946-19921f863583 h1:UCLVGNJptATClAs4CbClVmn5b4YA6GTG3yoCObI//0E=
github.com/grafana/dskit v0.0.0-20220211095946-19921f863583/go.mod h1:q51XdMLLHNZJSG6KOGujC20ed2OoLFdx0hBmOEVfRs0=
github.com/grafana/dskit v0.0.0-20220329084310-1c453c3bd57a h1:UZ2OOtCZl2SbNrvE1BK0+3e35jryMiIuQIVikMfM1IM=
github.com/grafana/dskit v0.0.0-20220329084310-1c453c3bd57a/go.mod h1:q51XdMLLHNZJSG6KOGujC20ed2OoLFdx0hBmOEVfRs0=
github.com/grafana/go-gelf v0.0.0-20211112153804-126646b86de8 h1:aEOagXOTqtN9gd4jiDuP/5a81HdoJBqkVfn8WaxbsK4=
github.com/grafana/go-gelf v0.0.0-20211112153804-126646b86de8/go.mod h1:QAvS2C7TtQRhhv9Uf/sxD+BUhpkrPFm5jK/9MzUiDCY=
github.com/grafana/gocql v0.0.0-20200605141915-ba5dc39ece85 h1:xLuzPoOzdfNb/RF/IENCw+oLVdZB4G21VPhkHBgwSHY=

@ -21,13 +21,14 @@ import (
"go.uber.org/atomic"
"google.golang.org/grpc/health/grpc_health_v1"
"github.com/grafana/dskit/tenant"
"github.com/grafana/loki/pkg/distributor/clientpool"
"github.com/grafana/loki/pkg/ingester/client"
"github.com/grafana/loki/pkg/logproto"
"github.com/grafana/loki/pkg/logql/syntax"
"github.com/grafana/loki/pkg/runtime"
"github.com/grafana/loki/pkg/storage/stores/shipper/compactor/retention"
"github.com/grafana/loki/pkg/tenant"
"github.com/grafana/loki/pkg/usagestats"
"github.com/grafana/loki/pkg/util"
util_log "github.com/grafana/loki/pkg/util/log"

@ -9,8 +9,9 @@ import (
"github.com/grafana/loki/pkg/util"
"github.com/grafana/dskit/tenant"
"github.com/grafana/loki/pkg/loghttp/push"
"github.com/grafana/loki/pkg/tenant"
util_log "github.com/grafana/loki/pkg/util/log"
serverutil "github.com/grafana/loki/pkg/util/server"
"github.com/grafana/loki/pkg/validation"

@ -15,9 +15,10 @@ import (
"github.com/weaveworks/common/user"
"golang.org/x/net/context"
"github.com/grafana/dskit/tenant"
"github.com/grafana/loki/pkg/chunkenc"
"github.com/grafana/loki/pkg/storage/chunk"
"github.com/grafana/loki/pkg/tenant"
"github.com/grafana/loki/pkg/usagestats"
"github.com/grafana/loki/pkg/util"
loki_util "github.com/grafana/loki/pkg/util"

@ -20,6 +20,8 @@ import (
"github.com/weaveworks/common/user"
"golang.org/x/net/context"
"github.com/grafana/dskit/tenant"
"github.com/grafana/loki/pkg/chunkenc"
"github.com/grafana/loki/pkg/ingester/client"
"github.com/grafana/loki/pkg/iter"
@ -29,7 +31,6 @@ import (
"github.com/grafana/loki/pkg/runtime"
"github.com/grafana/loki/pkg/storage"
"github.com/grafana/loki/pkg/storage/chunk"
"github.com/grafana/loki/pkg/tenant"
"github.com/grafana/loki/pkg/validation"
)

@ -20,6 +20,8 @@ import (
"github.com/prometheus/prometheus/model/labels"
"google.golang.org/grpc/health/grpc_health_v1"
"github.com/grafana/dskit/tenant"
"github.com/grafana/loki/pkg/chunkenc"
"github.com/grafana/loki/pkg/ingester/client"
"github.com/grafana/loki/pkg/ingester/index"
@ -32,7 +34,6 @@ import (
"github.com/grafana/loki/pkg/storage"
"github.com/grafana/loki/pkg/storage/chunk"
"github.com/grafana/loki/pkg/storage/stores/shipper"
"github.com/grafana/loki/pkg/tenant"
"github.com/grafana/loki/pkg/usagestats"
"github.com/grafana/loki/pkg/util"
errUtil "github.com/grafana/loki/pkg/util"

@ -24,6 +24,8 @@ import (
"google.golang.org/grpc/metadata"
"google.golang.org/grpc/test/bufconn"
"github.com/grafana/dskit/tenant"
"github.com/grafana/loki/pkg/chunkenc"
"github.com/grafana/loki/pkg/ingester/client"
"github.com/grafana/loki/pkg/ingester/index"
@ -33,7 +35,6 @@ import (
"github.com/grafana/loki/pkg/runtime"
"github.com/grafana/loki/pkg/storage"
"github.com/grafana/loki/pkg/storage/chunk"
"github.com/grafana/loki/pkg/tenant"
"github.com/grafana/loki/pkg/validation"
)

@ -18,12 +18,13 @@ import (
"github.com/prometheus/prometheus/promql"
promql_parser "github.com/prometheus/prometheus/promql/parser"
"github.com/grafana/dskit/tenant"
"github.com/grafana/loki/pkg/iter"
"github.com/grafana/loki/pkg/logproto"
"github.com/grafana/loki/pkg/logql/syntax"
"github.com/grafana/loki/pkg/logqlmodel"
"github.com/grafana/loki/pkg/logqlmodel/stats"
"github.com/grafana/loki/pkg/tenant"
"github.com/grafana/loki/pkg/util"
"github.com/grafana/loki/pkg/util/httpreq"
"github.com/grafana/loki/pkg/util/spanlogger"

@ -10,8 +10,9 @@ import (
"os"
"time"
"github.com/grafana/dskit/tenant"
"github.com/grafana/loki/pkg/storage/stores/shipper/compactor/deletion"
"github.com/grafana/loki/pkg/tenant"
"github.com/NYTimes/gziphandler"
"github.com/go-kit/log"

@ -18,8 +18,9 @@ import (
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promauto"
"github.com/grafana/dskit/tenant"
querier_stats "github.com/grafana/loki/pkg/querier/stats"
"github.com/grafana/loki/pkg/tenant"
"github.com/grafana/loki/pkg/util"
util_log "github.com/grafana/loki/pkg/util/log"
serverutil "github.com/grafana/loki/pkg/util/server"

@ -16,10 +16,11 @@ import (
"github.com/prometheus/client_golang/prometheus/promauto"
"github.com/weaveworks/common/httpgrpc"
"github.com/grafana/dskit/tenant"
"github.com/grafana/loki/pkg/lokifrontend/frontend/v1/frontendv1pb"
"github.com/grafana/loki/pkg/querier/stats"
"github.com/grafana/loki/pkg/scheduler/queue"
"github.com/grafana/loki/pkg/tenant"
"github.com/grafana/loki/pkg/util"
lokigrpc "github.com/grafana/loki/pkg/util/httpgrpc"
"github.com/grafana/loki/pkg/util/validation"

@ -23,9 +23,10 @@ import (
"github.com/weaveworks/common/httpgrpc"
"go.uber.org/atomic"
"github.com/grafana/dskit/tenant"
"github.com/grafana/loki/pkg/lokifrontend/frontend/v2/frontendv2pb"
"github.com/grafana/loki/pkg/querier/stats"
"github.com/grafana/loki/pkg/tenant"
lokigrpc "github.com/grafana/loki/pkg/util/httpgrpc"
util_log "github.com/grafana/loki/pkg/util/log"
)

@ -12,12 +12,13 @@ import (
"github.com/prometheus/prometheus/promql/parser"
"github.com/weaveworks/common/httpgrpc"
"github.com/grafana/dskit/tenant"
"github.com/grafana/loki/pkg/loghttp"
loghttp_legacy "github.com/grafana/loki/pkg/loghttp/legacy"
"github.com/grafana/loki/pkg/logql"
"github.com/grafana/loki/pkg/logql/syntax"
"github.com/grafana/loki/pkg/logqlmodel"
"github.com/grafana/loki/pkg/tenant"
util_log "github.com/grafana/loki/pkg/util/log"
"github.com/grafana/loki/pkg/util/marshal"
marshal_legacy "github.com/grafana/loki/pkg/util/marshal/legacy"

@ -7,10 +7,11 @@ import (
"github.com/prometheus/prometheus/model/labels"
"github.com/weaveworks/common/user"
"github.com/grafana/dskit/tenant"
"github.com/grafana/loki/pkg/iter"
"github.com/grafana/loki/pkg/logql"
"github.com/grafana/loki/pkg/logql/syntax"
"github.com/grafana/loki/pkg/tenant"
)
const (

@ -13,17 +13,16 @@ import (
"github.com/stretchr/testify/require"
"github.com/weaveworks/common/user"
"github.com/grafana/dskit/tenant"
"github.com/grafana/loki/pkg/iter"
"github.com/grafana/loki/pkg/logproto"
"github.com/grafana/loki/pkg/logql"
"github.com/grafana/loki/pkg/logql/syntax"
"github.com/grafana/loki/pkg/tenant"
)
func TestMultiTenantQuerier_SelectLogs(t *testing.T) {
original := tenant.DefaultResolver
tenant.WithDefaultResolver(tenant.NewMultiResolver())
defer tenant.WithDefaultResolver(original)
for _, tc := range []struct {
desc string
@ -82,9 +81,7 @@ func TestMultiTenantQuerier_SelectLogs(t *testing.T) {
}
func TestMultiTenantQuerier_SelectSamples(t *testing.T) {
original := tenant.DefaultResolver
tenant.WithDefaultResolver(tenant.NewMultiResolver())
defer tenant.WithDefaultResolver(original)
for _, tc := range []struct {
desc string

@ -14,12 +14,13 @@ import (
"github.com/weaveworks/common/httpgrpc"
"google.golang.org/grpc/health/grpc_health_v1"
"github.com/grafana/dskit/tenant"
"github.com/grafana/loki/pkg/iter"
"github.com/grafana/loki/pkg/loghttp"
"github.com/grafana/loki/pkg/logproto"
"github.com/grafana/loki/pkg/logql"
"github.com/grafana/loki/pkg/storage"
"github.com/grafana/loki/pkg/tenant"
listutil "github.com/grafana/loki/pkg/util"
"github.com/grafana/loki/pkg/util/spanlogger"
util_validation "github.com/grafana/loki/pkg/util/validation"

@ -13,10 +13,11 @@ import (
"github.com/weaveworks/common/httpgrpc"
"github.com/weaveworks/common/user"
"github.com/grafana/dskit/tenant"
"github.com/grafana/loki/pkg/logproto"
"github.com/grafana/loki/pkg/logql"
"github.com/grafana/loki/pkg/querier/queryrange/queryrangebase"
"github.com/grafana/loki/pkg/tenant"
"github.com/grafana/loki/pkg/util"
"github.com/grafana/loki/pkg/util/spanlogger"
"github.com/grafana/loki/pkg/util/validation"

@ -15,12 +15,13 @@ import (
"github.com/weaveworks/common/httpgrpc"
"golang.org/x/sync/errgroup"
"github.com/grafana/dskit/tenant"
"github.com/grafana/loki/pkg/loghttp"
"github.com/grafana/loki/pkg/logproto"
"github.com/grafana/loki/pkg/logqlmodel/stats"
"github.com/grafana/loki/pkg/querier/queryrange/queryrangebase"
"github.com/grafana/loki/pkg/storage/chunk/cache"
"github.com/grafana/loki/pkg/tenant"
"github.com/grafana/loki/pkg/util/validation"
)

@ -25,9 +25,10 @@ import (
"github.com/uber/jaeger-client-go"
"github.com/weaveworks/common/httpgrpc"
"github.com/grafana/dskit/tenant"
"github.com/grafana/loki/pkg/logproto"
"github.com/grafana/loki/pkg/storage/chunk/cache"
"github.com/grafana/loki/pkg/tenant"
util_log "github.com/grafana/loki/pkg/util/log"
"github.com/grafana/loki/pkg/util/spanlogger"
"github.com/grafana/loki/pkg/util/validation"

@ -6,7 +6,8 @@ import (
"github.com/weaveworks/common/httpgrpc"
"github.com/grafana/loki/pkg/tenant"
"github.com/grafana/dskit/tenant"
"github.com/grafana/loki/pkg/util/validation"
)

@ -12,13 +12,14 @@ import (
"github.com/prometheus/prometheus/promql/parser"
"github.com/weaveworks/common/httpgrpc"
"github.com/grafana/dskit/tenant"
"github.com/grafana/loki/pkg/loghttp"
"github.com/grafana/loki/pkg/logql"
"github.com/grafana/loki/pkg/logqlmodel"
"github.com/grafana/loki/pkg/querier/astmapper"
"github.com/grafana/loki/pkg/querier/queryrange/queryrangebase"
"github.com/grafana/loki/pkg/storage/chunk"
"github.com/grafana/loki/pkg/tenant"
"github.com/grafana/loki/pkg/util"
util_log "github.com/grafana/loki/pkg/util/log"
"github.com/grafana/loki/pkg/util/marshal"

@ -11,12 +11,13 @@ import (
"github.com/prometheus/prometheus/model/labels"
"github.com/weaveworks/common/httpgrpc"
"github.com/grafana/dskit/tenant"
"github.com/grafana/loki/pkg/loghttp"
"github.com/grafana/loki/pkg/logql/syntax"
"github.com/grafana/loki/pkg/querier/queryrange/queryrangebase"
"github.com/grafana/loki/pkg/storage/chunk"
"github.com/grafana/loki/pkg/storage/chunk/cache"
"github.com/grafana/loki/pkg/tenant"
"github.com/grafana/loki/pkg/util/validation"
)

@ -11,10 +11,11 @@ import (
"github.com/prometheus/client_golang/prometheus/promauto"
"github.com/weaveworks/common/httpgrpc"
"github.com/grafana/dskit/tenant"
"github.com/grafana/loki/pkg/logproto"
"github.com/grafana/loki/pkg/logql/syntax"
"github.com/grafana/loki/pkg/querier/queryrange/queryrangebase"
"github.com/grafana/loki/pkg/tenant"
"github.com/grafana/loki/pkg/util"
"github.com/grafana/loki/pkg/util/validation"
)

@ -22,10 +22,11 @@ import (
"google.golang.org/grpc"
"google.golang.org/grpc/health/grpc_health_v1"
"github.com/grafana/dskit/tenant"
"github.com/grafana/loki/pkg/lokifrontend/frontend/v2/frontendv2pb"
querier_stats "github.com/grafana/loki/pkg/querier/stats"
"github.com/grafana/loki/pkg/scheduler/schedulerpb"
"github.com/grafana/loki/pkg/tenant"
util_log "github.com/grafana/loki/pkg/util/log"
)

@ -20,10 +20,11 @@ import (
"github.com/weaveworks/common/user"
"gopkg.in/yaml.v3"
"github.com/grafana/dskit/tenant"
"github.com/grafana/loki/pkg/logproto"
"github.com/grafana/loki/pkg/ruler/rulespb"
"github.com/grafana/loki/pkg/ruler/rulestore"
"github.com/grafana/loki/pkg/tenant"
util_log "github.com/grafana/loki/pkg/util/log"
)

@ -31,10 +31,11 @@ import (
"github.com/weaveworks/common/user"
"golang.org/x/sync/errgroup"
"github.com/grafana/dskit/tenant"
"github.com/grafana/loki/pkg/logproto"
"github.com/grafana/loki/pkg/ruler/rulespb"
"github.com/grafana/loki/pkg/ruler/rulestore"
"github.com/grafana/loki/pkg/tenant"
"github.com/grafana/loki/pkg/util"
util_log "github.com/grafana/loki/pkg/util/log"
"github.com/grafana/loki/pkg/util/validation"

@ -40,6 +40,8 @@ import (
"google.golang.org/grpc"
"gopkg.in/yaml.v2"
"github.com/grafana/dskit/tenant"
"github.com/grafana/loki/pkg/logproto"
"github.com/grafana/loki/pkg/querier/series"
"github.com/grafana/loki/pkg/ruler/rulespb"
@ -48,7 +50,6 @@ import (
"github.com/grafana/loki/pkg/storage/chunk"
"github.com/grafana/loki/pkg/storage/chunk/hedging"
chunk_storage "github.com/grafana/loki/pkg/storage/chunk/storage"
"github.com/grafana/loki/pkg/tenant"
"github.com/grafana/loki/pkg/util"
)

@ -26,10 +26,11 @@ import (
"go.uber.org/atomic"
"google.golang.org/grpc"
"github.com/grafana/dskit/tenant"
"github.com/grafana/loki/pkg/lokifrontend/frontend/v2/frontendv2pb"
"github.com/grafana/loki/pkg/scheduler/queue"
"github.com/grafana/loki/pkg/scheduler/schedulerpb"
"github.com/grafana/loki/pkg/tenant"
"github.com/grafana/loki/pkg/util"
lokiutil "github.com/grafana/loki/pkg/util"
lokigrpc "github.com/grafana/loki/pkg/util/httpgrpc"

@ -11,10 +11,11 @@ import (
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promauto"
"github.com/grafana/dskit/tenant"
"github.com/grafana/loki/pkg/storage/chunk"
"github.com/grafana/loki/pkg/storage/chunk/cache"
chunk_util "github.com/grafana/loki/pkg/storage/chunk/util"
"github.com/grafana/loki/pkg/tenant"
util_log "github.com/grafana/loki/pkg/util/log"
"github.com/grafana/loki/pkg/util/spanlogger"
)

@ -14,6 +14,8 @@ import (
"github.com/prometheus/common/model"
"github.com/prometheus/prometheus/model/labels"
"github.com/grafana/dskit/tenant"
"github.com/grafana/loki/pkg/iter"
"github.com/grafana/loki/pkg/logproto"
"github.com/grafana/loki/pkg/logql"
@ -23,7 +25,6 @@ import (
chunk_local "github.com/grafana/loki/pkg/storage/chunk/local"
"github.com/grafana/loki/pkg/storage/chunk/storage"
"github.com/grafana/loki/pkg/storage/stores/shipper"
"github.com/grafana/loki/pkg/tenant"
"github.com/grafana/loki/pkg/usagestats"
"github.com/grafana/loki/pkg/util"
)

@ -10,7 +10,8 @@ import (
"github.com/prometheus/common/model"
"github.com/prometheus/prometheus/promql/parser"
"github.com/grafana/loki/pkg/tenant"
"github.com/grafana/dskit/tenant"
"github.com/grafana/loki/pkg/util"
util_log "github.com/grafana/loki/pkg/util/log"
serverutil "github.com/grafana/loki/pkg/util/server"

@ -15,12 +15,13 @@ import (
"github.com/grafana/dskit/concurrency"
"go.etcd.io/bbolt"
"github.com/grafana/dskit/tenant"
"github.com/grafana/loki/pkg/storage/chunk"
"github.com/grafana/loki/pkg/storage/chunk/local"
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"
"github.com/grafana/loki/pkg/tenant"
util_log "github.com/grafana/loki/pkg/util/log"
"github.com/grafana/loki/pkg/util/spanlogger"
)

@ -14,10 +14,11 @@ import (
"github.com/pkg/errors"
"go.etcd.io/bbolt"
"github.com/grafana/dskit/tenant"
"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"
"github.com/grafana/loki/pkg/tenant"
util_log "github.com/grafana/loki/pkg/util/log"
"github.com/grafana/loki/pkg/util/spanlogger"
)

@ -16,12 +16,13 @@ import (
"github.com/go-kit/log/level"
"go.etcd.io/bbolt"
"github.com/grafana/dskit/tenant"
"github.com/grafana/loki/pkg/chunkenc"
"github.com/grafana/loki/pkg/storage/chunk"
"github.com/grafana/loki/pkg/storage/chunk/local"
chunk_util "github.com/grafana/loki/pkg/storage/chunk/util"
shipper_util "github.com/grafana/loki/pkg/storage/stores/shipper/util"
"github.com/grafana/loki/pkg/tenant"
util_log "github.com/grafana/loki/pkg/util/log"
)

@ -6,7 +6,7 @@ import (
"github.com/go-kit/log"
"github.com/weaveworks/common/tracing"
"github.com/grafana/loki/pkg/tenant"
"github.com/grafana/dskit/tenant"
)
// WithUserID returns a Logger that has information about the current user in

@ -7,7 +7,8 @@ import (
"github.com/grafana/dskit/spanlogger"
"github.com/opentracing/opentracing-go"
"github.com/grafana/loki/pkg/tenant"
"github.com/grafana/dskit/tenant"
util_log "github.com/grafana/loki/pkg/util/log"
)
@ -18,8 +19,19 @@ const (
TenantIDsTagName = spanlogger.TenantIDsTagName
)
type resolverProxy struct{}
func (r *resolverProxy) TenantID(ctx context.Context) (string, error) {
return tenant.TenantID(ctx)
}
func (r *resolverProxy) TenantIDs(ctx context.Context) ([]string, error) {
return tenant.TenantIDs(ctx)
}
var (
loggerCtxKey = &loggerCtxMarker{}
resolver = &resolverProxy{}
)
// SpanLogger unifies tracing and logging, to reduce repetition.
@ -28,12 +40,12 @@ type SpanLogger = spanlogger.SpanLogger
// New makes a new SpanLogger with a log.Logger to send logs to. The provided context will have the logger attached
// to it and can be retrieved with FromContext.
func New(ctx context.Context, method string, kvps ...interface{}) (*SpanLogger, context.Context) {
return spanlogger.New(ctx, util_log.Logger, method, tenant.DefaultResolver, kvps...)
return spanlogger.New(ctx, util_log.Logger, method, resolver, kvps...)
}
// NewWithLogger is like New but allows to pass a logger.
func NewWithLogger(ctx context.Context, logger log.Logger, method string, kvps ...interface{}) (*SpanLogger, context.Context) {
return spanlogger.New(ctx, logger, method, tenant.DefaultResolver, kvps...)
return spanlogger.New(ctx, logger, method, resolver, kvps...)
}
// FromContext returns a SpanLogger using the current parent span.
@ -41,7 +53,7 @@ func NewWithLogger(ctx context.Context, logger log.Logger, method string, kvps .
// within the context. If the context doesn't have a logger, the fallback
// logger is used.
func FromContext(ctx context.Context) *SpanLogger {
return spanlogger.FromContext(ctx, util_log.Logger, tenant.DefaultResolver)
return spanlogger.FromContext(ctx, util_log.Logger, resolver)
}
// FromContextWithFallback returns a span logger using the current parent span.

@ -59,11 +59,25 @@ func (m *Manager) RegisterModule(name string, initFn func() (services.Service, e
// AddDependency adds a dependency from name(source) to dependsOn(targets)
// An error is returned if the source module name is not found
func (m *Manager) AddDependency(name string, dependsOn ...string) error {
if mod, ok := m.modules[name]; ok {
mod.deps = append(mod.deps, dependsOn...)
} else {
mod, ok := m.modules[name]
if !ok {
return fmt.Errorf("no such module: %s", name)
}
// Ensure it doesn't introduce any circular dependency.
for _, newDep := range dependsOn {
if _, ok := m.modules[newDep]; !ok {
return fmt.Errorf("no such module: %s", newDep)
}
for _, prevDep := range m.DependenciesForModule(newDep) {
if prevDep == name {
return fmt.Errorf("found a circular dependency: %s depends on %s", newDep, name)
}
}
}
mod.deps = append(mod.deps, dependsOn...)
return nil
}
@ -92,7 +106,7 @@ func (m *Manager) initModule(name string, initMap map[string]bool, servicesMap m
deps := m.orderedDeps(name)
deps = append(deps, name) // lastly, initialize the requested module
for ix, n := range deps {
for _, n := range deps {
// Skip already initialized modules
if initMap[n] {
continue
@ -111,7 +125,7 @@ func (m *Manager) initModule(name string, initMap map[string]bool, servicesMap m
if s != nil {
// We pass servicesMap, which isn't yet complete. By the time service starts,
// it will be fully built, so there is no need for extra synchronization.
serv = newModuleServiceWrapper(servicesMap, n, m.logger, s, m.DependenciesForModule(n), m.findInverseDependencies(n, deps[ix+1:]))
serv = newModuleServiceWrapper(servicesMap, n, m.logger, s, m.DependenciesForModule(n), m.inverseDependenciesForModule(n))
}
}
@ -205,12 +219,12 @@ func (m *Manager) orderedDeps(mod string) []string {
return result
}
// find modules in the supplied list, that depend on mod
func (m *Manager) findInverseDependencies(mod string, mods []string) []string {
// inverseDependenciesForModule returns the list of modules depending on the input module, sorted by name.
func (m *Manager) inverseDependenciesForModule(mod string) []string {
result := []string(nil)
for _, n := range mods {
for _, d := range m.modules[n].deps {
for n := range m.modules {
for _, d := range m.DependenciesForModule(n) {
if d == mod {
result = append(result, n)
break
@ -218,6 +232,7 @@ func (m *Manager) findInverseDependencies(mod string, mods []string) []string {
}
}
sort.Strings(result)
return result
}

@ -9,11 +9,11 @@ import (
"github.com/weaveworks/common/user"
)
var DefaultResolver Resolver = NewSingleResolver()
var defaultResolver Resolver = NewSingleResolver()
// WithDefaultResolver updates the resolver used for the package methods.
func WithDefaultResolver(r Resolver) {
DefaultResolver = r
defaultResolver = r
}
// TenantID returns exactly a single tenant ID from the context. It should be
@ -22,9 +22,9 @@ func WithDefaultResolver(r Resolver) {
// supplied or user.ErrTooManyOrgIDs if there are multiple tenant IDs present.
//
// ignore stutter warning
//nolint:golint,revive
//nolint:revive
func TenantID(ctx context.Context) (string, error) {
return DefaultResolver.TenantID(ctx)
return defaultResolver.TenantID(ctx)
}
// TenantIDs returns all tenant IDs from the context. It should return
@ -32,9 +32,9 @@ func TenantID(ctx context.Context) (string, error) {
// NormalizeTenantIDs).
//
// ignore stutter warning
//nolint:golint,revive
//nolint:revive
func TenantIDs(ctx context.Context) ([]string, error) {
return DefaultResolver.TenantIDs(ctx)
return defaultResolver.TenantIDs(ctx)
}
type Resolver interface {
@ -149,7 +149,7 @@ func ExtractTenantIDFromHTTPRequest(req *http.Request) (string, context.Context,
return "", nil, err
}
tenantID, err := DefaultResolver.TenantID(ctx)
tenantID, err := defaultResolver.TenantID(ctx)
if err != nil {
return "", nil, err
}

@ -99,7 +99,7 @@ func isSupported(c rune) bool {
// TenantIDsFromOrgID extracts different tenants from an orgID string value
//
// ignore stutter warning
//nolint:golint,revive
//nolint:revive
func TenantIDsFromOrgID(orgID string) ([]string, error) {
return TenantIDs(user.InjectOrgID(context.TODO(), orgID))
}

@ -518,7 +518,7 @@ github.com/gorilla/mux
# github.com/gorilla/websocket v1.4.2
## explicit; go 1.12
github.com/gorilla/websocket
# github.com/grafana/dskit v0.0.0-20220211095946-19921f863583
# github.com/grafana/dskit v0.0.0-20220329084310-1c453c3bd57a
## explicit; go 1.17
github.com/grafana/dskit/backoff
github.com/grafana/dskit/concurrency
@ -545,6 +545,7 @@ github.com/grafana/dskit/ring/util
github.com/grafana/dskit/runtimeconfig
github.com/grafana/dskit/services
github.com/grafana/dskit/spanlogger
github.com/grafana/dskit/tenant
# github.com/grafana/regexp v0.0.0-20220304100321-149c8afcd6cb
## explicit; go 1.17
github.com/grafana/regexp

Loading…
Cancel
Save