[ARVADOS] updated: c52c3788fbbf161db40118261c4cfff52ebf8ceb

Git user git at public.curoverse.com
Thu Nov 17 16:33:20 EST 2016


Summary of changes:
 sdk/python/tests/run_test_server.py |  1 +
 services/ws/handler.go              | 13 ++-----------
 services/ws/log.go                  | 15 +++++++++------
 services/ws/main.go                 | 16 +++++++++-------
 services/ws/router.go               |  9 +++++----
 services/ws/session.go              |  6 ++++--
 services/ws/session_v0.go           | 18 +++++++++---------
 7 files changed, 39 insertions(+), 39 deletions(-)

       via  c52c3788fbbf161db40118261c4cfff52ebf8ceb (commit)
       via  a6d6a57a908b1cac8ebcc5bc4261b7c906d249a4 (commit)
       via  259252b7b9418c931e59d67257e50632c83261c5 (commit)
      from  1a17734f7264bc74463e1e6fe115cdad6ec4c521 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.


commit c52c3788fbbf161db40118261c4cfff52ebf8ceb
Author: Tom Clegg <tom at curoverse.com>
Date:   Thu Nov 17 16:33:13 2016 -0500

    8460: Fix up logging.

diff --git a/services/ws/handler.go b/services/ws/handler.go
index 09ab945..ab25805 100644
--- a/services/ws/handler.go
+++ b/services/ws/handler.go
@@ -5,7 +5,6 @@ import (
 	"time"
 
 	"git.curoverse.com/arvados.git/sdk/go/arvados"
-	log "github.com/Sirupsen/logrus"
 )
 
 type handler struct {
@@ -23,13 +22,9 @@ type handlerStats struct {
 }
 
 func (h *handler) Handle(ws wsConn, incoming <-chan *event) (stats handlerStats) {
-	ctx := contextWithLogger(ws.Request().Context(), log.WithFields(log.Fields{
-		"RemoteAddr": ws.Request().RemoteAddr,
-	}))
-
+	log := logger(ws.Request().Context())
 	queue := make(chan interface{}, h.QueueSize)
 	sess, err := h.NewSession(ws, queue)
-	log := logger(ctx)
 	if err != nil {
 		log.WithError(err).Error("NewSession failed")
 		return
diff --git a/services/ws/log.go b/services/ws/log.go
index d3aa82d..fbf21b9 100644
--- a/services/ws/log.go
+++ b/services/ws/log.go
@@ -3,20 +3,23 @@ package main
 import (
 	"context"
 
-	log "github.com/Sirupsen/logrus"
+	"github.com/Sirupsen/logrus"
 )
 
-var loggerCtxKey = new(int)
+var (
+	loggerCtxKey = new(int)
+	rootLogger   = logrus.New()
+)
 
-func contextWithLogger(ctx context.Context, logger *log.Entry) context.Context {
+func contextWithLogger(ctx context.Context, logger *logrus.Entry) context.Context {
 	return context.WithValue(ctx, loggerCtxKey, logger)
 }
 
-func logger(ctx context.Context) *log.Entry {
+func logger(ctx context.Context) *logrus.Entry {
 	if ctx != nil {
-		if logger, ok := ctx.Value(loggerCtxKey).(*log.Entry); ok {
+		if logger, ok := ctx.Value(loggerCtxKey).(*logrus.Entry); ok {
 			return logger
 		}
 	}
-	return log.WithFields(nil)
+	return rootLogger.WithFields(nil)
 }
diff --git a/services/ws/main.go b/services/ws/main.go
index c83f8d9..16fe87f 100644
--- a/services/ws/main.go
+++ b/services/ws/main.go
@@ -7,10 +7,12 @@ import (
 	"time"
 
 	"git.curoverse.com/arvados.git/sdk/go/config"
-	log "github.com/Sirupsen/logrus"
+	"github.com/Sirupsen/logrus"
 )
 
 func main() {
+	log := logger(nil)
+
 	configPath := flag.String("config", "/etc/arvados/ws/ws.yml", "`path` to config file")
 	dumpConfig := flag.Bool("dump-config", false, "show current configuration and exit")
 	cfg := DefaultConfig()
@@ -21,21 +23,21 @@ func main() {
 		log.Fatal(err)
 	}
 
-	lvl, err := log.ParseLevel(cfg.LogLevel)
+	lvl, err := logrus.ParseLevel(cfg.LogLevel)
 	if err != nil {
 		log.Fatal(err)
 	}
-	log.SetLevel(lvl)
+	rootLogger.Level = lvl
 	switch cfg.LogFormat {
 	case "text":
-		log.SetFormatter(&log.TextFormatter{
+		rootLogger.Formatter = &logrus.TextFormatter{
 			FullTimestamp:   true,
 			TimestampFormat: time.RFC3339Nano,
-		})
+		}
 	case "json":
-		log.SetFormatter(&log.JSONFormatter{
+		rootLogger.Formatter = &logrus.JSONFormatter{
 			TimestampFormat: time.RFC3339Nano,
-		})
+		}
 	default:
 		log.WithField("LogFormat", cfg.LogFormat).Fatal("unknown log format")
 	}
diff --git a/services/ws/router.go b/services/ws/router.go
index e6cec0f..6aef647 100644
--- a/services/ws/router.go
+++ b/services/ws/router.go
@@ -9,7 +9,7 @@ import (
 	"time"
 
 	"git.curoverse.com/arvados.git/sdk/go/arvados"
-	log "github.com/Sirupsen/logrus"
+	"github.com/Sirupsen/logrus"
 	"golang.org/x/net/websocket"
 )
 
@@ -54,11 +54,12 @@ func (rtr *router) makeServer(newSession sessionFactory) *websocket.Server {
 		Handler: websocket.Handler(func(ws *websocket.Conn) {
 			t0 := time.Now()
 			sink := rtr.eventSource.NewSink()
-			logger(ws.Request().Context()).Info("connected")
+			log := logger(ws.Request().Context())
+			log.Info("connected")
 
 			stats := handler.Handle(ws, sink.Channel())
 
-			logger(ws.Request().Context()).WithFields(log.Fields{
+			log.WithFields(logrus.Fields{
 				"Elapsed": time.Now().Sub(t0).Seconds(),
 				"Stats":   stats,
 			}).Info("disconnect")
@@ -85,7 +86,7 @@ func (rtr *router) ServeHTTP(resp http.ResponseWriter, req *http.Request) {
 		WithField("RequestID", rtr.newReqID())
 	ctx := contextWithLogger(req.Context(), logger)
 	req = req.WithContext(ctx)
-	logger.WithFields(log.Fields{
+	logger.WithFields(logrus.Fields{
 		"RemoteAddr":      req.RemoteAddr,
 		"X-Forwarded-For": req.Header.Get("X-Forwarded-For"),
 	}).Info("accept request")
diff --git a/services/ws/session_v0.go b/services/ws/session_v0.go
index 0fd5003..2bcce60 100644
--- a/services/ws/session_v0.go
+++ b/services/ws/session_v0.go
@@ -9,7 +9,7 @@ import (
 	"time"
 
 	"git.curoverse.com/arvados.git/sdk/go/arvados"
-	log "github.com/Sirupsen/logrus"
+	"github.com/Sirupsen/logrus"
 )
 
 var (
@@ -29,7 +29,7 @@ type v0session struct {
 	permChecker   permChecker
 	subscriptions []v0subscribe
 	lastMsgID     uint64
-	log           *log.Entry
+	log           *logrus.Entry
 	mtx           sync.Mutex
 	setupOnce     sync.Once
 }

commit a6d6a57a908b1cac8ebcc5bc4261b7c906d249a4
Author: Tom Clegg <tom at curoverse.com>
Date:   Thu Nov 17 15:23:01 2016 -0500

    8460: Reply to unparsable messages with status:400.

diff --git a/services/ws/handler.go b/services/ws/handler.go
index 3d42b9a..09ab945 100644
--- a/services/ws/handler.go
+++ b/services/ws/handler.go
@@ -1,7 +1,6 @@
 package main
 
 import (
-	"encoding/json"
 	"io"
 	"time"
 
@@ -61,14 +60,11 @@ func (h *handler) Handle(ws wsConn, incoming <-chan *event) (stats handlerStats)
 				stop <- err
 				return
 			}
-			msg := make(map[string]interface{})
-			err = json.Unmarshal(buf, &msg)
+			err = sess.Receive(buf)
 			if err != nil {
-				log.WithError(err).Info("invalid json from client")
 				stop <- err
 				return
 			}
-			sess.Receive(msg, buf)
 		}
 	}()
 
diff --git a/services/ws/session.go b/services/ws/session.go
index 9c3cef1..d469737 100644
--- a/services/ws/session.go
+++ b/services/ws/session.go
@@ -1,8 +1,10 @@
 package main
 
 type session interface {
-	// Receive processes a message received from the client.
-	Receive(map[string]interface{}, []byte)
+	// Receive processes a message received from the client. If a
+	// non-nil error is returned, the connection will be
+	// terminated.
+	Receive([]byte) error
 
 	// Filter returns true if the event should be queued for
 	// sending to the client. It should return as fast as
diff --git a/services/ws/session_v0.go b/services/ws/session_v0.go
index 4143282..0fd5003 100644
--- a/services/ws/session_v0.go
+++ b/services/ws/session_v0.go
@@ -55,14 +55,11 @@ func NewSessionV0(ws wsConn, sendq chan<- interface{}, ac arvados.Client, db *sq
 	return sess, nil
 }
 
-func (sess *v0session) Receive(msg map[string]interface{}, buf []byte) {
-	sess.log.WithField("data", msg).Debug("received message")
+func (sess *v0session) Receive(buf []byte) error {
 	var sub v0subscribe
 	if err := json.Unmarshal(buf, &sub); err != nil {
-		sess.log.WithError(err).Info("ignored invalid request")
-		return
-	}
-	if sub.Method == "subscribe" {
+		sess.log.WithError(err).Info("invalid message from client")
+	} else if sub.Method == "subscribe" {
 		sub.prepare(sess)
 		sess.log.WithField("sub", sub).Debug("sub prepared")
 		sess.sendq <- v0subscribeOK
@@ -70,9 +67,12 @@ func (sess *v0session) Receive(msg map[string]interface{}, buf []byte) {
 		sess.subscriptions = append(sess.subscriptions, sub)
 		sess.mtx.Unlock()
 		sub.sendOldEvents(sess)
-		return
+		return nil
+	} else {
+		sess.log.WithField("Method", sub.Method).Info("unknown method")
 	}
 	sess.sendq <- v0subscribeFail
+	return nil
 }
 
 func (sess *v0session) EventMessage(e *event) ([]byte, error) {

commit 259252b7b9418c931e59d67257e50632c83261c5
Author: Tom Clegg <tom at curoverse.com>
Date:   Thu Nov 17 15:10:56 2016 -0500

    8460: Stop existing nginx server, if any, before starting new.

diff --git a/sdk/python/tests/run_test_server.py b/sdk/python/tests/run_test_server.py
index bd37daa..75b4f4d 100644
--- a/sdk/python/tests/run_test_server.py
+++ b/sdk/python/tests/run_test_server.py
@@ -585,6 +585,7 @@ def stop_keep_web():
 def run_nginx():
     if 'ARVADOS_TEST_PROXY_SERVICES' in os.environ:
         return
+    stop_nginx()
     nginxconf = {}
     nginxconf['KEEPWEBPORT'] = _getport('keep-web')
     nginxconf['KEEPWEBDLSSLPORT'] = find_available_port()

-----------------------------------------------------------------------


hooks/post-receive
-- 




More information about the arvados-commits mailing list