[ARVADOS] updated: b94b54c25a57a26925eaf739dcf59a4ff94238ae
Git user
git at public.curoverse.com
Thu Dec 15 11:34:21 EST 2016
Summary of changes:
sdk/go/arvados/client.go | 2 +-
{services/ws => sdk/go/ctxlog}/log.go | 27 ++++++++++++++++-----------
sdk/python/tests/run_test_server.py | 5 ++++-
services/api/config/application.default.yml | 2 ++
services/ws/doc.go | 6 ++++++
services/ws/handler.go | 5 +++++
services/ws/main.go | 6 +++++-
services/ws/router.go | 3 ++-
services/ws/session_v0.go | 3 +++
services/ws/session_v1.go | 2 ++
10 files changed, 46 insertions(+), 15 deletions(-)
rename {services/ws => sdk/go/ctxlog}/log.go (55%)
via b94b54c25a57a26925eaf739dcf59a4ff94238ae (commit)
via 18c3e601c065e5afd526b29e214b497fad04ce32 (commit)
via 0b898bf7c9337ac0f2385159329d2f3e6a1694ec (commit)
from 62d8f575a93374a235097b88499fa65eef2f56ec (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 b94b54c25a57a26925eaf739dcf59a4ff94238ae
Author: Tom Clegg <tom at curoverse.com>
Date: Thu Dec 15 11:29:50 2016 -0500
8460: Use new ws server for integration tests only if ARVADOS_TEST_EXPERIMENTAL_WS is set.
diff --git a/sdk/python/tests/run_test_server.py b/sdk/python/tests/run_test_server.py
index 75b4f4d..b969b12 100644
--- a/sdk/python/tests/run_test_server.py
+++ b/sdk/python/tests/run_test_server.py
@@ -294,7 +294,10 @@ def run(leave_running_atexit=False):
env = os.environ.copy()
env['RAILS_ENV'] = 'test'
env['ARVADOS_TEST_WSS_PORT'] = str(wss_port)
- env.pop('ARVADOS_WEBSOCKETS', None)
+ if env.get('ARVADOS_TEST_EXPERIMENTAL_WS'):
+ env.pop('ARVADOS_WEBSOCKETS', None)
+ else:
+ env['ARVADOS_WEBSOCKETS'] = 'yes'
env.pop('ARVADOS_TEST_API_HOST', None)
env.pop('ARVADOS_API_HOST', None)
env.pop('ARVADOS_API_HOST_INSECURE', None)
diff --git a/services/api/config/application.default.yml b/services/api/config/application.default.yml
index ab560d7..b2a1602 100644
--- a/services/api/config/application.default.yml
+++ b/services/api/config/application.default.yml
@@ -444,4 +444,6 @@ test:
workbench_address: https://localhost:3001/
git_repositories_dir: <%= Rails.root.join 'tmp', 'git', 'test' %>
git_internal_dir: <%= Rails.root.join 'tmp', 'internal.git' %>
+ <% if ENV['ARVADOS_TEST_EXPERIMENTAL_WS'] %>
websocket_address: "wss://0.0.0.0:<%= ENV['ARVADOS_TEST_WSS_PORT'] %>/websocket"
+ <% end %>
commit 18c3e601c065e5afd526b29e214b497fad04ce32
Author: Tom Clegg <tom at curoverse.com>
Date: Thu Dec 15 11:08:37 2016 -0500
8460: Move context-aware-logger code to ctxlog pkg.
diff --git a/services/ws/log.go b/sdk/go/ctxlog/log.go
similarity index 55%
rename from services/ws/log.go
rename to sdk/go/ctxlog/log.go
index 1fbfbad..6565c88 100644
--- a/services/ws/log.go
+++ b/sdk/go/ctxlog/log.go
@@ -1,4 +1,4 @@
-package main
+package ctxlog
import (
"context"
@@ -13,16 +13,16 @@ var (
const rfc3339NanoFixed = "2006-01-02T15:04:05.000000000Z07:00"
-// contextWithLogger returns a new child context such that
-// logger(child) returns the given logger.
-func contextWithLogger(ctx context.Context, logger *logrus.Entry) context.Context {
+// Context returns a new child context such that FromContext(child)
+// returns the given logger.
+func Context(ctx context.Context, logger *logrus.Entry) context.Context {
return context.WithValue(ctx, loggerCtxKey, logger)
}
-// logger returns the logger suitable for the given context -- the one
+// FromContext returns the logger suitable for the given context -- the one
// attached by contextWithLogger() if applicable, otherwise the
// top-level logger with no fields/values.
-func logger(ctx context.Context) *logrus.Entry {
+func FromContext(ctx context.Context) *logrus.Entry {
if ctx != nil {
if logger, ok := ctx.Value(loggerCtxKey).(*logrus.Entry); ok {
return logger
@@ -31,14 +31,19 @@ func logger(ctx context.Context) *logrus.Entry {
return rootLogger.WithFields(nil)
}
-// loggerConfig sets up logging to behave as configured.
-func loggerConfig(cfg wsConfig) {
- lvl, err := logrus.ParseLevel(cfg.LogLevel)
+// SetLevel sets the current logging level. See logrus for level
+// names.
+func SetLevel(level string) {
+ lvl, err := logrus.ParseLevel(level)
if err != nil {
logrus.Fatal(err)
}
rootLogger.Level = lvl
- switch cfg.LogFormat {
+}
+
+// SetFormat sets the current logging format to "json" or "text".
+func SetFormat(format string) {
+ switch format {
case "text":
rootLogger.Formatter = &logrus.TextFormatter{
FullTimestamp: true,
@@ -49,6 +54,6 @@ func loggerConfig(cfg wsConfig) {
TimestampFormat: rfc3339NanoFixed,
}
default:
- logrus.WithField("LogFormat", cfg.LogFormat).Fatal("unknown log format")
+ logrus.WithField("LogFormat", format).Fatal("unknown log format")
}
}
diff --git a/services/ws/main.go b/services/ws/main.go
index 77ebf9e..7c3625b 100644
--- a/services/ws/main.go
+++ b/services/ws/main.go
@@ -7,9 +7,12 @@ import (
"time"
"git.curoverse.com/arvados.git/sdk/go/config"
+ "git.curoverse.com/arvados.git/sdk/go/ctxlog"
"github.com/coreos/go-systemd/daemon"
)
+var logger = ctxlog.FromContext
+
func main() {
log := logger(nil)
@@ -23,7 +26,8 @@ func main() {
log.Fatal(err)
}
- loggerConfig(cfg)
+ ctxlog.SetLevel(cfg.LogLevel)
+ ctxlog.SetFormat(cfg.LogFormat)
if *dumpConfig {
txt, err := config.Dump(&cfg)
diff --git a/services/ws/router.go b/services/ws/router.go
index 0420745..15b825f 100644
--- a/services/ws/router.go
+++ b/services/ws/router.go
@@ -9,6 +9,7 @@ import (
"sync/atomic"
"time"
+ "git.curoverse.com/arvados.git/sdk/go/ctxlog"
"github.com/Sirupsen/logrus"
"golang.org/x/net/websocket"
)
@@ -115,7 +116,7 @@ func (rtr *router) ServeHTTP(resp http.ResponseWriter, req *http.Request) {
logger := logger(req.Context()).
WithField("RequestID", rtr.newReqID())
- ctx := contextWithLogger(req.Context(), logger)
+ ctx := ctxlog.Context(req.Context(), logger)
req = req.WithContext(ctx)
logger.WithFields(logrus.Fields{
"remoteAddr": req.RemoteAddr,
commit 0b898bf7c9337ac0f2385159329d2f3e6a1694ec
Author: Tom Clegg <tom at curoverse.com>
Date: Thu Dec 15 10:40:43 2016 -0500
8460: Add some docs/comments.
diff --git a/sdk/go/arvados/client.go b/sdk/go/arvados/client.go
index a7d8c4a..fc93749 100644
--- a/sdk/go/arvados/client.go
+++ b/sdk/go/arvados/client.go
@@ -254,7 +254,7 @@ func (c *Client) modelForUUID(dd *DiscoveryDocument, uuid string) (string, error
}
}
if model == "" {
- return "", fmt.Errorf("unrecognized UUID infix: %q", infix)
+ return "", fmt.Errorf("unrecognized type portion %q in UUID %q", infix, uuid)
}
return model, nil
}
diff --git a/services/ws/doc.go b/services/ws/doc.go
index c2d3187..7ccb588 100644
--- a/services/ws/doc.go
+++ b/services/ws/doc.go
@@ -2,8 +2,14 @@
// cache-invalidation event feed at "ws://.../websocket") to
// websocket clients.
//
+// Installation
+//
// See https://doc.arvados.org/install/install-ws.html.
//
+// Developer info
+//
+// See https://dev.arvados.org/projects/arvados/wiki/Hacking_websocket_server.
+//
// Usage
//
// arvados-ws [-config /etc/arvados/ws/ws.yml] [-dump-config]
diff --git a/services/ws/handler.go b/services/ws/handler.go
index b07b78c..7229190 100644
--- a/services/ws/handler.go
+++ b/services/ws/handler.go
@@ -53,6 +53,8 @@ func (h *handler) Handle(ws wsConn, eventSource eventSource, newSession func(wsC
return
}
+ // Receive websocket frames from the client and pass them to
+ // sess.Receive().
go func() {
buf := make([]byte, 2<<20)
for {
@@ -84,6 +86,9 @@ func (h *handler) Handle(ws wsConn, eventSource eventSource, newSession func(wsC
}
}()
+ // Take items from the outgoing queue, serialize them using
+ // sess.EventMessage() as needed, and send them to the client
+ // as websocket frames.
go func() {
for {
var ok bool
diff --git a/services/ws/session_v0.go b/services/ws/session_v0.go
index 364555a..44e2a1d 100644
--- a/services/ws/session_v0.go
+++ b/services/ws/session_v0.go
@@ -35,6 +35,9 @@ type v0session struct {
setupOnce sync.Once
}
+// newSessionV0 returns a v0 session: a partial port of the Rails/puma
+// implementation, with just enough functionality to support Workbench
+// and arv-mount.
func newSessionV0(ws wsConn, sendq chan<- interface{}, db *sql.DB, pc permChecker, ac *arvados.Client) (session, error) {
sess := &v0session{
sendq: sendq,
diff --git a/services/ws/session_v1.go b/services/ws/session_v1.go
index f773f18..71a1303 100644
--- a/services/ws/session_v1.go
+++ b/services/ws/session_v1.go
@@ -7,6 +7,8 @@ import (
"git.curoverse.com/arvados.git/sdk/go/arvados"
)
+// newSessionV1 returns a v1 session -- see
+// https://dev.arvados.org/projects/arvados/wiki/Websocket_server
func newSessionV1(ws wsConn, sendq chan<- interface{}, db *sql.DB, pc permChecker, ac *arvados.Client) (session, error) {
return nil, errors.New("Not implemented")
}
-----------------------------------------------------------------------
hooks/post-receive
--
More information about the arvados-commits
mailing list