-
Notifications
You must be signed in to change notification settings - Fork 110
api,client,http,main,prod,storage: Add query param for publisher and solve flooding in recovery #2202
api,client,http,main,prod,storage: Add query param for publisher and solve flooding in recovery #2202
Changes from 4 commits
540187d
0463f7a
0e8b18e
ca488fd
f5236ec
754739b
0787628
f1b0fbf
e25597e
6a9a30a
d5d3de9
19edb39
aecc382
41cfbe5
688122a
79f3867
5e57f81
3494897
6cc23bf
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,6 +23,7 @@ import ( | |
"bytes" | ||
"context" | ||
"encoding/json" | ||
"errors" | ||
"fmt" | ||
"io" | ||
"io/ioutil" | ||
|
@@ -52,28 +53,29 @@ import ( | |
) | ||
|
||
var ( | ||
postRawCount = metrics.NewRegisteredCounter("api/http/post/raw/count", nil) | ||
postRawFail = metrics.NewRegisteredCounter("api/http/post/raw/fail", nil) | ||
postFilesCount = metrics.NewRegisteredCounter("api/http/post/files/count", nil) | ||
postFilesFail = metrics.NewRegisteredCounter("api/http/post/files/fail", nil) | ||
deleteCount = metrics.NewRegisteredCounter("api/http/delete/count", nil) | ||
deleteFail = metrics.NewRegisteredCounter("api/http/delete/fail", nil) | ||
getCount = metrics.NewRegisteredCounter("api/http/get/count", nil) | ||
getFail = metrics.NewRegisteredCounter("api/http/get/fail", nil) | ||
getFileCount = metrics.NewRegisteredCounter("api/http/get/file/count", nil) | ||
getFileNotFound = metrics.NewRegisteredCounter("api/http/get/file/notfound", nil) | ||
getFileFail = metrics.NewRegisteredCounter("api/http/get/file/fail", nil) | ||
getListCount = metrics.NewRegisteredCounter("api/http/get/list/count", nil) | ||
getListFail = metrics.NewRegisteredCounter("api/http/get/list/fail", nil) | ||
getTagCount = metrics.NewRegisteredCounter("api/http/get/tag/count", nil) | ||
getTagNotFound = metrics.NewRegisteredCounter("api/http/get/tag/notfound", nil) | ||
getTagFail = metrics.NewRegisteredCounter("api/http/get/tag/fail", nil) | ||
getPinCount = metrics.NewRegisteredCounter("api/http/get/pin/count", nil) | ||
getPinFail = metrics.NewRegisteredCounter("api/http/get/pin/fail", nil) | ||
postPinCount = metrics.NewRegisteredCounter("api/http/post/pin/count", nil) | ||
postPinFail = metrics.NewRegisteredCounter("api/http/post/pin/fail", nil) | ||
deletePinCount = metrics.NewRegisteredCounter("api/http/delete/pin/count", nil) | ||
deletePinFail = metrics.NewRegisteredCounter("api/http/delete/pin/fail", nil) | ||
postRawCount = metrics.NewRegisteredCounter("api/http/post/raw/count", nil) | ||
postRawFail = metrics.NewRegisteredCounter("api/http/post/raw/fail", nil) | ||
postFilesCount = metrics.NewRegisteredCounter("api/http/post/files/count", nil) | ||
postFilesFail = metrics.NewRegisteredCounter("api/http/post/files/fail", nil) | ||
deleteCount = metrics.NewRegisteredCounter("api/http/delete/count", nil) | ||
deleteFail = metrics.NewRegisteredCounter("api/http/delete/fail", nil) | ||
getCount = metrics.NewRegisteredCounter("api/http/get/count", nil) | ||
getFail = metrics.NewRegisteredCounter("api/http/get/fail", nil) | ||
getFileCount = metrics.NewRegisteredCounter("api/http/get/file/count", nil) | ||
getFileNotFound = metrics.NewRegisteredCounter("api/http/get/file/notfound", nil) | ||
getFileFail = metrics.NewRegisteredCounter("api/http/get/file/fail", nil) | ||
getListCount = metrics.NewRegisteredCounter("api/http/get/list/count", nil) | ||
getListFail = metrics.NewRegisteredCounter("api/http/get/list/fail", nil) | ||
getTagCount = metrics.NewRegisteredCounter("api/http/get/tag/count", nil) | ||
getTagNotFound = metrics.NewRegisteredCounter("api/http/get/tag/notfound", nil) | ||
getTagFail = metrics.NewRegisteredCounter("api/http/get/tag/fail", nil) | ||
getPinCount = metrics.NewRegisteredCounter("api/http/get/pin/count", nil) | ||
getPinFail = metrics.NewRegisteredCounter("api/http/get/pin/fail", nil) | ||
postPinCount = metrics.NewRegisteredCounter("api/http/post/pin/count", nil) | ||
postPinFail = metrics.NewRegisteredCounter("api/http/post/pin/fail", nil) | ||
deletePinCount = metrics.NewRegisteredCounter("api/http/delete/pin/count", nil) | ||
deletePinFail = metrics.NewRegisteredCounter("api/http/delete/pin/fail", nil) | ||
errRecoveryAttempt = errors.New("recovery was initiated") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. define this in netstore once There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was worried about circular dependency, moved it.
mortelli marked this conversation as resolved.
Show resolved
Hide resolved
|
||
) | ||
|
||
const ( | ||
|
@@ -252,6 +254,11 @@ func (s *Server) HandleBzzGet(w http.ResponseWriter, r *http.Request) { | |
respondError(w, r, err.Error(), http.StatusUnauthorized) | ||
return | ||
} | ||
if isRecoveryAttemptError(err) { | ||
w.Header().Set("WWW-Authenticate", fmt.Sprintf("Basic realm=%q", uri.Address().String())) | ||
respondError(w, r, err.Error(), http.StatusPaymentRequired) | ||
mortelli marked this conversation as resolved.
Show resolved
Hide resolved
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. no i meant 420 not 402, you can just construct the response as:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. My bad, I was confused it did not make sense. |
||
return | ||
} | ||
respondError(w, r, fmt.Sprintf("Had an error building the tarball: %v", err), http.StatusInternalServerError) | ||
return | ||
} | ||
|
@@ -868,6 +875,11 @@ func (s *Server) HandleGetList(w http.ResponseWriter, r *http.Request) { | |
respondError(w, r, err.Error(), http.StatusUnauthorized) | ||
return | ||
} | ||
if isRecoveryAttemptError(err) { | ||
w.Header().Set("WWW-Authenticate", fmt.Sprintf("Basic realm=%q", uri.Address().String())) | ||
mortelli marked this conversation as resolved.
Show resolved
Hide resolved
|
||
respondError(w, r, err.Error(), http.StatusPaymentRequired) | ||
mortelli marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return | ||
} | ||
respondError(w, r, err.Error(), http.StatusInternalServerError) | ||
return | ||
} | ||
|
@@ -1177,3 +1189,7 @@ func (lrw *loggingResponseWriter) WriteHeader(code int) { | |
func isDecryptError(err error) bool { | ||
return strings.Contains(err.Error(), api.ErrDecrypt.Error()) | ||
} | ||
|
||
func isRecoveryAttemptError(err error) bool { | ||
return strings.Contains(err.Error(), errRecoveryAttempt.Error()) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -242,7 +242,6 @@ func readManifest(mr storage.LazySectionReader, addr storage.Address, fileStore | |
if err != nil { // size == 0 | ||
// can't determine size means we don't have the root chunk | ||
log.Trace("manifest not found", "addr", addr) | ||
err = fmt.Errorf("Manifest not Found") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. leaving a comment here mainly for @zelig: the in any case, i believe without line There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes exactly, the error code becomes Manifest not found and the error code is 500. |
||
return | ||
} | ||
if size > manifestSizeLimit { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -207,9 +207,8 @@ func (n *NetStore) Get(ctx context.Context, mode chunk.ModeGet, req *Request) (c | |
if err != nil { | ||
if n.recoveryCallback != nil && publisher != "" { | ||
log.Debug("content recovery callback triggered", "ref", ref.String()) | ||
n.recoveryCallback(ctx, ref) | ||
time.Sleep(500 * time.Millisecond) // TODO: view what the ideal timeout is | ||
return n.RemoteFetch(ctx, req, fi) | ||
go n.recoveryCallback(ctx, ref) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. based on some tests, we think it might be necessary to call the recovery callback with do you see any issues with this @zelig? |
||
return nil, errors.New("recovery was initiated") | ||
} | ||
return nil, err | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why not just
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I used
req.URL.Query().Add("publisher", publisher)
and the query param was not reaching the other side.I looked at other places of the code using Add/Set and it was encoding after adding it.
After changing it to
.Encode()
it works correctly.@mortelli saw the same thing