diff --git a/Gopkg.lock b/Gopkg.lock index eaa6c663353ab..9e51ec61956a5 100644 --- a/Gopkg.lock +++ b/Gopkg.lock @@ -900,8 +900,8 @@ version = "v2.0.0" [[projects]] - branch = "master" - digest = "1:81403343bc9a102e3c924f87ad81e5a13bb7c36211714475c906853f4e887933" + branch = "server-listen-addr" + digest = "1:0184d699d4cbbbc3073fbbdd7cc0c8592d484c6f23914c89fb6d218e90de171a" name = "github.com/weaveworks/common" packages = [ "aws", @@ -918,7 +918,8 @@ "user", ] pruneopts = "UT" - revision = "81a1a4d158e60de72dbead600ec011fb90344f8c" + revision = "5bf824591a6567784789cf9b2169f74f162bf80d" + source = "https://github.com/tomwilkie/weaveworks-common" [[projects]] digest = "1:bb40f7ff970145324f2a2acafdff3a23ed3f05db49cb5eb519b3d6bee86a5887" @@ -1413,6 +1414,7 @@ "github.com/prometheus/prometheus/pkg/modtimevfs", "github.com/prometheus/prometheus/pkg/relabel", "github.com/prometheus/prometheus/pkg/textparse", + "github.com/prometheus/prometheus/promql", "github.com/prometheus/prometheus/relabel", "github.com/prometheus/prometheus/template", "github.com/shurcooL/httpfs/filter", diff --git a/Gopkg.toml b/Gopkg.toml index a190ef2980525..35b9221f209b4 100644 --- a/Gopkg.toml +++ b/Gopkg.toml @@ -31,7 +31,8 @@ [[constraint]] name = "github.com/weaveworks/common" - branch = "master" + source = "https://github.com/tomwilkie/weaveworks-common" + branch = "server-listen-addr" [[constraint]] name = "gopkg.in/fsnotify.v1" diff --git a/pkg/ingester/flush_test.go b/pkg/ingester/flush_test.go index f5c146803a35d..0b53c08e1cf38 100644 --- a/pkg/ingester/flush_test.go +++ b/pkg/ingester/flush_test.go @@ -2,7 +2,6 @@ package ingester import ( "fmt" - "os" "sort" "sync" "testing" @@ -10,9 +9,7 @@ import ( "github.com/cortexproject/cortex/pkg/chunk" "github.com/cortexproject/cortex/pkg/ring" - "github.com/cortexproject/cortex/pkg/util" "github.com/cortexproject/cortex/pkg/util/flagext" - "github.com/go-kit/kit/log" "github.com/grafana/loki/pkg/chunkenc" "github.com/grafana/loki/pkg/logproto" "github.com/prometheus/common/model" @@ -27,7 +24,7 @@ const ( ) func init() { - util.Logger = log.NewLogfmtLogger(os.Stdout) + //util.Logger = log.NewLogfmtLogger(os.Stdout) } func TestChunkFlushingIdle(t *testing.T) { @@ -81,6 +78,7 @@ func defaultIngesterTestConfig() Config { cfg.LifecyclerConfig.ListenPort = func(i int) *int { return &i }(0) cfg.LifecyclerConfig.Addr = "localhost" cfg.LifecyclerConfig.ID = "localhost" + cfg.LifecyclerConfig.FinalSleep = 0 return cfg } diff --git a/pkg/ingester/ingester_test.go b/pkg/ingester/ingester_test.go index 995366b78962c..16f395b5becb6 100644 --- a/pkg/ingester/ingester_test.go +++ b/pkg/ingester/ingester_test.go @@ -13,19 +13,10 @@ import ( "google.golang.org/grpc" "github.com/cortexproject/cortex/pkg/chunk" - "github.com/cortexproject/cortex/pkg/ring" - "github.com/cortexproject/cortex/pkg/util/flagext" ) func TestIngester(t *testing.T) { - var ingesterConfig Config - flagext.DefaultValues(&ingesterConfig) - ingesterConfig.LifecyclerConfig.RingConfig.Mock = ring.NewInMemoryKVClient() - ingesterConfig.LifecyclerConfig.NumTokens = 1 - ingesterConfig.LifecyclerConfig.ListenPort = func(i int) *int { return &i }(0) - ingesterConfig.LifecyclerConfig.Addr = "localhost" - ingesterConfig.LifecyclerConfig.ID = "localhost" - + ingesterConfig := defaultIngesterTestConfig() store := &mockStore{ chunks: map[string][]chunk.Chunk{}, } diff --git a/pkg/promtail/promtail_test.go b/pkg/promtail/promtail_test.go index 31f5b2aaa580e..02cfa5c11302e 100644 --- a/pkg/promtail/promtail_test.go +++ b/pkg/promtail/promtail_test.go @@ -31,10 +31,11 @@ import ( "github.com/grafana/loki/pkg/promtail/scrape" ) +const httpTestPort = 9080 + func TestPromtail(t *testing.T) { // Setup. - w := log.NewSyncWriter(os.Stderr) logger := log.NewLogfmtLogger(w) logger = level.NewFilter(logger, level.AllowInfo()) @@ -71,7 +72,7 @@ func TestPromtail(t *testing.T) { } }() go func() { - if err = http.ListenAndServe("127.0.0.1:3100", nil); err != nil { + if err = http.ListenAndServe("localhost:3100", nil); err != nil { err = errors.Wrap(err, "Failed to start web server to receive logs") } }() @@ -398,7 +399,7 @@ func (h *testServerHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { } func getPromMetrics(t *testing.T) ([]byte, string) { - resp, err := http.Get("http://localhost:80/metrics") + resp, err := http.Get(fmt.Sprintf("http://localhost:%d/metrics", httpTestPort)) if err != nil { t.Fatal("Could not query metrics endpoint", err) } @@ -457,6 +458,11 @@ func buildTestConfig(t *testing.T, positionsFileName string, logDirName string) // Init everything with default values. flagext.RegisterFlags(&cfg) + // Make promtail listen on localhost to avoid prompts on MacOS. + cfg.ServerConfig.HTTPListenHost = "localhost" + cfg.ServerConfig.HTTPListenPort = httpTestPort + cfg.ServerConfig.GRPCListenHost = "localhost" + // Override some of those defaults cfg.ClientConfig.URL = clientURL cfg.ClientConfig.BatchWait = 10 * time.Millisecond diff --git a/vendor/github.com/weaveworks/common/logging/level.go b/vendor/github.com/weaveworks/common/logging/level.go index 971b3a2b8440c..fba3e51dfb6b5 100644 --- a/vendor/github.com/weaveworks/common/logging/level.go +++ b/vendor/github.com/weaveworks/common/logging/level.go @@ -49,6 +49,11 @@ func (l *Level) UnmarshalYAML(unmarshal func(interface{}) error) error { return l.Set(level) } +// MarshalYAML implements yaml.Marshaler. +func (l Level) MarshalYAML() (interface{}, error) { + return l.String(), nil +} + // Set updates the value of the allowed level. Implments flag.Value. func (l *Level) Set(s string) error { switch s { diff --git a/vendor/github.com/weaveworks/common/middleware/grpc_logging.go b/vendor/github.com/weaveworks/common/middleware/grpc_logging.go index bc9c9f37d5190..75328eafc887e 100644 --- a/vendor/github.com/weaveworks/common/middleware/grpc_logging.go +++ b/vendor/github.com/weaveworks/common/middleware/grpc_logging.go @@ -31,7 +31,11 @@ func (s GRPCServerLog) UnaryServerInterceptor(ctx context.Context, req interface if s.WithRequest { entry = entry.WithField("request", req) } - entry.WithField(errorKey, err).Warnln(gRPC) + if err == context.Canceled { + entry.WithField(errorKey, err).Debugln(gRPC) + } else { + entry.WithField(errorKey, err).Warnln(gRPC) + } } else { entry.Debugf("%s (success)", gRPC) } @@ -44,7 +48,11 @@ func (s GRPCServerLog) StreamServerInterceptor(srv interface{}, ss grpc.ServerSt err := handler(srv, ss) entry := user.LogWith(ss.Context(), s.Log).WithFields(logging.Fields{"method": info.FullMethod, "duration": time.Since(begin)}) if err != nil { - entry.WithField(errorKey, err).Warnln(gRPC) + if err == context.Canceled { + entry.WithField(errorKey, err).Debugln(gRPC) + } else { + entry.WithField(errorKey, err).Warnln(gRPC) + } } else { entry.Debugf("%s (success)", gRPC) } diff --git a/vendor/github.com/weaveworks/common/middleware/logging.go b/vendor/github.com/weaveworks/common/middleware/logging.go index 148a87e73d870..06f816e8fd191 100644 --- a/vendor/github.com/weaveworks/common/middleware/logging.go +++ b/vendor/github.com/weaveworks/common/middleware/logging.go @@ -63,8 +63,9 @@ func dumpRequest(req *http.Request) ([]byte, error) { // Exclude some headers for security, or just that we don't need them when debugging err := req.Header.WriteSubset(&b, map[string]bool{ - "Cookie": true, - "X-Csrf-Token": true, + "Cookie": true, + "X-Csrf-Token": true, + "Authorization": true, }) if err != nil { return nil, err diff --git a/vendor/github.com/weaveworks/common/server/server.go b/vendor/github.com/weaveworks/common/server/server.go index dce01f4b7cd74..f2081fb630d71 100644 --- a/vendor/github.com/weaveworks/common/server/server.go +++ b/vendor/github.com/weaveworks/common/server/server.go @@ -27,7 +27,9 @@ import ( // Config for a Server type Config struct { MetricsNamespace string `yaml:"-"` + HTTPListenHost string `yaml:"http_listen_host"` HTTPListenPort int `yaml:"http_listen_port"` + GRPCListenHost string `yaml:"grpc_listen_host"` GRPCListenPort int `yaml:"grpc_listen_port"` RegisterInstrumentation bool `yaml:"-"` @@ -55,7 +57,9 @@ type Config struct { // RegisterFlags adds the flags required to config this to the given FlagSet func (cfg *Config) RegisterFlags(f *flag.FlagSet) { + f.StringVar(&cfg.HTTPListenHost, "server.http-listen-host", "", "HTTP server listen host.") f.IntVar(&cfg.HTTPListenPort, "server.http-listen-port", 80, "HTTP server listen port.") + f.StringVar(&cfg.GRPCListenHost, "server.grpc-listen-host", "", "gRPC server listen host.") f.IntVar(&cfg.GRPCListenPort, "server.grpc-listen-port", 9095, "gRPC server listen port.") f.BoolVar(&cfg.RegisterInstrumentation, "server.register-instrumentation", true, "Register the intrumentation handlers (/metrics etc).") f.DurationVar(&cfg.ServerGracefulShutdownTimeout, "server.graceful-shutdown-timeout", 30*time.Second, "Timeout for graceful shutdowns") @@ -87,12 +91,12 @@ type Server struct { // New makes a new Server func New(cfg Config) (*Server, error) { // Setup listeners first, so we can fail early if the port is in use. - httpListener, err := net.Listen("tcp", fmt.Sprintf(":%d", cfg.HTTPListenPort)) + httpListener, err := net.Listen("tcp", fmt.Sprintf("%s:%d", cfg.HTTPListenHost, cfg.HTTPListenPort)) if err != nil { return nil, err } - grpcListener, err := net.Listen("tcp", fmt.Sprintf(":%d", cfg.GRPCListenPort)) + grpcListener, err := net.Listen("tcp", fmt.Sprintf("%s:%d", cfg.GRPCListenHost, cfg.GRPCListenPort)) if err != nil { return nil, err } @@ -150,12 +154,14 @@ func New(cfg Config) (*Server, error) { // Setup HTTP server router := mux.NewRouter() - if cfg.RegisterInstrumentation { - RegisterInstrumentation(router) - } if cfg.PathPrefix != "" { + // Expect metrics and pprof handlers to be prefixed with server's path prefix. + // e.g. /loki/metrics or /loki/debug/pprof router = router.PathPrefix(cfg.PathPrefix).Subrouter() } + if cfg.RegisterInstrumentation { + RegisterInstrumentation(router) + } httpMiddleware := []middleware.Interface{ middleware.Tracer{ RouteMatcher: router,