-
Notifications
You must be signed in to change notification settings - Fork 260
Add log to happy path #1929
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
Add log to happy path #1929
Conversation
|
@bohuini pls read this #1921 (comment) |
rbtr
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the log should not speculate on the intent of what is happening, the log should describe what is happening concisely and in enough detail to be useful during debugging
cns/restserver/api.go
Outdated
| // If received "GET": Return all NCs in CNS's state file to DNC in order to check if NC refresh is needed | ||
| // If received "POST": Store all the NCs (from the request body that client sent) into CNS's state file | ||
| func (service *HTTPRestService) getOrRefreshNetworkContainers(w http.ResponseWriter, r *http.Request) { | ||
| logger.Printf("[Azure CNS] NC refresh is initiated by DNC. The state file in CNS will get updated if it is lost.") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unnecessary to add an informational log here if all branches of the switch have a log
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed.
cns/restserver/api.go
Outdated
|
|
||
| switch r.Method { | ||
| case http.MethodGet: | ||
| logger.Printf("[Azure CNS] DNC is attempting to check if the state file in CNS is intact.") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
or, GET from getOrRefreshNetworkContainers
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you don't have to use my example, but it provides just as much info as yours without the potential of lying to me if that's not why this method was called
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Make sense. Addressed.
cns/restserver/api.go
Outdated
| service.handleGetNetworkContainers(w) | ||
| return | ||
| case http.MethodPost: | ||
| logger.Printf("[Azure CNS] The state file in CNS is lost. CNS will store all the NCs sent from DNC into state file.") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
or, POST to getOrRefreshNetworkContainers
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Addressed.
|
I'm with @rbtr here... I think concise logs are better because they tend to tell fewer lies about what's going on as things change over time. Log just the facts, given what's known at the time the log is generated. Given what I see, it would likely be better to have a middleware that logs requests (path, method, some request ID), and responses (HTTP response code, end-to-end time, the same ID for correlation). All of those should be structured using zap. Something like: func logHTTP(next http.Handler) http.Handler {
return http.HandlerFunc(func(rw http.ResponseWriter, r *http.Request) {
logger.Info("request", zap.String("uri", r.URL.RequestURI()), zap.String("method", r.Method))
// need to wrap the ResponseWriter in something that can capture the response code
wrw := WrappedResponseWriter{rw} // this doesn't exist and needs to be written
next(wrw, r)
logger.Info("response", zap.Int("code", wrw.ResponseCode)) // etc.
})
} |
963a4e0 to
af66656
Compare
|
@rbtr Revised the log and rebased branch. Please review again when you get a chance. Thanks! |
|
@timraymond That's a good point and I do agree. But for this time I am just making it simple for integration testing purposes. |
af66656 to
68d49f8
Compare
|
LGTM 👍 Awaiting @rbtr to hit the approval button. |
|
/azp run |
|
Azure Pipelines successfully started running 2 pipeline(s). |
Reason for Change:
DNC requiring to refresh CNS NC associations is not expected to happen too often, but when it does, we need to log all pertinent details. Added the log in CNS should to show refresh detected and initiated by DNC.
Issue Fixed:
Requirements:
Notes: