diff --git a/CHANGELOG.md b/CHANGELOG.md index 24e99ce4c44b..9db640a68cb6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -28,7 +28,8 @@ files to the new format. - [ENHANCEMENT] The `/agent/api/v1/targets` API will now include discovered labels on the target pre-relabeling in a `discovered_labels` field. (@rfratto) -- [ENHANCEMENT] Update to Cortex v1.7.0-rc.0 (@rfratto) +- [ENHANCEMENT] Update Loki to 59a34f9867ce. This is a non-release build, and was needed + to support multiple Loki instances. (@rfratto) - [ENHANCEMENT] Scraping service: Unhealthy Agents in the ring will no longer cause job distribution to fail. (@rfratto) diff --git a/cmd/agent/main.go b/cmd/agent/main.go index be5ef276ccdc..79adfb45c541 100644 --- a/cmd/agent/main.go +++ b/cmd/agent/main.go @@ -14,7 +14,7 @@ import ( "github.com/grafana/agent/pkg/loki" "github.com/grafana/agent/pkg/tempo" - "github.com/cortexproject/cortex/pkg/util" + util_log "github.com/cortexproject/cortex/pkg/util/log" "github.com/go-kit/kit/log/level" "github.com/grafana/agent/pkg/config" "github.com/grafana/agent/pkg/prom" @@ -40,8 +40,9 @@ func main() { log.Fatalln(err) } - // After this point we can use util.Logger and stop using the log package - util.InitLogger(&cfg.Server) + // After this point we can use util_log.Logger and stop using the log package + util_log.InitLogger(&cfg.Server) + logger := util_log.Logger var ( promMetrics *prom.Agent @@ -52,14 +53,14 @@ func main() { srv, err := server.New(cfg.Server) if err != nil { - level.Error(util.Logger).Log("msg", "failed to create server", "err", err) + level.Error(logger).Log("msg", "failed to create server", "err", err) os.Exit(1) } if cfg.Prometheus.Enabled { - promMetrics, err = prom.New(prometheus.DefaultRegisterer, cfg.Prometheus, util.Logger) + promMetrics, err = prom.New(prometheus.DefaultRegisterer, cfg.Prometheus, logger) if err != nil { - level.Error(util.Logger).Log("msg", "failed to create prometheus instance", "err", err) + level.Error(logger).Log("msg", "failed to create prometheus instance", "err", err) os.Exit(1) } @@ -69,9 +70,9 @@ func main() { } if cfg.Loki.Enabled { - lokiLogs, err = loki.New(prometheus.DefaultRegisterer, cfg.Loki, util.Logger) + lokiLogs, err = loki.New(prometheus.DefaultRegisterer, cfg.Loki, logger) if err != nil { - level.Error(util.Logger).Log("msg", "failed to create loki log collection instance", "err", err) + level.Error(logger).Log("msg", "failed to create loki log collection instance", "err", err) os.Exit(1) } } @@ -79,20 +80,20 @@ func main() { if cfg.Tempo.Enabled { tempoTraces, err = tempo.New(prometheus.DefaultRegisterer, cfg.Tempo, cfg.Server.LogLevel) if err != nil { - level.Error(util.Logger).Log("msg", "failed to create tempo trace collection instance", "err", err) + level.Error(logger).Log("msg", "failed to create tempo trace collection instance", "err", err) os.Exit(1) } } if cfg.Integrations.Enabled { - manager, err = integrations.NewManager(cfg.Integrations, util.Logger, promMetrics.InstanceManager()) + manager, err = integrations.NewManager(cfg.Integrations, logger, promMetrics.InstanceManager()) if err != nil { - level.Error(util.Logger).Log("msg", "failed to create integrations manager", "err", err) + level.Error(logger).Log("msg", "failed to create integrations manager", "err", err) os.Exit(1) } if err := manager.WireAPI(srv.HTTP); err != nil { - level.Error(util.Logger).Log("msg", "failed wiring endpoints for integrations", "err", err) + level.Error(logger).Log("msg", "failed wiring endpoints for integrations", "err", err) os.Exit(1) } } @@ -107,7 +108,7 @@ func main() { }) if err := srv.Run(); err != nil { - level.Error(util.Logger).Log("msg", "error running agent", "err", err) + level.Error(logger).Log("msg", "error running agent", "err", err) // Don't os.Exit here; we want to do cleanup by stopping promMetrics } @@ -124,5 +125,5 @@ func main() { if tempoTraces != nil { tempoTraces.Stop() } - level.Info(util.Logger).Log("msg", "agent exiting") + level.Info(logger).Log("msg", "agent exiting") } diff --git a/go.mod b/go.mod index 10ab0e68321d..6108332647b5 100644 --- a/go.mod +++ b/go.mod @@ -5,7 +5,7 @@ go 1.15 require ( contrib.go.opencensus.io/exporter/prometheus v0.2.0 github.com/aws/aws-sdk-go v1.36.15 - github.com/cortexproject/cortex v1.6.1-0.20210129172402-0976147451ee + github.com/cortexproject/cortex v1.6.1-0.20210204145131-7dac81171c66 github.com/drone/envsubst v1.0.2 github.com/go-kit/kit v0.10.0 github.com/go-playground/validator/v10 v10.4.0 // indirect @@ -13,7 +13,7 @@ require ( github.com/golang/protobuf v1.4.3 github.com/google/dnsmasq_exporter v0.0.0-00010101000000-000000000000 github.com/gorilla/mux v1.8.0 - github.com/grafana/loki v1.6.2-0.20210203125540-d667dd20f287 + github.com/grafana/loki v1.6.2-0.20210205130758-59a34f9867ce github.com/hashicorp/consul/api v1.8.1 github.com/hashicorp/yamux v0.0.0-20190923154419-df201c70410d // indirect github.com/joshdk/go-junit v0.0.0-20200702055522-6efcf4050909 // indirect diff --git a/go.sum b/go.sum index f04c6143fb3d..c98e3e7694fa 100644 --- a/go.sum +++ b/go.sum @@ -378,10 +378,13 @@ github.com/cortexproject/cortex v1.4.1-0.20201022071705-85942c5703cf h1:TGmSZFMN github.com/cortexproject/cortex v1.4.1-0.20201022071705-85942c5703cf/go.mod h1:MBJnS5mzVcHqivBp2391HpflMeMiT+f8r4VNkJlsZFs= github.com/cortexproject/cortex v1.4.1-0.20201030080541-83ad6df2abea/go.mod h1:kXo5F3jlF7Ky3+I31jt/bXTzOlQjl2X/vGDpy0RY1gU= github.com/cortexproject/cortex v1.5.1-0.20201111110551-ba512881b076/go.mod h1:zFBGVsvRBfVp6ARXZ7pmiLaGlbjda5ZnA4Y6qSJyrQg= +github.com/cortexproject/cortex v1.6.1-0.20210108144208-6c2dab103f20/go.mod h1:fOsaeeFSyWrjd9nFJO8KVUpsikcxnYsjEzQyjURBoQk= github.com/cortexproject/cortex v1.6.1-0.20210121163251-a59b811d5952 h1:6fjboCnRBAp5QevLOeAyDXf1MW4EzzaCTmwZlrOYV0k= github.com/cortexproject/cortex v1.6.1-0.20210121163251-a59b811d5952/go.mod h1:t7gTMLe7db0dcrKsjoQ5o13Ep16dzqkSepYAkiQLwyU= github.com/cortexproject/cortex v1.6.1-0.20210129172402-0976147451ee h1:Lj7kPgeuMHzoejxD4QQjYNMDqPNB5Uiqj0GvYaINnG0= github.com/cortexproject/cortex v1.6.1-0.20210129172402-0976147451ee/go.mod h1:uwptskTaCiJPGHaEsIthCBtnOA1nN+KpLDezYvbvU8o= +github.com/cortexproject/cortex v1.6.1-0.20210204145131-7dac81171c66 h1:ZCpJ2TGDLw5dmDyO0owQLod4f+Q3oRwoqT8WXa1445g= +github.com/cortexproject/cortex v1.6.1-0.20210204145131-7dac81171c66/go.mod h1:hQ45oW8W7SKNBv4bkl1960kWyslLDbL2IWuzCQBCVGY= github.com/couchbase/go-couchbase v0.0.0-20180501122049-16db1f1fe037/go.mod h1:TWI8EKQMs5u5jLKW/tsb9VwauIrMIxQG1r5fMsswK5U= github.com/couchbase/gomemcached v0.0.0-20180502221210-0da75df14530/go.mod h1:srVSlQLB8iXBVXHgnqemxUXqN6FCvClgCMPCsjBDR7c= github.com/couchbase/goutils v0.0.0-20180530154633-e865a1461c8a/go.mod h1:BQwMFlJzDjFDG3DJUdU0KORxn88UlsOULuxLExMh3Hs= @@ -954,6 +957,8 @@ github.com/golang/snappy v0.0.1 h1:Qgr9rKW7uDUkrbSmQeiDsGa8SjGyCOGtuasMWwvp2P4= github.com/golang/snappy v0.0.1/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= github.com/golang/snappy v0.0.2 h1:aeE13tS0IiQgFjYdoL8qN3K1N2bXXtI6Vi51/y7BpMw= github.com/golang/snappy v0.0.2/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= +github.com/golang/snappy v0.0.3-0.20201103224600-674baa8c7fc3 h1:ur2rms48b3Ep1dxh7aUV2FZEQ8jEVO2F6ILKx8ofkAg= +github.com/golang/snappy v0.0.3-0.20201103224600-674baa8c7fc3/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= github.com/golangci/check v0.0.0-20180506172741-cfe4005ccda2 h1:23T5iq8rbUYlhpt5DB4XJkc6BU31uODLD1o1gKvZmD0= github.com/golangci/check v0.0.0-20180506172741-cfe4005ccda2/go.mod h1:k9Qvh+8juN+UKMCS/3jFtGICgW8O96FVaZsaxdzDkR4= github.com/golangci/dupl v0.0.0-20180902072040-3e9179ac440a h1:w8hkcTqaFpzKqonE9uMCefW1WDie15eSP/4MssdenaM= @@ -1114,6 +1119,8 @@ github.com/grafana/loki v1.6.2-0.20210126101127-33abab5e4203 h1:pepaoQed4SpUN2hO github.com/grafana/loki v1.6.2-0.20210126101127-33abab5e4203/go.mod h1:dhEOXEHU3i9M1YkRkVWKPI/60VjIqcy2hyXVu+9IuQs= github.com/grafana/loki v1.6.2-0.20210203125540-d667dd20f287 h1:ODZF4Z+FORRcuc87gOy94bWxh3plAFgh1/XJZS6HjBg= github.com/grafana/loki v1.6.2-0.20210203125540-d667dd20f287/go.mod h1:uhisKVH/w+t39vNKAhGy5mpXS57dKSCcTohvsQv/eOQ= +github.com/grafana/loki v1.6.2-0.20210205130758-59a34f9867ce h1:JAUj0bKdYAXQO3Xthv9w+NORgSgeHnrH3PxsKpiMhpo= +github.com/grafana/loki v1.6.2-0.20210205130758-59a34f9867ce/go.mod h1:zD6R/qL5IP9gfpDHmlxeY3g5c5SuABCxRqOpS9VZ67o= github.com/grafana/memcached_exporter v0.7.1-0.20201030142623-8e1997d4fbb7 h1:dNnnXHJoiOARawfVU4e/Z2S6uD9bn6oCbTpPLODV6QA= github.com/grafana/memcached_exporter v0.7.1-0.20201030142623-8e1997d4fbb7/go.mod h1:YCz9i2SVVjyOpN8XJpPWnu6zqXO1qvlWg27qOuY0rd0= github.com/grafana/mysqld_exporter v0.12.2-0.20201015182516-5ac885b2d38a h1:D5NSR64/6xMXnSFD9y1m1DPYIcBcHvtfeuI9/M/0qtI= @@ -2234,6 +2241,8 @@ github.com/thanos-io/thanos v0.13.1-0.20201019130456-f41940581d9a/go.mod h1:A3qU github.com/thanos-io/thanos v0.13.1-0.20201030101306-47f9a225cc52/go.mod h1:OqqX4x21cg5N5MMHd/yGQAc/V3wg8a7Do4Jk8HfaFZQ= github.com/thanos-io/thanos v0.13.1-0.20210108102609-f85e4003ba51 h1:cinCqkVci8c5Dg6uB3m3351EjLAXDbwJVFT+bgwu/Ew= github.com/thanos-io/thanos v0.13.1-0.20210108102609-f85e4003ba51/go.mod h1:kPvI4H0AynFiHDN95ZB28/k70ZPGCx+pBrRh6RZPimw= +github.com/thanos-io/thanos v0.13.1-0.20210204123931-82545cdd16fe h1:YMGaJuBKOK3XtCxxezHClrV2OTImnSdzpMQnXG9nqgw= +github.com/thanos-io/thanos v0.13.1-0.20210204123931-82545cdd16fe/go.mod h1:ZLDGYRNkgM+FCwYNOD+6tOV+DE2fpjzfV6iqXyOgFIw= github.com/tidwall/gjson v1.3.2/go.mod h1:P256ACg0Mn+j1RXIDXoss50DeIABTYK1PULOJHhxOls= github.com/tidwall/gjson v1.6.0/go.mod h1:P256ACg0Mn+j1RXIDXoss50DeIABTYK1PULOJHhxOls= github.com/tidwall/match v1.0.1/go.mod h1:LujAq0jyVjBy028G1WhWfIzbpQfMO8bBZ6Tyb0+pL9E= @@ -2309,6 +2318,7 @@ github.com/weaveworks/common v0.0.0-20200625145055-4b1847531bc9 h1:dNVIG9aKQHR9T github.com/weaveworks/common v0.0.0-20200625145055-4b1847531bc9/go.mod h1:c98fKi5B9u8OsKGiWHLRKus6ToQ1Tubeow44ECO1uxY= github.com/weaveworks/common v0.0.0-20200914083218-61ffdd448099 h1:MS5M2antM8wzMUqVxIfAi+yb6yjXvDINRFvLnmNXeIw= github.com/weaveworks/common v0.0.0-20200914083218-61ffdd448099/go.mod h1:hz10LOsAdzC3K/iXaKoFxOKTDRgxJl+BTGX1GY+TzO4= +github.com/weaveworks/common v0.0.0-20201119133501-0619918236ec/go.mod h1:ykzWac1LtVfOxdCK+jD754at1Ws9dKCwFeUzkFBffPs= github.com/weaveworks/common v0.0.0-20210112142934-23c8d7fa6120 h1:zQtcwREXYNvW116ipgc0bRDg1avD2b6QP0RGPLlPWkc= github.com/weaveworks/common v0.0.0-20210112142934-23c8d7fa6120/go.mod h1:ykzWac1LtVfOxdCK+jD754at1Ws9dKCwFeUzkFBffPs= github.com/weaveworks/promrus v1.2.0 h1:jOLf6pe6/vss4qGHjXmGz4oDJQA+AOCqEL3FvvZGz7M= diff --git a/pkg/prom/ha/server.go b/pkg/prom/ha/server.go index c9c6e6c311d4..62f48369c081 100644 --- a/pkg/prom/ha/server.go +++ b/pkg/prom/ha/server.go @@ -270,7 +270,7 @@ func (s *Server) waitNotifyReshard(ctx context.Context) error { return err } - _, err = rs.Do(ctx, time.Millisecond*250, func(ctx context.Context, desc *ring.IngesterDesc) (interface{}, error) { + _, err = rs.Do(ctx, time.Millisecond*250, func(ctx context.Context, desc *ring.InstanceDesc) (interface{}, error) { // Skip over ourselves; we'll reshard locally after this process finishes. if desc.Addr == s.addr { return nil, nil @@ -282,7 +282,7 @@ func (s *Server) waitNotifyReshard(ctx context.Context) error { return err } -func (s *Server) notifyReshard(ctx context.Context, desc *ring.IngesterDesc) error { +func (s *Server) notifyReshard(ctx context.Context, desc *ring.InstanceDesc) error { cli, err := client.New(s.clientConfig, desc.Addr) if err != nil { return err diff --git a/pkg/prom/ha/server_test.go b/pkg/prom/ha/server_test.go index 3bb8862fdb8d..d968ed954578 100644 --- a/pkg/prom/ha/server_test.go +++ b/pkg/prom/ha/server_test.go @@ -160,7 +160,7 @@ func TestServer_Cluster_Reshard_On_Start_And_Leave(t *testing.T) { injectRingIngester(r) r.GetAllHealthyFunc = func(_ ring.Operation) (ring.ReplicationSet, error) { return ring.ReplicationSet{ - Ingesters: []ring.IngesterDesc{ + Ingesters: []ring.InstanceDesc{ {Addr: "test"}, agent1Desc, agent2Desc, @@ -191,15 +191,15 @@ func TestServer_Cluster_Reshard_On_Start_And_Leave(t *testing.T) { } func injectRingIngester(r *mockFuncReadRing) { - r.GetFunc = func(_ uint32, _ ring.Operation, _ []ring.IngesterDesc, _, _ []string) (ring.ReplicationSet, error) { + r.GetFunc = func(_ uint32, _ ring.Operation, _ []ring.InstanceDesc, _, _ []string) (ring.ReplicationSet, error) { return ring.ReplicationSet{ - Ingesters: []ring.IngesterDesc{{Addr: "test"}}, + Ingesters: []ring.InstanceDesc{{Addr: "test"}}, }, nil } r.GetAllHealthyFunc = func(_ ring.Operation) (ring.ReplicationSet, error) { return ring.ReplicationSet{ - Ingesters: []ring.IngesterDesc{{Addr: "test"}}, + Ingesters: []ring.InstanceDesc{{Addr: "test"}}, }, nil } } @@ -399,10 +399,10 @@ func (m mockFuncAgentProtoServer) Reshard(ctx context.Context, req *agentproto.R } // startScrapingServiceServer launches a gRPC server and registers a ScrapingServiceServer -// against it. The ring.IngesterDesc to add to a ring implementation is returned. +// against it. The ring.InstanceDesc to add to a ring implementation is returned. // // The gRPC server will be stopped when the test exits. -func startScrapingServiceServer(t *testing.T, srv agentproto.ScrapingServiceServer) ring.IngesterDesc { +func startScrapingServiceServer(t *testing.T, srv agentproto.ScrapingServiceServer) ring.InstanceDesc { t.Helper() l, err := net.Listen("tcp", "127.0.0.1:0") @@ -416,7 +416,7 @@ func startScrapingServiceServer(t *testing.T, srv agentproto.ScrapingServiceServ }() t.Cleanup(func() { grpcServer.Stop() }) - return ring.IngesterDesc{ + return ring.InstanceDesc{ Addr: l.Addr().String(), State: ring.ACTIVE, Timestamp: math.MaxInt64, diff --git a/pkg/prom/ha/sharding.go b/pkg/prom/ha/sharding.go index 7b69a054c35e..1b167b3429bd 100644 --- a/pkg/prom/ha/sharding.go +++ b/pkg/prom/ha/sharding.go @@ -116,7 +116,7 @@ func (s *Server) AllConfigs(ctx context.Context) (<-chan instance.Config, error) type ReadRing interface { http.Handler - Get(key uint32, op ring.Operation, bufDescs []ring.IngesterDesc, bufHosts, bufZones []string) (ring.ReplicationSet, error) + Get(key uint32, op ring.Operation, bufDescs []ring.InstanceDesc, bufHosts, bufZones []string) (ring.ReplicationSet, error) GetAllHealthy(op ring.Operation) (ring.ReplicationSet, error) } diff --git a/pkg/prom/ha/sharding_test.go b/pkg/prom/ha/sharding_test.go index 433921ad0a74..330ef0f27509 100644 --- a/pkg/prom/ha/sharding_test.go +++ b/pkg/prom/ha/sharding_test.go @@ -58,9 +58,9 @@ func TestShardingInstanceManager(t *testing.T) { t.Run("only lists configs applied through sharded instance manager", func(t *testing.T) { fakeIm := newFakeInstanceManager() mockRing := &mockFuncReadRing{} - mockRing.GetFunc = func(_ uint32, _ ring.Operation, _ []ring.IngesterDesc, _, _ []string) (ring.ReplicationSet, error) { + mockRing.GetFunc = func(_ uint32, _ ring.Operation, _ []ring.InstanceDesc, _, _ []string) (ring.ReplicationSet, error) { return ring.ReplicationSet{ - Ingesters: []ring.IngesterDesc{{Addr: "same_machine"}}, + Ingesters: []ring.InstanceDesc{{Addr: "same_machine"}}, }, nil } @@ -79,9 +79,9 @@ func TestShardingInstanceManager(t *testing.T) { t.Run("applies owned config", func(t *testing.T) { fakeIm := newFakeInstanceManager() mockRing := &mockFuncReadRing{} - mockRing.GetFunc = func(_ uint32, _ ring.Operation, _ []ring.IngesterDesc, _, _ []string) (ring.ReplicationSet, error) { + mockRing.GetFunc = func(_ uint32, _ ring.Operation, _ []ring.InstanceDesc, _, _ []string) (ring.ReplicationSet, error) { return ring.ReplicationSet{ - Ingesters: []ring.IngesterDesc{{Addr: "same_machine"}}, + Ingesters: []ring.InstanceDesc{{Addr: "same_machine"}}, }, nil } @@ -94,9 +94,9 @@ func TestShardingInstanceManager(t *testing.T) { t.Run("ignores apply of unowned config", func(t *testing.T) { fakeIm := newFakeInstanceManager() mockRing := &mockFuncReadRing{} - mockRing.GetFunc = func(_ uint32, _ ring.Operation, _ []ring.IngesterDesc, _, _ []string) (ring.ReplicationSet, error) { + mockRing.GetFunc = func(_ uint32, _ ring.Operation, _ []ring.InstanceDesc, _, _ []string) (ring.ReplicationSet, error) { return ring.ReplicationSet{ - Ingesters: []ring.IngesterDesc{{Addr: "remote"}}, + Ingesters: []ring.InstanceDesc{{Addr: "remote"}}, }, nil } @@ -111,10 +111,10 @@ func TestShardingInstanceManager(t *testing.T) { fakeIm := newFakeInstanceManager() mockRing := &mockFuncReadRing{} - mockRing.GetFunc = func(key uint32, _ ring.Operation, _ []ring.IngesterDesc, _, _ []string) (ring.ReplicationSet, error) { + mockRing.GetFunc = func(key uint32, _ ring.Operation, _ []ring.InstanceDesc, _, _ []string) (ring.ReplicationSet, error) { hashes = append(hashes, key) return ring.ReplicationSet{ - Ingesters: []ring.IngesterDesc{{Addr: "remote"}}, + Ingesters: []ring.InstanceDesc{{Addr: "remote"}}, }, nil } @@ -132,9 +132,9 @@ func TestShardingInstanceManager(t *testing.T) { fakeIm := newFakeInstanceManager() mockRing := &mockFuncReadRing{} - mockRing.GetFunc = func(_ uint32, _ ring.Operation, _ []ring.IngesterDesc, _, _ []string) (ring.ReplicationSet, error) { + mockRing.GetFunc = func(_ uint32, _ ring.Operation, _ []ring.InstanceDesc, _, _ []string) (ring.ReplicationSet, error) { return ring.ReplicationSet{ - Ingesters: []ring.IngesterDesc{{Addr: returnRingAddr}}, + Ingesters: []ring.InstanceDesc{{Addr: returnRingAddr}}, }, nil } @@ -153,9 +153,9 @@ func TestShardingInstanceManager(t *testing.T) { t.Run("doesn't reapply unchanged config", func(t *testing.T) { fakeIm := newFakeInstanceManager() mockRing := &mockFuncReadRing{} - mockRing.GetFunc = func(_ uint32, _ ring.Operation, _ []ring.IngesterDesc, _, _ []string) (ring.ReplicationSet, error) { + mockRing.GetFunc = func(_ uint32, _ ring.Operation, _ []ring.InstanceDesc, _, _ []string) (ring.ReplicationSet, error) { return ring.ReplicationSet{ - Ingesters: []ring.IngesterDesc{{Addr: "same_machine"}}, + Ingesters: []ring.InstanceDesc{{Addr: "same_machine"}}, }, nil } @@ -174,9 +174,9 @@ func TestShardingInstanceManager(t *testing.T) { t.Run("reapplies changed config", func(t *testing.T) { fakeIm := newFakeInstanceManager() mockRing := &mockFuncReadRing{} - mockRing.GetFunc = func(_ uint32, _ ring.Operation, _ []ring.IngesterDesc, _, _ []string) (ring.ReplicationSet, error) { + mockRing.GetFunc = func(_ uint32, _ ring.Operation, _ []ring.InstanceDesc, _, _ []string) (ring.ReplicationSet, error) { return ring.ReplicationSet{ - Ingesters: []ring.IngesterDesc{{Addr: "same_machine"}}, + Ingesters: []ring.InstanceDesc{{Addr: "same_machine"}}, }, nil } @@ -206,9 +206,9 @@ func TestShardingInstanceManager(t *testing.T) { t.Run("deletes owned config", func(t *testing.T) { fakeIm := newFakeInstanceManager() mockRing := &mockFuncReadRing{} - mockRing.GetFunc = func(_ uint32, _ ring.Operation, _ []ring.IngesterDesc, _, _ []string) (ring.ReplicationSet, error) { + mockRing.GetFunc = func(_ uint32, _ ring.Operation, _ []ring.InstanceDesc, _, _ []string) (ring.ReplicationSet, error) { return ring.ReplicationSet{ - Ingesters: []ring.IngesterDesc{{Addr: "same_machine"}}, + Ingesters: []ring.InstanceDesc{{Addr: "same_machine"}}, }, nil } @@ -296,11 +296,11 @@ remote_write: type mockFuncReadRing struct { http.Handler - GetFunc func(key uint32, op ring.Operation, bufDescs []ring.IngesterDesc, bufHosts, bufZones []string) (ring.ReplicationSet, error) + GetFunc func(key uint32, op ring.Operation, bufDescs []ring.InstanceDesc, bufHosts, bufZones []string) (ring.ReplicationSet, error) GetAllHealthyFunc func(ring.Operation) (ring.ReplicationSet, error) } -func (r *mockFuncReadRing) Get(key uint32, op ring.Operation, bufDescs []ring.IngesterDesc, bufHosts, bufZones []string) (ring.ReplicationSet, error) { +func (r *mockFuncReadRing) Get(key uint32, op ring.Operation, bufDescs []ring.InstanceDesc, bufHosts, bufZones []string) (ring.ReplicationSet, error) { if r.GetFunc != nil { return r.GetFunc(key, op, bufDescs, bufHosts, bufZones) } diff --git a/pkg/tempo/promsdprocessor/factory.go b/pkg/tempo/promsdprocessor/factory.go index b87dd3567102..0409046b66c3 100644 --- a/pkg/tempo/promsdprocessor/factory.go +++ b/pkg/tempo/promsdprocessor/factory.go @@ -24,7 +24,8 @@ func NewFactory() component.ProcessorFactory { return processorhelper.NewFactory( TypeStr, createDefaultConfig, - processorhelper.WithTraces(createTraceProcessor)) + processorhelper.WithTraces(createTraceProcessor), + ) } func createDefaultConfig() configmodels.Processor { @@ -38,7 +39,7 @@ func createDefaultConfig() configmodels.Processor { func createTraceProcessor( _ context.Context, - _ component.ProcessorCreateParams, + cp component.ProcessorCreateParams, cfg configmodels.Processor, nextConsumer consumer.TracesConsumer, ) (component.TracesProcessor, error) { diff --git a/pkg/tempo/promsdprocessor/prom_sd_processor.go b/pkg/tempo/promsdprocessor/prom_sd_processor.go index e09dc38a826a..b62b987ce350 100644 --- a/pkg/tempo/promsdprocessor/prom_sd_processor.go +++ b/pkg/tempo/promsdprocessor/prom_sd_processor.go @@ -6,7 +6,7 @@ import ( "strings" "sync" - "github.com/cortexproject/cortex/pkg/util" + util "github.com/cortexproject/cortex/pkg/util/log" "github.com/go-kit/kit/log" "github.com/go-kit/kit/log/level" "github.com/prometheus/common/model" diff --git a/vendor/github.com/cortexproject/cortex/pkg/distributor/distributor.go b/vendor/github.com/cortexproject/cortex/pkg/distributor/distributor.go index 1b4679ec5800..45a3c3c3f346 100644 --- a/vendor/github.com/cortexproject/cortex/pkg/distributor/distributor.go +++ b/vendor/github.com/cortexproject/cortex/pkg/distributor/distributor.go @@ -170,10 +170,6 @@ type Config struct { // for testing and for extending the ingester by adding calls to the client IngesterClientFactory ring_client.PoolFactory `yaml:"-"` - // when true the distributor does not validate the label name, Cortex doesn't directly use - // this (and should never use it) but this feature is used by other projects built on top of it - SkipLabelNameValidation bool `yaml:"-"` - // This config is dynamically injected because defined in the querier config. ShuffleShardingLookbackPeriod time.Duration `yaml:"-"` } @@ -496,8 +492,7 @@ func (d *Distributor) Push(ctx context.Context, req *ingester_client.WriteReques return nil, err } - skipLabelNameValidation := d.cfg.SkipLabelNameValidation || req.GetSkipLabelNameValidation() - validatedSeries, err := d.validateSeries(ts, userID, skipLabelNameValidation) + validatedSeries, err := d.validateSeries(ts, userID, req.GetSkipLabelNameValidation()) // Errors in validation are considered non-fatal, as one series in a request may contain // invalid data but all the remaining series could be perfectly valid. @@ -568,7 +563,7 @@ func (d *Distributor) Push(ctx context.Context, req *ingester_client.WriteReques op = ring.Write } - err = ring.DoBatch(ctx, op, subRing, keys, func(ingester ring.IngesterDesc, indexes []int) error { + err = ring.DoBatch(ctx, op, subRing, keys, func(ingester ring.InstanceDesc, indexes []int) error { timeseries := make([]ingester_client.PreallocTimeseries, 0, len(indexes)) var metadata []*ingester_client.MetricMetadata @@ -621,7 +616,7 @@ func sortLabelsIfNeeded(labels []ingester_client.LabelAdapter) { }) } -func (d *Distributor) send(ctx context.Context, ingester ring.IngesterDesc, timeseries []ingester_client.PreallocTimeseries, metadata []*ingester_client.MetricMetadata, source ingester_client.WriteRequest_SourceEnum) error { +func (d *Distributor) send(ctx context.Context, ingester ring.InstanceDesc, timeseries []ingester_client.PreallocTimeseries, metadata []*ingester_client.MetricMetadata, source ingester_client.WriteRequest_SourceEnum) error { h, err := d.ingesterPool.GetClientFor(ingester.Addr) if err != nil { return err @@ -653,7 +648,7 @@ func (d *Distributor) send(ctx context.Context, ingester ring.IngesterDesc, time // ForReplicationSet runs f, in parallel, for all ingesters in the input replication set. func (d *Distributor) ForReplicationSet(ctx context.Context, replicationSet ring.ReplicationSet, f func(context.Context, ingester_client.IngesterClient) (interface{}, error)) ([]interface{}, error) { - return replicationSet.Do(ctx, d.cfg.ExtraQueryDelay, func(ctx context.Context, ing *ring.IngesterDesc) (interface{}, error) { + return replicationSet.Do(ctx, d.cfg.ExtraQueryDelay, func(ctx context.Context, ing *ring.InstanceDesc) (interface{}, error) { client, err := d.ingesterPool.GetClientFor(ing.Addr) if err != nil { return nil, err diff --git a/vendor/github.com/cortexproject/cortex/pkg/distributor/distributor_ring.go b/vendor/github.com/cortexproject/cortex/pkg/distributor/distributor_ring.go index af77a5d98bce..78296341f78a 100644 --- a/vendor/github.com/cortexproject/cortex/pkg/distributor/distributor_ring.go +++ b/vendor/github.com/cortexproject/cortex/pkg/distributor/distributor_ring.go @@ -9,8 +9,8 @@ import ( "github.com/cortexproject/cortex/pkg/ring" "github.com/cortexproject/cortex/pkg/ring/kv" - "github.com/cortexproject/cortex/pkg/util" "github.com/cortexproject/cortex/pkg/util/flagext" + util_log "github.com/cortexproject/cortex/pkg/util/log" ) // RingConfig masks the ring lifecycler config which contains @@ -36,7 +36,7 @@ type RingConfig struct { func (cfg *RingConfig) RegisterFlags(f *flag.FlagSet) { hostname, err := os.Hostname() if err != nil { - level.Error(util.Logger).Log("msg", "failed to get hostname", "err", err) + level.Error(util_log.Logger).Log("msg", "failed to get hostname", "err", err) os.Exit(1) } diff --git a/vendor/github.com/cortexproject/cortex/pkg/distributor/ha_tracker.go b/vendor/github.com/cortexproject/cortex/pkg/distributor/ha_tracker.go index d7b526b497f2..6aef3e7fd317 100644 --- a/vendor/github.com/cortexproject/cortex/pkg/distributor/ha_tracker.go +++ b/vendor/github.com/cortexproject/cortex/pkg/distributor/ha_tracker.go @@ -21,7 +21,7 @@ import ( "github.com/cortexproject/cortex/pkg/ingester/client" "github.com/cortexproject/cortex/pkg/ring/kv" "github.com/cortexproject/cortex/pkg/ring/kv/codec" - "github.com/cortexproject/cortex/pkg/util" + util_log "github.com/cortexproject/cortex/pkg/util/log" "github.com/cortexproject/cortex/pkg/util/services" ) @@ -155,7 +155,7 @@ func newClusterTracker(cfg HATrackerConfig, limits haTrackerLimits, reg promethe } t := &haTracker{ - logger: util.Logger, + logger: util_log.Logger, cfg: cfg, updateTimeoutJitter: jitter, limits: limits, @@ -259,7 +259,7 @@ func (c *haTracker) checkReplica(ctx context.Context, userID, cluster, replica s // The callback within checkKVStore will return a replicasNotMatchError if the sample is being deduped, // otherwise there may have been an actual error CAS'ing that we should log. if !errors.Is(err, replicasNotMatchError{}) { - level.Error(util.Logger).Log("msg", "rejecting sample", "err", err) + level.Error(util_log.Logger).Log("msg", "rejecting sample", "err", err) } } return err diff --git a/vendor/github.com/cortexproject/cortex/pkg/distributor/query.go b/vendor/github.com/cortexproject/cortex/pkg/distributor/query.go index 501ce4a42236..b8a214ab98ce 100644 --- a/vendor/github.com/cortexproject/cortex/pkg/distributor/query.go +++ b/vendor/github.com/cortexproject/cortex/pkg/distributor/query.go @@ -129,7 +129,7 @@ func (d *Distributor) GetIngestersForMetadata(ctx context.Context) (ring.Replica func (d *Distributor) queryIngesters(ctx context.Context, replicationSet ring.ReplicationSet, req *ingester_client.QueryRequest) (model.Matrix, error) { // Fetch samples from multiple ingesters in parallel, using the replicationSet // to deal with consistency. - results, err := replicationSet.Do(ctx, d.cfg.ExtraQueryDelay, func(ctx context.Context, ing *ring.IngesterDesc) (interface{}, error) { + results, err := replicationSet.Do(ctx, d.cfg.ExtraQueryDelay, func(ctx context.Context, ing *ring.InstanceDesc) (interface{}, error) { client, err := d.ingesterPool.GetClientFor(ing.Addr) if err != nil { return nil, err @@ -174,7 +174,7 @@ func (d *Distributor) queryIngesters(ctx context.Context, replicationSet ring.Re // queryIngesterStream queries the ingesters using the new streaming API. func (d *Distributor) queryIngesterStream(ctx context.Context, replicationSet ring.ReplicationSet, req *ingester_client.QueryRequest) (*ingester_client.QueryStreamResponse, error) { // Fetch samples from multiple ingesters - results, err := replicationSet.Do(ctx, d.cfg.ExtraQueryDelay, func(ctx context.Context, ing *ring.IngesterDesc) (interface{}, error) { + results, err := replicationSet.Do(ctx, d.cfg.ExtraQueryDelay, func(ctx context.Context, ing *ring.InstanceDesc) (interface{}, error) { client, err := d.ingesterPool.GetClientFor(ing.Addr) if err != nil { return nil, err diff --git a/vendor/github.com/cortexproject/cortex/pkg/querier/astmapper/parallel.go b/vendor/github.com/cortexproject/cortex/pkg/querier/astmapper/parallel.go index 989c6bdb92f0..d9f309e1112c 100644 --- a/vendor/github.com/cortexproject/cortex/pkg/querier/astmapper/parallel.go +++ b/vendor/github.com/cortexproject/cortex/pkg/querier/astmapper/parallel.go @@ -6,7 +6,7 @@ import ( "github.com/go-kit/kit/log/level" "github.com/prometheus/prometheus/promql/parser" - "github.com/cortexproject/cortex/pkg/util" + util_log "github.com/cortexproject/cortex/pkg/util/log" ) var summableAggregates = map[parser.ItemType]struct{}{ @@ -90,7 +90,7 @@ func CanParallelize(node parser.Node) bool { return true default: - level.Error(util.Logger).Log("err", fmt.Sprintf("CanParallel: unhandled node type %T", node)) + level.Error(util_log.Logger).Log("err", fmt.Sprintf("CanParallel: unhandled node type %T", node)) return false } diff --git a/vendor/github.com/cortexproject/cortex/pkg/ring/basic_lifecycler.go b/vendor/github.com/cortexproject/cortex/pkg/ring/basic_lifecycler.go index 102865ede1aa..efe10149386b 100644 --- a/vendor/github.com/cortexproject/cortex/pkg/ring/basic_lifecycler.go +++ b/vendor/github.com/cortexproject/cortex/pkg/ring/basic_lifecycler.go @@ -13,7 +13,7 @@ import ( "github.com/prometheus/client_golang/prometheus" "github.com/cortexproject/cortex/pkg/ring/kv" - "github.com/cortexproject/cortex/pkg/util" + util_log "github.com/cortexproject/cortex/pkg/util/log" "github.com/cortexproject/cortex/pkg/util/services" ) @@ -21,7 +21,7 @@ type BasicLifecyclerDelegate interface { // OnRingInstanceRegister is called while the lifecycler is registering the // instance within the ring and should return the state and set of tokens to // use for the instance itself. - OnRingInstanceRegister(lifecycler *BasicLifecycler, ringDesc Desc, instanceExists bool, instanceID string, instanceDesc IngesterDesc) (IngesterState, Tokens) + OnRingInstanceRegister(lifecycler *BasicLifecycler, ringDesc Desc, instanceExists bool, instanceID string, instanceDesc InstanceDesc) (IngesterState, Tokens) // OnRingInstanceTokens is called once the instance tokens are set and are // stable within the ring (honoring the observe period, if set). @@ -34,7 +34,7 @@ type BasicLifecyclerDelegate interface { // OnRingInstanceHeartbeat is called while the instance is updating its heartbeat // in the ring. - OnRingInstanceHeartbeat(lifecycler *BasicLifecycler, ringDesc *Desc, instanceDesc *IngesterDesc) + OnRingInstanceHeartbeat(lifecycler *BasicLifecycler, ringDesc *Desc, instanceDesc *InstanceDesc) } type BasicLifecyclerConfig struct { @@ -77,7 +77,7 @@ type BasicLifecycler struct { // The current instance state. currState sync.RWMutex - currInstanceDesc *IngesterDesc + currInstanceDesc *InstanceDesc } // NewBasicLifecycler makes a new BasicLifecycler. @@ -194,7 +194,7 @@ func (l *BasicLifecycler) running(ctx context.Context) error { f() case <-ctx.Done(): - level.Info(util.Logger).Log("msg", "ring lifecycler is shutting down", "ring", l.ringName) + level.Info(util_log.Logger).Log("msg", "ring lifecycler is shutting down", "ring", l.ringName) return nil } } @@ -239,7 +239,7 @@ heartbeatLoop: // registerInstance registers the instance in the ring. The initial state and set of tokens // depends on the OnRingInstanceRegister() delegate function. func (l *BasicLifecycler) registerInstance(ctx context.Context) error { - var instanceDesc IngesterDesc + var instanceDesc InstanceDesc err := l.store.CAS(ctx, l.ringKey, func(in interface{}) (out interface{}, retry bool, err error) { ringDesc := GetOrCreateRingDesc(in) @@ -327,7 +327,7 @@ func (l *BasicLifecycler) waitStableTokens(ctx context.Context, period time.Dura func (l *BasicLifecycler) verifyTokens(ctx context.Context) bool { result := false - err := l.updateInstance(ctx, func(r *Desc, i *IngesterDesc) bool { + err := l.updateInstance(ctx, func(r *Desc, i *InstanceDesc) bool { // At this point, we should have the same tokens as we have registered before. actualTokens, takenTokens := r.TokensFor(l.cfg.ID) @@ -385,8 +385,8 @@ func (l *BasicLifecycler) unregisterInstance(ctx context.Context) error { return nil } -func (l *BasicLifecycler) updateInstance(ctx context.Context, update func(*Desc, *IngesterDesc) bool) error { - var instanceDesc IngesterDesc +func (l *BasicLifecycler) updateInstance(ctx context.Context, update func(*Desc, *InstanceDesc) bool) error { + var instanceDesc InstanceDesc err := l.store.CAS(ctx, l.ringKey, func(in interface{}) (out interface{}, retry bool, err error) { ringDesc := GetOrCreateRingDesc(in) @@ -431,7 +431,7 @@ func (l *BasicLifecycler) updateInstance(ctx context.Context, update func(*Desc, // heartbeat updates the instance timestamp within the ring. This function is guaranteed // to be called within the lifecycler main goroutine. func (l *BasicLifecycler) heartbeat(ctx context.Context) { - err := l.updateInstance(ctx, func(r *Desc, i *IngesterDesc) bool { + err := l.updateInstance(ctx, func(r *Desc, i *InstanceDesc) bool { l.delegate.OnRingInstanceHeartbeat(l, r, i) i.Timestamp = time.Now().Unix() return true @@ -448,7 +448,7 @@ func (l *BasicLifecycler) heartbeat(ctx context.Context) { // changeState of the instance within the ring. This function is guaranteed // to be called within the lifecycler main goroutine. func (l *BasicLifecycler) changeState(ctx context.Context, state IngesterState) error { - err := l.updateInstance(ctx, func(_ *Desc, i *IngesterDesc) bool { + err := l.updateInstance(ctx, func(_ *Desc, i *InstanceDesc) bool { // No-op if the state hasn't changed. if i.State == state { return false diff --git a/vendor/github.com/cortexproject/cortex/pkg/ring/basic_lifecycler_delegates.go b/vendor/github.com/cortexproject/cortex/pkg/ring/basic_lifecycler_delegates.go index 8006d350767e..7126198e1504 100644 --- a/vendor/github.com/cortexproject/cortex/pkg/ring/basic_lifecycler_delegates.go +++ b/vendor/github.com/cortexproject/cortex/pkg/ring/basic_lifecycler_delegates.go @@ -21,7 +21,7 @@ func NewLeaveOnStoppingDelegate(next BasicLifecyclerDelegate, logger log.Logger) } } -func (d *LeaveOnStoppingDelegate) OnRingInstanceRegister(lifecycler *BasicLifecycler, ringDesc Desc, instanceExists bool, instanceID string, instanceDesc IngesterDesc) (IngesterState, Tokens) { +func (d *LeaveOnStoppingDelegate) OnRingInstanceRegister(lifecycler *BasicLifecycler, ringDesc Desc, instanceExists bool, instanceID string, instanceDesc InstanceDesc) (IngesterState, Tokens) { return d.next.OnRingInstanceRegister(lifecycler, ringDesc, instanceExists, instanceID, instanceDesc) } @@ -37,7 +37,7 @@ func (d *LeaveOnStoppingDelegate) OnRingInstanceStopping(lifecycler *BasicLifecy d.next.OnRingInstanceStopping(lifecycler) } -func (d *LeaveOnStoppingDelegate) OnRingInstanceHeartbeat(lifecycler *BasicLifecycler, ringDesc *Desc, instanceDesc *IngesterDesc) { +func (d *LeaveOnStoppingDelegate) OnRingInstanceHeartbeat(lifecycler *BasicLifecycler, ringDesc *Desc, instanceDesc *InstanceDesc) { d.next.OnRingInstanceHeartbeat(lifecycler, ringDesc, instanceDesc) } @@ -57,7 +57,7 @@ func NewTokensPersistencyDelegate(path string, state IngesterState, next BasicLi } } -func (d *TokensPersistencyDelegate) OnRingInstanceRegister(lifecycler *BasicLifecycler, ringDesc Desc, instanceExists bool, instanceID string, instanceDesc IngesterDesc) (IngesterState, Tokens) { +func (d *TokensPersistencyDelegate) OnRingInstanceRegister(lifecycler *BasicLifecycler, ringDesc Desc, instanceExists bool, instanceID string, instanceDesc InstanceDesc) (IngesterState, Tokens) { // Skip if no path has been configured. if d.tokensPath == "" { level.Info(d.logger).Log("msg", "not loading tokens from file, tokens file path is empty") @@ -82,7 +82,7 @@ func (d *TokensPersistencyDelegate) OnRingInstanceRegister(lifecycler *BasicLife // Signal the next delegate that the tokens have been loaded, miming the // case the instance exist in the ring (which is OK because the lifecycler // will correctly reconcile this case too). - return d.next.OnRingInstanceRegister(lifecycler, ringDesc, true, lifecycler.GetInstanceID(), IngesterDesc{ + return d.next.OnRingInstanceRegister(lifecycler, ringDesc, true, lifecycler.GetInstanceID(), InstanceDesc{ Addr: lifecycler.GetInstanceAddr(), Timestamp: time.Now().Unix(), RegisteredTimestamp: lifecycler.GetRegisteredAt().Unix(), @@ -106,7 +106,7 @@ func (d *TokensPersistencyDelegate) OnRingInstanceStopping(lifecycler *BasicLife d.next.OnRingInstanceStopping(lifecycler) } -func (d *TokensPersistencyDelegate) OnRingInstanceHeartbeat(lifecycler *BasicLifecycler, ringDesc *Desc, instanceDesc *IngesterDesc) { +func (d *TokensPersistencyDelegate) OnRingInstanceHeartbeat(lifecycler *BasicLifecycler, ringDesc *Desc, instanceDesc *InstanceDesc) { d.next.OnRingInstanceHeartbeat(lifecycler, ringDesc, instanceDesc) } @@ -126,7 +126,7 @@ func NewAutoForgetDelegate(forgetPeriod time.Duration, next BasicLifecyclerDeleg } } -func (d *AutoForgetDelegate) OnRingInstanceRegister(lifecycler *BasicLifecycler, ringDesc Desc, instanceExists bool, instanceID string, instanceDesc IngesterDesc) (IngesterState, Tokens) { +func (d *AutoForgetDelegate) OnRingInstanceRegister(lifecycler *BasicLifecycler, ringDesc Desc, instanceExists bool, instanceID string, instanceDesc InstanceDesc) (IngesterState, Tokens) { return d.next.OnRingInstanceRegister(lifecycler, ringDesc, instanceExists, instanceID, instanceDesc) } @@ -138,7 +138,7 @@ func (d *AutoForgetDelegate) OnRingInstanceStopping(lifecycler *BasicLifecycler) d.next.OnRingInstanceStopping(lifecycler) } -func (d *AutoForgetDelegate) OnRingInstanceHeartbeat(lifecycler *BasicLifecycler, ringDesc *Desc, instanceDesc *IngesterDesc) { +func (d *AutoForgetDelegate) OnRingInstanceHeartbeat(lifecycler *BasicLifecycler, ringDesc *Desc, instanceDesc *InstanceDesc) { for id, instance := range ringDesc.Ingesters { lastHeartbeat := time.Unix(instance.GetTimestamp(), 0) diff --git a/vendor/github.com/cortexproject/cortex/pkg/ring/batch.go b/vendor/github.com/cortexproject/cortex/pkg/ring/batch.go index 3990bdd4dd30..c24dc200deea 100644 --- a/vendor/github.com/cortexproject/cortex/pkg/ring/batch.go +++ b/vendor/github.com/cortexproject/cortex/pkg/ring/batch.go @@ -16,7 +16,7 @@ type batchTracker struct { } type instance struct { - desc IngesterDesc + desc InstanceDesc itemTrackers []*itemTracker indexes []int } @@ -38,7 +38,7 @@ type itemTracker struct { // to send to that instance. // // Not implemented as a method on Ring so we can test separately. -func DoBatch(ctx context.Context, op Operation, r ReadRing, keys []uint32, callback func(IngesterDesc, []int) error, cleanup func()) error { +func DoBatch(ctx context.Context, op Operation, r ReadRing, keys []uint32, callback func(InstanceDesc, []int) error, cleanup func()) error { if r.InstancesCount() <= 0 { return fmt.Errorf("DoBatch: InstancesCount <= 0") } @@ -47,7 +47,7 @@ func DoBatch(ctx context.Context, op Operation, r ReadRing, keys []uint32, callb instances := make(map[string]instance, r.InstancesCount()) var ( - bufDescs [GetBufferSize]IngesterDesc + bufDescs [GetBufferSize]InstanceDesc bufHosts [GetBufferSize]string bufZones [GetBufferSize]string ) diff --git a/vendor/github.com/cortexproject/cortex/pkg/ring/client/pool.go b/vendor/github.com/cortexproject/cortex/pkg/ring/client/pool.go index 41bc8728abb3..39da1db688a9 100644 --- a/vendor/github.com/cortexproject/cortex/pkg/ring/client/pool.go +++ b/vendor/github.com/cortexproject/cortex/pkg/ring/client/pool.go @@ -14,6 +14,7 @@ import ( "google.golang.org/grpc/health/grpc_health_v1" "github.com/cortexproject/cortex/pkg/util" + util_log "github.com/cortexproject/cortex/pkg/util/log" "github.com/cortexproject/cortex/pkg/util/services" ) @@ -158,7 +159,7 @@ func (p *Pool) removeStaleClients() { serviceAddrs, err := p.discovery() if err != nil { - level.Error(util.Logger).Log("msg", "error removing stale clients", "err", err) + level.Error(util_log.Logger).Log("msg", "error removing stale clients", "err", err) return } @@ -166,7 +167,7 @@ func (p *Pool) removeStaleClients() { if util.StringsContain(serviceAddrs, addr) { continue } - level.Info(util.Logger).Log("msg", "removing stale client", "addr", addr) + level.Info(util_log.Logger).Log("msg", "removing stale client", "addr", addr) p.RemoveClientFor(addr) } } @@ -179,7 +180,7 @@ func (p *Pool) cleanUnhealthy() { if ok { err := healthCheck(client, p.cfg.HealthCheckTimeout) if err != nil { - level.Warn(util.Logger).Log("msg", fmt.Sprintf("removing %s failing healthcheck", p.clientName), "addr", addr, "reason", err) + level.Warn(util_log.Logger).Log("msg", fmt.Sprintf("removing %s failing healthcheck", p.clientName), "addr", addr, "reason", err) p.RemoveClientFor(addr) } } diff --git a/vendor/github.com/cortexproject/cortex/pkg/ring/client/ring_service_discovery.go b/vendor/github.com/cortexproject/cortex/pkg/ring/client/ring_service_discovery.go index e0ab7ce64b93..1706edb2a175 100644 --- a/vendor/github.com/cortexproject/cortex/pkg/ring/client/ring_service_discovery.go +++ b/vendor/github.com/cortexproject/cortex/pkg/ring/client/ring_service_discovery.go @@ -1,12 +1,17 @@ package client import ( + "errors" + "github.com/cortexproject/cortex/pkg/ring" ) func NewRingServiceDiscovery(r ring.ReadRing) PoolServiceDiscovery { return func() ([]string, error) { replicationSet, err := r.GetAllHealthy(ring.Reporting) + if errors.Is(err, ring.ErrEmptyRing) { + return nil, nil + } if err != nil { return nil, err } diff --git a/vendor/github.com/cortexproject/cortex/pkg/ring/kv/consul/client.go b/vendor/github.com/cortexproject/cortex/pkg/ring/kv/consul/client.go index c1e12863e957..1c39a473ced7 100644 --- a/vendor/github.com/cortexproject/cortex/pkg/ring/kv/consul/client.go +++ b/vendor/github.com/cortexproject/cortex/pkg/ring/kv/consul/client.go @@ -17,6 +17,7 @@ import ( "github.com/cortexproject/cortex/pkg/ring/kv/codec" "github.com/cortexproject/cortex/pkg/util" + util_log "github.com/cortexproject/cortex/pkg/util/log" ) const ( @@ -143,14 +144,14 @@ func (c *Client) cas(ctx context.Context, key string, f func(in interface{}) (ou options := &consul.QueryOptions{} kvp, _, err := c.kv.Get(key, options.WithContext(ctx)) if err != nil { - level.Error(util.Logger).Log("msg", "error getting key", "key", key, "err", err) + level.Error(util_log.Logger).Log("msg", "error getting key", "key", key, "err", err) continue } var intermediate interface{} if kvp != nil { out, err := c.codec.Decode(kvp.Value) if err != nil { - level.Error(util.Logger).Log("msg", "error decoding key", "key", key, "err", err) + level.Error(util_log.Logger).Log("msg", "error decoding key", "key", key, "err", err) continue } // If key doesn't exist, index will be 0. @@ -174,7 +175,7 @@ func (c *Client) cas(ctx context.Context, key string, f func(in interface{}) (ou bytes, err := c.codec.Encode(intermediate) if err != nil { - level.Error(util.Logger).Log("msg", "error serialising value", "key", key, "err", err) + level.Error(util_log.Logger).Log("msg", "error serialising value", "key", key, "err", err) continue } ok, _, err := c.kv.CAS(&consul.KVPair{ @@ -183,11 +184,11 @@ func (c *Client) cas(ctx context.Context, key string, f func(in interface{}) (ou ModifyIndex: index, }, writeOptions.WithContext(ctx)) if err != nil { - level.Error(util.Logger).Log("msg", "error CASing", "key", key, "err", err) + level.Error(util_log.Logger).Log("msg", "error CASing", "key", key, "err", err) continue } if !ok { - level.Debug(util.Logger).Log("msg", "error CASing, trying again", "key", key, "index", index) + level.Debug(util_log.Logger).Log("msg", "error CASing, trying again", "key", key, "index", index) continue } return nil @@ -213,7 +214,7 @@ func (c *Client) WatchKey(ctx context.Context, key string, f func(interface{}) b if errors.Is(err, context.Canceled) { break } - level.Error(util.Logger).Log("msg", "error while rate-limiting", "key", key, "err", err) + level.Error(util_log.Logger).Log("msg", "error while rate-limiting", "key", key, "err", err) backoff.Wait() continue } @@ -230,7 +231,7 @@ func (c *Client) WatchKey(ctx context.Context, key string, f func(interface{}) b // Don't backoff if value is not found (kvp == nil). In that case, Consul still returns index value, // and next call to Get will block as expected. We handle missing value below. if err != nil { - level.Error(util.Logger).Log("msg", "error getting path", "key", key, "err", err) + level.Error(util_log.Logger).Log("msg", "error getting path", "key", key, "err", err) backoff.Wait() continue } @@ -243,13 +244,13 @@ func (c *Client) WatchKey(ctx context.Context, key string, f func(interface{}) b } if kvp == nil { - level.Info(util.Logger).Log("msg", "value is nil", "key", key, "index", index) + level.Info(util_log.Logger).Log("msg", "value is nil", "key", key, "index", index) continue } out, err := c.codec.Decode(kvp.Value) if err != nil { - level.Error(util.Logger).Log("msg", "error decoding key", "key", key, "err", err) + level.Error(util_log.Logger).Log("msg", "error decoding key", "key", key, "err", err) continue } if !f(out) { @@ -273,7 +274,7 @@ func (c *Client) WatchPrefix(ctx context.Context, prefix string, f func(string, if errors.Is(err, context.Canceled) { break } - level.Error(util.Logger).Log("msg", "error while rate-limiting", "prefix", prefix, "err", err) + level.Error(util_log.Logger).Log("msg", "error while rate-limiting", "prefix", prefix, "err", err) backoff.Wait() continue } @@ -289,7 +290,7 @@ func (c *Client) WatchPrefix(ctx context.Context, prefix string, f func(string, // kvps being nil here is not an error -- quite the opposite. Consul returns index, // which makes next query blocking, so there is no need to detect this and act on it. if err != nil { - level.Error(util.Logger).Log("msg", "error getting path", "prefix", prefix, "err", err) + level.Error(util_log.Logger).Log("msg", "error getting path", "prefix", prefix, "err", err) backoff.Wait() continue } @@ -309,7 +310,7 @@ func (c *Client) WatchPrefix(ctx context.Context, prefix string, f func(string, out, err := c.codec.Decode(kvp.Value) if err != nil { - level.Error(util.Logger).Log("msg", "error decoding list of values for prefix:key", "prefix", prefix, "key", kvp.Key, "err", err) + level.Error(util_log.Logger).Log("msg", "error decoding list of values for prefix:key", "prefix", prefix, "key", kvp.Key, "err", err) continue } if !f(kvp.Key, out) { diff --git a/vendor/github.com/cortexproject/cortex/pkg/ring/kv/consul/mock.go b/vendor/github.com/cortexproject/cortex/pkg/ring/kv/consul/mock.go index 708bea76205f..5d1e4557395b 100644 --- a/vendor/github.com/cortexproject/cortex/pkg/ring/kv/consul/mock.go +++ b/vendor/github.com/cortexproject/cortex/pkg/ring/kv/consul/mock.go @@ -10,7 +10,7 @@ import ( consul "github.com/hashicorp/consul/api" "github.com/cortexproject/cortex/pkg/ring/kv/codec" - "github.com/cortexproject/cortex/pkg/util" + util_log "github.com/cortexproject/cortex/pkg/util/log" ) type mockKV struct { @@ -78,12 +78,12 @@ func (m *mockKV) Put(p *consul.KVPair, q *consul.WriteOptions) (*consul.WriteMet m.cond.Broadcast() - level.Debug(util.Logger).Log("msg", "Put", "key", p.Key, "value", fmt.Sprintf("%.40q", p.Value), "modify_index", m.current) + level.Debug(util_log.Logger).Log("msg", "Put", "key", p.Key, "value", fmt.Sprintf("%.40q", p.Value), "modify_index", m.current) return nil, nil } func (m *mockKV) CAS(p *consul.KVPair, q *consul.WriteOptions) (bool, *consul.WriteMeta, error) { - level.Debug(util.Logger).Log("msg", "CAS", "key", p.Key, "modify_index", p.ModifyIndex, "value", fmt.Sprintf("%.40q", p.Value)) + level.Debug(util_log.Logger).Log("msg", "CAS", "key", p.Key, "modify_index", p.ModifyIndex, "value", fmt.Sprintf("%.40q", p.Value)) m.mtx.Lock() defer m.mtx.Unlock() @@ -110,14 +110,14 @@ func (m *mockKV) CAS(p *consul.KVPair, q *consul.WriteOptions) (bool, *consul.Wr } func (m *mockKV) Get(key string, q *consul.QueryOptions) (*consul.KVPair, *consul.QueryMeta, error) { - level.Debug(util.Logger).Log("msg", "Get", "key", key, "wait_index", q.WaitIndex) + level.Debug(util_log.Logger).Log("msg", "Get", "key", key, "wait_index", q.WaitIndex) m.mtx.Lock() defer m.mtx.Unlock() value := m.kvps[key] if value == nil && q.WaitIndex == 0 { - level.Debug(util.Logger).Log("msg", "Get - not found", "key", key) + level.Debug(util_log.Logger).Log("msg", "Get - not found", "key", key) return nil, &consul.QueryMeta{LastIndex: m.current}, nil } @@ -146,17 +146,17 @@ func (m *mockKV) Get(key string, q *consul.QueryOptions) (*consul.KVPair, *consu } } if time.Now().After(deadline) { - level.Debug(util.Logger).Log("msg", "Get - deadline exceeded", "key", key) + level.Debug(util_log.Logger).Log("msg", "Get - deadline exceeded", "key", key) return nil, &consul.QueryMeta{LastIndex: q.WaitIndex}, nil } } if value == nil { - level.Debug(util.Logger).Log("msg", "Get - not found", "key", key) + level.Debug(util_log.Logger).Log("msg", "Get - not found", "key", key) return nil, &consul.QueryMeta{LastIndex: m.current}, nil } - level.Debug(util.Logger).Log("msg", "Get", "key", key, "modify_index", value.ModifyIndex, "value", fmt.Sprintf("%.40q", value.Value)) + level.Debug(util_log.Logger).Log("msg", "Get", "key", key, "modify_index", value.ModifyIndex, "value", fmt.Sprintf("%.40q", value.Value)) return copyKVPair(value), &consul.QueryMeta{LastIndex: value.ModifyIndex}, nil } @@ -203,7 +203,7 @@ func (m *mockKV) ResetIndex() { m.current = 0 m.cond.Broadcast() - level.Debug(util.Logger).Log("msg", "Reset") + level.Debug(util_log.Logger).Log("msg", "Reset") } func (m *mockKV) ResetIndexForKey(key string) { @@ -215,7 +215,7 @@ func (m *mockKV) ResetIndexForKey(key string) { } m.cond.Broadcast() - level.Debug(util.Logger).Log("msg", "ResetIndexForKey", "key", key) + level.Debug(util_log.Logger).Log("msg", "ResetIndexForKey", "key", key) } // mockedMaxWaitTime returns the minimum duration between the input duration diff --git a/vendor/github.com/cortexproject/cortex/pkg/ring/kv/etcd/etcd.go b/vendor/github.com/cortexproject/cortex/pkg/ring/kv/etcd/etcd.go index fa1e61732689..222fb4ee3198 100644 --- a/vendor/github.com/cortexproject/cortex/pkg/ring/kv/etcd/etcd.go +++ b/vendor/github.com/cortexproject/cortex/pkg/ring/kv/etcd/etcd.go @@ -15,6 +15,7 @@ import ( "github.com/cortexproject/cortex/pkg/ring/kv/codec" "github.com/cortexproject/cortex/pkg/util" "github.com/cortexproject/cortex/pkg/util/flagext" + util_log "github.com/cortexproject/cortex/pkg/util/log" cortex_tls "github.com/cortexproject/cortex/pkg/util/tls" ) @@ -106,7 +107,7 @@ func (c *Client) CAS(ctx context.Context, key string, f func(in interface{}) (ou for i := 0; i < c.cfg.MaxRetries; i++ { resp, err := c.cli.Get(ctx, key) if err != nil { - level.Error(util.Logger).Log("msg", "error getting key", "key", key, "err", err) + level.Error(util_log.Logger).Log("msg", "error getting key", "key", key, "err", err) lastErr = err continue } @@ -115,7 +116,7 @@ func (c *Client) CAS(ctx context.Context, key string, f func(in interface{}) (ou if len(resp.Kvs) > 0 { intermediate, err = c.codec.Decode(resp.Kvs[0].Value) if err != nil { - level.Error(util.Logger).Log("msg", "error decoding key", "key", key, "err", err) + level.Error(util_log.Logger).Log("msg", "error decoding key", "key", key, "err", err) lastErr = err continue } @@ -139,7 +140,7 @@ func (c *Client) CAS(ctx context.Context, key string, f func(in interface{}) (ou buf, err := c.codec.Encode(intermediate) if err != nil { - level.Error(util.Logger).Log("msg", "error serialising value", "key", key, "err", err) + level.Error(util_log.Logger).Log("msg", "error serialising value", "key", key, "err", err) lastErr = err continue } @@ -149,13 +150,13 @@ func (c *Client) CAS(ctx context.Context, key string, f func(in interface{}) (ou Then(clientv3.OpPut(key, string(buf))). Commit() if err != nil { - level.Error(util.Logger).Log("msg", "error CASing", "key", key, "err", err) + level.Error(util_log.Logger).Log("msg", "error CASing", "key", key, "err", err) lastErr = err continue } // result is not Succeeded if the the comparison was false, meaning if the modify indexes did not match. if !result.Succeeded { - level.Debug(util.Logger).Log("msg", "failed to CAS, revision and version did not match in etcd", "key", key, "revision", revision) + level.Debug(util_log.Logger).Log("msg", "failed to CAS, revision and version did not match in etcd", "key", key, "revision", revision) continue } @@ -183,7 +184,7 @@ outer: for backoff.Ongoing() { for resp := range c.cli.Watch(watchCtx, key) { if err := resp.Err(); err != nil { - level.Error(util.Logger).Log("msg", "watch error", "key", key, "err", err) + level.Error(util_log.Logger).Log("msg", "watch error", "key", key, "err", err) continue outer } @@ -192,7 +193,7 @@ outer: for _, event := range resp.Events { out, err := c.codec.Decode(event.Kv.Value) if err != nil { - level.Error(util.Logger).Log("msg", "error decoding key", "key", key, "err", err) + level.Error(util_log.Logger).Log("msg", "error decoding key", "key", key, "err", err) continue } @@ -219,7 +220,7 @@ outer: for backoff.Ongoing() { for resp := range c.cli.Watch(watchCtx, key, clientv3.WithPrefix()) { if err := resp.Err(); err != nil { - level.Error(util.Logger).Log("msg", "watch error", "key", key, "err", err) + level.Error(util_log.Logger).Log("msg", "watch error", "key", key, "err", err) continue outer } @@ -228,7 +229,7 @@ outer: for _, event := range resp.Events { out, err := c.codec.Decode(event.Kv.Value) if err != nil { - level.Error(util.Logger).Log("msg", "error decoding key", "key", key, "err", err) + level.Error(util_log.Logger).Log("msg", "error decoding key", "key", key, "err", err) continue } diff --git a/vendor/github.com/cortexproject/cortex/pkg/ring/kv/memberlist/broadcast.go b/vendor/github.com/cortexproject/cortex/pkg/ring/kv/memberlist/broadcast.go index c4687721233c..f739b67241cd 100644 --- a/vendor/github.com/cortexproject/cortex/pkg/ring/kv/memberlist/broadcast.go +++ b/vendor/github.com/cortexproject/cortex/pkg/ring/kv/memberlist/broadcast.go @@ -6,7 +6,7 @@ import ( "github.com/go-kit/kit/log/level" "github.com/hashicorp/memberlist" - "github.com/cortexproject/cortex/pkg/util" + util_log "github.com/cortexproject/cortex/pkg/util/log" ) // ringBroadcast implements memberlist.Broadcast interface, which is used by memberlist.TransmitLimitedQueue. @@ -45,7 +45,7 @@ func (r ringBroadcast) Invalidates(old memberlist.Broadcast) bool { // otherwise, we may be invalidating some older messages, which however covered different // ingesters if r.version >= oldb.version { - level.Debug(util.Logger).Log("msg", "Invalidating forwarded broadcast", "key", r.key, "version", r.version, "oldVersion", oldb.version, "content", fmt.Sprintf("%v", r.content), "oldContent", fmt.Sprintf("%v", oldb.content)) + level.Debug(util_log.Logger).Log("msg", "Invalidating forwarded broadcast", "key", r.key, "version", r.version, "oldVersion", oldb.version, "content", fmt.Sprintf("%v", r.content), "oldContent", fmt.Sprintf("%v", oldb.content)) return true } } diff --git a/vendor/github.com/cortexproject/cortex/pkg/ring/kv/memberlist/memberlist_client.go b/vendor/github.com/cortexproject/cortex/pkg/ring/kv/memberlist/memberlist_client.go index 26495ff243bd..056cc7817187 100644 --- a/vendor/github.com/cortexproject/cortex/pkg/ring/kv/memberlist/memberlist_client.go +++ b/vendor/github.com/cortexproject/cortex/pkg/ring/kv/memberlist/memberlist_client.go @@ -23,6 +23,7 @@ import ( "github.com/cortexproject/cortex/pkg/ring/kv/codec" "github.com/cortexproject/cortex/pkg/util" "github.com/cortexproject/cortex/pkg/util/flagext" + util_log "github.com/cortexproject/cortex/pkg/util/log" "github.com/cortexproject/cortex/pkg/util/services" ) @@ -192,7 +193,7 @@ func generateRandomSuffix() string { suffix := make([]byte, 4) _, err := rand.Read(suffix) if err != nil { - level.Error(util.Logger).Log("msg", "failed to generate random suffix", "err", err) + level.Error(util_log.Logger).Log("msg", "failed to generate random suffix", "err", err) return "error" } return fmt.Sprintf("%2x", suffix) diff --git a/vendor/github.com/cortexproject/cortex/pkg/ring/kv/memberlist/memberlist_logger.go b/vendor/github.com/cortexproject/cortex/pkg/ring/kv/memberlist/memberlist_logger.go index f37d6fdc6656..6b35a1e69041 100644 --- a/vendor/github.com/cortexproject/cortex/pkg/ring/kv/memberlist/memberlist_logger.go +++ b/vendor/github.com/cortexproject/cortex/pkg/ring/kv/memberlist/memberlist_logger.go @@ -11,7 +11,7 @@ import ( // loggerAdapter wraps a Logger and allows it to be passed to the stdlib // logger's SetOutput. It understand and parses output produced by memberlist -// library (esp. level). Timestamp from memberlist can be ignored (eg. util.Logger +// library (esp. level). Timestamp from memberlist can be ignored (eg. pkg/util/log.Logger // is set up to auto-include timestamp with every message already) type loggerAdapter struct { log.Logger diff --git a/vendor/github.com/cortexproject/cortex/pkg/ring/kv/memberlist/metrics.go b/vendor/github.com/cortexproject/cortex/pkg/ring/kv/memberlist/metrics.go index e0fcf7c9964d..2cbcb6b15a98 100644 --- a/vendor/github.com/cortexproject/cortex/pkg/ring/kv/memberlist/metrics.go +++ b/vendor/github.com/cortexproject/cortex/pkg/ring/kv/memberlist/metrics.go @@ -8,7 +8,7 @@ import ( "github.com/go-kit/kit/log/level" "github.com/prometheus/client_golang/prometheus" - "github.com/cortexproject/cortex/pkg/util" + util_log "github.com/cortexproject/cortex/pkg/util/log" "github.com/cortexproject/cortex/pkg/util/services" ) @@ -191,7 +191,7 @@ func (m *KV) createAndRegisterMetrics() { } if err != nil { - level.Error(util.Logger).Log("msg", "failed to register prometheus metrics for memberlist", "err", err) + level.Error(util_log.Logger).Log("msg", "failed to register prometheus metrics for memberlist", "err", err) } } diff --git a/vendor/github.com/cortexproject/cortex/pkg/ring/kv/mock.go b/vendor/github.com/cortexproject/cortex/pkg/ring/kv/mock.go index c899b634326e..ac7ae011df71 100644 --- a/vendor/github.com/cortexproject/cortex/pkg/ring/kv/mock.go +++ b/vendor/github.com/cortexproject/cortex/pkg/ring/kv/mock.go @@ -5,7 +5,7 @@ import ( "github.com/go-kit/kit/log/level" - "github.com/cortexproject/cortex/pkg/util" + util_log "github.com/cortexproject/cortex/pkg/util/log" ) // The mockClient does not anything. @@ -13,7 +13,7 @@ import ( type mockClient struct{} func buildMockClient() (Client, error) { - level.Warn(util.Logger).Log("msg", "created mockClient for testing only") + level.Warn(util_log.Logger).Log("msg", "created mockClient for testing only") return mockClient{}, nil } diff --git a/vendor/github.com/cortexproject/cortex/pkg/ring/kv/multi.go b/vendor/github.com/cortexproject/cortex/pkg/ring/kv/multi.go index 3817725fe3a3..3bfb1bcdbba7 100644 --- a/vendor/github.com/cortexproject/cortex/pkg/ring/kv/multi.go +++ b/vendor/github.com/cortexproject/cortex/pkg/ring/kv/multi.go @@ -11,7 +11,7 @@ import ( "github.com/prometheus/client_golang/prometheus" "go.uber.org/atomic" - "github.com/cortexproject/cortex/pkg/util" + util_log "github.com/cortexproject/cortex/pkg/util/log" "github.com/go-kit/kit/log/level" ) @@ -118,7 +118,7 @@ func NewMultiClient(cfg MultiConfig, clients []kvclient) *MultiClient { mirrorTimeout: cfg.MirrorTimeout, mirroringEnabled: atomic.NewBool(cfg.MirrorEnabled), - logger: log.With(util.Logger, "component", "multikv"), + logger: log.With(util_log.Logger, "component", "multikv"), } ctx, cancelFn := context.WithCancel(context.Background()) diff --git a/vendor/github.com/cortexproject/cortex/pkg/ring/lifecycler.go b/vendor/github.com/cortexproject/cortex/pkg/ring/lifecycler.go index bd3d4bf3958b..4e82d645209b 100644 --- a/vendor/github.com/cortexproject/cortex/pkg/ring/lifecycler.go +++ b/vendor/github.com/cortexproject/cortex/pkg/ring/lifecycler.go @@ -528,7 +528,7 @@ func (i *Lifecycler) initRing(ctx context.Context) error { ringDesc = in.(*Desc) } - ingesterDesc, ok := ringDesc.Ingesters[i.ID] + instanceDesc, ok := ringDesc.Ingesters[i.ID] if !ok { // The instance doesn't exist in the ring, so it's safe to set the registered timestamp // as of now. @@ -554,27 +554,27 @@ func (i *Lifecycler) initRing(ctx context.Context) error { // The instance already exists in the ring, so we can't change the registered timestamp (even if it's zero) // but we need to update the local state accordingly. - i.setRegisteredAt(ingesterDesc.GetRegisteredAt()) + i.setRegisteredAt(instanceDesc.GetRegisteredAt()) // If the ingester is in the JOINING state this means it crashed due to // a failed token transfer or some other reason during startup. We want // to set it back to PENDING in order to start the lifecycle from the // beginning. - if ingesterDesc.State == JOINING { + if instanceDesc.State == JOINING { level.Warn(log.Logger).Log("msg", "instance found in ring as JOINING, setting to PENDING", "ring", i.RingName) - ingesterDesc.State = PENDING + instanceDesc.State = PENDING return ringDesc, true, nil } // If the ingester failed to clean it's ring entry up in can leave it's state in LEAVING. // Move it into ACTIVE to ensure the ingester joins the ring. - if ingesterDesc.State == LEAVING && len(ingesterDesc.Tokens) == i.cfg.NumTokens { - ingesterDesc.State = ACTIVE + if instanceDesc.State == LEAVING && len(instanceDesc.Tokens) == i.cfg.NumTokens { + instanceDesc.State = ACTIVE } // We exist in the ring, so assume the ring is right and copy out tokens & state out of there. - i.setState(ingesterDesc.State) + i.setState(instanceDesc.State) tokens, _ := ringDesc.TokensFor(i.ID) i.setTokens(tokens) @@ -705,18 +705,18 @@ func (i *Lifecycler) updateConsul(ctx context.Context) error { ringDesc = in.(*Desc) } - ingesterDesc, ok := ringDesc.Ingesters[i.ID] + instanceDesc, ok := ringDesc.Ingesters[i.ID] if !ok { // consul must have restarted level.Info(log.Logger).Log("msg", "found empty ring, inserting tokens", "ring", i.RingName) ringDesc.AddIngester(i.ID, i.Addr, i.Zone, i.getTokens(), i.GetState(), i.getRegisteredAt()) } else { - ingesterDesc.Timestamp = time.Now().Unix() - ingesterDesc.State = i.GetState() - ingesterDesc.Addr = i.Addr - ingesterDesc.Zone = i.Zone - ingesterDesc.RegisteredTimestamp = i.getRegisteredAt().Unix() - ringDesc.Ingesters[i.ID] = ingesterDesc + instanceDesc.Timestamp = time.Now().Unix() + instanceDesc.State = i.GetState() + instanceDesc.Addr = i.Addr + instanceDesc.Zone = i.Zone + instanceDesc.RegisteredTimestamp = i.getRegisteredAt().Unix() + ringDesc.Ingesters[i.ID] = instanceDesc } return ringDesc, true, nil diff --git a/vendor/github.com/cortexproject/cortex/pkg/ring/model.go b/vendor/github.com/cortexproject/cortex/pkg/ring/model.go index cd41039e57d6..4187275184f4 100644 --- a/vendor/github.com/cortexproject/cortex/pkg/ring/model.go +++ b/vendor/github.com/cortexproject/cortex/pkg/ring/model.go @@ -12,8 +12,8 @@ import ( "github.com/cortexproject/cortex/pkg/ring/kv/memberlist" ) -// ByAddr is a sortable list of IngesterDesc. -type ByAddr []IngesterDesc +// ByAddr is a sortable list of InstanceDesc. +type ByAddr []InstanceDesc func (ts ByAddr) Len() int { return len(ts) } func (ts ByAddr) Swap(i, j int) { ts[i], ts[j] = ts[j], ts[i] } @@ -32,15 +32,15 @@ func GetCodec() codec.Codec { // NewDesc returns an empty ring.Desc func NewDesc() *Desc { return &Desc{ - Ingesters: map[string]IngesterDesc{}, + Ingesters: map[string]InstanceDesc{}, } } // AddIngester adds the given ingester to the ring. Ingester will only use supplied tokens, // any other tokens are removed. -func (d *Desc) AddIngester(id, addr, zone string, tokens []uint32, state IngesterState, registeredAt time.Time) IngesterDesc { +func (d *Desc) AddIngester(id, addr, zone string, tokens []uint32, state IngesterState, registeredAt time.Time) InstanceDesc { if d.Ingesters == nil { - d.Ingesters = map[string]IngesterDesc{} + d.Ingesters = map[string]InstanceDesc{} } registeredTimestamp := int64(0) @@ -48,7 +48,7 @@ func (d *Desc) AddIngester(id, addr, zone string, tokens []uint32, state Ingeste registeredTimestamp = registeredAt.Unix() } - ingester := IngesterDesc{ + ingester := InstanceDesc{ Addr: addr, Timestamp: time.Now().Unix(), RegisteredTimestamp: registeredTimestamp, @@ -87,8 +87,8 @@ func (d *Desc) ClaimTokens(from, to string) Tokens { } // FindIngestersByState returns the list of ingesters in the given state -func (d *Desc) FindIngestersByState(state IngesterState) []IngesterDesc { - var result []IngesterDesc +func (d *Desc) FindIngestersByState(state IngesterState) []InstanceDesc { + var result []InstanceDesc for _, ing := range d.Ingesters { if ing.State == state { result = append(result, ing) @@ -125,7 +125,7 @@ func (d *Desc) TokensFor(id string) (myTokens, allTokens Tokens) { // GetRegisteredAt returns the timestamp when the instance has been registered to the ring // or a zero value if unknown. -func (i *IngesterDesc) GetRegisteredAt() time.Time { +func (i *InstanceDesc) GetRegisteredAt() time.Time { if i == nil || i.RegisteredTimestamp == 0 { return time.Time{} } @@ -133,7 +133,7 @@ func (i *IngesterDesc) GetRegisteredAt() time.Time { return time.Unix(i.RegisteredTimestamp, 0) } -func (i *IngesterDesc) IsHealthy(op Operation, heartbeatTimeout time.Duration, now time.Time) bool { +func (i *InstanceDesc) IsHealthy(op Operation, heartbeatTimeout time.Duration, now time.Time) bool { healthy := op.IsInstanceInStateHealthy(i.State) return healthy && now.Unix()-i.Timestamp <= heartbeatTimeout.Milliseconds()/1000 @@ -245,8 +245,8 @@ func (d *Desc) MergeContent() []string { // buildNormalizedIngestersMap will do the following: // - sorts tokens and removes duplicates (only within single ingester) // - it doesn't modify input ring -func buildNormalizedIngestersMap(inputRing *Desc) map[string]IngesterDesc { - out := map[string]IngesterDesc{} +func buildNormalizedIngestersMap(inputRing *Desc) map[string]InstanceDesc { + out := map[string]InstanceDesc{} // Make sure LEFT ingesters have no tokens for n, ing := range inputRing.Ingesters { @@ -284,7 +284,7 @@ func buildNormalizedIngestersMap(inputRing *Desc) map[string]IngesterDesc { return out } -func conflictingTokensExist(normalizedIngesters map[string]IngesterDesc) bool { +func conflictingTokensExist(normalizedIngesters map[string]InstanceDesc) bool { count := 0 for _, ing := range normalizedIngesters { count += len(ing.Tokens) @@ -309,7 +309,7 @@ func conflictingTokensExist(normalizedIngesters map[string]IngesterDesc) bool { // 2) otherwise node names are compared, and node with "lower" name wins the token // // Modifies ingesters map with updated tokens. -func resolveConflicts(normalizedIngesters map[string]IngesterDesc) { +func resolveConflicts(normalizedIngesters map[string]InstanceDesc) { size := 0 for _, ing := range normalizedIngesters { size += len(ing.Tokens) diff --git a/vendor/github.com/cortexproject/cortex/pkg/ring/replication_set.go b/vendor/github.com/cortexproject/cortex/pkg/ring/replication_set.go index adc619e85cbf..391773dff150 100644 --- a/vendor/github.com/cortexproject/cortex/pkg/ring/replication_set.go +++ b/vendor/github.com/cortexproject/cortex/pkg/ring/replication_set.go @@ -9,7 +9,7 @@ import ( // ReplicationSet describes the ingesters to talk to for a given key, and how // many errors to tolerate. type ReplicationSet struct { - Ingesters []IngesterDesc + Ingesters []InstanceDesc // Maximum number of tolerated failing instances. Max errors and max unavailable zones are // mutually exclusive. @@ -22,11 +22,11 @@ type ReplicationSet struct { // Do function f in parallel for all replicas in the set, erroring is we exceed // MaxErrors and returning early otherwise. -func (r ReplicationSet) Do(ctx context.Context, delay time.Duration, f func(context.Context, *IngesterDesc) (interface{}, error)) ([]interface{}, error) { +func (r ReplicationSet) Do(ctx context.Context, delay time.Duration, f func(context.Context, *InstanceDesc) (interface{}, error)) ([]interface{}, error) { type instanceResult struct { res interface{} err error - instance *IngesterDesc + instance *InstanceDesc } // Initialise the result tracker, which is use to keep track of successes and failures. @@ -46,7 +46,7 @@ func (r ReplicationSet) Do(ctx context.Context, delay time.Duration, f func(cont // Spawn a goroutine for each instance. for i := range r.Ingesters { - go func(i int, ing *IngesterDesc) { + go func(i int, ing *InstanceDesc) { // Wait to send extra requests. Works only when zone-awareness is disabled. if delay > 0 && r.MaxUnavailableZones == 0 && i >= len(r.Ingesters)-r.MaxErrors { after := time.NewTimer(delay) diff --git a/vendor/github.com/cortexproject/cortex/pkg/ring/replication_set_tracker.go b/vendor/github.com/cortexproject/cortex/pkg/ring/replication_set_tracker.go index 09f12e3cebbf..fcdf5441dd24 100644 --- a/vendor/github.com/cortexproject/cortex/pkg/ring/replication_set_tracker.go +++ b/vendor/github.com/cortexproject/cortex/pkg/ring/replication_set_tracker.go @@ -3,7 +3,7 @@ package ring type replicationSetResultTracker interface { // Signals an instance has done the execution, either successful (no error) // or failed (with error). - done(instance *IngesterDesc, err error) + done(instance *InstanceDesc, err error) // Returns true if the minimum number of successful results have been received. succeeded() bool @@ -19,7 +19,7 @@ type defaultResultTracker struct { maxErrors int } -func newDefaultResultTracker(instances []IngesterDesc, maxErrors int) *defaultResultTracker { +func newDefaultResultTracker(instances []InstanceDesc, maxErrors int) *defaultResultTracker { return &defaultResultTracker{ minSucceeded: len(instances) - maxErrors, numSucceeded: 0, @@ -28,7 +28,7 @@ func newDefaultResultTracker(instances []IngesterDesc, maxErrors int) *defaultRe } } -func (t *defaultResultTracker) done(_ *IngesterDesc, err error) { +func (t *defaultResultTracker) done(_ *InstanceDesc, err error) { if err == nil { t.numSucceeded++ } else { @@ -53,7 +53,7 @@ type zoneAwareResultTracker struct { maxUnavailableZones int } -func newZoneAwareResultTracker(instances []IngesterDesc, maxUnavailableZones int) *zoneAwareResultTracker { +func newZoneAwareResultTracker(instances []InstanceDesc, maxUnavailableZones int) *zoneAwareResultTracker { t := &zoneAwareResultTracker{ waitingByZone: make(map[string]int), failuresByZone: make(map[string]int), @@ -68,7 +68,7 @@ func newZoneAwareResultTracker(instances []IngesterDesc, maxUnavailableZones int return t } -func (t *zoneAwareResultTracker) done(instance *IngesterDesc, err error) { +func (t *zoneAwareResultTracker) done(instance *InstanceDesc, err error) { t.waitingByZone[instance.Zone]-- if err != nil { diff --git a/vendor/github.com/cortexproject/cortex/pkg/ring/replication_strategy.go b/vendor/github.com/cortexproject/cortex/pkg/ring/replication_strategy.go index f28a54e61827..e572cb77a441 100644 --- a/vendor/github.com/cortexproject/cortex/pkg/ring/replication_strategy.go +++ b/vendor/github.com/cortexproject/cortex/pkg/ring/replication_strategy.go @@ -11,7 +11,7 @@ type ReplicationStrategy interface { // Filter out unhealthy instances and checks if there're enough instances // for an operation to succeed. Returns an error if there are not enough // instances. - Filter(instances []IngesterDesc, op Operation, replicationFactor int, heartbeatTimeout time.Duration, zoneAwarenessEnabled bool) (healthy []IngesterDesc, maxFailures int, err error) + Filter(instances []InstanceDesc, op Operation, replicationFactor int, heartbeatTimeout time.Duration, zoneAwarenessEnabled bool) (healthy []InstanceDesc, maxFailures int, err error) } type defaultReplicationStrategy struct{} @@ -26,7 +26,7 @@ func NewDefaultReplicationStrategy() ReplicationStrategy { // - Filters out unhealthy instances so the one doesn't even try to write to them. // - Checks there are enough instances for an operation to succeed. // The instances argument may be overwritten. -func (s *defaultReplicationStrategy) Filter(instances []IngesterDesc, op Operation, replicationFactor int, heartbeatTimeout time.Duration, zoneAwarenessEnabled bool) ([]IngesterDesc, int, error) { +func (s *defaultReplicationStrategy) Filter(instances []InstanceDesc, op Operation, replicationFactor int, heartbeatTimeout time.Duration, zoneAwarenessEnabled bool) ([]InstanceDesc, int, error) { // We need a response from a quorum of instances, which is n/2 + 1. In the // case of a node joining/leaving, the actual replica set might be bigger // than the replication factor, so use the bigger or the two. @@ -71,7 +71,7 @@ func NewIgnoreUnhealthyInstancesReplicationStrategy() ReplicationStrategy { return &ignoreUnhealthyInstancesReplicationStrategy{} } -func (r *ignoreUnhealthyInstancesReplicationStrategy) Filter(instances []IngesterDesc, op Operation, _ int, heartbeatTimeout time.Duration, _ bool) (healthy []IngesterDesc, maxFailures int, err error) { +func (r *ignoreUnhealthyInstancesReplicationStrategy) Filter(instances []InstanceDesc, op Operation, _ int, heartbeatTimeout time.Duration, _ bool) (healthy []InstanceDesc, maxFailures int, err error) { now := time.Now() // Filter out unhealthy instances. for i := 0; i < len(instances); { @@ -90,7 +90,7 @@ func (r *ignoreUnhealthyInstancesReplicationStrategy) Filter(instances []Ingeste return instances, len(instances) - 1, nil } -func (r *Ring) IsHealthy(instance *IngesterDesc, op Operation, now time.Time) bool { +func (r *Ring) IsHealthy(instance *InstanceDesc, op Operation, now time.Time) bool { return instance.IsHealthy(op, r.cfg.HeartbeatTimeout, now) } diff --git a/vendor/github.com/cortexproject/cortex/pkg/ring/ring.go b/vendor/github.com/cortexproject/cortex/pkg/ring/ring.go index ad24dc31a02e..60e3b6e772ee 100644 --- a/vendor/github.com/cortexproject/cortex/pkg/ring/ring.go +++ b/vendor/github.com/cortexproject/cortex/pkg/ring/ring.go @@ -49,7 +49,7 @@ type ReadRing interface { // Get returns n (or more) instances which form the replicas for the given key. // bufDescs, bufHosts and bufZones are slices to be overwritten for the return value // to avoid memory allocation; can be nil, or created with ring.MakeBuffersForGet(). - Get(key uint32, op Operation, bufDescs []IngesterDesc, bufHosts, bufZones []string) (ReplicationSet, error) + Get(key uint32, op Operation, bufDescs []InstanceDesc, bufHosts, bufZones []string) (ReplicationSet, error) // GetAllHealthy returns all healthy instances in the ring, for the given operation. // This function doesn't check if the quorum is honored, so doesn't fail if the number @@ -304,7 +304,7 @@ func (r *Ring) loop(ctx context.Context) error { } // Get returns n (or more) instances which form the replicas for the given key. -func (r *Ring) Get(key uint32, op Operation, bufDescs []IngesterDesc, bufHosts, bufZones []string) (ReplicationSet, error) { +func (r *Ring) Get(key uint32, op Operation, bufDescs []InstanceDesc, bufHosts, bufZones []string) (ReplicationSet, error) { r.mtx.RLock() defer r.mtx.RUnlock() if r.ringDesc == nil || len(r.ringTokens) == 0 { @@ -380,7 +380,7 @@ func (r *Ring) GetAllHealthy(op Operation) (ReplicationSet, error) { } now := time.Now() - instances := make([]IngesterDesc, 0, len(r.ringDesc.Ingesters)) + instances := make([]InstanceDesc, 0, len(r.ringDesc.Ingesters)) for _, instance := range r.ringDesc.Ingesters { if r.IsHealthy(&instance, op, now) { instances = append(instances, instance) @@ -403,7 +403,7 @@ func (r *Ring) GetReplicationSetForOperation(op Operation) (ReplicationSet, erro } // Build the initial replication set, excluding unhealthy instances. - healthyInstances := make([]IngesterDesc, 0, len(r.ringDesc.Ingesters)) + healthyInstances := make([]InstanceDesc, 0, len(r.ringDesc.Ingesters)) zoneFailures := make(map[string]struct{}) now := time.Now() @@ -438,7 +438,7 @@ func (r *Ring) GetReplicationSetForOperation(op Operation) (ReplicationSet, erro // enabled (data is replicated to RF different zones), there's no benefit in // querying healthy instances from "failing zones". A zone is considered // failed if there is single error. - filteredInstances := make([]IngesterDesc, 0, len(r.ringDesc.Ingesters)) + filteredInstances := make([]InstanceDesc, 0, len(r.ringDesc.Ingesters)) for _, instance := range healthyInstances { if _, ok := zoneFailures[instance.Zone]; !ok { filteredInstances = append(filteredInstances, instance) @@ -648,7 +648,7 @@ func (r *Ring) shuffleShard(identifier string, size int, lookbackPeriod time.Dur actualZones = []string{""} } - shard := make(map[string]IngesterDesc, size) + shard := make(map[string]InstanceDesc, size) // We need to iterate zones always in the same order to guarantee stability. for _, zone := range actualZones { diff --git a/vendor/github.com/cortexproject/cortex/pkg/ring/ring.pb.go b/vendor/github.com/cortexproject/cortex/pkg/ring/ring.pb.go index 30e1646acf5c..7bfadacad7b8 100644 --- a/vendor/github.com/cortexproject/cortex/pkg/ring/ring.pb.go +++ b/vendor/github.com/cortexproject/cortex/pkg/ring/ring.pb.go @@ -60,7 +60,7 @@ func (IngesterState) EnumDescriptor() ([]byte, []int) { } type Desc struct { - Ingesters map[string]IngesterDesc `protobuf:"bytes,1,rep,name=ingesters,proto3" json:"ingesters" protobuf_key:"bytes,1,opt,name=key,proto3" protobuf_val:"bytes,2,opt,name=value,proto3"` + Ingesters map[string]InstanceDesc `protobuf:"bytes,1,rep,name=ingesters,proto3" json:"ingesters" protobuf_key:"bytes,1,opt,name=key,proto3" protobuf_val:"bytes,2,opt,name=value,proto3"` } func (m *Desc) Reset() { *m = Desc{} } @@ -95,14 +95,14 @@ func (m *Desc) XXX_DiscardUnknown() { var xxx_messageInfo_Desc proto.InternalMessageInfo -func (m *Desc) GetIngesters() map[string]IngesterDesc { +func (m *Desc) GetIngesters() map[string]InstanceDesc { if m != nil { return m.Ingesters } return nil } -type IngesterDesc struct { +type InstanceDesc struct { Addr string `protobuf:"bytes,1,opt,name=addr,proto3" json:"addr,omitempty"` // Unix timestamp (with seconds precision) of the last heartbeat sent // by this instance. @@ -126,17 +126,17 @@ type IngesterDesc struct { RegisteredTimestamp int64 `protobuf:"varint,8,opt,name=registered_timestamp,json=registeredTimestamp,proto3" json:"registered_timestamp,omitempty"` } -func (m *IngesterDesc) Reset() { *m = IngesterDesc{} } -func (*IngesterDesc) ProtoMessage() {} -func (*IngesterDesc) Descriptor() ([]byte, []int) { +func (m *InstanceDesc) Reset() { *m = InstanceDesc{} } +func (*InstanceDesc) ProtoMessage() {} +func (*InstanceDesc) Descriptor() ([]byte, []int) { return fileDescriptor_26381ed67e202a6e, []int{1} } -func (m *IngesterDesc) XXX_Unmarshal(b []byte) error { +func (m *InstanceDesc) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) } -func (m *IngesterDesc) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { +func (m *InstanceDesc) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { if deterministic { - return xxx_messageInfo_IngesterDesc.Marshal(b, m, deterministic) + return xxx_messageInfo_InstanceDesc.Marshal(b, m, deterministic) } else { b = b[:cap(b)] n, err := m.MarshalToSizedBuffer(b) @@ -146,54 +146,54 @@ func (m *IngesterDesc) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) return b[:n], nil } } -func (m *IngesterDesc) XXX_Merge(src proto.Message) { - xxx_messageInfo_IngesterDesc.Merge(m, src) +func (m *InstanceDesc) XXX_Merge(src proto.Message) { + xxx_messageInfo_InstanceDesc.Merge(m, src) } -func (m *IngesterDesc) XXX_Size() int { +func (m *InstanceDesc) XXX_Size() int { return m.Size() } -func (m *IngesterDesc) XXX_DiscardUnknown() { - xxx_messageInfo_IngesterDesc.DiscardUnknown(m) +func (m *InstanceDesc) XXX_DiscardUnknown() { + xxx_messageInfo_InstanceDesc.DiscardUnknown(m) } -var xxx_messageInfo_IngesterDesc proto.InternalMessageInfo +var xxx_messageInfo_InstanceDesc proto.InternalMessageInfo -func (m *IngesterDesc) GetAddr() string { +func (m *InstanceDesc) GetAddr() string { if m != nil { return m.Addr } return "" } -func (m *IngesterDesc) GetTimestamp() int64 { +func (m *InstanceDesc) GetTimestamp() int64 { if m != nil { return m.Timestamp } return 0 } -func (m *IngesterDesc) GetState() IngesterState { +func (m *InstanceDesc) GetState() IngesterState { if m != nil { return m.State } return ACTIVE } -func (m *IngesterDesc) GetTokens() []uint32 { +func (m *InstanceDesc) GetTokens() []uint32 { if m != nil { return m.Tokens } return nil } -func (m *IngesterDesc) GetZone() string { +func (m *InstanceDesc) GetZone() string { if m != nil { return m.Zone } return "" } -func (m *IngesterDesc) GetRegisteredTimestamp() int64 { +func (m *InstanceDesc) GetRegisteredTimestamp() int64 { if m != nil { return m.RegisteredTimestamp } @@ -203,41 +203,41 @@ func (m *IngesterDesc) GetRegisteredTimestamp() int64 { func init() { proto.RegisterEnum("ring.IngesterState", IngesterState_name, IngesterState_value) proto.RegisterType((*Desc)(nil), "ring.Desc") - proto.RegisterMapType((map[string]IngesterDesc)(nil), "ring.Desc.IngestersEntry") - proto.RegisterType((*IngesterDesc)(nil), "ring.IngesterDesc") + proto.RegisterMapType((map[string]InstanceDesc)(nil), "ring.Desc.IngestersEntry") + proto.RegisterType((*InstanceDesc)(nil), "ring.InstanceDesc") } func init() { proto.RegisterFile("ring.proto", fileDescriptor_26381ed67e202a6e) } var fileDescriptor_26381ed67e202a6e = []byte{ - // 421 bytes of a gzipped FileDescriptorProto + // 427 bytes of a gzipped FileDescriptorProto 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x54, 0x92, 0x31, 0x6f, 0xd3, 0x40, 0x1c, 0xc5, 0xef, 0x1f, 0x5f, 0x5c, 0xe7, 0x1f, 0x5a, 0x59, 0x57, 0x84, 0x4c, 0x85, 0x0e, 0xab, 0x93, 0x41, 0xc2, 0x15, 0x81, 0x01, 0x21, 0x31, 0xb4, 0xd4, 0x20, 0x5b, 0x51, 0xa8, 0x4c, 0xd4, - 0x15, 0x39, 0xcd, 0x61, 0xac, 0x12, 0xbb, 0xb2, 0x2f, 0x48, 0x65, 0xe2, 0x23, 0xf0, 0x05, 0xd8, - 0xf9, 0x28, 0x1d, 0x33, 0xa1, 0x4e, 0x88, 0x38, 0x0b, 0x63, 0x3f, 0x02, 0xba, 0x73, 0x23, 0x93, - 0xed, 0xfd, 0xfc, 0xde, 0xff, 0x3d, 0x0f, 0x87, 0x58, 0x66, 0x79, 0xea, 0x5f, 0x94, 0x85, 0x2c, - 0x18, 0x55, 0x7a, 0xef, 0x49, 0x9a, 0xc9, 0x4f, 0xf3, 0x89, 0x7f, 0x56, 0xcc, 0x0e, 0xd2, 0x22, - 0x2d, 0x0e, 0xb4, 0x39, 0x99, 0x7f, 0xd4, 0xa4, 0x41, 0xab, 0xe6, 0x68, 0xff, 0x07, 0x20, 0x3d, - 0x16, 0xd5, 0x19, 0x7b, 0x85, 0xbd, 0x2c, 0x4f, 0x45, 0x25, 0x45, 0x59, 0x39, 0xe0, 0x1a, 0x5e, - 0x7f, 0x70, 0xdf, 0xd7, 0xed, 0xca, 0xf6, 0xc3, 0xb5, 0x17, 0xe4, 0xb2, 0xbc, 0x3c, 0xa2, 0x57, - 0xbf, 0x1f, 0x92, 0xb8, 0xbd, 0xd8, 0x3b, 0xc1, 0x9d, 0xcd, 0x08, 0xb3, 0xd1, 0x38, 0x17, 0x97, - 0x0e, 0xb8, 0xe0, 0xf5, 0x62, 0x25, 0x99, 0x87, 0xdd, 0x2f, 0xc9, 0xe7, 0xb9, 0x70, 0x3a, 0x2e, - 0x78, 0xfd, 0x01, 0x6b, 0xea, 0xd7, 0x67, 0x6a, 0x26, 0x6e, 0x02, 0x2f, 0x3b, 0x2f, 0x20, 0xa2, - 0x56, 0xc7, 0x36, 0xf6, 0x7f, 0x01, 0xde, 0xf9, 0x3f, 0xc1, 0x18, 0xd2, 0x64, 0x3a, 0x2d, 0x6f, - 0x7b, 0xb5, 0x66, 0x0f, 0xb0, 0x27, 0xb3, 0x99, 0xa8, 0x64, 0x32, 0xbb, 0xd0, 0xe5, 0x46, 0xdc, - 0x7e, 0x60, 0x8f, 0xb0, 0x5b, 0xc9, 0x44, 0x0a, 0xc7, 0x70, 0xc1, 0xdb, 0x19, 0xec, 0x6e, 0xce, - 0xbe, 0x57, 0x56, 0xdc, 0x24, 0xd8, 0x3d, 0x34, 0x65, 0x71, 0x2e, 0xf2, 0xca, 0x31, 0x5d, 0xc3, - 0xdb, 0x8e, 0x6f, 0x49, 0x8d, 0x7e, 0x2d, 0x72, 0xe1, 0x6c, 0x35, 0xa3, 0x4a, 0xb3, 0xa7, 0x78, - 0xb7, 0x14, 0x69, 0xa6, 0x3a, 0xc4, 0xf4, 0x43, 0xbb, 0x6f, 0xe9, 0xfd, 0xdd, 0xd6, 0x1b, 0xaf, - 0xad, 0x88, 0x5a, 0xd4, 0xee, 0x46, 0xd4, 0xea, 0xda, 0xe6, 0xe3, 0x21, 0x6e, 0x6f, 0xfc, 0x02, - 0x43, 0x34, 0x0f, 0x5f, 0x8f, 0xc3, 0xd3, 0xc0, 0x26, 0xac, 0x8f, 0x5b, 0xc3, 0xe0, 0xf0, 0x34, - 0x1c, 0xbd, 0xb5, 0x41, 0xc1, 0x49, 0x30, 0x3a, 0x56, 0xd0, 0x51, 0x10, 0xbd, 0x0b, 0x47, 0x0a, - 0x0c, 0x66, 0x21, 0x1d, 0x06, 0x6f, 0xc6, 0x36, 0x3d, 0x7a, 0xbe, 0x58, 0x72, 0x72, 0xbd, 0xe4, - 0xe4, 0x66, 0xc9, 0xe1, 0x5b, 0xcd, 0xe1, 0x67, 0xcd, 0xe1, 0xaa, 0xe6, 0xb0, 0xa8, 0x39, 0xfc, - 0xa9, 0x39, 0xfc, 0xad, 0x39, 0xb9, 0xa9, 0x39, 0x7c, 0x5f, 0x71, 0xb2, 0x58, 0x71, 0x72, 0xbd, - 0xe2, 0x64, 0x62, 0xea, 0x37, 0xf0, 0xec, 0x5f, 0x00, 0x00, 0x00, 0xff, 0xff, 0x56, 0xd8, 0x87, - 0x71, 0x46, 0x02, 0x00, 0x00, + 0x15, 0x39, 0xc9, 0x61, 0xac, 0x12, 0xbb, 0xb2, 0x2f, 0x48, 0x65, 0xe2, 0x23, 0xf0, 0x05, 0xd8, + 0xf9, 0x28, 0x1d, 0x33, 0xa1, 0x4e, 0x88, 0x38, 0x0b, 0x63, 0x3f, 0x02, 0xba, 0x73, 0x23, 0xd3, + 0xed, 0xfd, 0xfc, 0xde, 0xbd, 0xf7, 0x1f, 0x8c, 0x58, 0x66, 0x79, 0xea, 0x9f, 0x97, 0x85, 0x2c, + 0x18, 0x55, 0x7a, 0xef, 0x49, 0x9a, 0xc9, 0x4f, 0x8b, 0x89, 0x3f, 0x2d, 0xe6, 0x07, 0x69, 0x91, + 0x16, 0x07, 0xda, 0x9c, 0x2c, 0x3e, 0x6a, 0xd2, 0xa0, 0x55, 0xf3, 0x68, 0xff, 0x07, 0x20, 0x3d, + 0x16, 0xd5, 0x94, 0xbd, 0xc2, 0x5e, 0x96, 0xa7, 0xa2, 0x92, 0xa2, 0xac, 0x1c, 0x70, 0x0d, 0xaf, + 0x3f, 0xb8, 0xef, 0xeb, 0x76, 0x65, 0xfb, 0xe1, 0xc6, 0x0b, 0x72, 0x59, 0x5e, 0x1c, 0xd1, 0xcb, + 0xdf, 0x0f, 0x49, 0xdc, 0xbe, 0xd8, 0x3b, 0xc1, 0x9d, 0xdb, 0x11, 0x66, 0xa3, 0x71, 0x26, 0x2e, + 0x1c, 0x70, 0xc1, 0xeb, 0xc5, 0x4a, 0x32, 0x0f, 0xbb, 0x5f, 0x92, 0xcf, 0x0b, 0xe1, 0x74, 0x5c, + 0xf0, 0xfa, 0x03, 0xd6, 0xd4, 0x87, 0x79, 0x25, 0x93, 0x7c, 0x2a, 0xd4, 0x4c, 0xdc, 0x04, 0x5e, + 0x76, 0x5e, 0x40, 0x44, 0xad, 0x8e, 0x6d, 0xec, 0xff, 0x02, 0xbc, 0xf3, 0x7f, 0x82, 0x31, 0xa4, + 0xc9, 0x6c, 0x56, 0xde, 0xf4, 0x6a, 0xcd, 0x1e, 0x60, 0x4f, 0x66, 0x73, 0x51, 0xc9, 0x64, 0x7e, + 0xae, 0xcb, 0x8d, 0xb8, 0xfd, 0xc0, 0x1e, 0x61, 0xb7, 0x92, 0x89, 0x14, 0x8e, 0xe1, 0x82, 0xb7, + 0x33, 0xd8, 0xdd, 0xcc, 0x36, 0xd7, 0xbe, 0x57, 0x56, 0xdc, 0x24, 0xd8, 0x3d, 0x34, 0x65, 0x71, + 0x26, 0xf2, 0xca, 0x31, 0x5d, 0xc3, 0xdb, 0x8e, 0x6f, 0x48, 0x8d, 0x7e, 0x2d, 0x72, 0xe1, 0x6c, + 0x35, 0xa3, 0x4a, 0xb3, 0xa7, 0x78, 0xb7, 0x14, 0x69, 0xa6, 0x3a, 0xc4, 0xec, 0x43, 0xbb, 0x6f, + 0xe9, 0xfd, 0xdd, 0xd6, 0x1b, 0x6f, 0xac, 0x88, 0x5a, 0xd4, 0xee, 0x46, 0xd4, 0xea, 0xda, 0xe6, + 0xe3, 0x21, 0x6e, 0xdf, 0x3a, 0x81, 0x21, 0x9a, 0x87, 0xaf, 0xc7, 0xe1, 0x69, 0x60, 0x13, 0xd6, + 0xc7, 0xad, 0x61, 0x70, 0x78, 0x1a, 0x8e, 0xde, 0xda, 0xa0, 0xe0, 0x24, 0x18, 0x1d, 0x2b, 0xe8, + 0x28, 0x88, 0xde, 0x85, 0x23, 0x05, 0x06, 0xb3, 0x90, 0x0e, 0x83, 0x37, 0x63, 0x9b, 0x1e, 0x3d, + 0x5f, 0xae, 0x38, 0xb9, 0x5a, 0x71, 0x72, 0xbd, 0xe2, 0xf0, 0xad, 0xe6, 0xf0, 0xb3, 0xe6, 0x70, + 0x59, 0x73, 0x58, 0xd6, 0x1c, 0xfe, 0xd4, 0x1c, 0xfe, 0xd6, 0x9c, 0x5c, 0xd7, 0x1c, 0xbe, 0xaf, + 0x39, 0x59, 0xae, 0x39, 0xb9, 0x5a, 0x73, 0x32, 0x31, 0xf5, 0x3f, 0xf0, 0xec, 0x5f, 0x00, 0x00, + 0x00, 0xff, 0xff, 0x79, 0x5b, 0xe1, 0x8b, 0x46, 0x02, 0x00, 0x00, } func (x IngesterState) String() string { @@ -278,14 +278,14 @@ func (this *Desc) Equal(that interface{}) bool { } return true } -func (this *IngesterDesc) Equal(that interface{}) bool { +func (this *InstanceDesc) Equal(that interface{}) bool { if that == nil { return this == nil } - that1, ok := that.(*IngesterDesc) + that1, ok := that.(*InstanceDesc) if !ok { - that2, ok := that.(IngesterDesc) + that2, ok := that.(InstanceDesc) if ok { that1 = &that2 } else { @@ -333,7 +333,7 @@ func (this *Desc) GoString() string { keysForIngesters = append(keysForIngesters, k) } github_com_gogo_protobuf_sortkeys.Strings(keysForIngesters) - mapStringForIngesters := "map[string]IngesterDesc{" + mapStringForIngesters := "map[string]InstanceDesc{" for _, k := range keysForIngesters { mapStringForIngesters += fmt.Sprintf("%#v: %#v,", k, this.Ingesters[k]) } @@ -344,12 +344,12 @@ func (this *Desc) GoString() string { s = append(s, "}") return strings.Join(s, "") } -func (this *IngesterDesc) GoString() string { +func (this *InstanceDesc) GoString() string { if this == nil { return "nil" } s := make([]string, 0, 10) - s = append(s, "&ring.IngesterDesc{") + s = append(s, "&ring.InstanceDesc{") s = append(s, "Addr: "+fmt.Sprintf("%#v", this.Addr)+",\n") s = append(s, "Timestamp: "+fmt.Sprintf("%#v", this.Timestamp)+",\n") s = append(s, "State: "+fmt.Sprintf("%#v", this.State)+",\n") @@ -414,7 +414,7 @@ func (m *Desc) MarshalToSizedBuffer(dAtA []byte) (int, error) { return len(dAtA) - i, nil } -func (m *IngesterDesc) Marshal() (dAtA []byte, err error) { +func (m *InstanceDesc) Marshal() (dAtA []byte, err error) { size := m.Size() dAtA = make([]byte, size) n, err := m.MarshalToSizedBuffer(dAtA[:size]) @@ -424,12 +424,12 @@ func (m *IngesterDesc) Marshal() (dAtA []byte, err error) { return dAtA[:n], nil } -func (m *IngesterDesc) MarshalTo(dAtA []byte) (int, error) { +func (m *InstanceDesc) MarshalTo(dAtA []byte) (int, error) { size := m.Size() return m.MarshalToSizedBuffer(dAtA[:size]) } -func (m *IngesterDesc) MarshalToSizedBuffer(dAtA []byte) (int, error) { +func (m *InstanceDesc) MarshalToSizedBuffer(dAtA []byte) (int, error) { i := len(dAtA) _ = i var l int @@ -513,7 +513,7 @@ func (m *Desc) Size() (n int) { return n } -func (m *IngesterDesc) Size() (n int) { +func (m *InstanceDesc) Size() (n int) { if m == nil { return 0 } @@ -561,7 +561,7 @@ func (this *Desc) String() string { keysForIngesters = append(keysForIngesters, k) } github_com_gogo_protobuf_sortkeys.Strings(keysForIngesters) - mapStringForIngesters := "map[string]IngesterDesc{" + mapStringForIngesters := "map[string]InstanceDesc{" for _, k := range keysForIngesters { mapStringForIngesters += fmt.Sprintf("%v: %v,", k, this.Ingesters[k]) } @@ -572,11 +572,11 @@ func (this *Desc) String() string { }, "") return s } -func (this *IngesterDesc) String() string { +func (this *InstanceDesc) String() string { if this == nil { return "nil" } - s := strings.Join([]string{`&IngesterDesc{`, + s := strings.Join([]string{`&InstanceDesc{`, `Addr:` + fmt.Sprintf("%v", this.Addr) + `,`, `Timestamp:` + fmt.Sprintf("%v", this.Timestamp) + `,`, `State:` + fmt.Sprintf("%v", this.State) + `,`, @@ -654,10 +654,10 @@ func (m *Desc) Unmarshal(dAtA []byte) error { return io.ErrUnexpectedEOF } if m.Ingesters == nil { - m.Ingesters = make(map[string]IngesterDesc) + m.Ingesters = make(map[string]InstanceDesc) } var mapkey string - mapvalue := &IngesterDesc{} + mapvalue := &InstanceDesc{} for iNdEx < postIndex { entryPreIndex := iNdEx var wire uint64 @@ -731,7 +731,7 @@ func (m *Desc) Unmarshal(dAtA []byte) error { if postmsgIndex > l { return io.ErrUnexpectedEOF } - mapvalue = &IngesterDesc{} + mapvalue = &InstanceDesc{} if err := mapvalue.Unmarshal(dAtA[iNdEx:postmsgIndex]); err != nil { return err } @@ -777,7 +777,7 @@ func (m *Desc) Unmarshal(dAtA []byte) error { } return nil } -func (m *IngesterDesc) Unmarshal(dAtA []byte) error { +func (m *InstanceDesc) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 for iNdEx < l { @@ -800,10 +800,10 @@ func (m *IngesterDesc) Unmarshal(dAtA []byte) error { fieldNum := int32(wire >> 3) wireType := int(wire & 0x7) if wireType == 4 { - return fmt.Errorf("proto: IngesterDesc: wiretype end group for non-group") + return fmt.Errorf("proto: InstanceDesc: wiretype end group for non-group") } if fieldNum <= 0 { - return fmt.Errorf("proto: IngesterDesc: illegal tag %d (wire type %d)", fieldNum, wire) + return fmt.Errorf("proto: InstanceDesc: illegal tag %d (wire type %d)", fieldNum, wire) } switch fieldNum { case 1: diff --git a/vendor/github.com/cortexproject/cortex/pkg/ring/ring.proto b/vendor/github.com/cortexproject/cortex/pkg/ring/ring.proto index 2adc91a806c3..4eab6f733ccf 100644 --- a/vendor/github.com/cortexproject/cortex/pkg/ring/ring.proto +++ b/vendor/github.com/cortexproject/cortex/pkg/ring/ring.proto @@ -8,11 +8,11 @@ option (gogoproto.marshaler_all) = true; option (gogoproto.unmarshaler_all) = true; message Desc { - map ingesters = 1 [(gogoproto.nullable) = false]; + map ingesters = 1 [(gogoproto.nullable) = false]; reserved 2; } -message IngesterDesc { +message InstanceDesc { reserved 4, 5; // old, deprecated fields string addr = 1; diff --git a/vendor/github.com/cortexproject/cortex/pkg/ring/util.go b/vendor/github.com/cortexproject/cortex/pkg/ring/util.go index 921900c2dc1a..b1cf8210c75c 100644 --- a/vendor/github.com/cortexproject/cortex/pkg/ring/util.go +++ b/vendor/github.com/cortexproject/cortex/pkg/ring/util.go @@ -122,8 +122,8 @@ func WaitRingStability(ctx context.Context, r *Ring, op Operation, minStability, } // MakeBuffersForGet returns buffers to use with Ring.Get(). -func MakeBuffersForGet() (bufDescs []IngesterDesc, bufHosts, bufZones []string) { - bufDescs = make([]IngesterDesc, 0, GetBufferSize) +func MakeBuffersForGet() (bufDescs []InstanceDesc, bufHosts, bufZones []string) { + bufDescs = make([]InstanceDesc, 0, GetBufferSize) bufHosts = make([]string, 0, GetBufferSize) bufZones = make([]string, 0, GetBufferSize) return diff --git a/vendor/github.com/cortexproject/cortex/pkg/util/http.go b/vendor/github.com/cortexproject/cortex/pkg/util/http.go index f02da30b8d1d..f06363e537f0 100644 --- a/vendor/github.com/cortexproject/cortex/pkg/util/http.go +++ b/vendor/github.com/cortexproject/cortex/pkg/util/http.go @@ -4,6 +4,7 @@ import ( "bytes" "context" "encoding/json" + "flag" "fmt" "html/template" "io" @@ -19,6 +20,22 @@ import ( const messageSizeLargerErrFmt = "received message larger than max (%d vs %d)" +// BasicAuth configures basic authentication for HTTP clients. +type BasicAuth struct { + Username string `yaml:"basic_auth_username"` + Password string `yaml:"basic_auth_password"` +} + +func (b *BasicAuth) RegisterFlagsWithPrefix(prefix string, f *flag.FlagSet) { + f.StringVar(&b.Username, prefix+"basic-auth-username", "", "HTTP Basic authentication username. It overrides the username set in the URL (if any).") + f.StringVar(&b.Password, prefix+"basic-auth-password", "", "HTTP Basic authentication password. It overrides the password set in the URL (if any).") +} + +// IsEnabled returns false if basic authentication isn't enabled. +func (b BasicAuth) IsEnabled() bool { + return b.Username != "" || b.Password != "" +} + // WriteJSONResponse writes some JSON as a HTTP response. func WriteJSONResponse(w http.ResponseWriter, v interface{}) { w.Header().Set("Content-Type", "application/json") diff --git a/vendor/github.com/cortexproject/cortex/pkg/util/log.go b/vendor/github.com/cortexproject/cortex/pkg/util/log.go deleted file mode 100644 index df0d464d4570..000000000000 --- a/vendor/github.com/cortexproject/cortex/pkg/util/log.go +++ /dev/null @@ -1,96 +0,0 @@ -package util - -import ( - "os" - - "github.com/go-kit/kit/log" - "github.com/go-kit/kit/log/level" - "github.com/prometheus/client_golang/prometheus" - "github.com/weaveworks/common/logging" - "github.com/weaveworks/common/server" - - logutil "github.com/cortexproject/cortex/pkg/util/log" -) - -var ( - // Logger is a shared go-kit logger. - // TODO: Change all components to take a non-global logger via their constructors. - // Deprecated and moved to `pkg/util/log`. Prefer accepting a non-global logger as an argument. - Logger = logutil.Logger - - logMessages = prometheus.NewCounterVec(prometheus.CounterOpts{ - Name: "log_messages_total", - Help: "Total number of log messages.", - }, []string{"level"}) - - supportedLevels = []level.Value{ - level.DebugValue(), - level.InfoValue(), - level.WarnValue(), - level.ErrorValue(), - } -) - -func init() { - prometheus.MustRegister(logMessages) -} - -// InitLogger initialises the global gokit logger (util.Logger) and overrides the -// default logger for the server. -func InitLogger(cfg *server.Config) { - l, err := NewPrometheusLogger(cfg.LogLevel, cfg.LogFormat) - if err != nil { - panic(err) - } - - // when use util.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 -} - -// NewPrometheusLogger creates a new instance of PrometheusLogger which exposes -// Prometheus counters for various log levels. -func NewPrometheusLogger(l logging.Level, format logging.Format) (log.Logger, error) { - logger := log.NewLogfmtLogger(log.NewSyncWriter(os.Stderr)) - if format.String() == "json" { - logger = log.NewJSONLogger(log.NewSyncWriter(os.Stderr)) - } - logger = level.NewFilter(logger, l.Gokit) - - // Initialise counters for all supported levels: - for _, level := range supportedLevels { - logMessages.WithLabelValues(level.String()) - } - - logger = &PrometheusLogger{ - logger: logger, - } - - // return a Logger without caller information, shouldn't use directly - logger = log.With(logger, "ts", log.DefaultTimestampUTC) - return logger, nil -} - -// 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 - } - } - logMessages.WithLabelValues(l).Inc() - return nil -} diff --git a/vendor/github.com/cortexproject/cortex/pkg/util/log/log.go b/vendor/github.com/cortexproject/cortex/pkg/util/log/log.go index 2f146db276c8..92ea3f697d18 100644 --- a/vendor/github.com/cortexproject/cortex/pkg/util/log/log.go +++ b/vendor/github.com/cortexproject/cortex/pkg/util/log/log.go @@ -7,6 +7,9 @@ import ( "github.com/go-kit/kit/log" kitlog "github.com/go-kit/kit/log" "github.com/go-kit/kit/log/level" + "github.com/prometheus/client_golang/prometheus" + "github.com/weaveworks/common/logging" + "github.com/weaveworks/common/server" ) var ( @@ -14,8 +17,84 @@ var ( // TODO: Change all components to take a non-global logger via their constructors. // Prefer accepting a non-global logger as an argument. Logger = kitlog.NewNopLogger() + + logMessages = prometheus.NewCounterVec(prometheus.CounterOpts{ + Name: "log_messages_total", + Help: "Total number of log messages.", + }, []string{"level"}) + + supportedLevels = []level.Value{ + level.DebugValue(), + level.InfoValue(), + level.WarnValue(), + level.ErrorValue(), + } ) +func init() { + prometheus.MustRegister(logMessages) +} + +// InitLogger initialises the global gokit logger (util_log.Logger) and overrides the +// default logger for the server. +func InitLogger(cfg *server.Config) { + l, err := NewPrometheusLogger(cfg.LogLevel, cfg.LogFormat) + if err != nil { + panic(err) + } + + // 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 +} + +// NewPrometheusLogger creates a new instance of PrometheusLogger which exposes +// Prometheus counters for various log levels. +func NewPrometheusLogger(l logging.Level, format logging.Format) (log.Logger, error) { + logger := log.NewLogfmtLogger(log.NewSyncWriter(os.Stderr)) + if format.String() == "json" { + logger = log.NewJSONLogger(log.NewSyncWriter(os.Stderr)) + } + logger = level.NewFilter(logger, l.Gokit) + + // Initialise counters for all supported levels: + for _, level := range supportedLevels { + logMessages.WithLabelValues(level.String()) + } + + logger = &PrometheusLogger{ + logger: logger, + } + + // return a Logger without caller information, shouldn't use directly + logger = log.With(logger, "ts", log.DefaultTimestampUTC) + return logger, nil +} + +// 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 + } + } + 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) { if err != nil { diff --git a/vendor/github.com/cortexproject/cortex/pkg/util/metrics_helper.go b/vendor/github.com/cortexproject/cortex/pkg/util/metrics_helper.go index e90b21dd18e7..be413ee236dd 100644 --- a/vendor/github.com/cortexproject/cortex/pkg/util/metrics_helper.go +++ b/vendor/github.com/cortexproject/cortex/pkg/util/metrics_helper.go @@ -11,6 +11,8 @@ import ( "github.com/prometheus/client_golang/prometheus" dto "github.com/prometheus/client_model/go" "github.com/prometheus/prometheus/pkg/labels" + + util_log "github.com/cortexproject/cortex/pkg/util/log" ) // Data for single value (counter/gauge) with labels. @@ -583,7 +585,7 @@ func (r *UserRegistries) RemoveUserRegistry(user string, hard bool) { func (r *UserRegistries) softRemoveUserRegistry(ur *UserRegistry) bool { last, err := ur.reg.Gather() if err != nil { - level.Warn(Logger).Log("msg", "failed to gather metrics from registry", "user", ur.user, "err", err) + level.Warn(util_log.Logger).Log("msg", "failed to gather metrics from registry", "user", ur.user, "err", err) return false } @@ -605,7 +607,7 @@ func (r *UserRegistries) softRemoveUserRegistry(ur *UserRegistry) bool { ur.lastGather, err = NewMetricFamilyMap(last) if err != nil { - level.Warn(Logger).Log("msg", "failed to gather metrics from registry", "user", ur.user, "err", err) + level.Warn(util_log.Logger).Log("msg", "failed to gather metrics from registry", "user", ur.user, "err", err) return false } @@ -656,7 +658,7 @@ func (r *UserRegistries) BuildMetricFamiliesPerUser() MetricFamiliesPerUser { } if err != nil { - level.Warn(Logger).Log("msg", "failed to gather metrics from registry", "user", entry.user, "err", err) + level.Warn(util_log.Logger).Log("msg", "failed to gather metrics from registry", "user", entry.user, "err", err) continue } } diff --git a/vendor/github.com/cortexproject/cortex/pkg/util/module_service.go b/vendor/github.com/cortexproject/cortex/pkg/util/module_service.go index be12157ac266..0d4fb43d1f2b 100644 --- a/vendor/github.com/cortexproject/cortex/pkg/util/module_service.go +++ b/vendor/github.com/cortexproject/cortex/pkg/util/module_service.go @@ -7,6 +7,7 @@ import ( "github.com/go-kit/kit/log/level" "github.com/pkg/errors" + util_log "github.com/cortexproject/cortex/pkg/util/log" "github.com/cortexproject/cortex/pkg/util/services" ) @@ -45,7 +46,7 @@ func (w *moduleService) start(serviceContext context.Context) error { continue } - level.Debug(Logger).Log("msg", "module waiting for initialization", "module", w.name, "waiting_for", m) + level.Debug(util_log.Logger).Log("msg", "module waiting for initialization", "module", w.name, "waiting_for", m) err := s.AwaitRunning(serviceContext) if err != nil { @@ -55,7 +56,7 @@ func (w *moduleService) start(serviceContext context.Context) error { // we don't want to let this service to stop until all dependant services are stopped, // so we use independent context here - level.Info(Logger).Log("msg", "initialising", "module", w.name) + level.Info(util_log.Logger).Log("msg", "initialising", "module", w.name) err := w.service.StartAsync(context.Background()) if err != nil { return errors.Wrapf(err, "error starting module: %s", w.name) @@ -77,7 +78,7 @@ func (w *moduleService) stop(_ error) error { // Only wait for other modules, if underlying service is still running. w.waitForModulesToStop() - level.Debug(Logger).Log("msg", "stopping", "module", w.name) + level.Debug(util_log.Logger).Log("msg", "stopping", "module", w.name) err = services.StopAndAwaitTerminated(context.Background(), w.service) } else { @@ -85,9 +86,9 @@ func (w *moduleService) stop(_ error) error { } if err != nil && err != ErrStopProcess { - level.Warn(Logger).Log("msg", "module failed with error", "module", w.name, "err", err) + level.Warn(util_log.Logger).Log("msg", "module failed with error", "module", w.name, "err", err) } else { - level.Info(Logger).Log("msg", "module stopped", "module", w.name) + level.Info(util_log.Logger).Log("msg", "module stopped", "module", w.name) } return err } @@ -100,7 +101,7 @@ func (w *moduleService) waitForModulesToStop() { continue } - level.Debug(Logger).Log("msg", "module waiting for", "module", w.name, "waiting_for", n) + level.Debug(util_log.Logger).Log("msg", "module waiting for", "module", w.name, "waiting_for", n) // Passed context isn't canceled, so we can only get error here, if service // fails. But we don't care *how* service stops, as long as it is done. _ = s.AwaitTerminated(context.Background()) diff --git a/vendor/github.com/cortexproject/cortex/pkg/util/net.go b/vendor/github.com/cortexproject/cortex/pkg/util/net.go index e0fa12e6ffaa..f4cd184870fc 100644 --- a/vendor/github.com/cortexproject/cortex/pkg/util/net.go +++ b/vendor/github.com/cortexproject/cortex/pkg/util/net.go @@ -5,6 +5,8 @@ import ( "net" "github.com/go-kit/kit/log/level" + + util_log "github.com/cortexproject/cortex/pkg/util/log" ) // GetFirstAddressOf returns the first IPv4 address of the supplied interface names. @@ -12,17 +14,17 @@ func GetFirstAddressOf(names []string) (string, error) { for _, name := range names { inf, err := net.InterfaceByName(name) if err != nil { - level.Warn(Logger).Log("msg", "error getting interface", "inf", name, "err", err) + level.Warn(util_log.Logger).Log("msg", "error getting interface", "inf", name, "err", err) continue } addrs, err := inf.Addrs() if err != nil { - level.Warn(Logger).Log("msg", "error getting addresses for interface", "inf", name, "err", err) + level.Warn(util_log.Logger).Log("msg", "error getting addresses for interface", "inf", name, "err", err) continue } if len(addrs) <= 0 { - level.Warn(Logger).Log("msg", "no addresses found for interface", "inf", name, "err", err) + level.Warn(util_log.Logger).Log("msg", "no addresses found for interface", "inf", name, "err", err) continue } diff --git a/vendor/github.com/golang/snappy/decode_arm64.s b/vendor/github.com/golang/snappy/decode_arm64.s index bfafa0ccfce8..7a3ead17eacf 100644 --- a/vendor/github.com/golang/snappy/decode_arm64.s +++ b/vendor/github.com/golang/snappy/decode_arm64.s @@ -70,7 +70,7 @@ loop: // x := uint32(src[s] >> 2) // switch MOVW $60, R1 - ADD R4>>2, ZR, R4 + LSRW $2, R4, R4 CMPW R4, R1 BLS tagLit60Plus @@ -111,13 +111,12 @@ doLit: // is contiguous in memory and so it needs to leave enough source bytes to // read the next tag without refilling buffers, but Go's Decode assumes // contiguousness (the src argument is a []byte). - MOVD $16, R1 - CMP R1, R4 - BGT callMemmove - CMP R1, R2 - BLT callMemmove - CMP R1, R3 - BLT callMemmove + CMP $16, R4 + BGT callMemmove + CMP $16, R2 + BLT callMemmove + CMP $16, R3 + BLT callMemmove // !!! Implement the copy from src to dst as a 16-byte load and store. // (Decode's documentation says that dst and src must not overlap.) @@ -130,9 +129,8 @@ doLit: // Note that on arm64, it is legal and cheap to issue unaligned 8-byte or // 16-byte loads and stores. This technique probably wouldn't be as // effective on architectures that are fussier about alignment. - - VLD1 0(R6), [V0.B16] - VST1 [V0.B16], 0(R7) + LDP 0(R6), (R14, R15) + STP (R14, R15), 0(R7) // d += length // s += length @@ -210,8 +208,7 @@ tagLit61: B doLit tagLit62Plus: - MOVW $62, R1 - CMPW R1, R4 + CMPW $62, R4 BHI tagLit63 // case x == 62: @@ -273,10 +270,9 @@ tagCopy: // We have a copy tag. We assume that: // - R3 == src[s] & 0x03 // - R4 == src[s] - MOVD $2, R1 - CMP R1, R3 - BEQ tagCopy2 - BGT tagCopy4 + CMP $2, R3 + BEQ tagCopy2 + BGT tagCopy4 // case tagCopy1: // s += 2 @@ -346,13 +342,11 @@ doCopy: // } // copy 16 bytes // d += length - MOVD $16, R1 - MOVD $8, R0 - CMP R1, R4 + CMP $16, R4 BGT slowForwardCopy - CMP R0, R5 + CMP $8, R5 BLT slowForwardCopy - CMP R1, R14 + CMP $16, R14 BLT slowForwardCopy MOVD 0(R15), R2 MOVD R2, 0(R7) @@ -426,8 +420,7 @@ makeOffsetAtLeast8: // // The two previous lines together means that d-offset, and therefore // // R15, is unchanged. // } - MOVD $8, R1 - CMP R1, R5 + CMP $8, R5 BGE fixUpSlowForwardCopy MOVD (R15), R3 MOVD R3, (R7) @@ -477,9 +470,7 @@ verySlowForwardCopy: ADD $1, R15, R15 ADD $1, R7, R7 SUB $1, R4, R4 - MOVD $0, R1 - CMP R1, R4 - BNE verySlowForwardCopy + CBNZ R4, verySlowForwardCopy B loop // The code above handles copy tags. diff --git a/vendor/github.com/golang/snappy/encode_arm64.s b/vendor/github.com/golang/snappy/encode_arm64.s index 1f565ee75f2c..bf83667d711f 100644 --- a/vendor/github.com/golang/snappy/encode_arm64.s +++ b/vendor/github.com/golang/snappy/encode_arm64.s @@ -35,11 +35,9 @@ TEXT ·emitLiteral(SB), NOSPLIT, $32-56 MOVW R3, R4 SUBW $1, R4, R4 - MOVW $60, R2 - CMPW R2, R4 + CMPW $60, R4 BLT oneByte - MOVW $256, R2 - CMPW R2, R4 + CMPW $256, R4 BLT twoBytes threeBytes: @@ -98,8 +96,7 @@ TEXT ·emitCopy(SB), NOSPLIT, $0-48 loop0: // for length >= 68 { etc } - MOVW $68, R2 - CMPW R2, R3 + CMPW $68, R3 BLT step1 // Emit a length 64 copy, encoded as 3 bytes. @@ -112,9 +109,8 @@ loop0: step1: // if length > 64 { etc } - MOVD $64, R2 - CMP R2, R3 - BLE step2 + CMP $64, R3 + BLE step2 // Emit a length 60 copy, encoded as 3 bytes. MOVD $0xee, R2 @@ -125,11 +121,9 @@ step1: step2: // if length >= 12 || offset >= 2048 { goto step3 } - MOVD $12, R2 - CMP R2, R3 + CMP $12, R3 BGE step3 - MOVW $2048, R2 - CMPW R2, R11 + CMPW $2048, R11 BGE step3 // Emit the remaining copy, encoded as 2 bytes. @@ -295,27 +289,24 @@ varTable: // var table [maxTableSize]uint16 // // In the asm code, unlike the Go code, we can zero-initialize only the - // first tableSize elements. Each uint16 element is 2 bytes and each VST1 - // writes 64 bytes, so we can do only tableSize/32 writes instead of the - // 2048 writes that would zero-initialize all of table's 32768 bytes. - // This clear could overrun the first tableSize elements, but it won't - // overrun the allocated stack size. + // first tableSize elements. Each uint16 element is 2 bytes and each + // iterations writes 64 bytes, so we can do only tableSize/32 writes + // instead of the 2048 writes that would zero-initialize all of table's + // 32768 bytes. This clear could overrun the first tableSize elements, but + // it won't overrun the allocated stack size. ADD $128, RSP, R17 MOVD R17, R4 // !!! R6 = &src[tableSize] ADD R6<<1, R17, R6 - // zero the SIMD registers - VEOR V0.B16, V0.B16, V0.B16 - VEOR V1.B16, V1.B16, V1.B16 - VEOR V2.B16, V2.B16, V2.B16 - VEOR V3.B16, V3.B16, V3.B16 - memclr: - VST1.P [V0.B16, V1.B16, V2.B16, V3.B16], 64(R4) - CMP R4, R6 - BHI memclr + STP.P (ZR, ZR), 64(R4) + STP (ZR, ZR), -48(R4) + STP (ZR, ZR), -32(R4) + STP (ZR, ZR), -16(R4) + CMP R4, R6 + BHI memclr // !!! R6 = &src[0] MOVD R7, R6 @@ -404,8 +395,7 @@ fourByteMatch: // on inputMargin in encode.go. MOVD R7, R3 SUB R10, R3, R3 - MOVD $16, R2 - CMP R2, R3 + CMP $16, R3 BLE emitLiteralFastPath // ---------------------------------------- @@ -454,18 +444,21 @@ inlineEmitLiteralMemmove: MOVD R3, 24(RSP) // Finish the "d +=" part of "d += emitLiteral(etc)". - ADD R3, R8, R8 - MOVD R7, 80(RSP) - MOVD R8, 88(RSP) - MOVD R15, 120(RSP) - CALL runtime·memmove(SB) - MOVD 64(RSP), R5 - MOVD 72(RSP), R6 - MOVD 80(RSP), R7 - MOVD 88(RSP), R8 - MOVD 96(RSP), R9 - MOVD 120(RSP), R15 - B inner1 + ADD R3, R8, R8 + MOVD R7, 80(RSP) + MOVD R8, 88(RSP) + MOVD R15, 120(RSP) + CALL runtime·memmove(SB) + MOVD 64(RSP), R5 + MOVD 72(RSP), R6 + MOVD 80(RSP), R7 + MOVD 88(RSP), R8 + MOVD 96(RSP), R9 + MOVD 120(RSP), R15 + ADD $128, RSP, R17 + MOVW $0xa7bd, R16 + MOVKW $(0x1e35<<16), R16 + B inner1 inlineEmitLiteralEnd: // End inline of the emitLiteral call. @@ -489,9 +482,9 @@ emitLiteralFastPath: // Note that on arm64, it is legal and cheap to issue unaligned 8-byte or // 16-byte loads and stores. This technique probably wouldn't be as // effective on architectures that are fussier about alignment. - VLD1 0(R10), [V0.B16] - VST1 [V0.B16], 0(R8) - ADD R3, R8, R8 + LDP 0(R10), (R0, R1) + STP (R0, R1), 0(R8) + ADD R3, R8, R8 inner1: // for { etc } diff --git a/vendor/github.com/grafana/loki/pkg/distributor/distributor.go b/vendor/github.com/grafana/loki/pkg/distributor/distributor.go index 3ee704b7e1cc..eb88bc418713 100644 --- a/vendor/github.com/grafana/loki/pkg/distributor/distributor.go +++ b/vendor/github.com/grafana/loki/pkg/distributor/distributor.go @@ -9,8 +9,8 @@ import ( cortex_distributor "github.com/cortexproject/cortex/pkg/distributor" "github.com/cortexproject/cortex/pkg/ring" ring_client "github.com/cortexproject/cortex/pkg/ring/client" - cortex_util "github.com/cortexproject/cortex/pkg/util" "github.com/cortexproject/cortex/pkg/util/limiter" + util_log "github.com/cortexproject/cortex/pkg/util/log" "github.com/cortexproject/cortex/pkg/util/services" lru "github.com/hashicorp/golang-lru" "github.com/pkg/errors" @@ -124,7 +124,7 @@ func New(cfg Config, clientCfg client.Config, ingestersRing ring.ReadRing, overr ingestersRing: ingestersRing, distributorsRing: distributorsRing, validator: validator, - pool: cortex_distributor.NewPool(clientCfg.PoolConfig, ingestersRing, factory, cortex_util.Logger), + pool: cortex_distributor.NewPool(clientCfg.PoolConfig, ingestersRing, factory, util_log.Logger), ingestionRateLimiter: limiter.NewRateLimiter(ingestionRateStrategy, 10*time.Second), labelCache: labelCache, } @@ -234,10 +234,10 @@ func (d *Distributor) Push(ctx context.Context, req *logproto.PushRequest) (*log } const maxExpectedReplicationSet = 5 // typical replication factor 3 plus one for inactive plus one for luck - var descs [maxExpectedReplicationSet]ring.IngesterDesc + var descs [maxExpectedReplicationSet]ring.InstanceDesc samplesByIngester := map[string][]*streamTracker{} - ingesterDescs := map[string]ring.IngesterDesc{} + ingesterDescs := map[string]ring.InstanceDesc{} for i, key := range keys { replicationSet, err := d.ingestersRing.Get(key, ring.Write, descs[:0], nil, nil) if err != nil { @@ -258,7 +258,7 @@ func (d *Distributor) Push(ctx context.Context, req *logproto.PushRequest) (*log } tracker.samplesPending.Store(int32(len(streams))) for ingester, samples := range samplesByIngester { - go func(ingester ring.IngesterDesc, samples []*streamTracker) { + go func(ingester ring.InstanceDesc, samples []*streamTracker) { // Use a background context to make sure all ingesters get samples even if we return early localCtx, cancel := context.WithTimeout(context.Background(), d.clientCfg.RemoteTimeout) defer cancel() @@ -280,7 +280,7 @@ func (d *Distributor) Push(ctx context.Context, req *logproto.PushRequest) (*log } // TODO taken from Cortex, see if we can refactor out an usable interface. -func (d *Distributor) sendSamples(ctx context.Context, ingester ring.IngesterDesc, streamTrackers []*streamTracker, pushTracker *pushTracker) { +func (d *Distributor) sendSamples(ctx context.Context, ingester ring.InstanceDesc, streamTrackers []*streamTracker, pushTracker *pushTracker) { err := d.sendSamplesErr(ctx, ingester, streamTrackers) // If we succeed, decrement each sample's pending count by one. If we reach @@ -312,7 +312,7 @@ func (d *Distributor) sendSamples(ctx context.Context, ingester ring.IngesterDes } // TODO taken from Cortex, see if we can refactor out an usable interface. -func (d *Distributor) sendSamplesErr(ctx context.Context, ingester ring.IngesterDesc, streams []*streamTracker) error { +func (d *Distributor) sendSamplesErr(ctx context.Context, ingester ring.InstanceDesc, streams []*streamTracker) error { c, err := d.pool.GetClientFor(ingester.Addr) if err != nil { return err diff --git a/vendor/github.com/grafana/loki/pkg/distributor/http.go b/vendor/github.com/grafana/loki/pkg/distributor/http.go index 4f8cdd355d07..661a74c9c492 100644 --- a/vendor/github.com/grafana/loki/pkg/distributor/http.go +++ b/vendor/github.com/grafana/loki/pkg/distributor/http.go @@ -62,7 +62,7 @@ func (d *Distributor) PushHandler(w http.ResponseWriter, r *http.Request) { func ParseRequest(r *http.Request) (*logproto.PushRequest, error) { userID, _ := user.ExtractOrgID(r.Context()) - logger := util_log.WithContext(r.Context(), util.Logger) + logger := util_log.WithContext(r.Context(), util_log.Logger) body := lokiutil.NewSizeReader(r.Body) contentType := r.Header.Get(contentType) var req logproto.PushRequest diff --git a/vendor/github.com/grafana/loki/pkg/helpers/logerror.go b/vendor/github.com/grafana/loki/pkg/helpers/logerror.go index b6c723ee4e7e..7fc90291da1e 100644 --- a/vendor/github.com/grafana/loki/pkg/helpers/logerror.go +++ b/vendor/github.com/grafana/loki/pkg/helpers/logerror.go @@ -3,7 +3,6 @@ package helpers import ( "context" - "github.com/cortexproject/cortex/pkg/util" util_log "github.com/cortexproject/cortex/pkg/util/log" "github.com/go-kit/kit/log/level" ) @@ -11,13 +10,13 @@ import ( // LogError logs any error returned by f; useful when deferring Close etc. func LogError(message string, f func() error) { if err := f(); err != nil { - level.Error(util.Logger).Log("message", message, "error", err) + level.Error(util_log.Logger).Log("message", message, "error", err) } } // LogError logs any error returned by f; useful when deferring Close etc. func LogErrorWithContext(ctx context.Context, message string, f func() error) { if err := f(); err != nil { - level.Error(util_log.WithContext(ctx, util.Logger)).Log("message", message, "error", err) + level.Error(util_log.WithContext(ctx, util_log.Logger)).Log("message", message, "error", err) } } diff --git a/vendor/github.com/grafana/loki/pkg/logql/metrics.go b/vendor/github.com/grafana/loki/pkg/logql/metrics.go index 50489c723552..d992691aeb7d 100644 --- a/vendor/github.com/grafana/loki/pkg/logql/metrics.go +++ b/vendor/github.com/grafana/loki/pkg/logql/metrics.go @@ -5,7 +5,6 @@ import ( "strings" "time" - "github.com/cortexproject/cortex/pkg/util" util_log "github.com/cortexproject/cortex/pkg/util/log" "github.com/dustin/go-humanize" "github.com/go-kit/kit/log/level" @@ -66,7 +65,7 @@ var ( ) func RecordMetrics(ctx context.Context, p Params, status string, stats stats.Result) { - logger := util_log.WithContext(ctx, util.Logger) + logger := util_log.WithContext(ctx, util_log.Logger) queryType, err := QueryType(p.Query()) if err != nil { level.Warn(logger).Log("msg", "error parsing query type", "err", err) diff --git a/vendor/github.com/grafana/loki/pkg/logql/sharding.go b/vendor/github.com/grafana/loki/pkg/logql/sharding.go index 4f060d3d4d51..f315000893b6 100644 --- a/vendor/github.com/grafana/loki/pkg/logql/sharding.go +++ b/vendor/github.com/grafana/loki/pkg/logql/sharding.go @@ -7,7 +7,7 @@ import ( "time" "github.com/cortexproject/cortex/pkg/querier/astmapper" - "github.com/cortexproject/cortex/pkg/util" + util_log "github.com/cortexproject/cortex/pkg/util/log" "github.com/go-kit/kit/log/level" "github.com/prometheus/prometheus/promql" @@ -168,7 +168,7 @@ func (ev DownstreamEvaluator) Downstream(ctx context.Context, queries []Downstre for _, res := range results { if err := stats.JoinResults(ctx, res.Statistics); err != nil { - level.Warn(util.Logger).Log("msg", "unable to merge downstream results", "err", err) + level.Warn(util_log.Logger).Log("msg", "unable to merge downstream results", "err", err) } } @@ -241,7 +241,7 @@ func (ev *DownstreamEvaluator) StepEvaluator( for i, res := range results { stepper, err := ResultStepEvaluator(res, params) if err != nil { - level.Warn(util.Logger).Log( + level.Warn(util_log.Logger).Log( "msg", "could not extract StepEvaluator", "err", err, "expr", queries[i].Expr.String(), @@ -306,7 +306,7 @@ func (ev *DownstreamEvaluator) Iterator( for i, res := range results { iter, err := ResultIterator(res, params) if err != nil { - level.Warn(util.Logger).Log( + level.Warn(util_log.Logger).Log( "msg", "could not extract Iterator", "err", err, "expr", queries[i].Expr.String(), diff --git a/vendor/github.com/grafana/loki/pkg/logql/shardmapper.go b/vendor/github.com/grafana/loki/pkg/logql/shardmapper.go index 628fa1895666..893febe8b09d 100644 --- a/vendor/github.com/grafana/loki/pkg/logql/shardmapper.go +++ b/vendor/github.com/grafana/loki/pkg/logql/shardmapper.go @@ -4,7 +4,7 @@ import ( "fmt" "github.com/cortexproject/cortex/pkg/querier/astmapper" - "github.com/cortexproject/cortex/pkg/util" + util_log "github.com/cortexproject/cortex/pkg/util/log" "github.com/go-kit/kit/log/level" "github.com/pkg/errors" "github.com/prometheus/client_golang/prometheus" @@ -271,7 +271,7 @@ func (m ShardMapper) mapVectorAggregationExpr(expr *vectorAggregationExpr, r *sh default: // this should not be reachable. If an operation is shardable it should // have an optimization listed. - level.Warn(util.Logger).Log( + level.Warn(util_log.Logger).Log( "msg", "unexpected operation which appears shardable, ignoring", "operation", expr.operation, ) diff --git a/vendor/github.com/grafana/loki/pkg/logql/stats/grpc.go b/vendor/github.com/grafana/loki/pkg/logql/stats/grpc.go index 0dcd8c403c8e..0c9239987b7e 100644 --- a/vendor/github.com/grafana/loki/pkg/logql/stats/grpc.go +++ b/vendor/github.com/grafana/loki/pkg/logql/stats/grpc.go @@ -4,7 +4,6 @@ import ( "context" "sync" - "github.com/cortexproject/cortex/pkg/util" util_log "github.com/cortexproject/cortex/pkg/util/log" "github.com/go-kit/kit/log/level" jsoniter "github.com/json-iterator/go" @@ -48,7 +47,7 @@ func CollectTrailer(ctx context.Context) grpc.CallOption { func SendAsTrailer(ctx context.Context, stream grpc.ServerStream) { trailer, err := encodeTrailer(ctx) if err != nil { - level.Warn(util_log.WithContext(ctx, util.Logger)).Log("msg", "failed to encode trailer", "err", err) + level.Warn(util_log.WithContext(ctx, util_log.Logger)).Log("msg", "failed to encode trailer", "err", err) return } stream.SetTrailer(trailer) @@ -111,7 +110,7 @@ func decodeTrailers(ctx context.Context) Result { } func decodeTrailer(ctx context.Context, meta *metadata.MD) Result { - logger := util_log.WithContext(ctx, util.Logger) + logger := util_log.WithContext(ctx, util_log.Logger) var ingData IngesterData values := meta.Get(ingesterDataKey) if len(values) == 1 { diff --git a/vendor/github.com/grafana/loki/pkg/promtail/promtail.go b/vendor/github.com/grafana/loki/pkg/promtail/promtail.go index 777df8c1cc4d..cb59014914ed 100644 --- a/vendor/github.com/grafana/loki/pkg/promtail/promtail.go +++ b/vendor/github.com/grafana/loki/pkg/promtail/promtail.go @@ -3,7 +3,7 @@ package promtail import ( "sync" - "github.com/cortexproject/cortex/pkg/util" + util_log "github.com/cortexproject/cortex/pkg/util/log" "github.com/go-kit/kit/log" "github.com/prometheus/client_golang/prometheus" @@ -48,7 +48,7 @@ func New(cfg config.Config, dryRun bool, opts ...Option) (*Promtail, error) { // Initialize promtail with some defaults and allow the options to override // them. promtail := &Promtail{ - logger: util.Logger, + logger: util_log.Logger, reg: prometheus.DefaultRegisterer, } for _, o := range opts { diff --git a/vendor/github.com/grafana/loki/pkg/promtail/targets/gcplog/formatter.go b/vendor/github.com/grafana/loki/pkg/promtail/targets/gcplog/formatter.go index 52607e2f0ead..96382bad0035 100644 --- a/vendor/github.com/grafana/loki/pkg/promtail/targets/gcplog/formatter.go +++ b/vendor/github.com/grafana/loki/pkg/promtail/targets/gcplog/formatter.go @@ -8,9 +8,12 @@ import ( "cloud.google.com/go/pubsub" json "github.com/json-iterator/go" "github.com/prometheus/common/model" + "github.com/prometheus/prometheus/pkg/labels" + "github.com/prometheus/prometheus/pkg/relabel" "github.com/grafana/loki/pkg/logproto" "github.com/grafana/loki/pkg/promtail/api" + "github.com/grafana/loki/pkg/util" ) // LogEntry that will be written to the pubsub topic. @@ -35,18 +38,51 @@ type GCPLogEntry struct { // anyway we will be sending the entire entry to Loki. } -func format(m *pubsub.Message, other model.LabelSet, useIncomingTimestamp bool) (api.Entry, error) { +func format( + m *pubsub.Message, + other model.LabelSet, + useIncomingTimestamp bool, + relabelConfig []*relabel.Config, +) (api.Entry, error) { var ge GCPLogEntry if err := json.Unmarshal(m.Data, &ge); err != nil { return api.Entry{}, err } - labels := model.LabelSet{ - "resource_type": model.LabelValue(ge.Resource.Type), + // mandatory label for gcplog + lbs := labels.NewBuilder(nil) + lbs.Set("resource_type", ge.Resource.Type) + + // labels from gcp log entry. Add it as internal labels + for k, v := range ge.Resource.Labels { + lbs.Set("__"+util.SnakeCase(k), v) + } + + var processed labels.Labels + + // apply relabeling + if len(relabelConfig) > 0 { + processed = relabel.Process(lbs.Labels(), relabelConfig...) + } else { + processed = lbs.Labels() + } + + // final labelset that will be sent to loki + labels := make(model.LabelSet) + for _, lbl := range processed { + // ignore internal labels + if strings.HasPrefix(lbl.Name, "__") { + continue + } + // ignore invalid labels + if !model.LabelName(lbl.Name).IsValid() || !model.LabelValue(lbl.Value).IsValid() { + continue + } + labels[model.LabelName(lbl.Name)] = model.LabelValue(lbl.Value) } - // add labels from config as well. + // add labels coming from scrapeconfig labels = labels.Merge(other) ts := time.Now() diff --git a/vendor/github.com/grafana/loki/pkg/promtail/targets/gcplog/target.go b/vendor/github.com/grafana/loki/pkg/promtail/targets/gcplog/target.go index 05dfe5d8d954..b5207da9d06c 100644 --- a/vendor/github.com/grafana/loki/pkg/promtail/targets/gcplog/target.go +++ b/vendor/github.com/grafana/loki/pkg/promtail/targets/gcplog/target.go @@ -116,7 +116,7 @@ func (t *GcplogTarget) run() error { case <-t.ctx.Done(): return t.ctx.Err() case m := <-t.msgs: - entry, err := format(m, t.config.Labels, t.config.UseIncomingTimestamp) + entry, err := format(m, t.config.Labels, t.config.UseIncomingTimestamp, t.relabelConfig) if err != nil { level.Error(t.logger).Log("event", "error formating log entry", "cause", err) m.Ack() diff --git a/vendor/github.com/grafana/loki/pkg/promtail/targets/lokipush/pushtarget.go b/vendor/github.com/grafana/loki/pkg/promtail/targets/lokipush/pushtarget.go index fce793dcebe5..9c3ea6d936ca 100644 --- a/vendor/github.com/grafana/loki/pkg/promtail/targets/lokipush/pushtarget.go +++ b/vendor/github.com/grafana/loki/pkg/promtail/targets/lokipush/pushtarget.go @@ -6,7 +6,7 @@ import ( "strings" "time" - cortex_util "github.com/cortexproject/cortex/pkg/util" + util_log "github.com/cortexproject/cortex/pkg/util/log" "github.com/go-kit/kit/log" "github.com/go-kit/kit/log/level" "github.com/imdario/mergo" @@ -81,7 +81,7 @@ func (t *PushTarget) run() error { // We don't want the /debug and /metrics endpoints running t.config.Server.RegisterInstrumentation = false - cortex_util.InitLogger(&t.config.Server) + util_log.InitLogger(&t.config.Server) srv, err := server.New(t.config.Server) if err != nil { diff --git a/vendor/github.com/grafana/loki/pkg/promtail/targets/windows/target.go b/vendor/github.com/grafana/loki/pkg/promtail/targets/windows/target.go index 30734ef977c6..0048a378d758 100644 --- a/vendor/github.com/grafana/loki/pkg/promtail/targets/windows/target.go +++ b/vendor/github.com/grafana/loki/pkg/promtail/targets/windows/target.go @@ -8,7 +8,7 @@ import ( "sync" "time" - "github.com/cortexproject/cortex/pkg/util" + util_log "github.com/cortexproject/cortex/pkg/util/log" "github.com/go-kit/kit/log" "github.com/go-kit/kit/log/level" "github.com/prometheus/common/model" @@ -112,7 +112,7 @@ func (t *Target) loop() { if err != nil { if err != win_eventlog.ERROR_NO_MORE_ITEMS { t.err = err - level.Error(util.Logger).Log("msg", "error fetching events", "err", err) + level.Error(util_log.Logger).Log("msg", "error fetching events", "err", err) } break loop } @@ -122,7 +122,7 @@ func (t *Target) loop() { t.handler.Chan() <- entry if err := t.bm.save(handles[i]); err != nil { t.err = err - level.Error(util.Logger).Log("msg", "error saving bookmark", "err", err) + level.Error(util_log.Logger).Log("msg", "error saving bookmark", "err", err) } } win_eventlog.Close(handles) diff --git a/vendor/github.com/grafana/loki/pkg/promtail/targets/windows/win_eventlog/win_eventlog.go b/vendor/github.com/grafana/loki/pkg/promtail/targets/windows/win_eventlog/win_eventlog.go index 0ccf0fa6ae5a..982e2ace6697 100644 --- a/vendor/github.com/grafana/loki/pkg/promtail/targets/windows/win_eventlog/win_eventlog.go +++ b/vendor/github.com/grafana/loki/pkg/promtail/targets/windows/win_eventlog/win_eventlog.go @@ -32,7 +32,7 @@ import ( "strings" "syscall" - "github.com/cortexproject/cortex/pkg/util" + util_log "github.com/cortexproject/cortex/pkg/util/log" "github.com/go-kit/kit/log/level" "github.com/influxdata/telegraf" "github.com/influxdata/telegraf/plugins/inputs" @@ -365,7 +365,7 @@ func EvtSubscribe(logName, xquery string) (EvtHandle, error) { if err != nil { return 0, err } - level.Debug(util.Logger).Log("msg", "Subcribed with handle id", "id", subsHandle) + level.Debug(util_log.Logger).Log("msg", "Subcribed with handle id", "id", subsHandle) return subsHandle, nil } @@ -394,7 +394,7 @@ func EvtSubscribeWithBookmark(logName, xquery string, bookMark EvtHandle) (EvtHa if err != nil { return 0, err } - level.Debug(util.Logger).Log("msg", "Subcribed with handle id", "id", subsHandle) + level.Debug(util_log.Logger).Log("msg", "Subcribed with handle id", "id", subsHandle) return subsHandle, nil } diff --git a/vendor/github.com/grafana/loki/pkg/util/config.go b/vendor/github.com/grafana/loki/pkg/util/config.go index 481d16c6ca7e..9b803d9640ea 100644 --- a/vendor/github.com/grafana/loki/pkg/util/config.go +++ b/vendor/github.com/grafana/loki/pkg/util/config.go @@ -5,7 +5,7 @@ import ( "io" "strings" - "github.com/cortexproject/cortex/pkg/util" + util_log "github.com/cortexproject/cortex/pkg/util/log" "github.com/go-kit/kit/log/level" "github.com/prometheus/common/version" "gopkg.in/yaml.v2" @@ -22,7 +22,7 @@ func LogConfig(cfg interface{}) error { cfgStr := string(lc) cfgStrs := strings.Split(cfgStr, "\n") for i := len(cfgStrs) - 1; i >= 0; i-- { - level.Info(util.Logger).Log("type", "config", "msg", cfgStrs[i]) + level.Info(util_log.Logger).Log("type", "config", "msg", cfgStrs[i]) } return nil } diff --git a/vendor/github.com/grafana/loki/pkg/util/string.go b/vendor/github.com/grafana/loki/pkg/util/string.go index 26a2f549a9d4..3312fb89b624 100644 --- a/vendor/github.com/grafana/loki/pkg/util/string.go +++ b/vendor/github.com/grafana/loki/pkg/util/string.go @@ -1,5 +1,11 @@ package util +import ( + "bytes" + "fmt" + "unicode" +) + func StringRef(value string) *string { return &value } @@ -13,3 +19,16 @@ func StringSliceContains(slice []string, value string) bool { return false } + +// SnakeCase converts given string `s` into `snake_case`. +func SnakeCase(s string) string { + var buf bytes.Buffer + for i, r := range s { + if unicode.IsUpper(r) && i > 0 && s[i-1] != '_' { + fmt.Fprintf(&buf, "_") + } + r = unicode.ToLower(r) + fmt.Fprintf(&buf, "%c", r) + } + return buf.String() +} diff --git a/vendor/github.com/thanos-io/thanos/pkg/errutil/multierror.go.go b/vendor/github.com/thanos-io/thanos/pkg/errutil/multierror.go similarity index 100% rename from vendor/github.com/thanos-io/thanos/pkg/errutil/multierror.go.go rename to vendor/github.com/thanos-io/thanos/pkg/errutil/multierror.go diff --git a/vendor/modules.txt b/vendor/modules.txt index 2a210fddfbd5..4bb834229c19 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -122,7 +122,7 @@ github.com/coreos/go-systemd/journal github.com/coreos/go-systemd/sdjournal # github.com/coreos/pkg v0.0.0-20180928190104-399ea9e2e55f github.com/coreos/pkg/capnslog -# github.com/cortexproject/cortex v1.6.1-0.20210129172402-0976147451ee +# github.com/cortexproject/cortex v1.6.1-0.20210204145131-7dac81171c66 ## explicit github.com/cortexproject/cortex/pkg/distributor github.com/cortexproject/cortex/pkg/ingester/client @@ -247,7 +247,7 @@ github.com/golang/protobuf/ptypes/empty github.com/golang/protobuf/ptypes/struct github.com/golang/protobuf/ptypes/timestamp github.com/golang/protobuf/ptypes/wrappers -# github.com/golang/snappy v0.0.2 +# github.com/golang/snappy v0.0.3-0.20201103224600-674baa8c7fc3 github.com/golang/snappy # github.com/gomodule/redigo v2.0.0+incompatible => github.com/gomodule/redigo v1.8.2 github.com/gomodule/redigo/redis @@ -292,7 +292,7 @@ github.com/gophercloud/gophercloud/pagination github.com/gorilla/mux # github.com/gorilla/websocket v1.4.2 github.com/gorilla/websocket -# github.com/grafana/loki v1.6.2-0.20210203125540-d667dd20f287 +# github.com/grafana/loki v1.6.2-0.20210205130758-59a34f9867ce ## explicit github.com/grafana/loki/pkg/distributor github.com/grafana/loki/pkg/helpers @@ -704,7 +704,7 @@ github.com/stretchr/testify/mock github.com/stretchr/testify/require # github.com/subosito/gotenv v1.2.0 github.com/subosito/gotenv -# github.com/thanos-io/thanos v0.13.1-0.20210108102609-f85e4003ba51 +# github.com/thanos-io/thanos v0.13.1-0.20210204123931-82545cdd16fe github.com/thanos-io/thanos/pkg/discovery/dns github.com/thanos-io/thanos/pkg/discovery/dns/godns github.com/thanos-io/thanos/pkg/discovery/dns/miekgdns