From ba5ea44d7b68dfe06c389ba45daa91635421b291 Mon Sep 17 00:00:00 2001 From: Arve Knudsen Date: Wed, 19 Jan 2022 17:15:50 +0100 Subject: [PATCH 1/3] Chore: Add pkg/util/log package Signed-off-by: Arve Knudsen --- clients/cmd/docker-driver/config_test.go | 3 +- clients/cmd/docker-driver/loki_test.go | 3 +- clients/cmd/docker-driver/main.go | 2 +- clients/cmd/promtail/main.go | 12 +- clients/pkg/logentry/stages/drop_test.go | 5 +- .../pkg/logentry/stages/extensions_test.go | 3 +- clients/pkg/logentry/stages/json_test.go | 3 +- .../pkg/logentry/stages/labelallow_test.go | 5 +- clients/pkg/logentry/stages/labeldrop_test.go | 5 +- clients/pkg/logentry/stages/labels_test.go | 3 +- clients/pkg/logentry/stages/logfmt_test.go | 3 +- clients/pkg/logentry/stages/match_test.go | 3 +- clients/pkg/logentry/stages/metrics_test.go | 3 +- clients/pkg/logentry/stages/multiline_test.go | 8 +- clients/pkg/logentry/stages/output_test.go | 3 +- clients/pkg/logentry/stages/pack_test.go | 4 +- clients/pkg/logentry/stages/pipeline_test.go | 2 +- clients/pkg/logentry/stages/regex_test.go | 3 +- clients/pkg/logentry/stages/replace_test.go | 3 +- .../pkg/logentry/stages/static_labels_test.go | 3 +- clients/pkg/logentry/stages/template_test.go | 3 +- clients/pkg/logentry/stages/tenant_test.go | 2 +- clients/pkg/logentry/stages/timestamp_test.go | 2 +- clients/pkg/promtail/client/logger_test.go | 2 +- clients/pkg/promtail/client/multi_test.go | 8 +- .../pkg/promtail/positions/positions_test.go | 3 +- clients/pkg/promtail/promtail.go | 5 +- clients/pkg/promtail/promtail_test.go | 10 +- .../promtail/targets/lokipush/pushtarget.go | 11 +- .../targets/lokipush/pushtarget_test.go | 4 +- .../targets/lokipush/pushtargetmanager.go | 2 +- .../stdin/stdin_target_manager_test.go | 2 +- .../pkg/promtail/targets/windows/target.go | 3 +- .../promtail/targets/windows/target_test.go | 4 +- .../windows/win_eventlog/win_eventlog.go | 3 +- cmd/loki/main.go | 16 +-- cmd/migrate/main.go | 2 +- cmd/querytee/main.go | 4 +- cmd/querytee/response_comparator.go | 2 +- pkg/chunkenc/memchunk.go | 5 +- pkg/distributor/distributor.go | 2 +- pkg/distributor/distributor_ring.go | 2 +- pkg/distributor/http.go | 2 +- pkg/ingester/checkpoint.go | 2 +- pkg/ingester/flush.go | 8 +- pkg/ingester/flush_test.go | 3 +- pkg/ingester/ingester.go | 5 +- pkg/ingester/ingester_test.go | 3 +- pkg/ingester/instance.go | 5 +- pkg/ingester/mapper.go | 6 +- pkg/ingester/recovery.go | 2 +- pkg/ingester/replay_controller.go | 3 +- pkg/ingester/stream.go | 2 +- pkg/ingester/tailer.go | 2 +- pkg/ingester/transfer.go | 2 +- pkg/ingester/transfer_test.go | 2 +- pkg/ingester/wal.go | 2 +- pkg/logcli/client/file.go | 3 +- pkg/logcli/query/query.go | 4 +- pkg/logcli/query/query_test.go | 65 +++++----- pkg/loghttp/push/push_test.go | 3 +- pkg/logql/engine.go | 16 ++- pkg/logql/engine_test.go | 15 +-- pkg/logql/metrics.go | 2 +- pkg/logql/metrics_test.go | 2 +- pkg/logql/sharding.go | 8 +- pkg/logql/sharding_test.go | 5 +- pkg/logql/shardmapper.go | 2 +- pkg/logqlmodel/stats/context_test.go | 3 +- pkg/loki/loki.go | 2 +- pkg/loki/modules.go | 9 +- pkg/loki/runtime_config.go | 2 +- .../frontend/transport/handler.go | 2 +- pkg/querier/astmapper/parallel.go | 2 +- pkg/querier/http.go | 5 +- pkg/querier/ingester_querier.go | 2 +- pkg/querier/querier.go | 11 +- pkg/querier/queryrange/limits_test.go | 2 +- .../queryrangebase/results_cache.go | 2 +- .../queryrange/queryrangebase/retry.go | 2 +- pkg/querier/queryrange/querysharding.go | 5 +- pkg/querier/queryrange/roundtrip_test.go | 2 +- pkg/querier/tail.go | 2 +- pkg/querier/worker/scheduler_processor.go | 2 +- pkg/querier/worker_service.go | 2 +- pkg/ruler/base/api.go | 2 +- pkg/ruler/base/compat.go | 2 +- pkg/ruler/base/ruler.go | 9 +- pkg/ruler/compat_test.go | 3 +- pkg/ruler/storage/instance/manager.go | 3 +- pkg/scheduler/scheduler.go | 3 +- pkg/scheduler/scheduler_test.go | 6 +- pkg/storage/async_store.go | 2 +- pkg/storage/batch.go | 2 +- .../chunk/aws/dynamodb_storage_client.go | 2 +- .../chunk/aws/dynamodb_table_client.go | 2 +- pkg/storage/chunk/aws/metrics_autoscaling.go | 3 +- pkg/storage/chunk/aws/mock.go | 2 +- .../chunk/azure/blob_storage_client.go | 11 +- pkg/storage/chunk/cache/background.go | 3 +- pkg/storage/chunk/cache/fifo_cache.go | 5 +- pkg/storage/chunk/cache/memcached.go | 3 +- pkg/storage/chunk/cache/memcached_client.go | 4 +- pkg/storage/chunk/cache/redis_cache.go | 4 +- pkg/storage/chunk/cassandra/storage_client.go | 5 +- pkg/storage/chunk/chunk_store.go | 7 +- pkg/storage/chunk/chunk_store_utils.go | 6 +- pkg/storage/chunk/inmemory_storage_client.go | 2 +- .../chunk/local/boltdb_index_client.go | 3 +- pkg/storage/chunk/local/fs_object_client.go | 3 +- .../chunk/openstack/swift_object_client.go | 4 +- pkg/storage/chunk/schema.go | 3 +- pkg/storage/chunk/schema_config.go | 3 +- pkg/storage/chunk/series_store.go | 2 +- .../chunk/storage/caching_index_client.go | 6 +- pkg/storage/chunk/storage/factory.go | 3 +- pkg/storage/chunk/table_manager.go | 2 +- pkg/storage/hack/main.go | 5 +- pkg/storage/lazy_chunk.go | 2 +- pkg/storage/store_test.go | 3 +- .../stores/shipper/compactor/compactor.go | 2 +- .../deletion/delete_requests_manager.go | 3 +- .../deletion/delete_requests_table.go | 3 +- .../compactor/deletion/request_handler.go | 2 +- .../stores/shipper/compactor/index_set.go | 3 +- .../shipper/compactor/retention/expiration.go | 3 +- .../shipper/compactor/retention/index.go | 5 +- .../shipper/compactor/retention/marker.go | 2 +- .../shipper/compactor/retention/retention.go | 2 +- .../shipper/compactor/retention/util_test.go | 4 +- pkg/storage/stores/shipper/compactor/table.go | 3 +- .../stores/shipper/downloads/index_set.go | 2 +- .../shipper/downloads/index_set_test.go | 3 +- pkg/storage/stores/shipper/downloads/table.go | 5 +- .../stores/shipper/downloads/table_manager.go | 3 +- .../stores/shipper/downloads/table_test.go | 3 +- pkg/storage/stores/shipper/gateway_client.go | 2 +- .../stores/shipper/shipper_index_client.go | 2 +- .../stores/shipper/storage/cached_client.go | 3 +- pkg/storage/stores/shipper/uploads/table.go | 2 +- .../stores/shipper/uploads/table_manager.go | 2 +- pkg/storage/stores/shipper/util/util.go | 2 +- pkg/storage/stores/shipper/util/util_test.go | 3 +- pkg/storage/util_test.go | 3 +- pkg/util/config.go | 3 +- pkg/util/errors.go | 3 +- pkg/util/log/experimental.go | 22 ++++ pkg/util/log/log.go | 119 ++++++++++++++++++ pkg/util/log/wrappers.go | 39 ++++++ pkg/util/ring_config.go | 4 +- pkg/util/spanlogger/spanlogger.go | 3 +- tools/querytee/instrumentation.go | 2 +- tools/querytee/proxy_endpoint.go | 2 +- tools/querytee/response_comparator.go | 2 +- 154 files changed, 494 insertions(+), 309 deletions(-) create mode 100644 pkg/util/log/experimental.go create mode 100644 pkg/util/log/log.go create mode 100644 pkg/util/log/wrappers.go diff --git a/clients/cmd/docker-driver/config_test.go b/clients/cmd/docker-driver/config_test.go index 54b02cc6789ad..289274ef3ec98 100644 --- a/clients/cmd/docker-driver/config_test.go +++ b/clients/cmd/docker-driver/config_test.go @@ -7,13 +7,14 @@ import ( "reflect" "testing" - util_log "github.com/cortexproject/cortex/pkg/util/log" "github.com/docker/docker/daemon/logger" "github.com/prometheus/client_golang/prometheus" "github.com/prometheus/common/model" "github.com/stretchr/testify/require" "github.com/grafana/loki/clients/pkg/logentry/stages" + + util_log "github.com/grafana/loki/pkg/util/log" ) var jobRename = ` diff --git a/clients/cmd/docker-driver/loki_test.go b/clients/cmd/docker-driver/loki_test.go index 85fe1cefc8338..0edc7b0c76931 100644 --- a/clients/cmd/docker-driver/loki_test.go +++ b/clients/cmd/docker-driver/loki_test.go @@ -4,9 +4,10 @@ import ( "testing" "time" - util_log "github.com/cortexproject/cortex/pkg/util/log" "github.com/docker/docker/daemon/logger" "github.com/stretchr/testify/require" + + util_log "github.com/grafana/loki/pkg/util/log" ) func Test_loki_LogWhenClosed(t *testing.T) { diff --git a/clients/cmd/docker-driver/main.go b/clients/cmd/docker-driver/main.go index e5c7879121d7e..b2dbf52a18ef7 100644 --- a/clients/cmd/docker-driver/main.go +++ b/clients/cmd/docker-driver/main.go @@ -6,7 +6,6 @@ import ( _ "net/http/pprof" "os" - util_log "github.com/cortexproject/cortex/pkg/util/log" "github.com/docker/go-plugins-helpers/sdk" "github.com/go-kit/log" "github.com/go-kit/log/level" @@ -15,6 +14,7 @@ import ( "github.com/grafana/loki/pkg/util" _ "github.com/grafana/loki/pkg/util/build" + util_log "github.com/grafana/loki/pkg/util/log" ) const socketAddress = "/run/docker/plugins/loki.sock" diff --git a/clients/cmd/promtail/main.go b/clients/cmd/promtail/main.go index 274ac0a0e65b4..f75c9506f0c49 100644 --- a/clients/cmd/promtail/main.go +++ b/clients/cmd/promtail/main.go @@ -11,7 +11,6 @@ import ( "k8s.io/klog" - util_log "github.com/cortexproject/cortex/pkg/util/log" "github.com/go-kit/log/level" "github.com/grafana/dskit/flagext" "github.com/prometheus/client_golang/prometheus" @@ -22,9 +21,10 @@ import ( "github.com/grafana/loki/clients/pkg/promtail" "github.com/grafana/loki/clients/pkg/promtail/config" - logutil "github.com/grafana/loki/pkg/util" + "github.com/grafana/loki/pkg/util" _ "github.com/grafana/loki/pkg/util/build" "github.com/grafana/loki/pkg/util/cfg" + util_log "github.com/grafana/loki/pkg/util/log" ) func init() { @@ -81,7 +81,7 @@ func main() { fmt.Println("Invalid log level") os.Exit(1) } - util_log.InitLogger(&config.ServerConfig.Config) + util_log.InitLogger(&config.ServerConfig.Config, prometheus.DefaultRegisterer) // Use Stderr instead of files for the klog. klog.SetOutput(os.Stderr) @@ -97,20 +97,20 @@ func main() { } if config.printConfig { - err := logutil.PrintConfig(os.Stderr, &config) + err := util.PrintConfig(os.Stderr, &config) if err != nil { level.Error(util_log.Logger).Log("msg", "failed to print config to stderr", "err", err.Error()) } } if config.logConfig { - err := logutil.LogConfig(&config) + err := util.LogConfig(&config) if err != nil { level.Error(util_log.Logger).Log("msg", "failed to log config object", "err", err.Error()) } } - p, err := promtail.New(config.Config, config.dryRun) + p, err := promtail.New(config.Config, config.dryRun, prometheus.DefaultRegisterer) if err != nil { level.Error(util_log.Logger).Log("msg", "error creating promtail", "error", err) os.Exit(1) diff --git a/clients/pkg/logentry/stages/drop_test.go b/clients/pkg/logentry/stages/drop_test.go index 5e2f3b9e4649d..d7a76b4fe6c3d 100644 --- a/clients/pkg/logentry/stages/drop_test.go +++ b/clients/pkg/logentry/stages/drop_test.go @@ -6,12 +6,13 @@ import ( "testing" "time" - util_log "github.com/cortexproject/cortex/pkg/util/log" "github.com/prometheus/client_golang/prometheus" "github.com/prometheus/common/model" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ww "github.com/weaveworks/common/server" + + util_log "github.com/grafana/loki/pkg/util/log" ) // Not all these are tested but are here to make sure the different types marshal without error @@ -39,7 +40,7 @@ func Test_dropStage_Process(t *testing.T) { // Enable debug logging cfg := &ww.Config{} require.Nil(t, cfg.LogLevel.Set("debug")) - util_log.InitLogger(cfg) + util_log.InitLogger(cfg, nil) Debug = true tests := []struct { diff --git a/clients/pkg/logentry/stages/extensions_test.go b/clients/pkg/logentry/stages/extensions_test.go index b9d66b0b3d9c2..9899a5660b47a 100644 --- a/clients/pkg/logentry/stages/extensions_test.go +++ b/clients/pkg/logentry/stages/extensions_test.go @@ -4,9 +4,10 @@ import ( "testing" "time" - util_log "github.com/cortexproject/cortex/pkg/util/log" "github.com/prometheus/client_golang/prometheus" "github.com/stretchr/testify/assert" + + util_log "github.com/grafana/loki/pkg/util/log" ) var ( diff --git a/clients/pkg/logentry/stages/json_test.go b/clients/pkg/logentry/stages/json_test.go index 0b8144dfc5376..fe941b3f1a41e 100644 --- a/clients/pkg/logentry/stages/json_test.go +++ b/clients/pkg/logentry/stages/json_test.go @@ -5,11 +5,12 @@ import ( "testing" "time" - util_log "github.com/cortexproject/cortex/pkg/util/log" "github.com/pkg/errors" "github.com/prometheus/client_golang/prometheus" "github.com/stretchr/testify/assert" "gopkg.in/yaml.v2" + + util_log "github.com/grafana/loki/pkg/util/log" ) var testJSONYamlSingleStageWithoutSource = ` diff --git a/clients/pkg/logentry/stages/labelallow_test.go b/clients/pkg/logentry/stages/labelallow_test.go index 2c982db295445..231d39063f0a8 100644 --- a/clients/pkg/logentry/stages/labelallow_test.go +++ b/clients/pkg/logentry/stages/labelallow_test.go @@ -4,18 +4,19 @@ import ( "testing" "time" - util_log "github.com/cortexproject/cortex/pkg/util/log" "github.com/prometheus/common/model" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ww "github.com/weaveworks/common/server" + + util_log "github.com/grafana/loki/pkg/util/log" ) func Test_addLabelStage_Process(t *testing.T) { // Enable debug logging cfg := &ww.Config{} require.Nil(t, cfg.LogLevel.Set("debug")) - util_log.InitLogger(cfg) + util_log.InitLogger(cfg, nil) Debug = true tests := []struct { diff --git a/clients/pkg/logentry/stages/labeldrop_test.go b/clients/pkg/logentry/stages/labeldrop_test.go index 5111cc34108fb..5448feae24d79 100644 --- a/clients/pkg/logentry/stages/labeldrop_test.go +++ b/clients/pkg/logentry/stages/labeldrop_test.go @@ -4,18 +4,19 @@ import ( "testing" "time" - util_log "github.com/cortexproject/cortex/pkg/util/log" "github.com/prometheus/common/model" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ww "github.com/weaveworks/common/server" + + util_log "github.com/grafana/loki/pkg/util/log" ) func Test_dropLabelStage_Process(t *testing.T) { // Enable debug logging cfg := &ww.Config{} require.Nil(t, cfg.LogLevel.Set("debug")) - util_log.InitLogger(cfg) + util_log.InitLogger(cfg, nil) Debug = true tests := []struct { diff --git a/clients/pkg/logentry/stages/labels_test.go b/clients/pkg/logentry/stages/labels_test.go index aec786b733b53..175359606a2f4 100644 --- a/clients/pkg/logentry/stages/labels_test.go +++ b/clients/pkg/logentry/stages/labels_test.go @@ -8,11 +8,12 @@ import ( "testing" "time" - util_log "github.com/cortexproject/cortex/pkg/util/log" "github.com/go-kit/log" "github.com/prometheus/client_golang/prometheus" "github.com/prometheus/common/model" "github.com/stretchr/testify/assert" + + util_log "github.com/grafana/loki/pkg/util/log" ) var testLabelsYaml = ` diff --git a/clients/pkg/logentry/stages/logfmt_test.go b/clients/pkg/logentry/stages/logfmt_test.go index a4b2edf78b091..8258eeece501b 100644 --- a/clients/pkg/logentry/stages/logfmt_test.go +++ b/clients/pkg/logentry/stages/logfmt_test.go @@ -4,11 +4,12 @@ import ( "testing" "time" - util_log "github.com/cortexproject/cortex/pkg/util/log" "github.com/pkg/errors" "github.com/prometheus/client_golang/prometheus" "github.com/stretchr/testify/assert" "gopkg.in/yaml.v2" + + util_log "github.com/grafana/loki/pkg/util/log" ) var testLogfmtYamlSingleStageWithoutSource = ` diff --git a/clients/pkg/logentry/stages/match_test.go b/clients/pkg/logentry/stages/match_test.go index 80eac40612549..ebaf7d5a9f43a 100644 --- a/clients/pkg/logentry/stages/match_test.go +++ b/clients/pkg/logentry/stages/match_test.go @@ -5,9 +5,10 @@ import ( "testing" "time" - util_log "github.com/cortexproject/cortex/pkg/util/log" "github.com/prometheus/client_golang/prometheus" "github.com/stretchr/testify/assert" + + util_log "github.com/grafana/loki/pkg/util/log" ) var testMatchYaml = ` diff --git a/clients/pkg/logentry/stages/metrics_test.go b/clients/pkg/logentry/stages/metrics_test.go index 38d989b5ff15c..c5ed7915273e8 100644 --- a/clients/pkg/logentry/stages/metrics_test.go +++ b/clients/pkg/logentry/stages/metrics_test.go @@ -6,7 +6,6 @@ import ( "testing" "time" - util_log "github.com/cortexproject/cortex/pkg/util/log" "github.com/go-kit/log" "github.com/pkg/errors" "github.com/prometheus/client_golang/prometheus" @@ -15,6 +14,8 @@ import ( "github.com/stretchr/testify/assert" "github.com/grafana/loki/clients/pkg/logentry/metric" + + util_log "github.com/grafana/loki/pkg/util/log" ) var testMetricYaml = ` diff --git a/clients/pkg/logentry/stages/multiline_test.go b/clients/pkg/logentry/stages/multiline_test.go index fbbd4eca647cc..847c99c3ea84f 100644 --- a/clients/pkg/logentry/stages/multiline_test.go +++ b/clients/pkg/logentry/stages/multiline_test.go @@ -6,7 +6,6 @@ import ( "testing" "time" - util_log "github.com/cortexproject/cortex/pkg/util/log" "github.com/prometheus/common/model" "github.com/stretchr/testify/require" ww "github.com/weaveworks/common/server" @@ -14,13 +13,14 @@ import ( "github.com/grafana/loki/clients/pkg/promtail/api" "github.com/grafana/loki/pkg/logproto" + util_log "github.com/grafana/loki/pkg/util/log" ) func Test_multilineStage_Process(t *testing.T) { // Enable debug logging cfg := &ww.Config{} require.Nil(t, cfg.LogLevel.Set("debug")) - util_log.InitLogger(cfg) + util_log.InitLogger(cfg, nil) Debug = true mcfg := &MultilineConfig{Expression: ptrFromString("^START"), MaxWaitTime: ptrFromString("3s")} @@ -52,7 +52,7 @@ func Test_multilineStage_MultiStreams(t *testing.T) { // Enable debug logging cfg := &ww.Config{} require.Nil(t, cfg.LogLevel.Set("debug")) - util_log.InitLogger(cfg) + util_log.InitLogger(cfg, nil) Debug = true mcfg := &MultilineConfig{Expression: ptrFromString("^START"), MaxWaitTime: ptrFromString("3s")} @@ -97,7 +97,7 @@ func Test_multilineStage_MaxWaitTime(t *testing.T) { // Enable debug logging cfg := &ww.Config{} require.Nil(t, cfg.LogLevel.Set("debug")) - util_log.InitLogger(cfg) + util_log.InitLogger(cfg, nil) Debug = true maxWait := 2 * time.Second diff --git a/clients/pkg/logentry/stages/output_test.go b/clients/pkg/logentry/stages/output_test.go index 9407dd1909efb..a7b02714faf74 100644 --- a/clients/pkg/logentry/stages/output_test.go +++ b/clients/pkg/logentry/stages/output_test.go @@ -6,11 +6,12 @@ import ( "testing" "time" - util_log "github.com/cortexproject/cortex/pkg/util/log" "github.com/go-kit/log" "github.com/pkg/errors" "github.com/prometheus/client_golang/prometheus" "github.com/stretchr/testify/assert" + + util_log "github.com/grafana/loki/pkg/util/log" ) var testOutputYaml = ` diff --git a/clients/pkg/logentry/stages/pack_test.go b/clients/pkg/logentry/stages/pack_test.go index 3ea3cc86fe189..938455f339426 100644 --- a/clients/pkg/logentry/stages/pack_test.go +++ b/clients/pkg/logentry/stages/pack_test.go @@ -4,7 +4,6 @@ import ( "testing" "time" - util_log "github.com/cortexproject/cortex/pkg/util/log" json "github.com/json-iterator/go" "github.com/prometheus/client_golang/prometheus" "github.com/prometheus/common/model" @@ -16,6 +15,7 @@ import ( "github.com/grafana/loki/pkg/logproto" "github.com/grafana/loki/pkg/logqlmodel" + util_log "github.com/grafana/loki/pkg/util/log" ) // Not all these are tested but are here to make sure the different types marshal without error @@ -105,7 +105,7 @@ func Test_packStage_Run(t *testing.T) { // Enable debug logging cfg := &ww.Config{} require.Nil(t, cfg.LogLevel.Set("debug")) - util_log.InitLogger(cfg) + util_log.InitLogger(cfg, nil) Debug = true tests := []struct { diff --git a/clients/pkg/logentry/stages/pipeline_test.go b/clients/pkg/logentry/stages/pipeline_test.go index 9071f7374c3e4..d9b900375bcc8 100644 --- a/clients/pkg/logentry/stages/pipeline_test.go +++ b/clients/pkg/logentry/stages/pipeline_test.go @@ -6,7 +6,6 @@ import ( "testing" "time" - util_log "github.com/cortexproject/cortex/pkg/util/log" "github.com/go-kit/log" "github.com/go-kit/log/level" "github.com/prometheus/client_golang/prometheus" @@ -19,6 +18,7 @@ import ( "github.com/grafana/loki/clients/pkg/promtail/client/fake" "github.com/grafana/loki/pkg/logproto" + util_log "github.com/grafana/loki/pkg/util/log" ) var ( diff --git a/clients/pkg/logentry/stages/regex_test.go b/clients/pkg/logentry/stages/regex_test.go index 686aca3eded11..115a51e8714a5 100644 --- a/clients/pkg/logentry/stages/regex_test.go +++ b/clients/pkg/logentry/stages/regex_test.go @@ -7,13 +7,14 @@ import ( "testing" "time" - util_log "github.com/cortexproject/cortex/pkg/util/log" "github.com/go-kit/log" "github.com/pkg/errors" "github.com/prometheus/client_golang/prometheus" "github.com/prometheus/common/model" "github.com/stretchr/testify/assert" "gopkg.in/yaml.v2" + + util_log "github.com/grafana/loki/pkg/util/log" ) var testRegexYamlSingleStageWithoutSource = ` diff --git a/clients/pkg/logentry/stages/replace_test.go b/clients/pkg/logentry/stages/replace_test.go index 0b44ca042d9f3..f8feef3c898df 100644 --- a/clients/pkg/logentry/stages/replace_test.go +++ b/clients/pkg/logentry/stages/replace_test.go @@ -5,11 +5,12 @@ import ( "testing" "time" - util_log "github.com/cortexproject/cortex/pkg/util/log" "github.com/pkg/errors" "github.com/prometheus/client_golang/prometheus" "github.com/stretchr/testify/assert" "gopkg.in/yaml.v2" + + util_log "github.com/grafana/loki/pkg/util/log" ) var testReplaceYamlSingleStageWithoutSource = ` diff --git a/clients/pkg/logentry/stages/static_labels_test.go b/clients/pkg/logentry/stages/static_labels_test.go index 8bd00564c7a75..9643d3da7aa51 100644 --- a/clients/pkg/logentry/stages/static_labels_test.go +++ b/clients/pkg/logentry/stages/static_labels_test.go @@ -4,9 +4,10 @@ import ( "testing" "time" - util_log "github.com/cortexproject/cortex/pkg/util/log" "github.com/prometheus/common/model" "github.com/stretchr/testify/assert" + + util_log "github.com/grafana/loki/pkg/util/log" ) func Test_staticLabelStage_Process(t *testing.T) { diff --git a/clients/pkg/logentry/stages/template_test.go b/clients/pkg/logentry/stages/template_test.go index d1e227efebf54..96e7f1b06a2df 100644 --- a/clients/pkg/logentry/stages/template_test.go +++ b/clients/pkg/logentry/stages/template_test.go @@ -7,11 +7,12 @@ import ( "testing" "time" - util_log "github.com/cortexproject/cortex/pkg/util/log" "github.com/go-kit/log" "github.com/prometheus/client_golang/prometheus" "github.com/prometheus/common/model" "github.com/stretchr/testify/assert" + + util_log "github.com/grafana/loki/pkg/util/log" ) var testTemplateYaml = ` diff --git a/clients/pkg/logentry/stages/tenant_test.go b/clients/pkg/logentry/stages/tenant_test.go index 6ee419737b62d..5824922e916ac 100644 --- a/clients/pkg/logentry/stages/tenant_test.go +++ b/clients/pkg/logentry/stages/tenant_test.go @@ -6,7 +6,6 @@ import ( "testing" "time" - util_log "github.com/cortexproject/cortex/pkg/util/log" "github.com/go-kit/log" "github.com/prometheus/client_golang/prometheus" "github.com/prometheus/common/model" @@ -16,6 +15,7 @@ import ( "github.com/grafana/loki/clients/pkg/promtail/client" lokiutil "github.com/grafana/loki/pkg/util" + util_log "github.com/grafana/loki/pkg/util/log" ) var testTenantYaml = ` diff --git a/clients/pkg/logentry/stages/timestamp_test.go b/clients/pkg/logentry/stages/timestamp_test.go index dc5013919a50c..73e4fb196b5b5 100644 --- a/clients/pkg/logentry/stages/timestamp_test.go +++ b/clients/pkg/logentry/stages/timestamp_test.go @@ -7,7 +7,6 @@ import ( "testing" "time" - util_log "github.com/cortexproject/cortex/pkg/util/log" "github.com/go-kit/log" "github.com/pkg/errors" "github.com/prometheus/client_golang/prometheus" @@ -16,6 +15,7 @@ import ( "github.com/stretchr/testify/require" lokiutil "github.com/grafana/loki/pkg/util" + util_log "github.com/grafana/loki/pkg/util/log" ) var testTimestampYaml = ` diff --git a/clients/pkg/promtail/client/logger_test.go b/clients/pkg/promtail/client/logger_test.go index f76825851a002..469c04b580f09 100644 --- a/clients/pkg/promtail/client/logger_test.go +++ b/clients/pkg/promtail/client/logger_test.go @@ -5,7 +5,6 @@ import ( "testing" "time" - 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" @@ -13,6 +12,7 @@ import ( "github.com/grafana/loki/clients/pkg/promtail/api" "github.com/grafana/loki/pkg/logproto" + util_log "github.com/grafana/loki/pkg/util/log" ) func TestNewLogger(t *testing.T) { diff --git a/clients/pkg/promtail/client/multi_test.go b/clients/pkg/promtail/client/multi_test.go index 92a07f39c96c7..73128318852e2 100644 --- a/clients/pkg/promtail/client/multi_test.go +++ b/clients/pkg/promtail/client/multi_test.go @@ -6,7 +6,6 @@ import ( "testing" "time" - util_log "github.com/cortexproject/cortex/pkg/util/log" "github.com/go-kit/log" "github.com/grafana/dskit/backoff" "github.com/grafana/dskit/flagext" @@ -14,11 +13,12 @@ import ( "github.com/prometheus/common/model" "github.com/stretchr/testify/require" - "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" + + "github.com/grafana/loki/pkg/logproto" + lokiflag "github.com/grafana/loki/pkg/util/flagext" + util_log "github.com/grafana/loki/pkg/util/log" ) func TestNewMulti(t *testing.T) { diff --git a/clients/pkg/promtail/positions/positions_test.go b/clients/pkg/promtail/positions/positions_test.go index 5b021f9e28826..64b30669b8a4f 100644 --- a/clients/pkg/promtail/positions/positions_test.go +++ b/clients/pkg/promtail/positions/positions_test.go @@ -7,9 +7,10 @@ import ( "testing" "time" - util_log "github.com/cortexproject/cortex/pkg/util/log" "github.com/go-kit/log" "github.com/stretchr/testify/require" + + util_log "github.com/grafana/loki/pkg/util/log" ) func tempFilename(t *testing.T) string { diff --git a/clients/pkg/promtail/promtail.go b/clients/pkg/promtail/promtail.go index b8f285af465c5..3d83b0a745b12 100644 --- a/clients/pkg/promtail/promtail.go +++ b/clients/pkg/promtail/promtail.go @@ -3,7 +3,6 @@ package promtail import ( "sync" - util_log "github.com/cortexproject/cortex/pkg/util/log" "github.com/go-kit/log" "github.com/grafana/loki/clients/pkg/logentry/stages" "github.com/prometheus/client_golang/prometheus" @@ -12,6 +11,8 @@ import ( "github.com/grafana/loki/clients/pkg/promtail/config" "github.com/grafana/loki/clients/pkg/promtail/server" "github.com/grafana/loki/clients/pkg/promtail/targets" + + util_log "github.com/grafana/loki/pkg/util/log" ) // Option is a function that can be passed to the New method of Promtail and @@ -45,7 +46,7 @@ type Promtail struct { } // New makes a new Promtail. -func New(cfg config.Config, dryRun bool, opts ...Option) (*Promtail, error) { +func New(cfg config.Config, dryRun bool, reg prometheus.Registerer, opts ...Option) (*Promtail, error) { // Initialize promtail with some defaults and allow the options to override // them. promtail := &Promtail{ diff --git a/clients/pkg/promtail/promtail_test.go b/clients/pkg/promtail/promtail_test.go index a08dd6e4a20e6..52706f5e94bd5 100644 --- a/clients/pkg/promtail/promtail_test.go +++ b/clients/pkg/promtail/promtail_test.go @@ -16,7 +16,6 @@ import ( "time" "github.com/cortexproject/cortex/pkg/util" - util_log "github.com/cortexproject/cortex/pkg/util/log" "github.com/go-kit/log" "github.com/go-kit/log/level" "github.com/grafana/dskit/flagext" @@ -41,6 +40,7 @@ import ( file2 "github.com/grafana/loki/clients/pkg/promtail/targets/file" "github.com/grafana/loki/pkg/logproto" + util_log "github.com/grafana/loki/pkg/util/log" ) const httpTestPort = 9080 @@ -103,7 +103,7 @@ func TestPromtail(t *testing.T) { }() // Run. - p, err := New(buildTestConfig(t, positionsFileName, testDir), false) + p, err := New(buildTestConfig(t, positionsFileName, testDir), false, nil) if err != nil { t.Error("error creating promtail", err) return @@ -646,7 +646,7 @@ func Test_DryRun(t *testing.T) { require.NoError(t, err) defer os.Remove(f.Name()) - _, err = New(config.Config{}, true) + _, err = New(config.Config{}, true, nil) require.Error(t, err) // Set the minimum config needed to start a server. We need to do this since we @@ -668,7 +668,7 @@ func Test_DryRun(t *testing.T) { PositionsFile: f.Name(), SyncPeriod: time.Second, }, - }, true) + }, true, nil) require.NoError(t, err) prometheus.DefaultRegisterer = prometheus.NewRegistry() @@ -680,7 +680,7 @@ func Test_DryRun(t *testing.T) { PositionsFile: f.Name(), SyncPeriod: time.Second, }, - }, false) + }, false, nil) require.NoError(t, err) require.IsType(t, &client.MultiClient{}, p.client) } diff --git a/clients/pkg/promtail/targets/lokipush/pushtarget.go b/clients/pkg/promtail/targets/lokipush/pushtarget.go index 017c0be5449ad..9668491bc3179 100644 --- a/clients/pkg/promtail/targets/lokipush/pushtarget.go +++ b/clients/pkg/promtail/targets/lokipush/pushtarget.go @@ -9,10 +9,10 @@ import ( "strings" "time" - util_log "github.com/cortexproject/cortex/pkg/util/log" "github.com/go-kit/log" "github.com/go-kit/log/level" "github.com/imdario/mergo" + "github.com/prometheus/client_golang/prometheus" "github.com/prometheus/common/model" "github.com/prometheus/prometheus/model/labels" "github.com/prometheus/prometheus/model/relabel" @@ -27,6 +27,7 @@ import ( "github.com/grafana/loki/pkg/loghttp/push" "github.com/grafana/loki/pkg/logproto" + util_log "github.com/grafana/loki/pkg/util/log" ) type PushTarget struct { @@ -36,13 +37,16 @@ type PushTarget struct { relabelConfig []*relabel.Config jobName string server *server.Server + registerer prometheus.Registerer } func NewPushTarget(logger log.Logger, handler api.EntryHandler, relabel []*relabel.Config, jobName string, - config *scrapeconfig.PushTargetConfig) (*PushTarget, error) { + config *scrapeconfig.PushTargetConfig, + reg prometheus.Registerer, +) (*PushTarget, error) { pt := &PushTarget{ logger: logger, @@ -50,6 +54,7 @@ func NewPushTarget(logger log.Logger, relabelConfig: relabel, jobName: jobName, config: config, + registerer: reg, } // Bit of a chicken and egg problem trying to register the defaults and apply overrides from the loaded config. @@ -87,7 +92,7 @@ func (t *PushTarget) run() error { // We don't want the /debug and /metrics endpoints running t.config.Server.RegisterInstrumentation = false - util_log.InitLogger(&t.config.Server) + util_log.InitLogger(&t.config.Server, t.registerer) srv, err := server.New(t.config.Server) if err != nil { diff --git a/clients/pkg/promtail/targets/lokipush/pushtarget_test.go b/clients/pkg/promtail/targets/lokipush/pushtarget_test.go index f27eba22306a3..24f1bbe81f1b1 100644 --- a/clients/pkg/promtail/targets/lokipush/pushtarget_test.go +++ b/clients/pkg/promtail/targets/lokipush/pushtarget_test.go @@ -70,7 +70,7 @@ func TestLokiPushTarget(t *testing.T) { }, } - pt, err := NewPushTarget(logger, eh, rlbl, "job1", config) + pt, err := NewPushTarget(logger, eh, rlbl, "job1", config, nil) require.NoError(t, err) // Build a client to send logs @@ -162,7 +162,7 @@ func TestPlaintextPushTarget(t *testing.T) { KeepTimestamp: true, } - pt, err := NewPushTarget(logger, eh, []*relabel.Config{}, "job2", config) + pt, err := NewPushTarget(logger, eh, []*relabel.Config{}, "job2", config, nil) require.NoError(t, err) // Send some logs diff --git a/clients/pkg/promtail/targets/lokipush/pushtargetmanager.go b/clients/pkg/promtail/targets/lokipush/pushtargetmanager.go index 5356e06ee78f8..0f7478f642d5b 100644 --- a/clients/pkg/promtail/targets/lokipush/pushtargetmanager.go +++ b/clients/pkg/promtail/targets/lokipush/pushtargetmanager.go @@ -44,7 +44,7 @@ func NewPushTargetManager( return nil, err } - t, err := NewPushTarget(logger, pipeline.Wrap(client), cfg.RelabelConfigs, cfg.JobName, cfg.PushConfig) + t, err := NewPushTarget(logger, pipeline.Wrap(client), cfg.RelabelConfigs, cfg.JobName, cfg.PushConfig, reg) if err != nil { return nil, err } diff --git a/clients/pkg/promtail/targets/stdin/stdin_target_manager_test.go b/clients/pkg/promtail/targets/stdin/stdin_target_manager_test.go index 9eff180700012..58abae3c802b8 100644 --- a/clients/pkg/promtail/targets/stdin/stdin_target_manager_test.go +++ b/clients/pkg/promtail/targets/stdin/stdin_target_manager_test.go @@ -7,7 +7,6 @@ import ( "strings" "testing" - util_log "github.com/cortexproject/cortex/pkg/util/log" "github.com/prometheus/client_golang/prometheus" "github.com/prometheus/common/model" "github.com/stretchr/testify/require" @@ -19,6 +18,7 @@ import ( "github.com/grafana/loki/clients/pkg/promtail/scrapeconfig" "github.com/grafana/loki/pkg/logproto" + util_log "github.com/grafana/loki/pkg/util/log" ) func Test_newReaderTarget(t *testing.T) { diff --git a/clients/pkg/promtail/targets/windows/target.go b/clients/pkg/promtail/targets/windows/target.go index 3493f587f9de9..a844da3c80f65 100644 --- a/clients/pkg/promtail/targets/windows/target.go +++ b/clients/pkg/promtail/targets/windows/target.go @@ -9,7 +9,6 @@ import ( "sync" "time" - util_log "github.com/cortexproject/cortex/pkg/util/log" "github.com/go-kit/log" "github.com/go-kit/log/level" "github.com/prometheus/common/model" @@ -23,6 +22,8 @@ import ( "github.com/grafana/loki/clients/pkg/promtail/scrapeconfig" "github.com/grafana/loki/clients/pkg/promtail/targets/target" "github.com/grafana/loki/clients/pkg/promtail/targets/windows/win_eventlog" + + util_log "github.com/grafana/loki/pkg/util/log" ) var fs = afero.NewOsFs() diff --git a/clients/pkg/promtail/targets/windows/target_test.go b/clients/pkg/promtail/targets/windows/target_test.go index 9f8f4e4d75d24..5434ee74b50b9 100644 --- a/clients/pkg/promtail/targets/windows/target_test.go +++ b/clients/pkg/promtail/targets/windows/target_test.go @@ -7,7 +7,6 @@ import ( "testing" "time" - util_log "github.com/cortexproject/cortex/pkg/util/log" jsoniter "github.com/json-iterator/go" "github.com/prometheus/common/model" "github.com/spf13/afero" @@ -21,6 +20,7 @@ import ( "github.com/grafana/loki/clients/pkg/promtail/targets/windows/win_eventlog" "github.com/grafana/loki/pkg/logproto" + util_log "github.com/grafana/loki/pkg/util/log" ) func init() { @@ -28,7 +28,7 @@ func init() { // Enable debug logging cfg := &server.Config{} _ = cfg.LogLevel.Set("debug") - util_log.InitLogger(cfg) + util_log.InitLogger(cfg, nil) } // Test that you can use to generate event logs locally. diff --git a/clients/pkg/promtail/targets/windows/win_eventlog/win_eventlog.go b/clients/pkg/promtail/targets/windows/win_eventlog/win_eventlog.go index 8eb6afb492d60..ffba0e34c5568 100644 --- a/clients/pkg/promtail/targets/windows/win_eventlog/win_eventlog.go +++ b/clients/pkg/promtail/targets/windows/win_eventlog/win_eventlog.go @@ -33,11 +33,12 @@ import ( "strings" "syscall" - util_log "github.com/cortexproject/cortex/pkg/util/log" "github.com/go-kit/log/level" "github.com/influxdata/telegraf" "github.com/influxdata/telegraf/plugins/inputs" "golang.org/x/sys/windows" + + util_log "github.com/grafana/loki/pkg/util/log" ) var sampleConfig = ` diff --git a/cmd/loki/main.go b/cmd/loki/main.go index 4dd3b85d92d10..1a7028ab07ab4 100644 --- a/cmd/loki/main.go +++ b/cmd/loki/main.go @@ -8,17 +8,17 @@ import ( "runtime" "github.com/go-kit/log/level" + "github.com/prometheus/client_golang/prometheus" "github.com/prometheus/common/version" "github.com/weaveworks/common/logging" "github.com/weaveworks/common/tracing" "github.com/grafana/loki/pkg/loki" - logutil "github.com/grafana/loki/pkg/util" + "github.com/grafana/loki/pkg/util" _ "github.com/grafana/loki/pkg/util/build" "github.com/grafana/loki/pkg/util/cfg" + util_log "github.com/grafana/loki/pkg/util/log" "github.com/grafana/loki/pkg/validation" - - util_log "github.com/cortexproject/cortex/pkg/util/log" ) func main() { @@ -43,7 +43,7 @@ func main() { level.Error(util_log.Logger).Log("msg", "invalid log level") os.Exit(1) } - util_log.InitLogger(&config.Server) + util_log.InitLogger(&config.Server, prometheus.DefaultRegisterer) // Validate the config once both the config file has been loaded // and CLI flags parsed. @@ -54,14 +54,14 @@ func main() { } if config.PrintConfig { - err := logutil.PrintConfig(os.Stderr, &config) + err := util.PrintConfig(os.Stderr, &config) if err != nil { level.Error(util_log.Logger).Log("msg", "failed to print config to stderr", "err", err.Error()) } } if config.LogConfig { - err := logutil.LogConfig(&config) + err := util.LogConfig(&config) if err != nil { level.Error(util_log.Logger).Log("msg", "failed to log config object", "err", err.Error()) } @@ -96,7 +96,7 @@ func main() { // Start Loki t, err := loki.New(config.Config) - util_log.CheckFatal("initialising loki", err) + util_log.CheckFatal("initialising loki", err, util_log.Logger) if config.ListTargets { t.ListTargets() @@ -106,5 +106,5 @@ func main() { level.Info(util_log.Logger).Log("msg", "Starting Loki", "version", version.Info()) err = t.Run(loki.RunOpts{}) - util_log.CheckFatal("running loki", err) + util_log.CheckFatal("running loki", err, util_log.Logger) } diff --git a/cmd/migrate/main.go b/cmd/migrate/main.go index 09f9c57ebf241..5cbeff4acbe3c 100644 --- a/cmd/migrate/main.go +++ b/cmd/migrate/main.go @@ -12,7 +12,6 @@ import ( "sync" "time" - util_log "github.com/cortexproject/cortex/pkg/util/log" "github.com/prometheus/client_golang/prometheus" "github.com/prometheus/common/model" @@ -28,6 +27,7 @@ import ( chunk_storage "github.com/grafana/loki/pkg/storage/chunk/storage" "github.com/grafana/loki/pkg/util" "github.com/grafana/loki/pkg/util/cfg" + util_log "github.com/grafana/loki/pkg/util/log" "github.com/grafana/loki/pkg/validation" ) diff --git a/cmd/querytee/main.go b/cmd/querytee/main.go index c23998dfb835a..ae28a6d5a9681 100644 --- a/cmd/querytee/main.go +++ b/cmd/querytee/main.go @@ -4,7 +4,6 @@ import ( "flag" "os" - util_log "github.com/cortexproject/cortex/pkg/util/log" "github.com/go-kit/log/level" "github.com/prometheus/client_golang/prometheus" "github.com/prometheus/client_golang/prometheus/collectors" @@ -12,6 +11,7 @@ import ( "github.com/weaveworks/common/server" "github.com/grafana/loki/pkg/loghttp" + util_log "github.com/grafana/loki/pkg/util/log" "github.com/grafana/loki/tools/querytee" ) @@ -31,7 +31,7 @@ func main() { util_log.InitLogger(&server.Config{ LogLevel: cfg.LogLevel, - }) + }, prometheus.DefaultRegisterer) // Run the instrumentation server. registry := prometheus.NewRegistry() diff --git a/cmd/querytee/response_comparator.go b/cmd/querytee/response_comparator.go index 0483619e907b2..14acfe1cc65af 100644 --- a/cmd/querytee/response_comparator.go +++ b/cmd/querytee/response_comparator.go @@ -4,11 +4,11 @@ import ( "encoding/json" "fmt" - util_log "github.com/cortexproject/cortex/pkg/util/log" "github.com/go-kit/log/level" jsoniter "github.com/json-iterator/go" "github.com/grafana/loki/pkg/loghttp" + util_log "github.com/grafana/loki/pkg/util/log" "github.com/grafana/loki/tools/querytee" ) diff --git a/pkg/chunkenc/memchunk.go b/pkg/chunkenc/memchunk.go index c3e67edadffcf..aa4239175fd44 100644 --- a/pkg/chunkenc/memchunk.go +++ b/pkg/chunkenc/memchunk.go @@ -14,17 +14,16 @@ import ( "unsafe" "github.com/cespare/xxhash/v2" - util_log "github.com/cortexproject/cortex/pkg/util/log" "github.com/go-kit/log/level" "github.com/pkg/errors" "github.com/prometheus/prometheus/model/labels" - "github.com/grafana/loki/pkg/storage/chunk/encoding" - "github.com/grafana/loki/pkg/iter" "github.com/grafana/loki/pkg/logproto" "github.com/grafana/loki/pkg/logql/log" "github.com/grafana/loki/pkg/logqlmodel/stats" + "github.com/grafana/loki/pkg/storage/chunk/encoding" + util_log "github.com/grafana/loki/pkg/util/log" ) const ( diff --git a/pkg/distributor/distributor.go b/pkg/distributor/distributor.go index 40fe8f679f511..8030f3dee57a6 100644 --- a/pkg/distributor/distributor.go +++ b/pkg/distributor/distributor.go @@ -6,7 +6,6 @@ import ( "net/http" "time" - util_log "github.com/cortexproject/cortex/pkg/util/log" "github.com/grafana/dskit/kv" "github.com/grafana/dskit/limiter" "github.com/grafana/dskit/ring" @@ -30,6 +29,7 @@ import ( "github.com/grafana/loki/pkg/storage/stores/shipper/compactor/retention" "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/validation" ) diff --git a/pkg/distributor/distributor_ring.go b/pkg/distributor/distributor_ring.go index ceefa198c2d53..f650be4f7a43e 100644 --- a/pkg/distributor/distributor_ring.go +++ b/pkg/distributor/distributor_ring.go @@ -10,7 +10,7 @@ import ( "github.com/grafana/dskit/kv" "github.com/grafana/dskit/ring" - util_log "github.com/cortexproject/cortex/pkg/util/log" + util_log "github.com/grafana/loki/pkg/util/log" ) // RingConfig masks the ring lifecycler config which contains diff --git a/pkg/distributor/http.go b/pkg/distributor/http.go index 3e1130416c828..657f0e444f98d 100644 --- a/pkg/distributor/http.go +++ b/pkg/distributor/http.go @@ -4,7 +4,6 @@ import ( "net/http" "strings" - util_log "github.com/cortexproject/cortex/pkg/util/log" "github.com/go-kit/log/level" "github.com/weaveworks/common/httpgrpc" @@ -12,6 +11,7 @@ import ( "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" ) diff --git a/pkg/ingester/checkpoint.go b/pkg/ingester/checkpoint.go index 7e15ff543ac76..2893a668a1526 100644 --- a/pkg/ingester/checkpoint.go +++ b/pkg/ingester/checkpoint.go @@ -12,7 +12,6 @@ import ( "time" "github.com/cortexproject/cortex/pkg/cortexpb" - util_log "github.com/cortexproject/cortex/pkg/util/log" "github.com/dustin/go-humanize" "github.com/go-kit/log" "github.com/go-kit/log/level" @@ -24,6 +23,7 @@ import ( prompool "github.com/prometheus/prometheus/util/pool" "github.com/grafana/loki/pkg/chunkenc" + util_log "github.com/grafana/loki/pkg/util/log" "github.com/grafana/loki/pkg/util/pool" ) diff --git a/pkg/ingester/flush.go b/pkg/ingester/flush.go index 6aa8734de6f8f..0a37ffabe4360 100644 --- a/pkg/ingester/flush.go +++ b/pkg/ingester/flush.go @@ -9,6 +9,7 @@ import ( "golang.org/x/net/context" + "github.com/cortexproject/cortex/pkg/util" "github.com/go-kit/log/level" "github.com/prometheus/client_golang/prometheus" "github.com/prometheus/client_golang/prometheus/promauto" @@ -16,14 +17,11 @@ import ( "github.com/prometheus/prometheus/model/labels" "github.com/weaveworks/common/user" - "github.com/cortexproject/cortex/pkg/util" - util_log "github.com/cortexproject/cortex/pkg/util/log" - - "github.com/grafana/loki/pkg/tenant" - "github.com/grafana/loki/pkg/chunkenc" "github.com/grafana/loki/pkg/storage/chunk" + "github.com/grafana/loki/pkg/tenant" loki_util "github.com/grafana/loki/pkg/util" + util_log "github.com/grafana/loki/pkg/util/log" ) var ( diff --git a/pkg/ingester/flush_test.go b/pkg/ingester/flush_test.go index 93cc3d15b9c18..a39fb6ef32b0c 100644 --- a/pkg/ingester/flush_test.go +++ b/pkg/ingester/flush_test.go @@ -21,8 +21,6 @@ import ( "github.com/weaveworks/common/user" "golang.org/x/net/context" - "github.com/grafana/loki/pkg/tenant" - "github.com/grafana/loki/pkg/chunkenc" "github.com/grafana/loki/pkg/ingester/client" "github.com/grafana/loki/pkg/iter" @@ -32,6 +30,7 @@ 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" ) diff --git a/pkg/ingester/ingester.go b/pkg/ingester/ingester.go index a9616456b02fc..a71dac39fb431 100644 --- a/pkg/ingester/ingester.go +++ b/pkg/ingester/ingester.go @@ -11,7 +11,6 @@ import ( "time" "github.com/cortexproject/cortex/pkg/util" - util_log "github.com/cortexproject/cortex/pkg/util/log" "github.com/go-kit/log/level" "github.com/grafana/dskit/ring" "github.com/grafana/dskit/services" @@ -22,8 +21,6 @@ import ( "github.com/prometheus/prometheus/model/labels" "google.golang.org/grpc/health/grpc_health_v1" - "github.com/grafana/loki/pkg/tenant" - "github.com/grafana/loki/pkg/chunkenc" "github.com/grafana/loki/pkg/ingester/client" "github.com/grafana/loki/pkg/ingester/index" @@ -35,7 +32,9 @@ 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" errUtil "github.com/grafana/loki/pkg/util" + util_log "github.com/grafana/loki/pkg/util/log" "github.com/grafana/loki/pkg/validation" ) diff --git a/pkg/ingester/ingester_test.go b/pkg/ingester/ingester_test.go index 640d9b09b47b2..8eb09dfdcda96 100644 --- a/pkg/ingester/ingester_test.go +++ b/pkg/ingester/ingester_test.go @@ -18,8 +18,6 @@ import ( "google.golang.org/grpc" "google.golang.org/grpc/metadata" - "github.com/grafana/loki/pkg/tenant" - "github.com/grafana/loki/pkg/chunkenc" "github.com/grafana/loki/pkg/ingester/client" "github.com/grafana/loki/pkg/ingester/index" @@ -29,6 +27,7 @@ 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" ) diff --git a/pkg/ingester/instance.go b/pkg/ingester/instance.go index 35cfe3ce7ab32..ae120896d1513 100644 --- a/pkg/ingester/instance.go +++ b/pkg/ingester/instance.go @@ -8,6 +8,7 @@ import ( "syscall" "github.com/cortexproject/cortex/pkg/cortexpb" + cutil "github.com/cortexproject/cortex/pkg/util" "github.com/go-kit/log/level" "github.com/pkg/errors" "github.com/prometheus/client_golang/prometheus" @@ -19,9 +20,6 @@ import ( "github.com/weaveworks/common/httpgrpc" "go.uber.org/atomic" - cutil "github.com/cortexproject/cortex/pkg/util" - util_log "github.com/cortexproject/cortex/pkg/util/log" - "github.com/grafana/loki/pkg/ingester/index" "github.com/grafana/loki/pkg/iter" "github.com/grafana/loki/pkg/logproto" @@ -30,6 +28,7 @@ import ( "github.com/grafana/loki/pkg/querier/astmapper" "github.com/grafana/loki/pkg/runtime" "github.com/grafana/loki/pkg/storage" + util_log "github.com/grafana/loki/pkg/util/log" "github.com/grafana/loki/pkg/util/math" "github.com/grafana/loki/pkg/validation" ) diff --git a/pkg/ingester/mapper.go b/pkg/ingester/mapper.go index 4e65bf1c58356..5677a2a08dbec 100644 --- a/pkg/ingester/mapper.go +++ b/pkg/ingester/mapper.go @@ -6,12 +6,12 @@ import ( "strings" "sync" - "github.com/prometheus/prometheus/model/labels" - - util_log "github.com/cortexproject/cortex/pkg/util/log" "github.com/go-kit/log/level" "github.com/prometheus/common/model" + "github.com/prometheus/prometheus/model/labels" "go.uber.org/atomic" + + util_log "github.com/grafana/loki/pkg/util/log" ) const maxMappedFP = 1 << 20 // About 1M fingerprints reserved for mapping. diff --git a/pkg/ingester/recovery.go b/pkg/ingester/recovery.go index e2add24581aaf..04fd12de43a36 100644 --- a/pkg/ingester/recovery.go +++ b/pkg/ingester/recovery.go @@ -6,7 +6,6 @@ import ( "sync" "github.com/cortexproject/cortex/pkg/cortexpb" - util_log "github.com/cortexproject/cortex/pkg/util/log" "github.com/go-kit/log/level" "github.com/pkg/errors" "github.com/prometheus/prometheus/tsdb/chunks" @@ -15,6 +14,7 @@ import ( "golang.org/x/net/context" "github.com/grafana/loki/pkg/logproto" + util_log "github.com/grafana/loki/pkg/util/log" ) type WALReader interface { diff --git a/pkg/ingester/replay_controller.go b/pkg/ingester/replay_controller.go index 5b6b76d28978a..a2e3e5de6239d 100644 --- a/pkg/ingester/replay_controller.go +++ b/pkg/ingester/replay_controller.go @@ -3,10 +3,11 @@ package ingester import ( "sync" - util_log "github.com/cortexproject/cortex/pkg/util/log" "github.com/dustin/go-humanize" "github.com/go-kit/log/level" "go.uber.org/atomic" + + util_log "github.com/grafana/loki/pkg/util/log" ) type replayFlusher struct { diff --git a/pkg/ingester/stream.go b/pkg/ingester/stream.go index d8f3bc6cd2ab7..75d3746b65226 100644 --- a/pkg/ingester/stream.go +++ b/pkg/ingester/stream.go @@ -8,7 +8,6 @@ import ( "sync" "time" - util_log "github.com/cortexproject/cortex/pkg/util/log" "github.com/go-kit/log/level" "github.com/pkg/errors" "github.com/prometheus/client_golang/prometheus" @@ -22,6 +21,7 @@ import ( "github.com/grafana/loki/pkg/logql/log" "github.com/grafana/loki/pkg/logqlmodel/stats" "github.com/grafana/loki/pkg/util/flagext" + util_log "github.com/grafana/loki/pkg/util/log" "github.com/grafana/loki/pkg/validation" ) diff --git a/pkg/ingester/tailer.go b/pkg/ingester/tailer.go index 08a8484e5d943..57558a4eecacc 100644 --- a/pkg/ingester/tailer.go +++ b/pkg/ingester/tailer.go @@ -6,7 +6,6 @@ import ( "sync" "time" - util_log "github.com/cortexproject/cortex/pkg/util/log" "github.com/go-kit/log/level" "github.com/prometheus/prometheus/model/labels" "golang.org/x/net/context" @@ -15,6 +14,7 @@ import ( "github.com/grafana/loki/pkg/logql" "github.com/grafana/loki/pkg/logql/log" "github.com/grafana/loki/pkg/util" + util_log "github.com/grafana/loki/pkg/util/log" ) const bufferSizeForTailResponse = 5 diff --git a/pkg/ingester/transfer.go b/pkg/ingester/transfer.go index 6b19d8bb09291..73cac24898d7b 100644 --- a/pkg/ingester/transfer.go +++ b/pkg/ingester/transfer.go @@ -6,7 +6,6 @@ import ( "os" "time" - util_log "github.com/cortexproject/cortex/pkg/util/log" "github.com/go-kit/log/level" "github.com/grafana/dskit/backoff" "github.com/grafana/dskit/ring" @@ -19,6 +18,7 @@ import ( "github.com/grafana/loki/pkg/logproto" lokiutil "github.com/grafana/loki/pkg/util" + util_log "github.com/grafana/loki/pkg/util/log" ) var ( diff --git a/pkg/ingester/transfer_test.go b/pkg/ingester/transfer_test.go index 885335f748305..01ee0c340b507 100644 --- a/pkg/ingester/transfer_test.go +++ b/pkg/ingester/transfer_test.go @@ -8,7 +8,6 @@ import ( "testing" "time" - util_log "github.com/cortexproject/cortex/pkg/util/log" gokitlog "github.com/go-kit/log" "github.com/go-kit/log/level" "github.com/grafana/dskit/kv" @@ -24,6 +23,7 @@ import ( "github.com/grafana/loki/pkg/ingester/client" "github.com/grafana/loki/pkg/logproto" "github.com/grafana/loki/pkg/logql/log" + util_log "github.com/grafana/loki/pkg/util/log" ) func TestTransferOut(t *testing.T) { diff --git a/pkg/ingester/wal.go b/pkg/ingester/wal.go index 00efc054fe846..89a8569416ae9 100644 --- a/pkg/ingester/wal.go +++ b/pkg/ingester/wal.go @@ -5,7 +5,6 @@ import ( "sync" "time" - util_log "github.com/cortexproject/cortex/pkg/util/log" "github.com/go-kit/log/level" "github.com/pkg/errors" "github.com/prometheus/client_golang/prometheus" @@ -13,6 +12,7 @@ import ( "github.com/grafana/loki/pkg/logproto" "github.com/grafana/loki/pkg/util/flagext" + util_log "github.com/grafana/loki/pkg/util/log" ) var ( diff --git a/pkg/logcli/client/file.go b/pkg/logcli/client/file.go index f0902f6a5b777..8debdf58e16e7 100644 --- a/pkg/logcli/client/file.go +++ b/pkg/logcli/client/file.go @@ -17,6 +17,7 @@ import ( "github.com/grafana/loki/pkg/logproto" "github.com/grafana/loki/pkg/logql" logqllog "github.com/grafana/loki/pkg/logql/log" + "github.com/grafana/loki/pkg/util/log" "github.com/grafana/loki/pkg/util/marshal" "github.com/prometheus/prometheus/model/labels" @@ -54,7 +55,7 @@ func NewFileClient(r io.ReadCloser) *FileClient { }, } - eng := logql.NewEngine(logql.EngineOpts{}, &querier{r: r, labels: lbs}, &limiter{n: defaultMetricSeriesLimit}) + eng := logql.NewEngine(logql.EngineOpts{}, &querier{r: r, labels: lbs}, &limiter{n: defaultMetricSeriesLimit}, log.Logger) return &FileClient{ r: r, orgID: defaultOrgID, diff --git a/pkg/logcli/query/query.go b/pkg/logcli/query/query.go index 97d8657614bf3..2be2416cecaa1 100644 --- a/pkg/logcli/query/query.go +++ b/pkg/logcli/query/query.go @@ -12,7 +12,6 @@ import ( "text/tabwriter" "time" - util_log "github.com/cortexproject/cortex/pkg/util/log" "github.com/fatih/color" json "github.com/json-iterator/go" "github.com/prometheus/client_golang/prometheus" @@ -30,6 +29,7 @@ import ( chunk_storage "github.com/grafana/loki/pkg/storage/chunk/storage" "github.com/grafana/loki/pkg/storage/stores/shipper" "github.com/grafana/loki/pkg/util/cfg" + util_log "github.com/grafana/loki/pkg/util/log" "github.com/grafana/loki/pkg/util/marshal" "github.com/grafana/loki/pkg/validation" ) @@ -201,7 +201,7 @@ func (q *Query) DoLocalQuery(out output.LogOutput, statistics bool, orgID string return err } - eng := logql.NewEngine(conf.Querier.Engine, querier, limits) + eng := logql.NewEngine(conf.Querier.Engine, querier, limits, util_log.Logger) var query logql.Query if q.isInstant() { diff --git a/pkg/logcli/query/query_test.go b/pkg/logcli/query/query_test.go index a618f89621854..9ab4cd1f832bb 100644 --- a/pkg/logcli/query/query_test.go +++ b/pkg/logcli/query/query_test.go @@ -3,14 +3,15 @@ package query import ( "bytes" "context" - "log" "reflect" "strings" "testing" "time" + "github.com/go-kit/log" "github.com/gorilla/websocket" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/grafana/loki/pkg/logcli/output" "github.com/grafana/loki/pkg/loghttp" @@ -31,35 +32,35 @@ func Test_commonLabels(t *testing.T) { { "Extract common labels source > target", args{ - []loghttp.LabelSet{mustParseLabels(`{foo="bar", bar="foo"}`), mustParseLabels(`{bar="foo", foo="foo", baz="baz"}`)}, + []loghttp.LabelSet{mustParseLabels(t, `{foo="bar", bar="foo"}`), mustParseLabels(t, `{bar="foo", foo="foo", baz="baz"}`)}, }, - mustParseLabels(`{bar="foo"}`), + mustParseLabels(t, `{bar="foo"}`), }, { "Extract common labels source > target", args{ - []loghttp.LabelSet{mustParseLabels(`{foo="bar", bar="foo"}`), mustParseLabels(`{bar="foo", foo="bar", baz="baz"}`)}, + []loghttp.LabelSet{mustParseLabels(t, `{foo="bar", bar="foo"}`), mustParseLabels(t, `{bar="foo", foo="bar", baz="baz"}`)}, }, - mustParseLabels(`{foo="bar", bar="foo"}`), + mustParseLabels(t, `{foo="bar", bar="foo"}`), }, { "Extract common labels source < target", args{ - []loghttp.LabelSet{mustParseLabels(`{foo="bar", bar="foo"}`), mustParseLabels(`{bar="foo"}`)}, + []loghttp.LabelSet{mustParseLabels(t, `{foo="bar", bar="foo"}`), mustParseLabels(t, `{bar="foo"}`)}, }, - mustParseLabels(`{bar="foo"}`), + mustParseLabels(t, `{bar="foo"}`), }, { "Extract common labels source < target no common", args{ - []loghttp.LabelSet{mustParseLabels(`{foo="bar", bar="foo"}`), mustParseLabels(`{fo="bar"}`)}, + []loghttp.LabelSet{mustParseLabels(t, `{foo="bar", bar="foo"}`), mustParseLabels(t, `{fo="bar"}`)}, }, loghttp.LabelSet{}, }, { "Extract common labels source = target no common", args{ - []loghttp.LabelSet{mustParseLabels(`{foo="bar"}`), mustParseLabels(`{fooo="bar"}`)}, + []loghttp.LabelSet{mustParseLabels(t, `{foo="bar"}`), mustParseLabels(t, `{fooo="bar"}`)}, }, loghttp.LabelSet{}, }, @@ -95,50 +96,50 @@ func Test_subtract(t *testing.T) { { "Subtract labels source > target", args{ - mustParseLabels(`{foo="bar", bar="foo"}`), - mustParseLabels(`{bar="foo", foo="foo", baz="baz"}`), + mustParseLabels(t, `{foo="bar", bar="foo"}`), + mustParseLabels(t, `{bar="foo", foo="foo", baz="baz"}`), }, - mustParseLabels(`{foo="bar"}`), + mustParseLabels(t, `{foo="bar"}`), }, { "Subtract labels source < target", args{ - mustParseLabels(`{foo="bar", bar="foo"}`), - mustParseLabels(`{bar="foo"}`), + mustParseLabels(t, `{foo="bar", bar="foo"}`), + mustParseLabels(t, `{bar="foo"}`), }, - mustParseLabels(`{foo="bar"}`), + mustParseLabels(t, `{foo="bar"}`), }, { "Subtract labels source < target no sub", args{ - mustParseLabels(`{foo="bar", bar="foo"}`), - mustParseLabels(`{fo="bar"}`), + mustParseLabels(t, `{foo="bar", bar="foo"}`), + mustParseLabels(t, `{fo="bar"}`), }, - mustParseLabels(`{bar="foo", foo="bar"}`), + mustParseLabels(t, `{bar="foo", foo="bar"}`), }, { "Subtract labels source = target no sub", args{ - mustParseLabels(`{foo="bar"}`), - mustParseLabels(`{fiz="buz"}`), + mustParseLabels(t, `{foo="bar"}`), + mustParseLabels(t, `{fiz="buz"}`), }, - mustParseLabels(`{foo="bar"}`), + mustParseLabels(t, `{foo="bar"}`), }, { "Subtract labels source > target no sub", args{ - mustParseLabels(`{foo="bar"}`), - mustParseLabels(`{fiz="buz", foo="baz"}`), + mustParseLabels(t, `{foo="bar"}`), + mustParseLabels(t, `{fiz="buz", foo="baz"}`), }, - mustParseLabels(`{foo="bar"}`), + mustParseLabels(t, `{foo="bar"}`), }, { "Subtract labels source > target no sub", args{ - mustParseLabels(`{a="b", foo="bar", baz="baz", fizz="fizz"}`), - mustParseLabels(`{foo="bar", baz="baz", buzz="buzz", fizz="fizz"}`), + mustParseLabels(t, `{a="b", foo="bar", baz="baz", fizz="fizz"}`), + mustParseLabels(t, `{foo="bar", baz="baz", buzz="buzz", fizz="fizz"}`), }, - mustParseLabels(`{a="b"}`), + mustParseLabels(t, `{a="b"}`), }, } for _, tt := range tests { @@ -485,12 +486,10 @@ func Test_batch(t *testing.T) { } } -func mustParseLabels(s string) loghttp.LabelSet { +func mustParseLabels(t *testing.T, s string) loghttp.LabelSet { + t.Helper() l, err := marshal.NewLabelSet(s) - - if err != nil { - log.Fatalf("Failed to parse %s", s) - } + require.NoErrorf(t, err, "Failed to parse %q", s) return l } @@ -502,7 +501,7 @@ type testQueryClient struct { func newTestQueryClient(testStreams ...logproto.Stream) *testQueryClient { q := logql.NewMockQuerier(0, testStreams) - e := logql.NewEngine(logql.EngineOpts{}, q, logql.NoLimits) + e := logql.NewEngine(logql.EngineOpts{}, q, logql.NoLimits, log.NewNopLogger()) return &testQueryClient{ engine: e, queryRangeCalls: 0, diff --git a/pkg/loghttp/push/push_test.go b/pkg/loghttp/push/push_test.go index c0970bd450d4b..f83a12404e71f 100644 --- a/pkg/loghttp/push/push_test.go +++ b/pkg/loghttp/push/push_test.go @@ -8,8 +8,9 @@ import ( "strings" "testing" - util_log "github.com/cortexproject/cortex/pkg/util/log" "github.com/stretchr/testify/assert" + + util_log "github.com/grafana/loki/pkg/util/log" ) // GZip source string and return compressed string diff --git a/pkg/logql/engine.go b/pkg/logql/engine.go index 6b411efbfbe56..942bf5ba02722 100644 --- a/pkg/logql/engine.go +++ b/pkg/logql/engine.go @@ -8,6 +8,7 @@ import ( "sort" "time" + "github.com/go-kit/log" "github.com/go-kit/log/level" "github.com/prometheus/client_golang/prometheus" "github.com/prometheus/client_golang/prometheus/promauto" @@ -15,16 +16,14 @@ import ( "github.com/prometheus/prometheus/promql" promql_parser "github.com/prometheus/prometheus/promql/parser" - "github.com/grafana/loki/pkg/util/spanlogger" - - "github.com/grafana/loki/pkg/tenant" - "github.com/grafana/loki/pkg/iter" "github.com/grafana/loki/pkg/logproto" "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" ) var ( @@ -62,15 +61,20 @@ func (opts *EngineOpts) applyDefault() { // Engine is the LogQL engine. type Engine struct { + logger log.Logger timeout time.Duration evaluator Evaluator limits Limits } // NewEngine creates a new LogQL Engine. -func NewEngine(opts EngineOpts, q Querier, l Limits) *Engine { +func NewEngine(opts EngineOpts, q Querier, l Limits, logger log.Logger) *Engine { opts.applyDefault() + if logger == nil { + logger = log.NewNopLogger() + } return &Engine{ + logger: logger, timeout: opts.Timeout, evaluator: NewDefaultEvaluator(q, opts.MaxLookBackPeriod), limits: l, @@ -80,6 +84,7 @@ func NewEngine(opts EngineOpts, q Querier, l Limits) *Engine { // Query creates a new LogQL query. Instant/Range type is derived from the parameters. func (ng *Engine) Query(params Params) Query { return &query{ + logger: ng.logger, timeout: ng.timeout, params: params, evaluator: ng.evaluator, @@ -98,6 +103,7 @@ type Query interface { } type query struct { + logger log.Logger timeout time.Duration params Params parse func(context.Context, string) (Expr, error) diff --git a/pkg/logql/engine_test.go b/pkg/logql/engine_test.go index 920f230f59da3..544bcac4cde27 100644 --- a/pkg/logql/engine_test.go +++ b/pkg/logql/engine_test.go @@ -9,6 +9,7 @@ import ( "testing" "time" + "github.com/go-kit/log" json "github.com/json-iterator/go" "github.com/prometheus/prometheus/model/labels" "github.com/prometheus/prometheus/promql" @@ -62,7 +63,7 @@ func TestEngine_LogsRateUnwrap(t *testing.T) { t.Run(fmt.Sprintf("%s %s", test.qs, test.direction), func(t *testing.T) { t.Parallel() - eng := NewEngine(EngineOpts{}, newQuerierRecorder(t, test.data, test.params), NoLimits) + eng := NewEngine(EngineOpts{}, newQuerierRecorder(t, test.data, test.params), NoLimits, log.NewNopLogger()) q := eng.Query(LiteralParams{ qs: test.qs, start: test.ts, @@ -827,7 +828,7 @@ func TestEngine_LogsInstantQuery(t *testing.T) { t.Run(fmt.Sprintf("%s %s", test.qs, test.direction), func(t *testing.T) { t.Parallel() - eng := NewEngine(EngineOpts{}, newQuerierRecorder(t, test.data, test.params), NoLimits) + eng := NewEngine(EngineOpts{}, newQuerierRecorder(t, test.data, test.params), NoLimits, log.NewNopLogger()) q := eng.Query(LiteralParams{ qs: test.qs, start: test.ts, @@ -2026,7 +2027,7 @@ func TestEngine_RangeQuery(t *testing.T) { t.Run(fmt.Sprintf("%s %s", test.qs, test.direction), func(t *testing.T) { t.Parallel() - eng := NewEngine(EngineOpts{}, newQuerierRecorder(t, test.data, test.params), NoLimits) + eng := NewEngine(EngineOpts{}, newQuerierRecorder(t, test.data, test.params), NoLimits, log.NewNopLogger()) q := eng.Query(LiteralParams{ qs: test.qs, @@ -2061,7 +2062,7 @@ func (statsQuerier) SelectSamples(ctx context.Context, p SelectSampleParams) (it } func TestEngine_Stats(t *testing.T) { - eng := NewEngine(EngineOpts{}, &statsQuerier{}, NoLimits) + eng := NewEngine(EngineOpts{}, &statsQuerier{}, NoLimits, log.NewNopLogger()) queueTime := 2 * time.Nanosecond q := eng.Query(LiteralParams{ @@ -2137,7 +2138,7 @@ func TestStepEvaluator_Error(t *testing.T) { t.Run(tc.name, func(t *testing.T) { t.Parallel() tc := tc - eng := NewEngine(EngineOpts{}, tc.querier, NoLimits) + eng := NewEngine(EngineOpts{}, tc.querier, NoLimits, log.NewNopLogger()) q := eng.Query(LiteralParams{ qs: tc.qs, start: time.Unix(0, 0), @@ -2151,7 +2152,7 @@ func TestStepEvaluator_Error(t *testing.T) { } func TestEngine_MaxSeries(t *testing.T) { - eng := NewEngine(EngineOpts{}, getLocalQuerier(100000), &fakeLimits{maxSeries: 1}) + eng := NewEngine(EngineOpts{}, getLocalQuerier(100000), &fakeLimits{maxSeries: 1}, log.NewNopLogger()) for _, test := range []struct { qs string @@ -2205,7 +2206,7 @@ var result promql_parser.Value func benchmarkRangeQuery(testsize int64, b *testing.B) { b.ReportAllocs() - eng := NewEngine(EngineOpts{}, getLocalQuerier(testsize), NoLimits) + eng := NewEngine(EngineOpts{}, getLocalQuerier(testsize), NoLimits, log.NewNopLogger()) start := time.Unix(0, 0) end := time.Unix(testsize, 0) b.ResetTimer() diff --git a/pkg/logql/metrics.go b/pkg/logql/metrics.go index 07516d1f7bec0..56b82b5091a89 100644 --- a/pkg/logql/metrics.go +++ b/pkg/logql/metrics.go @@ -4,7 +4,6 @@ import ( "context" "strings" - util_log "github.com/cortexproject/cortex/pkg/util/log" "github.com/dustin/go-humanize" "github.com/go-kit/log/level" "github.com/prometheus/client_golang/prometheus" @@ -14,6 +13,7 @@ import ( "github.com/grafana/loki/pkg/logqlmodel" logql_stats "github.com/grafana/loki/pkg/logqlmodel/stats" "github.com/grafana/loki/pkg/util/httpreq" + util_log "github.com/grafana/loki/pkg/util/log" ) const ( diff --git a/pkg/logql/metrics_test.go b/pkg/logql/metrics_test.go index 3678d2acf5f82..ecf7d4a7437d7 100644 --- a/pkg/logql/metrics_test.go +++ b/pkg/logql/metrics_test.go @@ -7,7 +7,6 @@ import ( "testing" "time" - util_log "github.com/cortexproject/cortex/pkg/util/log" "github.com/go-kit/log" "github.com/opentracing/opentracing-go" "github.com/stretchr/testify/assert" @@ -19,6 +18,7 @@ import ( "github.com/grafana/loki/pkg/logqlmodel" "github.com/grafana/loki/pkg/logqlmodel/stats" "github.com/grafana/loki/pkg/util/httpreq" + util_log "github.com/grafana/loki/pkg/util/log" ) func TestQueryType(t *testing.T) { diff --git a/pkg/logql/sharding.go b/pkg/logql/sharding.go index b4828e3fac454..aca924b9a953c 100644 --- a/pkg/logql/sharding.go +++ b/pkg/logql/sharding.go @@ -6,7 +6,7 @@ import ( "fmt" "time" - util_log "github.com/cortexproject/cortex/pkg/util/log" + "github.com/go-kit/log" "github.com/go-kit/log/level" "github.com/prometheus/prometheus/promql" @@ -15,6 +15,7 @@ import ( "github.com/grafana/loki/pkg/logqlmodel/stats" "github.com/grafana/loki/pkg/querier/astmapper" "github.com/grafana/loki/pkg/util" + util_log "github.com/grafana/loki/pkg/util/log" ) /* @@ -31,6 +32,7 @@ which can then take advantage of our sharded execution model. // ShardedEngine is an Engine implementation that can split queries into more parallelizable forms via // querying the underlying backend shards individually and reaggregating them. type ShardedEngine struct { + logger log.Logger timeout time.Duration downstreamable Downstreamable limits Limits @@ -38,9 +40,10 @@ type ShardedEngine struct { } // NewShardedEngine constructs a *ShardedEngine -func NewShardedEngine(opts EngineOpts, downstreamable Downstreamable, metrics *ShardingMetrics, limits Limits) *ShardedEngine { +func NewShardedEngine(opts EngineOpts, downstreamable Downstreamable, metrics *ShardingMetrics, limits Limits, logger log.Logger) *ShardedEngine { opts.applyDefault() return &ShardedEngine{ + logger: logger, timeout: opts.Timeout, downstreamable: downstreamable, metrics: metrics, @@ -51,6 +54,7 @@ func NewShardedEngine(opts EngineOpts, downstreamable Downstreamable, metrics *S // Query constructs a Query func (ng *ShardedEngine) Query(p Params, mapped Expr) Query { return &query{ + logger: ng.logger, timeout: ng.timeout, params: p, evaluator: NewDownstreamEvaluator(ng.downstreamable.Downstreamer()), diff --git a/pkg/logql/sharding_test.go b/pkg/logql/sharding_test.go index 6270711bc99d3..578196b50439c 100644 --- a/pkg/logql/sharding_test.go +++ b/pkg/logql/sharding_test.go @@ -6,6 +6,7 @@ import ( "testing" "time" + "github.com/go-kit/log" "github.com/prometheus/prometheus/promql" "github.com/stretchr/testify/require" "github.com/weaveworks/common/user" @@ -59,8 +60,8 @@ func TestMappingEquivalence(t *testing.T) { ) opts := EngineOpts{} - regular := NewEngine(opts, q, NoLimits) - sharded := NewShardedEngine(opts, MockDownstreamer{regular}, nilMetrics, NoLimits) + regular := NewEngine(opts, q, NoLimits, log.NewNopLogger()) + sharded := NewShardedEngine(opts, MockDownstreamer{regular}, nilMetrics, NoLimits, log.NewNopLogger()) t.Run(tc.query, func(t *testing.T) { params := NewLiteralParams( diff --git a/pkg/logql/shardmapper.go b/pkg/logql/shardmapper.go index c04d6514756f2..f7fdbfec3892f 100644 --- a/pkg/logql/shardmapper.go +++ b/pkg/logql/shardmapper.go @@ -3,13 +3,13 @@ package logql import ( "fmt" - util_log "github.com/cortexproject/cortex/pkg/util/log" "github.com/go-kit/log/level" "github.com/pkg/errors" "github.com/prometheus/client_golang/prometheus" "github.com/prometheus/client_golang/prometheus/promauto" "github.com/grafana/loki/pkg/querier/astmapper" + util_log "github.com/grafana/loki/pkg/util/log" ) // keys used in metrics diff --git a/pkg/logqlmodel/stats/context_test.go b/pkg/logqlmodel/stats/context_test.go index 671e8e19666c7..5f4e3fc6cbaff 100644 --- a/pkg/logqlmodel/stats/context_test.go +++ b/pkg/logqlmodel/stats/context_test.go @@ -5,8 +5,9 @@ import ( "testing" "time" - util_log "github.com/cortexproject/cortex/pkg/util/log" "github.com/stretchr/testify/require" + + util_log "github.com/grafana/loki/pkg/util/log" ) func TestResult(t *testing.T) { diff --git a/pkg/loki/loki.go b/pkg/loki/loki.go index 7f69677417476..b3ce79619aaf4 100644 --- a/pkg/loki/loki.go +++ b/pkg/loki/loki.go @@ -10,7 +10,6 @@ import ( rt "runtime" "github.com/cortexproject/cortex/pkg/util" - util_log "github.com/cortexproject/cortex/pkg/util/log" "github.com/fatih/color" "github.com/felixge/fgprof" "github.com/go-kit/log/level" @@ -47,6 +46,7 @@ import ( "github.com/grafana/loki/pkg/storage/stores/shipper/compactor" "github.com/grafana/loki/pkg/tracing" "github.com/grafana/loki/pkg/util/fakeauth" + util_log "github.com/grafana/loki/pkg/util/log" serverutil "github.com/grafana/loki/pkg/util/server" "github.com/grafana/loki/pkg/validation" ) diff --git a/pkg/loki/modules.go b/pkg/loki/modules.go index 152e99ea8e07b..2c06d4939451a 100644 --- a/pkg/loki/modules.go +++ b/pkg/loki/modules.go @@ -11,7 +11,6 @@ import ( "time" "github.com/NYTimes/gziphandler" - util_log "github.com/cortexproject/cortex/pkg/util/log" "github.com/go-kit/log/level" "github.com/grafana/dskit/kv/codec" "github.com/grafana/dskit/kv/memberlist" @@ -52,6 +51,7 @@ import ( "github.com/grafana/loki/pkg/storage/stores/shipper/indexgateway/indexgatewaypb" "github.com/grafana/loki/pkg/storage/stores/shipper/uploads" "github.com/grafana/loki/pkg/util/httpreq" + util_log "github.com/grafana/loki/pkg/util/log" serverutil "github.com/grafana/loki/pkg/util/server" "github.com/grafana/loki/pkg/validation" ) @@ -329,7 +329,7 @@ func (t *Loki) initTableManager() (services.Service, error) { } bucketClient, err := storage.NewBucketClient(t.Cfg.StorageConfig.Config) - util_log.CheckFatal("initializing bucket client", err) + util_log.CheckFatal("initializing bucket client", err, util_log.Logger) t.tableManager, err = chunk.NewTableManager(t.Cfg.TableManager, t.Cfg.SchemaConfig.SchemaConfig, maxChunkAgeForTableManager, tableClient, bucketClient, nil, prometheus.DefaultRegisterer) if err != nil { @@ -619,7 +619,7 @@ func (t *Loki) initRuler() (_ services.Service, err error) { return nil, err } - engine := logql.NewEngine(t.Cfg.Querier.Engine, q, t.overrides) + engine := logql.NewEngine(t.Cfg.Querier.Engine, q, t.overrides, util_log.Logger) t.ruler, err = ruler.NewRuler( t.Cfg.Ruler, @@ -668,7 +668,8 @@ func (t *Loki) initRuler() (_ services.Service, err error) { func (t *Loki) initMemberlistKV() (services.Service, error) { reg := prometheus.DefaultRegisterer - t.Cfg.MemberlistKV.MetricsRegisterer = prometheus.DefaultRegisterer + + t.Cfg.MemberlistKV.MetricsRegisterer = reg t.Cfg.MemberlistKV.Codecs = []codec.Codec{ ring.GetCodec(), } diff --git a/pkg/loki/runtime_config.go b/pkg/loki/runtime_config.go index ac4a27dd8fdbd..0111bb59453b3 100644 --- a/pkg/loki/runtime_config.go +++ b/pkg/loki/runtime_config.go @@ -4,13 +4,13 @@ import ( "fmt" "io" - util_log "github.com/cortexproject/cortex/pkg/util/log" "github.com/go-kit/log/level" "github.com/grafana/dskit/kv" "github.com/grafana/dskit/runtimeconfig" "gopkg.in/yaml.v2" "github.com/grafana/loki/pkg/runtime" + util_log "github.com/grafana/loki/pkg/util/log" "github.com/grafana/loki/pkg/validation" ) diff --git a/pkg/lokifrontend/frontend/transport/handler.go b/pkg/lokifrontend/frontend/transport/handler.go index 2b7d5db7464bc..6eb3e8c59b16f 100644 --- a/pkg/lokifrontend/frontend/transport/handler.go +++ b/pkg/lokifrontend/frontend/transport/handler.go @@ -14,7 +14,6 @@ import ( "time" "github.com/cortexproject/cortex/pkg/util" - util_log "github.com/cortexproject/cortex/pkg/util/log" "github.com/go-kit/log" "github.com/go-kit/log/level" "github.com/prometheus/client_golang/prometheus" @@ -22,6 +21,7 @@ import ( querier_stats "github.com/grafana/loki/pkg/querier/stats" "github.com/grafana/loki/pkg/tenant" + util_log "github.com/grafana/loki/pkg/util/log" serverutil "github.com/grafana/loki/pkg/util/server" ) diff --git a/pkg/querier/astmapper/parallel.go b/pkg/querier/astmapper/parallel.go index d7dc5129776a1..4ae5a5b5c7fbd 100644 --- a/pkg/querier/astmapper/parallel.go +++ b/pkg/querier/astmapper/parallel.go @@ -6,7 +6,7 @@ import ( "github.com/go-kit/log/level" "github.com/prometheus/prometheus/promql/parser" - util_log "github.com/cortexproject/cortex/pkg/util/log" + util_log "github.com/grafana/loki/pkg/util/log" ) var summableAggregates = map[parser.ItemType]struct{}{ diff --git a/pkg/querier/http.go b/pkg/querier/http.go index 483f65b8c4841..50a9fad41df96 100644 --- a/pkg/querier/http.go +++ b/pkg/querier/http.go @@ -5,19 +5,18 @@ import ( "net/http" "time" - util_log "github.com/cortexproject/cortex/pkg/util/log" "github.com/go-kit/log/level" "github.com/gorilla/websocket" "github.com/prometheus/prometheus/model/labels" "github.com/prometheus/prometheus/promql/parser" "github.com/weaveworks/common/httpgrpc" - "github.com/grafana/loki/pkg/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/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" serverutil "github.com/grafana/loki/pkg/util/server" diff --git a/pkg/querier/ingester_querier.go b/pkg/querier/ingester_querier.go index 6c33b7c6ecf90..710e5ea31b2ba 100644 --- a/pkg/querier/ingester_querier.go +++ b/pkg/querier/ingester_querier.go @@ -6,7 +6,6 @@ import ( "strings" "time" - util_log "github.com/cortexproject/cortex/pkg/util/log" "github.com/grafana/dskit/ring" ring_client "github.com/grafana/dskit/ring/client" "github.com/grafana/dskit/services" @@ -21,6 +20,7 @@ import ( "github.com/grafana/loki/pkg/logproto" "github.com/grafana/loki/pkg/logql" "github.com/grafana/loki/pkg/logqlmodel/stats" + util_log "github.com/grafana/loki/pkg/util/log" ) type responseFromIngesters struct { diff --git a/pkg/querier/querier.go b/pkg/querier/querier.go index d0778fca0e72c..676af2f36ebc6 100644 --- a/pkg/querier/querier.go +++ b/pkg/querier/querier.go @@ -14,16 +14,15 @@ import ( "github.com/go-kit/log/level" "github.com/pkg/errors" - "github.com/grafana/loki/pkg/util/spanlogger" - - "github.com/grafana/loki/pkg/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" + util_log "github.com/grafana/loki/pkg/util/log" + "github.com/grafana/loki/pkg/util/spanlogger" "github.com/grafana/loki/pkg/validation" ) @@ -91,13 +90,13 @@ func New(cfg Config, store storage.Store, ingesterQuerier *IngesterQuerier, limi limits: limits, } - querier.engine = logql.NewEngine(cfg.Engine, &querier, limits) + querier.engine = logql.NewEngine(cfg.Engine, &querier, limits, util_log.Logger) return &querier, nil } func (q *Querier) SetQueryable(queryable logql.Querier) { - q.engine = logql.NewEngine(q.cfg.Engine, queryable, q.limits) + q.engine = logql.NewEngine(q.cfg.Engine, queryable, q.limits, util_log.Logger) } // Select Implements logql.Querier which select logs via matchers and regex filters. diff --git a/pkg/querier/queryrange/limits_test.go b/pkg/querier/queryrange/limits_test.go index d2c5778f5e1c4..9cf61dc240537 100644 --- a/pkg/querier/queryrange/limits_test.go +++ b/pkg/querier/queryrange/limits_test.go @@ -8,7 +8,6 @@ import ( "testing" "time" - util_log "github.com/cortexproject/cortex/pkg/util/log" "github.com/prometheus/prometheus/model/labels" "github.com/prometheus/prometheus/promql" "github.com/stretchr/testify/require" @@ -19,6 +18,7 @@ import ( "github.com/grafana/loki/pkg/logqlmodel" "github.com/grafana/loki/pkg/querier/queryrange/queryrangebase" "github.com/grafana/loki/pkg/storage/chunk" + util_log "github.com/grafana/loki/pkg/util/log" "github.com/grafana/loki/pkg/util/marshal" ) diff --git a/pkg/querier/queryrange/queryrangebase/results_cache.go b/pkg/querier/queryrange/queryrangebase/results_cache.go index 18b396afb2eae..57e579646f91a 100644 --- a/pkg/querier/queryrange/queryrangebase/results_cache.go +++ b/pkg/querier/queryrange/queryrangebase/results_cache.go @@ -10,7 +10,6 @@ import ( "time" "github.com/cortexproject/cortex/pkg/cortexpb" - util_log "github.com/cortexproject/cortex/pkg/util/log" "github.com/cortexproject/cortex/pkg/util/validation" "github.com/go-kit/log" "github.com/go-kit/log/level" @@ -30,6 +29,7 @@ import ( "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" ) diff --git a/pkg/querier/queryrange/queryrangebase/retry.go b/pkg/querier/queryrange/queryrangebase/retry.go index b2339ea53e8f0..b0bc5af50e8ef 100644 --- a/pkg/querier/queryrange/queryrangebase/retry.go +++ b/pkg/querier/queryrange/queryrangebase/retry.go @@ -9,7 +9,7 @@ import ( "github.com/prometheus/client_golang/prometheus/promauto" "github.com/weaveworks/common/httpgrpc" - util_log "github.com/cortexproject/cortex/pkg/util/log" + util_log "github.com/grafana/loki/pkg/util/log" ) type RetryMiddlewareMetrics struct { diff --git a/pkg/querier/queryrange/querysharding.go b/pkg/querier/queryrange/querysharding.go index e88d35ee9e8d0..95d5e24d1a1e9 100644 --- a/pkg/querier/queryrange/querysharding.go +++ b/pkg/querier/queryrange/querysharding.go @@ -7,7 +7,6 @@ import ( "time" "github.com/cortexproject/cortex/pkg/util" - util_log "github.com/cortexproject/cortex/pkg/util/log" "github.com/go-kit/log" "github.com/go-kit/log/level" "github.com/pkg/errors" @@ -21,6 +20,7 @@ import ( "github.com/grafana/loki/pkg/querier/queryrange/queryrangebase" "github.com/grafana/loki/pkg/storage/chunk" "github.com/grafana/loki/pkg/tenant" + util_log "github.com/grafana/loki/pkg/util/log" "github.com/grafana/loki/pkg/util/marshal" ) @@ -70,12 +70,11 @@ func newASTMapperware( metrics *logql.ShardingMetrics, limits logql.Limits, ) *astMapperware { - return &astMapperware{ confs: confs, logger: log.With(logger, "middleware", "QueryShard.astMapperware"), next: next, - ng: logql.NewShardedEngine(logql.EngineOpts{}, DownstreamHandler{next}, metrics, limits), + ng: logql.NewShardedEngine(logql.EngineOpts{}, DownstreamHandler{next}, metrics, limits, logger), metrics: metrics, } } diff --git a/pkg/querier/queryrange/roundtrip_test.go b/pkg/querier/queryrange/roundtrip_test.go index c288f2081b7f6..f3a9385208f31 100644 --- a/pkg/querier/queryrange/roundtrip_test.go +++ b/pkg/querier/queryrange/roundtrip_test.go @@ -13,7 +13,6 @@ import ( "testing" "time" - util_log "github.com/cortexproject/cortex/pkg/util/log" "github.com/prometheus/prometheus/model/labels" "github.com/prometheus/prometheus/promql" "github.com/prometheus/prometheus/promql/parser" @@ -27,6 +26,7 @@ import ( "github.com/grafana/loki/pkg/querier/queryrange/queryrangebase" "github.com/grafana/loki/pkg/storage/chunk" "github.com/grafana/loki/pkg/storage/chunk/cache" + util_log "github.com/grafana/loki/pkg/util/log" "github.com/grafana/loki/pkg/util/marshal" ) diff --git a/pkg/querier/tail.go b/pkg/querier/tail.go index 63523db23f8fc..93938c44ec4ac 100644 --- a/pkg/querier/tail.go +++ b/pkg/querier/tail.go @@ -5,13 +5,13 @@ import ( "sync" "time" - util_log "github.com/cortexproject/cortex/pkg/util/log" "github.com/go-kit/log/level" "github.com/pkg/errors" "github.com/grafana/loki/pkg/iter" loghttp "github.com/grafana/loki/pkg/loghttp/legacy" "github.com/grafana/loki/pkg/logproto" + util_log "github.com/grafana/loki/pkg/util/log" ) const ( diff --git a/pkg/querier/worker/scheduler_processor.go b/pkg/querier/worker/scheduler_processor.go index 109d8a4afe7d5..787fa62714803 100644 --- a/pkg/querier/worker/scheduler_processor.go +++ b/pkg/querier/worker/scheduler_processor.go @@ -7,7 +7,6 @@ import ( "strings" "time" - util_log "github.com/cortexproject/cortex/pkg/util/log" "github.com/go-kit/log" "github.com/go-kit/log/level" "github.com/grafana/dskit/backoff" @@ -27,6 +26,7 @@ import ( 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" ) func newSchedulerProcessor(cfg Config, handler RequestHandler, log log.Logger, metrics *Metrics) (*schedulerProcessor, []services.Service) { diff --git a/pkg/querier/worker_service.go b/pkg/querier/worker_service.go index 12346323a30d6..58d4bc76301dc 100644 --- a/pkg/querier/worker_service.go +++ b/pkg/querier/worker_service.go @@ -4,7 +4,6 @@ import ( "fmt" "net/http" - util_log "github.com/cortexproject/cortex/pkg/util/log" "github.com/go-kit/log/level" "github.com/gorilla/mux" "github.com/grafana/dskit/ring" @@ -17,6 +16,7 @@ import ( querier_worker "github.com/grafana/loki/pkg/querier/worker" "github.com/grafana/loki/pkg/util/httpreq" + util_log "github.com/grafana/loki/pkg/util/log" serverutil "github.com/grafana/loki/pkg/util/server" ) diff --git a/pkg/ruler/base/api.go b/pkg/ruler/base/api.go index 3fb00e80e0f87..cd74afc793d11 100644 --- a/pkg/ruler/base/api.go +++ b/pkg/ruler/base/api.go @@ -11,7 +11,6 @@ import ( "time" "github.com/cortexproject/cortex/pkg/cortexpb" - util_log "github.com/cortexproject/cortex/pkg/util/log" "github.com/go-kit/log" "github.com/go-kit/log/level" "github.com/gorilla/mux" @@ -25,6 +24,7 @@ import ( "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" ) // In order to reimplement the prometheus rules API, a large amount of code was copied over diff --git a/pkg/ruler/base/compat.go b/pkg/ruler/base/compat.go index de1d7ed4fc02b..12be0db20b93a 100644 --- a/pkg/ruler/base/compat.go +++ b/pkg/ruler/base/compat.go @@ -6,7 +6,6 @@ import ( "time" "github.com/cortexproject/cortex/pkg/cortexpb" - util_log "github.com/cortexproject/cortex/pkg/util/log" "github.com/go-kit/log" "github.com/go-kit/log/level" "github.com/prometheus/client_golang/prometheus" @@ -22,6 +21,7 @@ import ( "github.com/weaveworks/common/user" "github.com/grafana/loki/pkg/querier" + util_log "github.com/grafana/loki/pkg/util/log" ) // Pusher is an ingester server that accepts pushes. diff --git a/pkg/ruler/base/ruler.go b/pkg/ruler/base/ruler.go index af6bf5b08bc16..3c88b6329d2ee 100644 --- a/pkg/ruler/base/ruler.go +++ b/pkg/ruler/base/ruler.go @@ -12,6 +12,9 @@ import ( "sync" "time" + "github.com/cortexproject/cortex/pkg/cortexpb" + "github.com/cortexproject/cortex/pkg/util" + "github.com/cortexproject/cortex/pkg/util/validation" "github.com/go-kit/log" "github.com/go-kit/log/level" "github.com/grafana/dskit/concurrency" @@ -30,14 +33,10 @@ import ( "github.com/weaveworks/common/user" "golang.org/x/sync/errgroup" - "github.com/cortexproject/cortex/pkg/cortexpb" - "github.com/cortexproject/cortex/pkg/util" - util_log "github.com/cortexproject/cortex/pkg/util/log" - "github.com/cortexproject/cortex/pkg/util/validation" - "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" ) var ( diff --git a/pkg/ruler/compat_test.go b/pkg/ruler/compat_test.go index 611ca198d5928..59bbe3bc5d1ed 100644 --- a/pkg/ruler/compat_test.go +++ b/pkg/ruler/compat_test.go @@ -15,6 +15,7 @@ import ( "github.com/grafana/loki/pkg/iter" "github.com/grafana/loki/pkg/logql" ruler "github.com/grafana/loki/pkg/ruler/base" + "github.com/grafana/loki/pkg/util/log" "github.com/grafana/loki/pkg/validation" ) @@ -304,7 +305,7 @@ func TestNonMetricQuery(t *testing.T) { overrides, err := validation.NewOverrides(validation.Limits{}, nil) require.Nil(t, err) - engine := logql.NewEngine(logql.EngineOpts{}, &FakeQuerier{}, overrides) + engine := logql.NewEngine(logql.EngineOpts{}, &FakeQuerier{}, overrides, log.Logger) queryFunc := engineQueryFunc(engine, overrides, fakeChecker{}, "fake") _, err = queryFunc(context.TODO(), `{job="nginx"}`, time.Now()) diff --git a/pkg/ruler/storage/instance/manager.go b/pkg/ruler/storage/instance/manager.go index fc38d0f33f400..0b11e0340a8b5 100644 --- a/pkg/ruler/storage/instance/manager.go +++ b/pkg/ruler/storage/instance/manager.go @@ -10,10 +10,11 @@ import ( "sync" "time" - util_log "github.com/cortexproject/cortex/pkg/util/log" "github.com/go-kit/log" "github.com/go-kit/log/level" "github.com/prometheus/prometheus/storage" + + util_log "github.com/grafana/loki/pkg/util/log" ) var ( diff --git a/pkg/scheduler/scheduler.go b/pkg/scheduler/scheduler.go index 86e5de1a26797..92ca2482d7d78 100644 --- a/pkg/scheduler/scheduler.go +++ b/pkg/scheduler/scheduler.go @@ -9,8 +9,6 @@ import ( "sync" "time" - util_log "github.com/cortexproject/cortex/pkg/util/log" - "github.com/cortexproject/cortex/pkg/util" "github.com/cortexproject/cortex/pkg/util/validation" "github.com/go-kit/log" @@ -39,6 +37,7 @@ import ( lokiutil "github.com/grafana/loki/pkg/util" lokigrpc "github.com/grafana/loki/pkg/util/httpgrpc" lokihttpreq "github.com/grafana/loki/pkg/util/httpreq" + util_log "github.com/grafana/loki/pkg/util/log" ) var errSchedulerIsNotRunning = errors.New("scheduler is not running") diff --git a/pkg/scheduler/scheduler_test.go b/pkg/scheduler/scheduler_test.go index 5d12568063eb4..64816eca5e4f0 100644 --- a/pkg/scheduler/scheduler_test.go +++ b/pkg/scheduler/scheduler_test.go @@ -4,14 +4,14 @@ import ( "context" "testing" - util_log "github.com/cortexproject/cortex/pkg/util/log" "github.com/prometheus/client_golang/prometheus" "github.com/prometheus/client_golang/prometheus/promauto" - "github.com/grafana/loki/pkg/scheduler/schedulerpb" - "github.com/stretchr/testify/assert" "google.golang.org/grpc/metadata" + + "github.com/grafana/loki/pkg/scheduler/schedulerpb" + util_log "github.com/grafana/loki/pkg/util/log" ) func TestScheduler_setRunState(t *testing.T) { diff --git a/pkg/storage/async_store.go b/pkg/storage/async_store.go index 125dfda9522a5..886534cb51db6 100644 --- a/pkg/storage/async_store.go +++ b/pkg/storage/async_store.go @@ -5,7 +5,6 @@ import ( "fmt" "time" - util_log "github.com/cortexproject/cortex/pkg/util/log" "github.com/go-kit/log/level" "github.com/prometheus/common/model" "github.com/prometheus/prometheus/model/labels" @@ -13,6 +12,7 @@ import ( "github.com/grafana/loki/pkg/util/spanlogger" "github.com/grafana/loki/pkg/storage/chunk" + util_log "github.com/grafana/loki/pkg/util/log" ) type IngesterQuerier interface { diff --git a/pkg/storage/batch.go b/pkg/storage/batch.go index 3a7af70bfa5bb..e3778ba9db330 100644 --- a/pkg/storage/batch.go +++ b/pkg/storage/batch.go @@ -5,7 +5,6 @@ import ( "sort" "time" - util_log "github.com/cortexproject/cortex/pkg/util/log" "github.com/go-kit/log/level" "github.com/pkg/errors" "github.com/prometheus/client_golang/prometheus" @@ -22,6 +21,7 @@ import ( "github.com/grafana/loki/pkg/logqlmodel/stats" "github.com/grafana/loki/pkg/querier/astmapper" "github.com/grafana/loki/pkg/storage/chunk" + util_log "github.com/grafana/loki/pkg/util/log" ) type ChunkMetrics struct { diff --git a/pkg/storage/chunk/aws/dynamodb_storage_client.go b/pkg/storage/chunk/aws/dynamodb_storage_client.go index 31ed9e1680a66..4627fba74c78b 100644 --- a/pkg/storage/chunk/aws/dynamodb_storage_client.go +++ b/pkg/storage/chunk/aws/dynamodb_storage_client.go @@ -18,7 +18,6 @@ import ( "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/go-kit/log/level" "github.com/grafana/dskit/backoff" "github.com/grafana/dskit/flagext" @@ -32,6 +31,7 @@ import ( "github.com/grafana/loki/pkg/storage/chunk" chunk_util "github.com/grafana/loki/pkg/storage/chunk/util" + "github.com/grafana/loki/pkg/util/log" "github.com/grafana/loki/pkg/util/math" "github.com/grafana/loki/pkg/util/spanlogger" ) diff --git a/pkg/storage/chunk/aws/dynamodb_table_client.go b/pkg/storage/chunk/aws/dynamodb_table_client.go index 4b7cc6d05cdf9..3783fada227ff 100644 --- a/pkg/storage/chunk/aws/dynamodb_table_client.go +++ b/pkg/storage/chunk/aws/dynamodb_table_client.go @@ -8,7 +8,6 @@ import ( "github.com/aws/aws-sdk-go/aws/awserr" "github.com/aws/aws-sdk-go/service/dynamodb" "github.com/aws/aws-sdk-go/service/dynamodb/dynamodbiface" - "github.com/cortexproject/cortex/pkg/util/log" "github.com/go-kit/log/level" "github.com/grafana/dskit/backoff" "github.com/pkg/errors" @@ -17,6 +16,7 @@ import ( "golang.org/x/time/rate" "github.com/grafana/loki/pkg/storage/chunk" + "github.com/grafana/loki/pkg/util/log" ) // Pluggable auto-scaler implementation diff --git a/pkg/storage/chunk/aws/metrics_autoscaling.go b/pkg/storage/chunk/aws/metrics_autoscaling.go index bef1fc8f3e21a..85039b2569f91 100644 --- a/pkg/storage/chunk/aws/metrics_autoscaling.go +++ b/pkg/storage/chunk/aws/metrics_autoscaling.go @@ -13,9 +13,8 @@ import ( "github.com/prometheus/common/model" "github.com/weaveworks/common/mtime" - util_log "github.com/cortexproject/cortex/pkg/util/log" - "github.com/grafana/loki/pkg/storage/chunk" + util_log "github.com/grafana/loki/pkg/util/log" ) const ( diff --git a/pkg/storage/chunk/aws/mock.go b/pkg/storage/chunk/aws/mock.go index 669cb9c2fc11c..3d2dfa576d527 100644 --- a/pkg/storage/chunk/aws/mock.go +++ b/pkg/storage/chunk/aws/mock.go @@ -18,7 +18,7 @@ import ( "github.com/aws/aws-sdk-go/service/s3/s3iface" "github.com/go-kit/log/level" - util_log "github.com/cortexproject/cortex/pkg/util/log" + util_log "github.com/grafana/loki/pkg/util/log" ) const arnPrefix = "arn:" diff --git a/pkg/storage/chunk/azure/blob_storage_client.go b/pkg/storage/chunk/azure/blob_storage_client.go index ac40f6e0f8c1b..fd5ee5ad07d55 100644 --- a/pkg/storage/chunk/azure/blob_storage_client.go +++ b/pkg/storage/chunk/azure/blob_storage_client.go @@ -15,18 +15,17 @@ import ( "github.com/Azure/azure-pipeline-go/pipeline" "github.com/Azure/azure-storage-blob-go/azblob" "github.com/Azure/go-autorest/autorest/adal" - "github.com/mattn/go-ieproxy" - "github.com/prometheus/client_golang/prometheus" - "github.com/weaveworks/common/instrument" - cortex_azure "github.com/cortexproject/cortex/pkg/chunk/azure" "github.com/cortexproject/cortex/pkg/util" - "github.com/cortexproject/cortex/pkg/util/log" "github.com/grafana/dskit/flagext" + "github.com/mattn/go-ieproxy" + "github.com/prometheus/client_golang/prometheus" + "github.com/weaveworks/common/instrument" "github.com/grafana/loki/pkg/storage/chunk" "github.com/grafana/loki/pkg/storage/chunk/hedging" chunk_util "github.com/grafana/loki/pkg/storage/chunk/util" + "github.com/grafana/loki/pkg/util/log" ) const ( @@ -169,7 +168,7 @@ type BlobStorage struct { // NewBlobStorage creates a new instance of the BlobStorage struct. func NewBlobStorage(cfg *BlobStorageConfig, hedgingCfg hedging.Config) (*BlobStorage, error) { - log.WarnExperimentalUse("Azure Blob Storage") + log.WarnExperimentalUse("Azure Blob Storage", log.Logger) blobStorage := &BlobStorage{ cfg: cfg, } diff --git a/pkg/storage/chunk/cache/background.go b/pkg/storage/chunk/cache/background.go index 10cf8048b949e..0140f1313f270 100644 --- a/pkg/storage/chunk/cache/background.go +++ b/pkg/storage/chunk/cache/background.go @@ -5,12 +5,13 @@ import ( "flag" "sync" - util_log "github.com/cortexproject/cortex/pkg/util/log" "github.com/go-kit/log/level" opentracing "github.com/opentracing/opentracing-go" otlog "github.com/opentracing/opentracing-go/log" "github.com/prometheus/client_golang/prometheus" "github.com/prometheus/client_golang/prometheus/promauto" + + util_log "github.com/grafana/loki/pkg/util/log" ) // BackgroundConfig is config for a Background Cache. diff --git a/pkg/storage/chunk/cache/fifo_cache.go b/pkg/storage/chunk/cache/fifo_cache.go index 4879c92648622..3f7470690eb3c 100644 --- a/pkg/storage/chunk/cache/fifo_cache.go +++ b/pkg/storage/chunk/cache/fifo_cache.go @@ -8,7 +8,6 @@ import ( "time" "unsafe" - util_log "github.com/cortexproject/cortex/pkg/util/log" "github.com/dustin/go-humanize" "github.com/go-kit/log" "github.com/go-kit/log/level" @@ -16,6 +15,8 @@ import ( "github.com/pkg/errors" "github.com/prometheus/client_golang/prometheus" "github.com/prometheus/client_golang/prometheus/promauto" + + util_log "github.com/grafana/loki/pkg/util/log" ) const ( @@ -92,7 +93,7 @@ type cacheEntry struct { // NewFifoCache returns a new initialised FifoCache of size. func NewFifoCache(name string, cfg FifoCacheConfig, reg prometheus.Registerer, logger log.Logger) *FifoCache { - util_log.WarnExperimentalUse("In-memory (FIFO) cache") + util_log.WarnExperimentalUse("In-memory (FIFO) cache", logger) if cfg.DeprecatedSize > 0 { flagext.DeprecatedFlagsUsed.Inc() diff --git a/pkg/storage/chunk/cache/memcached.go b/pkg/storage/chunk/cache/memcached.go index 42d88b6e0d5bb..39acf24ce0c4d 100644 --- a/pkg/storage/chunk/cache/memcached.go +++ b/pkg/storage/chunk/cache/memcached.go @@ -15,8 +15,7 @@ import ( "github.com/prometheus/client_golang/prometheus/promauto" instr "github.com/weaveworks/common/instrument" - util_log "github.com/cortexproject/cortex/pkg/util/log" - + util_log "github.com/grafana/loki/pkg/util/log" "github.com/grafana/loki/pkg/util/math" ) diff --git a/pkg/storage/chunk/cache/memcached_client.go b/pkg/storage/chunk/cache/memcached_client.go index 6e230c00de6f9..b8e2dacd14c75 100644 --- a/pkg/storage/chunk/cache/memcached_client.go +++ b/pkg/storage/chunk/cache/memcached_client.go @@ -19,7 +19,7 @@ import ( "github.com/sony/gobreaker" "github.com/thanos-io/thanos/pkg/discovery/dns" - util_log "github.com/cortexproject/cortex/pkg/util/log" + util_log "github.com/grafana/loki/pkg/util/log" ) // MemcachedClient interface exists for mocking memcacheClient. @@ -145,7 +145,7 @@ func NewMemcachedClient(cfg MemcachedClientConfig, name string, r prometheus.Reg } if len(cfg.Addresses) > 0 { - util_log.WarnExperimentalUse("DNS-based memcached service discovery") + util_log.WarnExperimentalUse("DNS-based memcached service discovery", logger) newClient.addresses = strings.Split(cfg.Addresses, ",") } diff --git a/pkg/storage/chunk/cache/redis_cache.go b/pkg/storage/chunk/cache/redis_cache.go index 6d7690a52fc2e..284457980330d 100644 --- a/pkg/storage/chunk/cache/redis_cache.go +++ b/pkg/storage/chunk/cache/redis_cache.go @@ -6,7 +6,7 @@ import ( "github.com/go-kit/log" "github.com/go-kit/log/level" - util_log "github.com/cortexproject/cortex/pkg/util/log" + util_log "github.com/grafana/loki/pkg/util/log" ) // RedisCache type caches chunks in redis @@ -18,7 +18,7 @@ type RedisCache struct { // NewRedisCache creates a new RedisCache func NewRedisCache(name string, redisClient *RedisClient, logger log.Logger) *RedisCache { - util_log.WarnExperimentalUse("Redis cache") + util_log.WarnExperimentalUse("Redis cache", logger) cache := &RedisCache{ name: name, redis: redisClient, diff --git a/pkg/storage/chunk/cassandra/storage_client.go b/pkg/storage/chunk/cassandra/storage_client.go index 65c8a0280c614..ff9522f63d246 100644 --- a/pkg/storage/chunk/cassandra/storage_client.go +++ b/pkg/storage/chunk/cassandra/storage_client.go @@ -13,15 +13,14 @@ import ( "github.com/go-kit/log" "github.com/go-kit/log/level" "github.com/gocql/gocql" + "github.com/grafana/dskit/flagext" "github.com/pkg/errors" "github.com/prometheus/client_golang/prometheus" "golang.org/x/sync/semaphore" - 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" + util_log "github.com/grafana/loki/pkg/util/log" ) // Config for a StorageClient diff --git a/pkg/storage/chunk/chunk_store.go b/pkg/storage/chunk/chunk_store.go index 8b691ab6885fc..47b69dd0ac2a8 100644 --- a/pkg/storage/chunk/chunk_store.go +++ b/pkg/storage/chunk/chunk_store.go @@ -8,6 +8,8 @@ import ( "sync" "time" + "github.com/cortexproject/cortex/pkg/util" + "github.com/cortexproject/cortex/pkg/util/validation" "github.com/go-kit/log" "github.com/go-kit/log/level" "github.com/pkg/errors" @@ -16,13 +18,10 @@ import ( "github.com/prometheus/common/model" "github.com/prometheus/prometheus/model/labels" - "github.com/cortexproject/cortex/pkg/util" - util_log "github.com/cortexproject/cortex/pkg/util/log" - "github.com/cortexproject/cortex/pkg/util/validation" - "github.com/grafana/loki/pkg/storage/chunk/cache" "github.com/grafana/loki/pkg/storage/chunk/encoding" "github.com/grafana/loki/pkg/util/extract" + util_log "github.com/grafana/loki/pkg/util/log" "github.com/grafana/loki/pkg/util/spanlogger" ) diff --git a/pkg/storage/chunk/chunk_store_utils.go b/pkg/storage/chunk/chunk_store_utils.go index 64429e732f70f..e03df92fd27f2 100644 --- a/pkg/storage/chunk/chunk_store_utils.go +++ b/pkg/storage/chunk/chunk_store_utils.go @@ -12,11 +12,9 @@ import ( "github.com/prometheus/prometheus/model/labels" "github.com/prometheus/prometheus/promql" - util_log "github.com/cortexproject/cortex/pkg/util/log" - - "github.com/grafana/loki/pkg/util/spanlogger" - "github.com/grafana/loki/pkg/storage/chunk/cache" + util_log "github.com/grafana/loki/pkg/util/log" + "github.com/grafana/loki/pkg/util/spanlogger" ) var ( diff --git a/pkg/storage/chunk/inmemory_storage_client.go b/pkg/storage/chunk/inmemory_storage_client.go index 0b2d64aa241c1..a72eb7e3ba30b 100644 --- a/pkg/storage/chunk/inmemory_storage_client.go +++ b/pkg/storage/chunk/inmemory_storage_client.go @@ -13,7 +13,7 @@ import ( "github.com/go-kit/log/level" - "github.com/cortexproject/cortex/pkg/util/log" + "github.com/grafana/loki/pkg/util/log" ) type MockStorageMode int diff --git a/pkg/storage/chunk/local/boltdb_index_client.go b/pkg/storage/chunk/local/boltdb_index_client.go index e7fc6588b83ff..1c39e5d68641d 100644 --- a/pkg/storage/chunk/local/boltdb_index_client.go +++ b/pkg/storage/chunk/local/boltdb_index_client.go @@ -15,10 +15,9 @@ import ( "github.com/go-kit/log/level" "go.etcd.io/bbolt" - util_log "github.com/cortexproject/cortex/pkg/util/log" - "github.com/grafana/loki/pkg/storage/chunk" chunk_util "github.com/grafana/loki/pkg/storage/chunk/util" + util_log "github.com/grafana/loki/pkg/util/log" ) var ( diff --git a/pkg/storage/chunk/local/fs_object_client.go b/pkg/storage/chunk/local/fs_object_client.go index c60797d3f1837..aeaf739e18706 100644 --- a/pkg/storage/chunk/local/fs_object_client.go +++ b/pkg/storage/chunk/local/fs_object_client.go @@ -13,11 +13,10 @@ import ( "github.com/pkg/errors" "github.com/thanos-io/thanos/pkg/runutil" - util_log "github.com/cortexproject/cortex/pkg/util/log" - "github.com/grafana/loki/pkg/ruler/rulestore/local" "github.com/grafana/loki/pkg/storage/chunk" "github.com/grafana/loki/pkg/storage/chunk/util" + util_log "github.com/grafana/loki/pkg/util/log" ) // FSConfig is the config for a FSObjectClient. diff --git a/pkg/storage/chunk/openstack/swift_object_client.go b/pkg/storage/chunk/openstack/swift_object_client.go index 8e306dcce38e5..06e7172630ca0 100644 --- a/pkg/storage/chunk/openstack/swift_object_client.go +++ b/pkg/storage/chunk/openstack/swift_object_client.go @@ -16,10 +16,10 @@ import ( cortex_openstack "github.com/cortexproject/cortex/pkg/chunk/openstack" cortex_swift "github.com/cortexproject/cortex/pkg/storage/bucket/swift" - "github.com/cortexproject/cortex/pkg/util/log" "github.com/grafana/loki/pkg/storage/chunk" "github.com/grafana/loki/pkg/storage/chunk/hedging" + "github.com/grafana/loki/pkg/util/log" ) var defaultTransport http.RoundTripper = &http.Transport{ @@ -63,7 +63,7 @@ func (cfg *SwiftConfig) ToCortexSwiftConfig() cortex_openstack.SwiftConfig { // NewSwiftObjectClient makes a new chunk.Client that writes chunks to OpenStack Swift. func NewSwiftObjectClient(cfg SwiftConfig, hedgingCfg hedging.Config) (*SwiftObjectClient, error) { - log.WarnExperimentalUse("OpenStack Swift Storage") + log.WarnExperimentalUse("OpenStack Swift Storage", log.Logger) c, err := createConnection(cfg, hedgingCfg, false) if err != nil { diff --git a/pkg/storage/chunk/schema.go b/pkg/storage/chunk/schema.go index f61f299cbdae5..710063706cab7 100644 --- a/pkg/storage/chunk/schema.go +++ b/pkg/storage/chunk/schema.go @@ -13,9 +13,8 @@ import ( "github.com/prometheus/common/model" "github.com/prometheus/prometheus/model/labels" - util_log "github.com/cortexproject/cortex/pkg/util/log" - "github.com/grafana/loki/pkg/querier/astmapper" + util_log "github.com/grafana/loki/pkg/util/log" ) const ( diff --git a/pkg/storage/chunk/schema_config.go b/pkg/storage/chunk/schema_config.go index 8daa95bda9e36..fb23243d7cb65 100644 --- a/pkg/storage/chunk/schema_config.go +++ b/pkg/storage/chunk/schema_config.go @@ -14,8 +14,7 @@ import ( "github.com/weaveworks/common/mtime" yaml "gopkg.in/yaml.v2" - "github.com/cortexproject/cortex/pkg/util/log" - + "github.com/grafana/loki/pkg/util/log" "github.com/grafana/loki/pkg/util/math" ) diff --git a/pkg/storage/chunk/series_store.go b/pkg/storage/chunk/series_store.go index fa3ee8622145c..2604fe5808aa1 100644 --- a/pkg/storage/chunk/series_store.go +++ b/pkg/storage/chunk/series_store.go @@ -14,12 +14,12 @@ import ( "github.com/prometheus/prometheus/model/labels" "github.com/cortexproject/cortex/pkg/util" - util_log "github.com/cortexproject/cortex/pkg/util/log" "github.com/grafana/loki/pkg/util/spanlogger" "github.com/grafana/loki/pkg/querier/astmapper" "github.com/grafana/loki/pkg/storage/chunk/cache" + util_log "github.com/grafana/loki/pkg/util/log" ) // CardinalityExceededError is returned when the user reads a row that diff --git a/pkg/storage/chunk/storage/caching_index_client.go b/pkg/storage/chunk/storage/caching_index_client.go index 40fea4cc1ea7b..6c61bed944254 100644 --- a/pkg/storage/chunk/storage/caching_index_client.go +++ b/pkg/storage/chunk/storage/caching_index_client.go @@ -11,13 +11,11 @@ import ( "github.com/prometheus/client_golang/prometheus" "github.com/prometheus/client_golang/prometheus/promauto" - "github.com/grafana/loki/pkg/util/spanlogger" - - "github.com/grafana/loki/pkg/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" + "github.com/grafana/loki/pkg/util/spanlogger" ) var ( diff --git a/pkg/storage/chunk/storage/factory.go b/pkg/storage/chunk/storage/factory.go index 427b932ea3248..cf4a157d99b2d 100644 --- a/pkg/storage/chunk/storage/factory.go +++ b/pkg/storage/chunk/storage/factory.go @@ -12,8 +12,6 @@ import ( "github.com/pkg/errors" "github.com/prometheus/client_golang/prometheus" - util_log "github.com/cortexproject/cortex/pkg/util/log" - "github.com/grafana/loki/pkg/storage/chunk" "github.com/grafana/loki/pkg/storage/chunk/aws" "github.com/grafana/loki/pkg/storage/chunk/azure" @@ -25,6 +23,7 @@ import ( "github.com/grafana/loki/pkg/storage/chunk/local" "github.com/grafana/loki/pkg/storage/chunk/objectclient" "github.com/grafana/loki/pkg/storage/chunk/openstack" + util_log "github.com/grafana/loki/pkg/util/log" ) // Supported storage engines diff --git a/pkg/storage/chunk/table_manager.go b/pkg/storage/chunk/table_manager.go index 34599319f4ffa..5b9943433c485 100644 --- a/pkg/storage/chunk/table_manager.go +++ b/pkg/storage/chunk/table_manager.go @@ -19,7 +19,7 @@ import ( "github.com/weaveworks/common/instrument" "github.com/weaveworks/common/mtime" - util_log "github.com/cortexproject/cortex/pkg/util/log" + util_log "github.com/grafana/loki/pkg/util/log" ) const ( diff --git a/pkg/storage/hack/main.go b/pkg/storage/hack/main.go index cb03c5a42a4f0..c5184b5aa3d79 100644 --- a/pkg/storage/hack/main.go +++ b/pkg/storage/hack/main.go @@ -9,14 +9,12 @@ import ( "sync" "time" + "github.com/cortexproject/cortex/pkg/ingester/client" "github.com/prometheus/client_golang/prometheus" "github.com/prometheus/common/model" "github.com/prometheus/prometheus/model/labels" "github.com/weaveworks/common/user" - "github.com/cortexproject/cortex/pkg/ingester/client" - util_log "github.com/cortexproject/cortex/pkg/util/log" - "github.com/grafana/loki/pkg/chunkenc" "github.com/grafana/loki/pkg/logproto" "github.com/grafana/loki/pkg/logql" @@ -24,6 +22,7 @@ import ( "github.com/grafana/loki/pkg/storage/chunk" "github.com/grafana/loki/pkg/storage/chunk/local" "github.com/grafana/loki/pkg/storage/chunk/storage" + util_log "github.com/grafana/loki/pkg/util/log" "github.com/grafana/loki/pkg/validation" ) diff --git a/pkg/storage/lazy_chunk.go b/pkg/storage/lazy_chunk.go index a2910a85406ff..436e0274dfe10 100644 --- a/pkg/storage/lazy_chunk.go +++ b/pkg/storage/lazy_chunk.go @@ -5,7 +5,6 @@ import ( "errors" "time" - util_log "github.com/cortexproject/cortex/pkg/util/log" "github.com/go-kit/log/level" "github.com/grafana/loki/pkg/chunkenc" @@ -13,6 +12,7 @@ import ( "github.com/grafana/loki/pkg/logproto" "github.com/grafana/loki/pkg/logql/log" "github.com/grafana/loki/pkg/storage/chunk" + util_log "github.com/grafana/loki/pkg/util/log" ) // LazyChunk loads the chunk when it is accessed. diff --git a/pkg/storage/store_test.go b/pkg/storage/store_test.go index ad0f5d6234bff..dd436e32208e5 100644 --- a/pkg/storage/store_test.go +++ b/pkg/storage/store_test.go @@ -12,8 +12,6 @@ import ( "testing" "time" - util_log "github.com/cortexproject/cortex/pkg/util/log" - "github.com/stretchr/testify/assert" "github.com/cespare/xxhash/v2" @@ -32,6 +30,7 @@ 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" + util_log "github.com/grafana/loki/pkg/util/log" "github.com/grafana/loki/pkg/util/marshal" "github.com/grafana/loki/pkg/validation" ) diff --git a/pkg/storage/stores/shipper/compactor/compactor.go b/pkg/storage/stores/shipper/compactor/compactor.go index a97966261748c..da76fe00886fd 100644 --- a/pkg/storage/stores/shipper/compactor/compactor.go +++ b/pkg/storage/stores/shipper/compactor/compactor.go @@ -9,7 +9,6 @@ import ( "sync" "time" - util_log "github.com/cortexproject/cortex/pkg/util/log" "github.com/go-kit/log/level" "github.com/grafana/dskit/kv" "github.com/grafana/dskit/ring" @@ -28,6 +27,7 @@ import ( shipper_storage "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/util" + util_log "github.com/grafana/loki/pkg/util/log" ) const ( diff --git a/pkg/storage/stores/shipper/compactor/deletion/delete_requests_manager.go b/pkg/storage/stores/shipper/compactor/deletion/delete_requests_manager.go index 77c75a948f96d..76a73124b2db8 100644 --- a/pkg/storage/stores/shipper/compactor/deletion/delete_requests_manager.go +++ b/pkg/storage/stores/shipper/compactor/deletion/delete_requests_manager.go @@ -10,9 +10,8 @@ import ( "github.com/prometheus/client_golang/prometheus" "github.com/prometheus/common/model" - util_log "github.com/cortexproject/cortex/pkg/util/log" - "github.com/grafana/loki/pkg/storage/stores/shipper/compactor/retention" + util_log "github.com/grafana/loki/pkg/util/log" ) const ( diff --git a/pkg/storage/stores/shipper/compactor/deletion/delete_requests_table.go b/pkg/storage/stores/shipper/compactor/deletion/delete_requests_table.go index 48479e29eab5e..eba19abec4b59 100644 --- a/pkg/storage/stores/shipper/compactor/deletion/delete_requests_table.go +++ b/pkg/storage/stores/shipper/compactor/deletion/delete_requests_table.go @@ -13,13 +13,12 @@ import ( "github.com/go-kit/log/level" "go.etcd.io/bbolt" - util_log "github.com/cortexproject/cortex/pkg/util/log" - "github.com/grafana/loki/pkg/chunkenc" "github.com/grafana/loki/pkg/storage/chunk" "github.com/grafana/loki/pkg/storage/chunk/local" "github.com/grafana/loki/pkg/storage/stores/shipper/storage" shipper_util "github.com/grafana/loki/pkg/storage/stores/shipper/util" + util_log "github.com/grafana/loki/pkg/util/log" ) type deleteRequestsTable struct { diff --git a/pkg/storage/stores/shipper/compactor/deletion/request_handler.go b/pkg/storage/stores/shipper/compactor/deletion/request_handler.go index 50cbb948466b7..0fc857f31b7cc 100644 --- a/pkg/storage/stores/shipper/compactor/deletion/request_handler.go +++ b/pkg/storage/stores/shipper/compactor/deletion/request_handler.go @@ -6,7 +6,6 @@ import ( "time" "github.com/cortexproject/cortex/pkg/util" - util_log "github.com/cortexproject/cortex/pkg/util/log" "github.com/go-kit/log/level" "github.com/prometheus/client_golang/prometheus" "github.com/prometheus/common/model" @@ -14,6 +13,7 @@ import ( "github.com/grafana/loki/pkg/tenant" + util_log "github.com/grafana/loki/pkg/util/log" serverutil "github.com/grafana/loki/pkg/util/server" ) diff --git a/pkg/storage/stores/shipper/compactor/index_set.go b/pkg/storage/stores/shipper/compactor/index_set.go index 35fc13d4dd407..8feab4b2fbbfe 100644 --- a/pkg/storage/stores/shipper/compactor/index_set.go +++ b/pkg/storage/stores/shipper/compactor/index_set.go @@ -11,12 +11,11 @@ import ( "github.com/go-kit/log/level" "go.etcd.io/bbolt" - util_log "github.com/cortexproject/cortex/pkg/util/log" - "github.com/grafana/loki/pkg/storage/chunk/util" "github.com/grafana/loki/pkg/storage/stores/shipper/compactor/retention" "github.com/grafana/loki/pkg/storage/stores/shipper/storage" shipper_util "github.com/grafana/loki/pkg/storage/stores/shipper/util" + util_log "github.com/grafana/loki/pkg/util/log" ) const userIndexReadinessTimeout = 15 * time.Minute diff --git a/pkg/storage/stores/shipper/compactor/retention/expiration.go b/pkg/storage/stores/shipper/compactor/retention/expiration.go index 9659a34a11a52..87c4e6d6ec056 100644 --- a/pkg/storage/stores/shipper/compactor/retention/expiration.go +++ b/pkg/storage/stores/shipper/compactor/retention/expiration.go @@ -8,8 +8,7 @@ import ( "github.com/prometheus/common/model" "github.com/prometheus/prometheus/model/labels" - util_log "github.com/cortexproject/cortex/pkg/util/log" - + util_log "github.com/grafana/loki/pkg/util/log" "github.com/grafana/loki/pkg/validation" ) diff --git a/pkg/storage/stores/shipper/compactor/retention/index.go b/pkg/storage/stores/shipper/compactor/retention/index.go index 3ef8db014a0ab..e36adc4161bce 100644 --- a/pkg/storage/stores/shipper/compactor/retention/index.go +++ b/pkg/storage/stores/shipper/compactor/retention/index.go @@ -7,14 +7,13 @@ import ( "strings" "time" - "github.com/prometheus/common/model" - - util_log "github.com/cortexproject/cortex/pkg/util/log" "github.com/go-kit/log/level" + "github.com/prometheus/common/model" "github.com/grafana/loki/pkg/storage" "github.com/grafana/loki/pkg/storage/chunk" "github.com/grafana/loki/pkg/storage/stores/shipper" + util_log "github.com/grafana/loki/pkg/util/log" ) const ( diff --git a/pkg/storage/stores/shipper/compactor/retention/marker.go b/pkg/storage/stores/shipper/compactor/retention/marker.go index edb3f2c77ee16..d88697d516310 100644 --- a/pkg/storage/stores/shipper/compactor/retention/marker.go +++ b/pkg/storage/stores/shipper/compactor/retention/marker.go @@ -13,12 +13,12 @@ import ( "sync" "time" - util_log "github.com/cortexproject/cortex/pkg/util/log" "github.com/go-kit/log/level" "go.etcd.io/bbolt" chunk_util "github.com/grafana/loki/pkg/storage/chunk/util" shipper_util "github.com/grafana/loki/pkg/storage/stores/shipper/util" + util_log "github.com/grafana/loki/pkg/util/log" ) var ( diff --git a/pkg/storage/stores/shipper/compactor/retention/retention.go b/pkg/storage/stores/shipper/compactor/retention/retention.go index fbc7a372f7ae2..0b3db49e461fa 100644 --- a/pkg/storage/stores/shipper/compactor/retention/retention.go +++ b/pkg/storage/stores/shipper/compactor/retention/retention.go @@ -7,7 +7,6 @@ import ( "fmt" "time" - util_log "github.com/cortexproject/cortex/pkg/util/log" "github.com/go-kit/log/level" "github.com/prometheus/client_golang/prometheus" "github.com/prometheus/common/model" @@ -16,6 +15,7 @@ import ( "github.com/grafana/loki/pkg/chunkenc" "github.com/grafana/loki/pkg/storage" "github.com/grafana/loki/pkg/storage/chunk" + util_log "github.com/grafana/loki/pkg/util/log" ) var ( diff --git a/pkg/storage/stores/shipper/compactor/retention/util_test.go b/pkg/storage/stores/shipper/compactor/retention/util_test.go index f4b77c0ae0975..4587e6ea83c2f 100644 --- a/pkg/storage/stores/shipper/compactor/retention/util_test.go +++ b/pkg/storage/stores/shipper/compactor/retention/util_test.go @@ -8,7 +8,6 @@ import ( "testing" "time" - util_log "github.com/cortexproject/cortex/pkg/util/log" "github.com/prometheus/client_golang/prometheus" "github.com/prometheus/common/model" "github.com/prometheus/prometheus/model/labels" @@ -25,6 +24,7 @@ import ( chunk_util "github.com/grafana/loki/pkg/storage/chunk/util" "github.com/grafana/loki/pkg/storage/stores/shipper" shipper_util "github.com/grafana/loki/pkg/storage/stores/shipper/util" + util_log "github.com/grafana/loki/pkg/util/log" "github.com/grafana/loki/pkg/validation" ) @@ -202,7 +202,7 @@ func newTestStore(t testing.TB) *testStore { t.Helper() cfg := &ww.Config{} require.Nil(t, cfg.LogLevel.Set("debug")) - util_log.InitLogger(cfg) + util_log.InitLogger(cfg, nil) workdir := t.TempDir() filepath.Join(workdir, "index") indexDir := filepath.Join(workdir, "index") diff --git a/pkg/storage/stores/shipper/compactor/table.go b/pkg/storage/stores/shipper/compactor/table.go index bdd74c34dfbba..f65cd19fd73bf 100644 --- a/pkg/storage/stores/shipper/compactor/table.go +++ b/pkg/storage/stores/shipper/compactor/table.go @@ -10,8 +10,6 @@ import ( "sync" "time" - util_log "github.com/cortexproject/cortex/pkg/util/log" - "github.com/go-kit/log" "github.com/go-kit/log/level" "github.com/grafana/dskit/concurrency" @@ -23,6 +21,7 @@ import ( "github.com/grafana/loki/pkg/storage/stores/shipper/compactor/retention" "github.com/grafana/loki/pkg/storage/stores/shipper/storage" shipper_util "github.com/grafana/loki/pkg/storage/stores/shipper/util" + util_log "github.com/grafana/loki/pkg/util/log" ) const ( diff --git a/pkg/storage/stores/shipper/downloads/index_set.go b/pkg/storage/stores/shipper/downloads/index_set.go index 3eaabf85af397..064351931d455 100644 --- a/pkg/storage/stores/shipper/downloads/index_set.go +++ b/pkg/storage/stores/shipper/downloads/index_set.go @@ -16,13 +16,13 @@ import ( "go.etcd.io/bbolt" "github.com/cortexproject/cortex/pkg/tenant" - util_log "github.com/cortexproject/cortex/pkg/util/log" "github.com/cortexproject/cortex/pkg/util/spanlogger" "github.com/grafana/loki/pkg/storage/chunk" chunk_util "github.com/grafana/loki/pkg/storage/chunk/util" "github.com/grafana/loki/pkg/storage/stores/shipper/storage" shipper_util "github.com/grafana/loki/pkg/storage/stores/shipper/util" + util_log "github.com/grafana/loki/pkg/util/log" ) type IndexSet interface { diff --git a/pkg/storage/stores/shipper/downloads/index_set_test.go b/pkg/storage/stores/shipper/downloads/index_set_test.go index d596b064aaf9c..3d48b1b277556 100644 --- a/pkg/storage/stores/shipper/downloads/index_set_test.go +++ b/pkg/storage/stores/shipper/downloads/index_set_test.go @@ -9,11 +9,10 @@ import ( "github.com/stretchr/testify/require" - util_log "github.com/cortexproject/cortex/pkg/util/log" - "github.com/grafana/loki/pkg/storage/chunk" "github.com/grafana/loki/pkg/storage/stores/shipper/storage" "github.com/grafana/loki/pkg/storage/stores/shipper/testutil" + util_log "github.com/grafana/loki/pkg/util/log" ) const tableName = "test" diff --git a/pkg/storage/stores/shipper/downloads/table.go b/pkg/storage/stores/shipper/downloads/table.go index ab9223d71c093..2e014b60a4709 100644 --- a/pkg/storage/stores/shipper/downloads/table.go +++ b/pkg/storage/stores/shipper/downloads/table.go @@ -9,18 +9,17 @@ import ( "sync" "time" + "github.com/cortexproject/cortex/pkg/tenant" "github.com/go-kit/log" "github.com/go-kit/log/level" "github.com/grafana/dskit/concurrency" "github.com/pkg/errors" "go.etcd.io/bbolt" - "github.com/cortexproject/cortex/pkg/tenant" - util_log "github.com/cortexproject/cortex/pkg/util/log" - "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" + util_log "github.com/grafana/loki/pkg/util/log" ) // timeout for downloading initial files for a table to avoid leaking resources by allowing it to take all the time. diff --git a/pkg/storage/stores/shipper/downloads/table_manager.go b/pkg/storage/stores/shipper/downloads/table_manager.go index 6682d104eda5d..668de4a5d19a7 100644 --- a/pkg/storage/stores/shipper/downloads/table_manager.go +++ b/pkg/storage/stores/shipper/downloads/table_manager.go @@ -10,8 +10,6 @@ import ( "sync" "time" - util_log "github.com/cortexproject/cortex/pkg/util/log" - "github.com/go-kit/log/level" "github.com/prometheus/client_golang/prometheus" @@ -19,6 +17,7 @@ import ( chunk_util "github.com/grafana/loki/pkg/storage/chunk/util" "github.com/grafana/loki/pkg/storage/stores/shipper/storage" "github.com/grafana/loki/pkg/storage/stores/shipper/util" + util_log "github.com/grafana/loki/pkg/util/log" ) const ( diff --git a/pkg/storage/stores/shipper/downloads/table_test.go b/pkg/storage/stores/shipper/downloads/table_test.go index 5f108401ef0ed..c302b448ff6cc 100644 --- a/pkg/storage/stores/shipper/downloads/table_test.go +++ b/pkg/storage/stores/shipper/downloads/table_test.go @@ -14,13 +14,12 @@ import ( "github.com/stretchr/testify/require" "github.com/weaveworks/common/user" - util_log "github.com/cortexproject/cortex/pkg/util/log" - "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" "github.com/grafana/loki/pkg/storage/stores/shipper/testutil" + util_log "github.com/grafana/loki/pkg/util/log" ) const ( diff --git a/pkg/storage/stores/shipper/gateway_client.go b/pkg/storage/stores/shipper/gateway_client.go index 4dec8b92b5aa0..88366d0aa77fe 100644 --- a/pkg/storage/stores/shipper/gateway_client.go +++ b/pkg/storage/stores/shipper/gateway_client.go @@ -6,7 +6,6 @@ import ( "fmt" "io" - util_log "github.com/cortexproject/cortex/pkg/util/log" "github.com/go-kit/log/level" "github.com/grafana/dskit/grpcclient" "github.com/pkg/errors" @@ -19,6 +18,7 @@ import ( "github.com/grafana/loki/pkg/storage/chunk/util" "github.com/grafana/loki/pkg/storage/stores/shipper/indexgateway/indexgatewaypb" shipper_util "github.com/grafana/loki/pkg/storage/stores/shipper/util" + util_log "github.com/grafana/loki/pkg/util/log" util_math "github.com/grafana/loki/pkg/util/math" ) diff --git a/pkg/storage/stores/shipper/shipper_index_client.go b/pkg/storage/stores/shipper/shipper_index_client.go index c711b8ce7cb75..6ae977c3b84f3 100644 --- a/pkg/storage/stores/shipper/shipper_index_client.go +++ b/pkg/storage/stores/shipper/shipper_index_client.go @@ -10,7 +10,6 @@ import ( "sync" "time" - util_log "github.com/cortexproject/cortex/pkg/util/log" "github.com/go-kit/log/level" "github.com/prometheus/client_golang/prometheus" "github.com/weaveworks/common/instrument" @@ -25,6 +24,7 @@ import ( "github.com/grafana/loki/pkg/storage/stores/shipper/storage" "github.com/grafana/loki/pkg/storage/stores/shipper/uploads" shipper_util "github.com/grafana/loki/pkg/storage/stores/shipper/util" + util_log "github.com/grafana/loki/pkg/util/log" ) const ( diff --git a/pkg/storage/stores/shipper/storage/cached_client.go b/pkg/storage/stores/shipper/storage/cached_client.go index e6a55a34d84a0..96ecc7f80da11 100644 --- a/pkg/storage/stores/shipper/storage/cached_client.go +++ b/pkg/storage/stores/shipper/storage/cached_client.go @@ -10,9 +10,8 @@ import ( "github.com/go-kit/log/level" - util_log "github.com/cortexproject/cortex/pkg/util/log" - "github.com/grafana/loki/pkg/storage/chunk" + util_log "github.com/grafana/loki/pkg/util/log" ) const ( diff --git a/pkg/storage/stores/shipper/uploads/table.go b/pkg/storage/stores/shipper/uploads/table.go index 65e4ed53260d0..ebad7afe5b864 100644 --- a/pkg/storage/stores/shipper/uploads/table.go +++ b/pkg/storage/stores/shipper/uploads/table.go @@ -13,7 +13,6 @@ import ( "sync" "time" - util_log "github.com/cortexproject/cortex/pkg/util/log" "github.com/go-kit/log/level" "go.etcd.io/bbolt" @@ -22,6 +21,7 @@ import ( "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" + util_log "github.com/grafana/loki/pkg/util/log" ) const ( diff --git a/pkg/storage/stores/shipper/uploads/table_manager.go b/pkg/storage/stores/shipper/uploads/table_manager.go index 336dfec42316e..8494a69036850 100644 --- a/pkg/storage/stores/shipper/uploads/table_manager.go +++ b/pkg/storage/stores/shipper/uploads/table_manager.go @@ -11,7 +11,6 @@ import ( "sync" "time" - util_log "github.com/cortexproject/cortex/pkg/util/log" "github.com/go-kit/log/level" "github.com/prometheus/client_golang/prometheus" @@ -19,6 +18,7 @@ import ( "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/util" + util_log "github.com/grafana/loki/pkg/util/log" ) type Config struct { diff --git a/pkg/storage/stores/shipper/util/util.go b/pkg/storage/stores/shipper/util/util.go index 7c4259b0fc634..4e39a6a5bf262 100644 --- a/pkg/storage/stores/shipper/util/util.go +++ b/pkg/storage/stores/shipper/util/util.go @@ -10,7 +10,6 @@ import ( "strings" "sync" - util_log "github.com/cortexproject/cortex/pkg/util/log" "github.com/go-kit/log" "github.com/go-kit/log/level" gzip "github.com/klauspost/pgzip" @@ -18,6 +17,7 @@ import ( "github.com/grafana/loki/pkg/storage/chunk" "github.com/grafana/loki/pkg/storage/chunk/local" + util_log "github.com/grafana/loki/pkg/util/log" ) const ( diff --git a/pkg/storage/stores/shipper/util/util_test.go b/pkg/storage/stores/shipper/util/util_test.go index 83ee1a965b79a..46f87335bca20 100644 --- a/pkg/storage/stores/shipper/util/util_test.go +++ b/pkg/storage/stores/shipper/util/util_test.go @@ -10,12 +10,11 @@ import ( "github.com/stretchr/testify/require" - util_log "github.com/cortexproject/cortex/pkg/util/log" - "github.com/grafana/loki/pkg/storage/chunk/local" "github.com/grafana/loki/pkg/storage/chunk/util" "github.com/grafana/loki/pkg/storage/stores/shipper/storage" "github.com/grafana/loki/pkg/storage/stores/shipper/testutil" + util_log "github.com/grafana/loki/pkg/util/log" ) func Test_GetFileFromStorage(t *testing.T) { diff --git a/pkg/storage/util_test.go b/pkg/storage/util_test.go index 8c3545abf5212..2844b9dc21a90 100644 --- a/pkg/storage/util_test.go +++ b/pkg/storage/util_test.go @@ -6,8 +6,6 @@ import ( "testing" "time" - util_log "github.com/cortexproject/cortex/pkg/util/log" - "github.com/cortexproject/cortex/pkg/ingester/client" "github.com/davecgh/go-spew/spew" "github.com/prometheus/common/model" @@ -21,6 +19,7 @@ import ( "github.com/grafana/loki/pkg/storage/chunk" "github.com/grafana/loki/pkg/storage/chunk/cache" loki_util "github.com/grafana/loki/pkg/util" + util_log "github.com/grafana/loki/pkg/util/log" ) var ( diff --git a/pkg/util/config.go b/pkg/util/config.go index 4571f42d6a85e..6989931fb618e 100644 --- a/pkg/util/config.go +++ b/pkg/util/config.go @@ -5,10 +5,11 @@ import ( "io" "strings" - util_log "github.com/cortexproject/cortex/pkg/util/log" "github.com/go-kit/log/level" "github.com/prometheus/common/version" "gopkg.in/yaml.v2" + + util_log "github.com/grafana/loki/pkg/util/log" ) // LogConfig takes a pointer to a config object, marshalls it to YAML and prints each line in REVERSE order diff --git a/pkg/util/errors.go b/pkg/util/errors.go index 70b1475f747d7..a6b890d6ddbe8 100644 --- a/pkg/util/errors.go +++ b/pkg/util/errors.go @@ -6,10 +6,11 @@ import ( "errors" "fmt" - "github.com/cortexproject/cortex/pkg/util/log" "github.com/go-kit/log/level" "google.golang.org/grpc/codes" "google.golang.org/grpc/status" + + "github.com/grafana/loki/pkg/util/log" ) // LogError logs any error returned by f; useful when deferring Close etc. diff --git a/pkg/util/log/experimental.go b/pkg/util/log/experimental.go new file mode 100644 index 0000000000000..6072e93e424d2 --- /dev/null +++ b/pkg/util/log/experimental.go @@ -0,0 +1,22 @@ +package log + +import ( + "github.com/go-kit/log" + "github.com/go-kit/log/level" + "github.com/prometheus/client_golang/prometheus" + "github.com/prometheus/client_golang/prometheus/promauto" +) + +var experimentalFeaturesInUse = promauto.NewCounter( + prometheus.CounterOpts{ + Namespace: "loki", + Name: "experimental_features_in_use_total", + Help: "The number of experimental features in use.", + }, +) + +// WarnExperimentalUse logs a warning and increments the experimental features metric. +func WarnExperimentalUse(feature string, logger log.Logger) { + level.Warn(logger).Log("msg", "experimental feature in use", "feature", feature) + experimentalFeaturesInUse.Inc() +} diff --git a/pkg/util/log/log.go b/pkg/util/log/log.go new file mode 100644 index 0000000000000..cf13d9a771034 --- /dev/null +++ b/pkg/util/log/log.go @@ -0,0 +1,119 @@ +package log + +import ( + "fmt" + "os" + + "github.com/go-kit/log" + "github.com/go-kit/log/level" + "github.com/prometheus/client_golang/prometheus" + "github.com/prometheus/client_golang/prometheus/promauto" + "github.com/weaveworks/common/logging" + "github.com/weaveworks/common/server" +) + +var ( + // Logger is a shared go-kit logger. + // TODO: Change all components to take a non-global logger via their constructors. + // Prefer accepting a non-global logger as an argument. + Logger = log.NewNopLogger() +) + +// InitLogger initialises the global gokit logger (util_log.Logger) and overrides the +// default logger for the server. +func InitLogger(cfg *server.Config, reg prometheus.Registerer) { + l := newPrometheusLogger(cfg.LogLevel, cfg.LogFormat, reg) + + // when use util_log.Logger, skip 3 stack frames. + Logger = log.With(l, "caller", log.Caller(3)) + + // cfg.Log wraps log function, skip 4 stack frames to get caller information. + // this works in go 1.12, but doesn't work in versions earlier. + // it will always shows the wrapper function generated by compiler + // marked in old versions. + cfg.Log = logging.GoKit(log.With(l, "caller", log.Caller(4))) +} + +// prometheusLogger exposes Prometheus counters for each of go-kit's log levels. +type prometheusLogger struct { + logger log.Logger + logMessages *prometheus.CounterVec +} + +// newPrometheusLogger creates a new instance of PrometheusLogger which exposes +// Prometheus counters for various log levels. +func newPrometheusLogger(l logging.Level, format logging.Format, reg prometheus.Registerer) log.Logger { + logger := log.NewLogfmtLogger(log.NewSyncWriter(os.Stderr)) + if format.String() == "json" { + logger = log.NewJSONLogger(log.NewSyncWriter(os.Stderr)) + } + logger = level.NewFilter(logger, levelFilter(l.String())) + + plogger := &prometheusLogger{ + logger: logger, + logMessages: promauto.With(reg).NewCounterVec(prometheus.CounterOpts{ + Namespace: "loki", + Name: "log_messages_total", + Help: "Total number of log messages.", + }, []string{"level"}), + } + // Initialise counters for all supported levels: + supportedLevels := []level.Value{ + level.DebugValue(), + level.InfoValue(), + level.WarnValue(), + level.ErrorValue(), + } + for _, level := range supportedLevels { + plogger.logMessages.WithLabelValues(level.String()) + } + + // return a Logger without caller information, shouldn't use directly + return log.With(plogger, "ts", log.DefaultTimestampUTC) +} + +// Log increments the appropriate Prometheus counter depending on the log level. +func (pl *prometheusLogger) Log(kv ...interface{}) error { + pl.logger.Log(kv...) + l := "unknown" + for i := 1; i < len(kv); i += 2 { + if v, ok := kv[i].(level.Value); ok { + l = v.String() + break + } + } + pl.logMessages.WithLabelValues(l).Inc() + return nil +} + +// CheckFatal prints an error and exits with error code 1 if err is non-nil. +func CheckFatal(location string, err error, logger log.Logger) { + if err == nil { + return + } + + logger = level.Error(logger) + if location != "" { + logger = log.With(logger, "msg", "error "+location) + } + // %+v gets the stack trace from errors using github.com/pkg/errors + logger.Log("err", fmt.Sprintf("%+v", err)) + os.Exit(1) +} + +// TODOe remove once weaveworks/common updates to go-kit/log +// -> we can then revert to using Level.Gokit +func levelFilter(l string) level.Option { + switch l { + case "debug": + return level.AllowDebug() + case "info": + return level.AllowInfo() + case "warn": + return level.AllowWarn() + case "error": + return level.AllowError() + default: + return level.AllowAll() + } +} diff --git a/pkg/util/log/wrappers.go b/pkg/util/log/wrappers.go new file mode 100644 index 0000000000000..2bcc255414b33 --- /dev/null +++ b/pkg/util/log/wrappers.go @@ -0,0 +1,39 @@ +package log + +import ( + "context" + + "github.com/go-kit/log" + "github.com/weaveworks/common/tracing" + + "github.com/grafana/loki/pkg/tenant" +) + +// WithUserID returns a Logger that has information about the current user in +// its details. +func WithUserID(userID string, l log.Logger) log.Logger { + // See note in WithContext. + return log.With(l, "org_id", userID) +} + +// WithContext returns a log.Logger that has information about the current user in +// its details. +// +// e.g. +// log := util.WithContext(ctx) +// log.Errorf("Could not chunk chunks: %v", err) +func WithContext(ctx context.Context, l log.Logger) log.Logger { + // Weaveworks uses "orgs" and "orgID" to represent Cortex users, + // even though the code-base generally uses `userID` to refer to the same thing. + userID, err := tenant.TenantID(ctx) + if err == nil { + l = WithUserID(userID, l) + } + + traceID, ok := tracing.ExtractSampledTraceID(ctx) + if !ok { + return l + } + + return log.With(l, "traceID", traceID) +} diff --git a/pkg/util/ring_config.go b/pkg/util/ring_config.go index 25f42840ed400..52da4df3dce13 100644 --- a/pkg/util/ring_config.go +++ b/pkg/util/ring_config.go @@ -11,9 +11,9 @@ import ( "github.com/go-kit/log/level" "github.com/grafana/dskit/flagext" "github.com/grafana/dskit/kv" - - util_log "github.com/cortexproject/cortex/pkg/util/log" "github.com/grafana/dskit/ring" + + util_log "github.com/grafana/loki/pkg/util/log" ) // RingConfig masks the ring lifecycler config which contains diff --git a/pkg/util/spanlogger/spanlogger.go b/pkg/util/spanlogger/spanlogger.go index 958f3d5e98717..e8f30481bf727 100644 --- a/pkg/util/spanlogger/spanlogger.go +++ b/pkg/util/spanlogger/spanlogger.go @@ -6,9 +6,8 @@ import ( "github.com/go-kit/log" "github.com/grafana/dskit/spanlogger" - util_log "github.com/cortexproject/cortex/pkg/util/log" - "github.com/grafana/loki/pkg/tenant" + util_log "github.com/grafana/loki/pkg/util/log" ) const ( diff --git a/tools/querytee/instrumentation.go b/tools/querytee/instrumentation.go index e0f4c25c0f967..7783374182c0b 100644 --- a/tools/querytee/instrumentation.go +++ b/tools/querytee/instrumentation.go @@ -10,7 +10,7 @@ import ( "github.com/prometheus/client_golang/prometheus" "github.com/prometheus/client_golang/prometheus/promhttp" - util_log "github.com/cortexproject/cortex/pkg/util/log" + util_log "github.com/grafana/loki/pkg/util/log" ) type InstrumentationServer struct { diff --git a/tools/querytee/proxy_endpoint.go b/tools/querytee/proxy_endpoint.go index babf6d53f0a95..9d3bf405d59b8 100644 --- a/tools/querytee/proxy_endpoint.go +++ b/tools/querytee/proxy_endpoint.go @@ -13,7 +13,7 @@ import ( "github.com/go-kit/log" "github.com/go-kit/log/level" - util_log "github.com/cortexproject/cortex/pkg/util/log" + util_log "github.com/grafana/loki/pkg/util/log" ) type ResponsesComparator interface { diff --git a/tools/querytee/response_comparator.go b/tools/querytee/response_comparator.go index bdd9f5b902ebc..a4231fab542a4 100644 --- a/tools/querytee/response_comparator.go +++ b/tools/querytee/response_comparator.go @@ -10,7 +10,7 @@ import ( "github.com/pkg/errors" "github.com/prometheus/common/model" - util_log "github.com/cortexproject/cortex/pkg/util/log" + util_log "github.com/grafana/loki/pkg/util/log" ) // SamplesComparatorFunc helps with comparing different types of samples coming from /api/v1/query and /api/v1/query_range routes. From 714dbcd0f7d35af203900ee7c06f5caf8b83d069 Mon Sep 17 00:00:00 2001 From: Arve Knudsen Date: Thu, 20 Jan 2022 11:39:05 +0100 Subject: [PATCH 2/3] Add changelog entry Signed-off-by: Arve Knudsen --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 022897ad842c0..d91c4640010f1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,6 @@ ## Main +* [5187](https://github.com/grafana/loki/pull/5187) **aknuds1** Rename metric `cortex_experimental_features_in_use_total` to `loki_experimental_features_in_use_total` and metric `log_messages_total` to `loki_log_messages_total`. * [5170](https://github.com/grafana/loki/pull/5170) **chaudum** Fix deadlock in Promtail caused when targets got removed from a target group by the discovery manager. * [5163](https://github.com/grafana/loki/pull/5163) **chaudum** Fix regression in fluentd plugin introduced with #5107 that caused `NoMethodError` when parsing non-string values of log lines. * [5144](https://github.com/grafana/loki/pull/5144) **dannykopping** Ruler: fix remote write basic auth credentials. From dfc5b73cea59d634522d66d1f23f0147df9ffb96 Mon Sep 17 00:00:00 2001 From: Arve Knudsen Date: Thu, 20 Jan 2022 18:21:37 +0100 Subject: [PATCH 3/3] Fix documentation of loki_log_messages_total Signed-off-by: Arve Knudsen --- docs/sources/operations/observability.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/sources/operations/observability.md b/docs/sources/operations/observability.md index 82a419e12d326..dd851c2553984 100644 --- a/docs/sources/operations/observability.md +++ b/docs/sources/operations/observability.md @@ -14,7 +14,7 @@ All components of Loki expose the following metrics: | Metric Name | Metric Type | Description | | ------------------------------- | ----------- | ---------------------------------------- | -| `log_messages_total` | Counter | Total number of messages logged by Loki. | +| `loki_log_messages_total` | Counter | Total number of messages logged by Loki. | | `loki_request_duration_seconds` | Histogram | Number of received HTTP requests. | The Loki Distributors expose the following metrics: