Skip to content

Conversation

peterfelts
Copy link

Reason for Change:
I was recently debugging an NC-publication failure and noticed that when filtering CNS logs by NC ID, the CNS logs where CNS logs that its returning to the caller were filtered out. This was because these logs didn't include the NC ID.

I've added a properties parameter to the Response function on the CNS logger so that callers can log additional details, such as the NC ID.

@peterfelts peterfelts requested review from a team as code owners September 30, 2025 22:15
@peterfelts peterfelts requested review from Copilot, neaggarwMS and santhoshmprabhu and removed request for neaggarwMS September 30, 2025 22:15
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds a properties parameter to the CNS logger's Response function to enable logging additional context information, such as Network Container (NC) IDs, which helps with debugging and log filtering.

  • Added properties parameter to logger Response method signature across all implementations
  • Updated all existing logger.Response calls to pass nil for the new properties parameter
  • Implemented properties logging in publishNetworkContainer method to include Network ID and NC ID

Reviewed Changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
log/stdapi.go Updated global Response function to pass nil for new properties parameter
log/logger.go Added properties parameter to Logger.Response method and implemented property formatting
cns/restserver/util.go Updated logger.Response calls to include nil properties parameter
cns/restserver/ipam.go Updated logger.Response calls to include nil properties parameter
cns/restserver/api.go Updated logger.Response calls and added properties map for publishNetworkContainer
cns/logger/v2/shim.go Updated shim Response method to include properties parameter
cns/logger/log.go Updated interface and global Response function signatures
cns/logger/cnslogger.go Implemented properties formatting in CNS logger Response method

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Comment on lines +212 to 226
func (logger *Logger) Response(tag string, response interface{}, returnCode int, returnStr string, properties any, err error) {
// Create a string for properties if they exist
props := ""
if properties != nil {
props = fmt.Sprintf(" Properties: %+v", properties)
}

if err == nil && returnCode == 0 {
logger.Printf("[%s] Sent %T %+v.", tag, response, response)
logger.Printf("[%s] Sent %T %+v.%s", tag, response, response, props)
} else if err != nil {
logger.Errorf("[%s] Code:%s, %+v %s.", tag, returnStr, response, err.Error())
logger.Errorf("[%s] Code:%s, %+v %s.%s", tag, returnStr, response, err.Error(), props)
} else {
logger.Errorf("[%s] Code:%s, %+v.", tag, returnStr, response)
logger.Errorf("[%s] Code:%s, %+v.%s", tag, returnStr, response, props)
}
}
Copy link

Copilot AI Sep 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] The properties formatting logic is duplicated across multiple files (log/logger.go and cns/logger/cnslogger.go). Consider extracting this into a shared helper function to avoid code duplication.

Copilot uses AI. Check for mistakes.

Comment on lines +151 to 175
func (c *logger) Response(tag string, response any, returnCode types.ResponseCode, properties any, err error) {
c.logger.Response(tag, response, int(returnCode), returnCode.String(), properties, err)
if c.th == nil || c.disableTraceLogging {
return
}
var msg string
lvl := ai.InfoLevel

// Create a string for properties if they exist
props := ""
if properties != nil {
props = fmt.Sprintf(" Properties: %+v", properties)
}

switch {
case err == nil && returnCode == 0:
msg = fmt.Sprintf("[%s] Sent %T %+v.", tag, response, response)
msg = fmt.Sprintf("[%s] Sent %T %+v.%s", tag, response, response, props)
case err != nil:
msg = fmt.Sprintf("[%s] Code:%s, %+v %s.", tag, returnCode.String(), response, err.Error())
msg = fmt.Sprintf("[%s] Code:%s, %+v %s.%s", tag, returnCode.String(), response, err.Error(), props)
lvl = ai.ErrorLevel
default:
msg = fmt.Sprintf("[%s] Code:%s, %+v.", tag, returnCode.String(), response)
msg = fmt.Sprintf("[%s] Code:%s, %+v.%s", tag, returnCode.String(), response, props)
}
c.sendTraceInternal(msg, lvl)
}
Copy link

Copilot AI Sep 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] The properties formatting logic is duplicated from log/logger.go. Consider extracting this into a shared helper function to avoid code duplication.

Copilot uses AI. Check for mistakes.

@peterfelts
Copy link
Author

/azp run

Copy link

Azure Pipelines successfully started running 3 pipeline(s).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant