-
Notifications
You must be signed in to change notification settings - Fork 14
[log] [metric] Log Setting API, More TRACE Logs, and Gatherer Support #201
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
Merged
Merged
Changes from all commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
6b5ffb0
[log] logr.Logger and logr.LogSink Support for controller-runtime Com…
onelapahead 143bde6
logr stores an internal ctx for fields; withlogfields and withfields …
onelapahead 4004679
use new withlogfields internally; document inefficiencies of logr imp…
onelapahead 4629a14
fixed linter
onelapahead f21e9a0
gatherer for custom metrics exporting
onelapahead 139bc91
eliminating monitoring server logs; supporting changing log level dyn…
onelapahead 864ecbb
fixed test; removed other noisy log from dbsql
onelapahead f656209
move http conn logs to trace
onelapahead 0e811ee
more flexible dynamic logging API for future settings
onelapahead d73a8c5
fix panic for klog.Object structs in controller-runtime
onelapahead e77cfe7
removing logr implementation
onelapahead 064c97e
less debug logs
onelapahead a1ff727
fix lint
onelapahead 57fc551
reverting dbsql log changes
onelapahead b5869c6
removing handler init in favor of simple setloglevel; and updated var…
onelapahead 4bcfa39
comments and log methods feedback
onelapahead 7feb10d
Fix test
onelapahead 542c507
Update pkg/ffapi/apiserver.go
onelapahead ecf04ba
ffapi
onelapahead 32c4e02
add remote/local addrs to conn ctx for httpserver
onelapahead c545757
Check ctx fields in unit test
onelapahead ee2c8e6
log local/remote in apiserver handlers now that they are in context
onelapahead b6d9c9f
validate user input for log level
onelapahead File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -34,6 +34,7 @@ import ( | |
| "github.com/ghodss/yaml" | ||
| "github.com/gorilla/mux" | ||
| "github.com/hyperledger/firefly-common/pkg/fftypes" | ||
| "github.com/hyperledger/firefly-common/pkg/httpserver" | ||
| "github.com/hyperledger/firefly-common/pkg/i18n" | ||
| "github.com/hyperledger/firefly-common/pkg/log" | ||
| "github.com/sirupsen/logrus" | ||
|
|
@@ -77,6 +78,8 @@ type HandlerFactory struct { | |
| SupportFieldRedaction bool | ||
| BasePath string | ||
| BasePathParams []*PathParam | ||
|
|
||
| apiEntryLoggingLevel logrus.Level // the log level at which entry/exit logging is enabled at all (does not affect trace logging) | ||
| } | ||
|
|
||
| var ffMsgCodeExtractor = regexp.MustCompile(`^(FF\d+):`) | ||
|
|
@@ -88,6 +91,10 @@ type multipartState struct { | |
| close func() | ||
| } | ||
|
|
||
| func (hs *HandlerFactory) SetAPIEntryLoggingLevel(logLevel logrus.Level) { | ||
| hs.apiEntryLoggingLevel = logLevel | ||
| } | ||
|
|
||
| func (hs *HandlerFactory) getFilePart(req *http.Request) (*multipartState, error) { | ||
| formParams := make(map[string]string) | ||
| ctx := req.Context() | ||
|
|
@@ -368,22 +375,28 @@ func (hs *HandlerFactory) APIWrapper(handler HandlerFunction) http.HandlerFunc { | |
| } | ||
| ctx = withRequestID(ctx, httpReqID) | ||
| ctx = withPassthroughHeaders(ctx, req, hs.PassthroughHeaders) | ||
| ctx = log.WithLogField(ctx, "httpreq", httpReqID) | ||
| ctx = log.WithLogFields(ctx, "httpreq", httpReqID) | ||
|
|
||
| req = req.WithContext(ctx) | ||
| defer cancel() | ||
|
|
||
| // Wrap the request itself in a log wrapper, that gives minimal request/response and timing info | ||
| l := log.L(ctx) | ||
| l.Infof("--> %s %s", req.Method, req.URL.Path) | ||
| addrFields := map[string]string{} | ||
| if remoteAddr := httpserver.RemoteAddr(ctx); remoteAddr != nil { | ||
| addrFields["remote"] = remoteAddr.String() | ||
| } | ||
| if localAddr := httpserver.LocalAddr(ctx); localAddr != nil { | ||
| addrFields["local"] = localAddr.String() | ||
| } | ||
| l := log.L(log.WithLogFieldsMap(ctx, addrFields)) | ||
| l.Logf(hs.apiEntryLoggingLevel, "--> %s %s", req.Method, req.URL.Path) | ||
|
Contributor
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. Was thinking you'd grab the |
||
| startTime := time.Now() | ||
| status, err := handler(res, req) | ||
| durationMS := float64(time.Since(startTime)) / float64(time.Millisecond) | ||
| if err != nil { | ||
|
|
||
| if ffe, ok := (interface{}(err)).(i18n.FFError); ok { | ||
| if logrus.IsLevelEnabled(logrus.DebugLevel) { | ||
| log.L(ctx).Debugf("%s:\n%s", ffe.Error(), ffe.StackTrace()) | ||
| l.Debugf("%s:\n%s", ffe.Error(), ffe.StackTrace()) | ||
| } | ||
| status = ffe.HTTPStatus() | ||
| } else { | ||
|
|
@@ -412,14 +425,14 @@ func (hs *HandlerFactory) APIWrapper(handler HandlerFunction) http.HandlerFunc { | |
| if status < 300 { | ||
| status = 500 | ||
| } | ||
| l.Infof("<-- %s %s [%d] (%.2fms): %s", req.Method, req.URL.Path, status, durationMS, err) | ||
| l.Logf(hs.apiEntryLoggingLevel, "<-- %s %s [%d] (%.2fms): %s", req.Method, req.URL.Path, status, durationMS, err) | ||
| res.Header().Add("Content-Type", "application/json") | ||
| res.WriteHeader(status) | ||
| _ = json.NewEncoder(res).Encode(&fftypes.RESTError{ | ||
| Error: err.Error(), | ||
| }) | ||
| } else { | ||
| l.Infof("<-- %s %s [%d] (%.2fms)", req.Method, req.URL.Path, status, durationMS) | ||
| l.Logf(hs.apiEntryLoggingLevel, "<-- %s %s [%d] (%.2fms)", req.Method, req.URL.Path, status, durationMS) | ||
| } | ||
| } | ||
| } | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.