From a23a9d826abcade2a90ea506bdf04371d57f1571 Mon Sep 17 00:00:00 2001 From: Anton Evangelatov Date: Thu, 15 Mar 2018 15:12:09 +0100 Subject: [PATCH] swarm/api: improved traces for manifest retrieval --- swarm/api/api.go | 10 +++++----- swarm/api/manifest.go | 13 +++++++------ 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/swarm/api/api.go b/swarm/api/api.go index aba4eeaf9f..a39f2556a8 100644 --- a/swarm/api/api.go +++ b/swarm/api/api.go @@ -308,6 +308,7 @@ func (self *Api) Put(content, contentType string) (k storage.Key, wait func(), e // to resolve basePath to content using dpa retrieve // it returns a section reader, mimeType, status and an error func (self *Api) Get(key storage.Key, path string) (reader storage.LazySectionReader, mimeType string, status int, err error) { + log.Debug("api.get", "key", key) apiGetCount.Inc(1) trie, err := loadManifest(self.dpa, key, nil) if err != nil { @@ -317,8 +318,7 @@ func (self *Api) Get(key storage.Key, path string) (reader storage.LazySectionRe return } - log.Trace(fmt.Sprintf("getEntry(%s)", path)) - + log.Trace("trie.getentry", "key", key, "path", path) entry, _ := trie.getEntry(path) if entry != nil { @@ -331,7 +331,7 @@ func (self *Api) Get(key storage.Key, path string) (reader storage.LazySectionRe // we return a typed error instead. Since for all other purposes this is an invalid manifest, // any normal interfacing code will just see an error fail accordingly. if entry.ContentType == ResourceContentType { - log.Warn("resource type", "hash", entry.Hash) + log.Warn("resource type", "key", key, "hash", entry.Hash) return nil, entry.ContentType, http.StatusOK, &ErrResourceReturn{entry.Hash} } key = common.Hex2Bytes(entry.Hash) @@ -341,14 +341,14 @@ func (self *Api) Get(key storage.Key, path string) (reader storage.LazySectionRe return } else { mimeType = entry.ContentType - log.Trace(fmt.Sprintf("content lookup key: '%v' (%v)", key, mimeType)) + log.Trace("content lookup key", "key", key, "mimetype", mimeType) reader = self.dpa.Retrieve(key) } } else { status = http.StatusNotFound apiGetNotFound.Inc(1) err = fmt.Errorf("manifest entry for '%s' not found", path) - log.Warn(fmt.Sprintf("%v", err)) + log.Trace("manifest entry not found", "key", key, "path", path) } return } diff --git a/swarm/api/manifest.go b/swarm/api/manifest.go index cd9444a321..787df1764a 100644 --- a/swarm/api/manifest.go +++ b/swarm/api/manifest.go @@ -201,10 +201,10 @@ type manifestTrieEntry struct { } func loadManifest(dpa *storage.DPA, hash storage.Key, quitC chan bool) (trie *manifestTrie, err error) { // non-recursive, subtrees are downloaded on-demand - - log.Trace(fmt.Sprintf("manifest lookup key: '%v'.", hash.Log())) + log.Trace("manifest lookup", "key", hash) // retrieve manifest via DPA manifestReader := dpa.Retrieve(hash) + log.Trace("reader retrieved", "key", hash) return readManifest(manifestReader, hash, dpa, quitC) } @@ -214,31 +214,32 @@ func readManifest(manifestReader storage.LazySectionReader, hash storage.Key, dp size, err := manifestReader.Size(quitC) if err != nil { // size == 0 // can't determine size means we don't have the root chunk + log.Trace("manifest not found", "key", hash) err = fmt.Errorf("Manifest not Found") return } manifestData := make([]byte, size) read, err := manifestReader.Read(manifestData) if int64(read) < size { - log.Trace(fmt.Sprintf("Manifest %v not found.", hash.Log())) + log.Trace("manifest not found", "key", hash) if err == nil { err = fmt.Errorf("Manifest retrieval cut short: read %v, expect %v", read, size) } return } - log.Trace(fmt.Sprintf("Manifest %v retrieved", hash.Log())) + log.Trace("manifest retrieved", "key", hash) var man struct { Entries []*manifestTrieEntry `json:"entries"` } err = json.Unmarshal(manifestData, &man) if err != nil { err = fmt.Errorf("Manifest %v is malformed: %v", hash.Log(), err) - log.Trace(fmt.Sprintf("%v", err)) + log.Trace("malformed manifest", "key", hash) return } - log.Trace(fmt.Sprintf("Manifest %v has %d entries.", hash.Log(), len(man.Entries))) + log.Trace("manifest entries", "key", hash, "len", len(man.Entries)) trie = &manifestTrie{ dpa: dpa,