[ARVADOS] created: 2.1.0-2166-g382074344

Git user git at public.arvados.org
Mon Mar 28 14:34:14 UTC 2022


        at  382074344ae9cae97739ec333203a7c688fbc5f3 (commit)


commit 382074344ae9cae97739ec333203a7c688fbc5f3
Author: Ward Vandewege <ward at curii.com>
Date:   Mon Mar 28 10:14:09 2022 -0400

    18896: review feedback, un-pyramid the logrus.Fields update.
    
    Arvados-DCO-1.1-Signed-off-by: Ward Vandewege <ward at curii.com>

diff --git a/sdk/go/httpserver/logger.go b/sdk/go/httpserver/logger.go
index ef2ec4170..5a46635e9 100644
--- a/sdk/go/httpserver/logger.go
+++ b/sdk/go/httpserver/logger.go
@@ -68,18 +68,15 @@ func HandlerWithDeadline(timeout time.Duration, next http.Handler) http.Handler
 }
 
 func SetResponseLogFields(ctx context.Context, fields logrus.Fields) {
-	m := ctx.Value(&mutexContextKey)
-	if mutex, ok := m.(sync.Mutex); ok {
-		mutex.Lock()
-		defer mutex.Unlock()
-		ctxfields := ctx.Value(&responseLogFieldsContextKey)
-		if c, ok := ctxfields.(logrus.Fields); ok {
-			for k, v := range fields {
-				c[k] = v
-			}
-		}
-	} else {
-		// We can't lock, don't set the fields
+	m, _ := ctx.Value(&mutexContextKey).(*sync.Mutex)
+	c, _ := ctx.Value(&responseLogFieldsContextKey).(logrus.Fields)
+	if m == nil || c == nil {
+		return
+	}
+	m.Lock()
+	defer m.Unlock()
+	for k, v := range fields {
+		c[k] = v
 	}
 }
 
@@ -101,7 +98,7 @@ func LogRequests(h http.Handler) http.Handler {
 		ctx := req.Context()
 		ctx = context.WithValue(ctx, &requestTimeContextKey, time.Now())
 		ctx = context.WithValue(ctx, &responseLogFieldsContextKey, logrus.Fields{})
-		ctx = context.WithValue(ctx, &mutexContextKey, sync.Mutex{})
+		ctx = context.WithValue(ctx, &mutexContextKey, &sync.Mutex{})
 		ctx = ctxlog.Context(ctx, lgr)
 		req = req.WithContext(ctx)
 

commit 8f0f3b495d0c715cc57d0d384bc5839acf9ece3f
Author: Ward Vandewege <ward at curii.com>
Date:   Fri Mar 25 16:37:28 2022 -0400

    18896: add locking. Also handle v1 tokens shorter than 5 characters.
    
    Arvados-DCO-1.1-Signed-off-by: Ward Vandewege <ward at curii.com>

diff --git a/lib/controller/router/router.go b/lib/controller/router/router.go
index e42d9a555..05bdb4754 100644
--- a/lib/controller/router/router.go
+++ b/lib/controller/router/router.go
@@ -597,7 +597,11 @@ func (rtr *router) addRoute(endpoint arvados.APIEndpoint, defaultOpts func() int
 					tokenUUIDs = append(tokenUUIDs, tokenParts[1])
 				}
 			} else {
-				tokenUUIDs = append(tokenUUIDs, "v1 token ending in "+t[len(t)-5:])
+				end := t
+				if len(t) > 5 {
+					end = t[len(t)-5:]
+				}
+				tokenUUIDs = append(tokenUUIDs, "v1 token ending in "+end)
 			}
 		}
 		httpserver.SetResponseLogFields(req.Context(), logrus.Fields{"tokenUUIDs": tokenUUIDs})
