[ARVADOS] created: b25e164d6cfc0712be5856c63f7592145669232d

git at public.curoverse.com git at public.curoverse.com
Tue Sep 23 17:39:33 EDT 2014


        at  b25e164d6cfc0712be5856c63f7592145669232d (commit)


commit b25e164d6cfc0712be5856c63f7592145669232d
Author: Ward Vandewege <ward at curoverse.com>
Date:   Tue Sep 23 17:38:55 2014 -0400

    Make keepstore log normal operation with more detail, and follow the
    standard apache logging pattern.
    
    refs #3967

diff --git a/services/keepstore/handlers.go b/services/keepstore/handlers.go
index fde6087..c6b0351 100644
--- a/services/keepstore/handlers.go
+++ b/services/keepstore/handlers.go
@@ -110,8 +110,6 @@ func FindKeepVolumes() []string {
 func GetBlockHandler(resp http.ResponseWriter, req *http.Request) {
 	hash := mux.Vars(req)["hash"]
 
-	log.Printf("%s %s", req.Method, hash)
-
 	hints := mux.Vars(req)["hints"]
 
 	// Parse the locator string and hints from the request.
@@ -130,6 +128,7 @@ func GetBlockHandler(resp http.ResponseWriter, req *http.Request) {
 				// presumed to be valid and ignored, to permit forward compatibility.
 			} else {
 				// Unknown format; not a valid locator.
+				log.Printf("%s %s %d %s", req.Method, hash, BadRequestError.HTTPCode, "-")
 				http.Error(resp, BadRequestError.Error(), BadRequestError.HTTPCode)
 				return
 			}
@@ -140,14 +139,17 @@ func GetBlockHandler(resp http.ResponseWriter, req *http.Request) {
 	// request's permission signature.
 	if enforce_permissions {
 		if signature == "" || timestamp == "" {
+			log.Printf("%s %s %d %s", req.Method, hash, PermissionError.HTTPCode, "-")
 			http.Error(resp, PermissionError.Error(), PermissionError.HTTPCode)
 			return
 		} else if IsExpired(timestamp) {
+			log.Printf("%s %s %d %s", req.Method, hash, ExpiredError.HTTPCode, "-")
 			http.Error(resp, ExpiredError.Error(), ExpiredError.HTTPCode)
 			return
 		} else {
 			req_locator := req.URL.Path[1:] // strip leading slash
 			if !VerifySignature(req_locator, GetApiToken(req)) {
+				log.Printf("%s %s %d %s", req.Method, hash, PermissionError.HTTPCode, "-")
 				http.Error(resp, PermissionError.Error(), PermissionError.HTTPCode)
 				return
 			}
@@ -168,6 +170,7 @@ func GetBlockHandler(resp http.ResponseWriter, req *http.Request) {
 		if err == NotFoundError {
 			log.Printf("%s: not found, giving up\n", hash)
 		}
+		log.Printf("%s %s %d %s", req.Method, hash, err.(*KeepError).HTTPCode, "-")
 		http.Error(resp, err.Error(), err.(*KeepError).HTTPCode)
 		return
 	}
@@ -176,7 +179,9 @@ func GetBlockHandler(resp http.ResponseWriter, req *http.Request) {
 
 	_, err = resp.Write(block)
 	if err != nil {
-		log.Printf("GetBlockHandler: writing response: %s", err)
+		log.Printf("%s %s %d %s", req.Method, hash, err.(*KeepError).HTTPCode, len(block), "-")
+	} else {
+		log.Printf("%s %s %d %d", req.Method, hash, 200, len(block))
 	}
 
 	return
@@ -189,12 +194,11 @@ func PutBlockHandler(resp http.ResponseWriter, req *http.Request) {
 
 	hash := mux.Vars(req)["hash"]
 
-	log.Printf("%s %s", req.Method, hash)
-
 	// Read the block data to be stored.
 	// If the request exceeds BLOCKSIZE bytes, issue a HTTP 500 error.
 	//
 	if req.ContentLength > BLOCKSIZE {
+		log.Printf("%s %s %d %d", req.Method, hash, TooLongError.HTTPCode, req.ContentLength)
 		http.Error(resp, TooLongError.Error(), TooLongError.HTTPCode)
 		return
 	}
@@ -202,8 +206,10 @@ func PutBlockHandler(resp http.ResponseWriter, req *http.Request) {
 	buf := make([]byte, req.ContentLength)
 	nread, err := io.ReadFull(req.Body, buf)
 	if err != nil {
+		log.Printf("%s %s %d %d", req.Method, hash, 500, req.ContentLength)
 		http.Error(resp, err.Error(), 500)
 	} else if int64(nread) < req.ContentLength {
+		log.Printf("%s %s %d %d", req.Method, hash, 500, req.ContentLength)
 		http.Error(resp, "request truncated", 500)
 	} else {
 		if err := PutBlock(buf, hash); err == nil {
@@ -215,9 +221,11 @@ func PutBlockHandler(resp http.ResponseWriter, req *http.Request) {
 				expiry := time.Now().Add(permission_ttl)
 				return_hash = SignLocator(return_hash, api_token, expiry)
 			}
+			log.Printf("%s %s %d %d", req.Method, hash, 200, req.ContentLength)
 			resp.Write([]byte(return_hash + "\n"))
 		} else {
 			ke := err.(*KeepError)
+			log.Printf("%s %s %d %d", req.Method, hash, ke.HTTPCode, req.ContentLength)
 			http.Error(resp, ke.Error(), ke.HTTPCode)
 		}
 	}

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


hooks/post-receive
-- 




More information about the arvados-commits mailing list