Skip to content

Commit

Permalink
Log query params
Browse files Browse the repository at this point in the history
  • Loading branch information
anbsky committed Jul 19, 2019
1 parent 1e850a7 commit a8e60b4
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 11 deletions.
2 changes: 1 addition & 1 deletion app/proxy/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ func ForwardCall(request jsonrpc.RPCRequest) ([]byte, error) {
}

if shouldLog(request.Method) {
monitor.LogSuccessfulQuery(request.Method, time.Now().Sub(queryStartTime).Seconds())
monitor.LogSuccessfulQuery(request.Method, time.Now().Sub(queryStartTime).Seconds(), request.Params)
}

if shouldCache(request.Method, request.Params) {
Expand Down
2 changes: 1 addition & 1 deletion app/proxy/proxy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,7 @@ func BenchmarkDirectResolve(b *testing.B) {
return
}
// monitor.Logger.WithFields(log.Fields{"n": n}).Info("response fully processed")
monitor.LogSuccessfulQuery(fmt.Sprintf("processed a call #%v", n), time.Now().Sub(queryStartTime).Seconds())
monitor.LogSuccessfulQuery(fmt.Sprintf("processed a call #%v", n), time.Now().Sub(queryStartTime).Seconds(), nil)
wg.Done()
}(n, &wg)
}
Expand Down
13 changes: 7 additions & 6 deletions internal/monitor/monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,19 +95,20 @@ func (l ModuleLogger) Log() *logrus.Entry {
return Logger.WithFields(logrus.Fields{"module": l.ModuleName})
}

// LogSuccessfulQuery takes a remote method name and execution time and logs it
func LogSuccessfulQuery(method string, time float64) {
// LogSuccessfulQuery takes a remote method name, execution time and params and logs it
func LogSuccessfulQuery(method string, time float64, params interface{}) {
Logger.WithFields(logrus.Fields{
"method": method,
"processing_time": time,
}).Info("processed a call")
"method": method,
"time": time,
"params": params,
}).Info("call processed")
}

// LogCachedQuery logs a cache hit for a given method
func LogCachedQuery(method string) {
Logger.WithFields(logrus.Fields{
"method": method,
}).Info("processed a cached query")
}).Info("cached query")
}

// LogFailedQuery takes a method name, query params, response error object and logs it
Expand Down
16 changes: 13 additions & 3 deletions internal/monitor/monitor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,23 @@ import (
func TestLogSuccessfulQuery(t *testing.T) {
hook := test.NewLocal(Logger)

LogSuccessfulQuery("account_balance", 0.025)
LogSuccessfulQuery("resolve", 0.025, map[string]string{"urls": "one"})

require.Equal(t, 1, len(hook.Entries))
require.Equal(t, log.InfoLevel, hook.LastEntry().Level)
require.Equal(t, "resolve", hook.LastEntry().Data["method"])
require.Equal(t, map[string]string{"urls": "one"}, hook.LastEntry().Data["params"])
require.Equal(t, 0.025, hook.LastEntry().Data["time"])
require.Equal(t, "call processed", hook.LastEntry().Message)

LogSuccessfulQuery("account_balance", 0.025, nil)

require.Equal(t, 2, len(hook.Entries))
require.Equal(t, log.InfoLevel, hook.LastEntry().Level)
require.Equal(t, "account_balance", hook.LastEntry().Data["method"])
require.Equal(t, 0.025, hook.LastEntry().Data["processing_time"])
require.Equal(t, "processed a call", hook.LastEntry().Message)
require.Equal(t, nil, hook.LastEntry().Data["params"])
require.Equal(t, 0.025, hook.LastEntry().Data["time"])
require.Equal(t, "call processed", hook.LastEntry().Message)

hook.Reset()
}
Expand Down

0 comments on commit a8e60b4

Please sign in to comment.