diff --git a/sdk/go/httpserver/logger.go b/sdk/go/httpserver/logger.go
index 437429611..ef2ec4170 100644
--- a/sdk/go/httpserver/logger.go
+++ b/sdk/go/httpserver/logger.go
@@ -9,6 +9,7 @@ import (
 	"context"
 	"net"
 	"net/http"
+	"sync"
 	"time"
 
 	"git.arvados.org/arvados.git/sdk/go/ctxlog"
@@ -23,6 +24,7 @@ type contextKey struct {
 var (
 	requestTimeContextKey       = contextKey{"requestTime"}
 	responseLogFieldsContextKey = contextKey{"responseLogFields"}
+	mutexContextKey             = contextKey{"mutex"}
 )
 
 type hijacker interface {
@@ -66,11 +68,18 @@ func HandlerWithDeadline(timeout time.Duration, next http.Handler) http.Handler
 }
 
 func SetResponseLogFields(ctx context.Context, fields logrus.Fields) {
-	ctxfields := ctx.Value(&responseLogFieldsContextKey)
-	if c, ok := ctxfields.(logrus.Fields); ok {
-		for k, v := range fields {
-			c[k] = v
+	m := ctx.Value(&mutexContextKey)
+	if mutex, ok := m.(sync.Mutex); ok {
+		mutex.Lock()
+		defer mutex.Unlock()
+		ctxfields := ctx.Value(&responseLogFieldsContextKey)
+		if c, ok := ctxfields.(logrus.Fields); ok {
+			for k, v := range fields {
+				c[k] = v
+			}
 		}
+	} else {
+		// We can't lock, don't set the fields
 	}
 }
 
@@ -92,6 +101,7 @@ func LogRequests(h http.Handler) http.Handler {
 		ctx := req.Context()
 		ctx = context.WithValue(ctx, &requestTimeContextKey, time.Now())
 		ctx = context.WithValue(ctx, &responseLogFieldsContextKey, logrus.Fields{})
+		ctx = context.WithValue(ctx, &mutexContextKey, sync.Mutex{})
 		ctx = ctxlog.Context(ctx, lgr)
 		req = req.WithContext(ctx)
 

commit 15661585c028bedf752603b37cab07746209c3cc
Author: Ward Vandewege <ward at curii.com>
Date:   Fri Mar 25 07:58:48 2022 -0400

    18896: controller logs the UUIDs of the tokens used in each request.
    
    Arvados-DCO-1.1-Signed-off-by: Ward Vandewege <ward at curii.com>

diff --git a/lib/controller/router/router.go b/lib/controller/router/router.go
index 2cfcc4fc2..e42d9a555 100644
--- a/lib/controller/router/router.go
+++ b/lib/controller/router/router.go
@@ -588,6 +588,19 @@ func (rtr *router) addRoute(endpoint arvados.APIEndpoint, defaultOpts func() int
 			"apiOptsType": fmt.Sprintf("%T", opts),
 			"apiOpts":     opts,
 		}).Debug("exec")
+		// Extract the token UUIDs (or a placeholder for v1 tokens)
+		var tokenUUIDs []string
+		for _, t := range creds.Tokens {
+			if strings.HasPrefix(t, "v2/") {
+				tokenParts := strings.Split(t, "/")
+				if len(tokenParts) >= 3 {
+					tokenUUIDs = append(tokenUUIDs, tokenParts[1])
+				}
+			} else {
+				tokenUUIDs = append(tokenUUIDs, "v1 token ending in "+t[len(t)-5:])
+			}
+		}
+		httpserver.SetResponseLogFields(req.Context(), logrus.Fields{"tokenUUIDs": tokenUUIDs})
 		resp, err := exec(ctx, opts)
 		if err != nil {
 			logger.WithError(err).Debugf("returning error type %T", err)
diff --git a/sdk/go/httpserver/logger.go b/sdk/go/httpserver/logger.go
index 7eb7f0f03..437429611 100644
--- a/sdk/go/httpserver/logger.go
+++ b/sdk/go/httpserver/logger.go
@@ -21,7 +21,8 @@ type contextKey struct {
 }
 
 var (
-	requestTimeContextKey = contextKey{"requestTime"}
+	requestTimeContextKey       = contextKey{"requestTime"}
+	responseLogFieldsContextKey = contextKey{"responseLogFields"}
 )
 
 type hijacker interface {
@@ -64,6 +65,15 @@ func HandlerWithDeadline(timeout time.Duration, next http.Handler) http.Handler
 	})
 }
 
+func SetResponseLogFields(ctx context.Context, fields logrus.Fields) {
+	ctxfields := ctx.Value(&responseLogFieldsContextKey)
+	if c, ok := ctxfields.(logrus.Fields); ok {
+		for k, v := range fields {
+			c[k] = v
+		}
+	}
+}
+
 // LogRequests wraps an http.Handler, logging each request and
 // response.
 func LogRequests(h http.Handler) http.Handler {
@@ -81,6 +91,7 @@ func LogRequests(h http.Handler) http.Handler {
 		})
 		ctx := req.Context()
 		ctx = context.WithValue(ctx, &requestTimeContextKey, time.Now())
+		ctx = context.WithValue(ctx, &responseLogFieldsContextKey, logrus.Fields{})
 		ctx = ctxlog.Context(ctx, lgr)
 		req = req.WithContext(ctx)
 
@@ -124,6 +135,9 @@ func logResponse(w *responseTimer, req *http.Request, lgr *logrus.Entry) {
 			"timeWriteBody": stats.Duration(tDone.Sub(writeTime)),
 		})
 	}
+	if responseLogFields, ok := req.Context().Value(&responseLogFieldsContextKey).(logrus.Fields); ok {
+		lgr = lgr.WithFields(responseLogFields)
+	}
 	respCode := w.WroteStatus()
 	if respCode == 0 {
 		respCode = http.StatusOK

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


hooks/post-receive
-- 




More information about the arvados-commits mailing list