Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refine gateway and namesys logging #4428

Merged
merged 2 commits into from
Dec 7, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 3 additions & 6 deletions core/corehttp/gateway_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,6 @@ func (i *gatewayHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
errmsg = errmsg + "bad request for " + r.URL.Path
}
fmt.Fprint(w, errmsg)
log.Error(errmsg) // TODO(cryptix): log errors until we have a better way to expose these (counter metrics maybe)
}

func (i *gatewayHandler) optionsHandler(w http.ResponseWriter, r *http.Request) {
Expand Down Expand Up @@ -287,14 +286,11 @@ func (i *gatewayHandler) getOrHeadHandler(ctx context.Context, w http.ResponseWr
ixnd, err := dirr.Find(ctx, "index.html")
switch {
case err == nil:
log.Debugf("found index.html link for %s", escapedURLPath)

dirwithoutslash := urlPath[len(urlPath)-1] != '/'
goget := r.URL.Query().Get("go-get") == "1"
if dirwithoutslash && !goget {
// See comment above where originalUrlPath is declared.
http.Redirect(w, r, originalUrlPath+"/", 302)
log.Debugf("redirect to %s", originalUrlPath+"/")
return
}

Expand Down Expand Up @@ -510,7 +506,6 @@ func (i *gatewayHandler) putHandler(w http.ResponseWriter, r *http.Request) {
return
}
default:
log.Warningf("putHandler: unhandled resolve error %T", ev)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this is a user error, we shouldn't be returning a 502. If it is, we should log it.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mh yes indeed - I'll cover this in the upcoming gateway+coreapi PR.

webError(w, "could not resolve root DAG", ev, http.StatusInternalServerError)
return
}
Expand Down Expand Up @@ -618,8 +613,10 @@ func webError(w http.ResponseWriter, message string, err error, defaultCode int)
func webErrorWithCode(w http.ResponseWriter, message string, err error, code int) {
w.WriteHeader(code)

log.Errorf("%s: %s", message, err) // TODO(cryptix): log until we have a better way to expose these (counter metrics maybe)
fmt.Fprintf(w, "%s: %s\n", message, err)
if code >= 500 {
log.Warningf("server error: %s: %s", err)
}
}

// return a 500 error and log
Expand Down
3 changes: 1 addition & 2 deletions namesys/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,9 @@ func resolve(ctx context.Context, r resolver, name string, depth int, prefixes .
for {
p, err := r.resolveOnce(ctx, name)
if err != nil {
log.Warningf("Could not resolve %s", name)
return "", err
}
log.Debugf("Resolved %s to %s", name, p.String())
log.Debugf("resolved %s to %s", name, p.String())

if strings.HasPrefix(p.String(), "/ipfs/") {
// we've bottomed out with an IPFS path
Expand Down
2 changes: 1 addition & 1 deletion namesys/dns.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func (r *DNSResolver) resolveOnce(ctx context.Context, name string) (path.Path,
if !isd.IsDomain(domain) {
return "", errors.New("not a valid domain name")
}
log.Infof("DNSResolver resolving %s", domain)
log.Debugf("DNSResolver resolving %s", domain)

rootChan := make(chan lookupRes, 1)
go workDomain(r, domain, rootChan)
Expand Down
4 changes: 2 additions & 2 deletions namesys/namesys.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ func (ns *mpns) resolveOnce(ctx context.Context, name string) (path.Path, error)
}
segments := strings.SplitN(name, "/", 4)
if len(segments) < 3 || segments[0] != "" {
log.Warningf("Invalid name syntax for %s", name)
log.Debugf("invalid name syntax for %s", name)
return "", ErrResolveFailed
}

Expand Down Expand Up @@ -153,7 +153,7 @@ func (ns *mpns) resolveOnce(ctx context.Context, name string) (path.Path, error)
return "", ErrResolveFailed
}

log.Warningf("No resolver found for %s", name)
log.Debugf("no resolver found for %s", name)
return "", ErrResolveFailed
}

Expand Down
10 changes: 5 additions & 5 deletions namesys/routing.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ func (r *routingResolver) ResolveN(ctx context.Context, name string, depth int)
// resolveOnce implements resolver. Uses the IPFS routing system to
// resolve SFS-like names.
func (r *routingResolver) resolveOnce(ctx context.Context, name string) (path.Path, error) {
log.Debugf("RoutingResolve: '%s'", name)
log.Debugf("RoutingResolver resolving %s", name)
cached, ok := r.cacheGet(name)
if ok {
return cached, nil
Expand All @@ -127,7 +127,7 @@ func (r *routingResolver) resolveOnce(ctx context.Context, name string) (path.Pa
hash, err := mh.FromB58String(name)
if err != nil {
// name should be a multihash. if it isn't, error out here.
log.Warningf("RoutingResolve: bad input hash: [%s]\n", name)
log.Debugf("RoutingResolver: bad input hash: [%s]\n", name)
return "", err
}

Expand All @@ -143,7 +143,7 @@ func (r *routingResolver) resolveOnce(ctx context.Context, name string) (path.Pa
ipnsKey := string(h)
val, err := r.routing.GetValue(ctx, ipnsKey)
if err != nil {
log.Warning("RoutingResolve get failed.")
log.Debugf("RoutingResolver: dht get failed: %s", err)
resp <- err
return
}
Expand Down Expand Up @@ -179,7 +179,7 @@ func (r *routingResolver) resolveOnce(ctx context.Context, name string) (path.Pa

// check sig with pk
if ok, err := pubkey.Verify(ipnsEntryDataForSig(entry), entry.GetSignature()); err != nil || !ok {
return "", fmt.Errorf("Invalid value. Not signed by PrivateKey corresponding to %v", pubkey)
return "", fmt.Errorf("ipns entry for %s has invalid signature", h)
}

// ok sig checks out. this is a valid name.
Expand All @@ -197,7 +197,7 @@ func (r *routingResolver) resolveOnce(ctx context.Context, name string) (path.Pa
return p, nil
} else {
// Its an old style multihash record
log.Warning("Detected old style multihash record")
log.Debugf("encountered CIDv0 ipns entry: %s", h)
p := path.FromCid(cid.NewCidV0(valh))
r.cacheSet(name, p, entry)
return p, nil
Expand Down