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

allow basic logging for http Get err with RegisterErrLogFn #81

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
21 changes: 17 additions & 4 deletions groupcache.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ package groupcache

import (
"errors"
"fmt"
"math/rand"
"strconv"
"sync"
Expand Down Expand Up @@ -60,6 +61,7 @@ var (

initPeerServerOnce sync.Once
initPeerServer func()
errLogHook func(error)
)

// GetGroup returns the named group previously created with NewGroup, or
Expand Down Expand Up @@ -121,6 +123,20 @@ func RegisterNewGroupHook(fn func(*Group)) {
newGroupHook = fn
}

// RegisterErrLogHook registers a log func that is used for HTTP error logging.
func RegisterErrLogHook(fn func(error)) {
if errLogHook != nil {
panic("RegisterErrLogHook called more than once")
}
errLogHook = fn
}

func logErr(err error) {
if errLogHook != nil {
errLogHook(err)
}
}

// RegisterServerStart registers a hook that is run when the first
// group is created.
func RegisterServerStart(fn func()) {
Expand Down Expand Up @@ -271,10 +287,7 @@ func (g *Group) load(ctx Context, key string, dest Sink) (value ByteView, destPo
return value, nil
}
g.Stats.PeerErrors.Add(1)
// TODO(bradfitz): log the peer's error? keep
// log of the past few for /groupcachez? It's
// probably boring (normal task movement), so not
// worth logging I imagine.
logErr(fmt.Errorf("%+v, %+v, %+v, %+v", ctx, peer, key, err))
}
value, err = g.getLocally(ctx, key, dest)
if err != nil {
Expand Down