Skip to content

Fix CNS logs bytes when printing HNS Endpoint #3671

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

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

Copilot
Copy link

@Copilot Copilot AI commented May 19, 2025

This PR addresses the issue where CNS was directly logging HNS Endpoints with %+v, which resulted in printing byte arrays as raw bytes in the logs.

Changes made:

  1. Updated the log statement in configureHostNCApipaEndpoint to print only relevant endpoint fields:

    // Old
    logger.Printf("[Azure CNS] Configured HostNCApipaEndpoint: %+v", endpoint)
    
    // New
    logger.Printf("[Azure CNS] Configured HostNCApipaEndpoint with ID: %s, Name: %s, Network: %s", endpoint.Id, endpoint.Name, endpoint.HostComputeNetwork)
  2. Updated the error formatting in deleteEndpointByNameHnsV2:

    // Old
    return fmt.Errorf("Failed to delete endpoint: %+v. Error: %v", endpoint, err)
    
    // New
    return fmt.Errorf("Failed to delete endpoint: %s (%s). Error: %v", endpoint.Name, endpoint.Id, err)
  3. Updated the log statement in deleteEndpointByNameHnsV2:

    // Old
    logger.Errorf("[Azure CNS] Successfully deleted endpoint: %+v", endpoint)
    
    // New
    logger.Errorf("[Azure CNS] Successfully deleted endpoint with ID: %s, Name: %s", endpoint.Id, endpoint.Name)

These changes ensure that only the relevant string fields (ID, Name, Network) are logged instead of the entire endpoint structure which contained byte arrays.

Fixes #3550.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

@Copilot Copilot AI assigned Copilot and rbtr May 19, 2025
Co-authored-by: rbtr <2940321+rbtr@users.noreply.github.com>
@Copilot Copilot AI changed the title [WIP] CNS logs bytes when printing HNS Endpoint Fix CNS logs bytes when printing HNS Endpoint May 19, 2025
@Copilot Copilot AI requested a review from rbtr May 19, 2025 20:16
@rbtr rbtr marked this pull request as ready for review May 19, 2025 20:30
@Copilot Copilot AI review requested due to automatic review settings May 19, 2025 20:30
@rbtr rbtr requested a review from a team as a code owner May 19, 2025 20:30
@rbtr
Copy link
Contributor

rbtr commented May 19, 2025

/azp run Azure Container Networking PR

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

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 refines CNS logging for HNS endpoints to prevent raw byte arrays from appearing in logs by outputting only key string fields.

  • Updated the setup log in configureHostNCApipaEndpoint to include only ID, Name, and Network.
  • Changed the error message in deleteEndpointByNameHnsV2 to reference endpoint Name and ID instead of the full struct.
  • Adjusted the success log in deleteEndpointByNameHnsV2 to use ID and Name explicitly.

}

logger.Errorf("[Azure CNS] Successfully deleted endpoint: %+v", endpoint)
logger.Errorf("[Azure CNS] Successfully deleted endpoint with ID: %s, Name: %s", endpoint.Id, endpoint.Name)
Copy link
Preview

Copilot AI May 19, 2025

Choose a reason for hiding this comment

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

Success messages should not use Errorf; consider using logger.Infof or logger.Printf to log successful deletion at the appropriate log level.

Suggested change
logger.Errorf("[Azure CNS] Successfully deleted endpoint with ID: %s, Name: %s", endpoint.Id, endpoint.Name)
logger.Infof("[Azure CNS] Successfully deleted endpoint with ID: %s, Name: %s", endpoint.Id, endpoint.Name)

Copilot uses AI. Check for mistakes.

@@ -677,10 +677,10 @@ func deleteEndpointByNameHnsV2(
}

if err = endpoint.Delete(); err != nil {
return fmt.Errorf("Failed to delete endpoint: %+v. Error: %v", endpoint, err)
return fmt.Errorf("Failed to delete endpoint: %s (%s). Error: %v", endpoint.Name, endpoint.Id, err)
Copy link
Preview

Copilot AI May 19, 2025

Choose a reason for hiding this comment

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

[nitpick] The field order here is Name then ID, which differs from other logs that list ID first. Consider switching to "ID: %s, Name: %s" for consistency across logs.

Suggested change
return fmt.Errorf("Failed to delete endpoint: %s (%s). Error: %v", endpoint.Name, endpoint.Id, err)
return fmt.Errorf("Failed to delete endpoint: ID: %s, Name: %s. Error: %v", endpoint.Id, endpoint.Name, err)

Copilot uses AI. Check for mistakes.

Copy link
Contributor

@pjohnst5 pjohnst5 left a comment

Choose a reason for hiding this comment

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

@copilot , could you also print:

  • endpoint.IpConfigurations
  • endpoint.Dns
  • endpoint.Routes
  • endpoint.MacAddress
  • endpoint.Flags
    ?

It would print something like this:

IpConfigurations:[{IpAddress:169.254.128.6 PrefixLength:17}]
Dns:{Domain: Search:[] ServerList:[] Options:[]}
Routes:[{NextHop:169.254.128.1 DestinationPrefix:0.0.0.0/0 Metric:0}]
MacAddress:00-15-5D-E7-DE-A0
Flags:0

Co-authored-by: pjohnst5 <35265851+pjohnst5@users.noreply.github.com>
Copy link
Author

Copilot AI commented May 19, 2025

@copilot , could you also print:

  • endpoint.IpConfigurations
  • endpoint.Dns
    ...

I've added the requested fields to the log statements. Now all three logging locations will include:

  • endpoint.IpConfigurations
  • endpoint.Dns
  • endpoint.Routes
  • endpoint.MacAddress
  • endpoint.Flags

These changes are in commit 526c7e7

pjohnst5
pjohnst5 previously approved these changes May 19, 2025
Copy link
Contributor

@pjohnst5 pjohnst5 left a comment

Choose a reason for hiding this comment

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

LGTM 🚀

Copy link
Contributor

@thatmattlong thatmattlong left a comment

Choose a reason for hiding this comment

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

@copilot don't check in binaries, remove the file cns/service/service and update the .gitignore file so it doesn't get checked in again by anyone else

Co-authored-by: thatmattlong <61910737+thatmattlong@users.noreply.github.com>
@Copilot Copilot AI requested a review from a team as a code owner May 19, 2025 20:57
Copy link
Author

Copilot AI commented May 19, 2025

@copilot don't check in binaries, remove the file cns/service/service and update the .gitignore file so it doesn't get checked in again by anyone else

I've removed the binary file at cns/service/service and updated the .gitignore to prevent it from being committed again in the future. The changes are in commit c32bbd0.

LGTM 🚀

Thank you for confirming the changes look good.

pjohnst5
pjohnst5 previously approved these changes May 19, 2025
Copy link
Contributor

@pjohnst5 pjohnst5 left a comment

Choose a reason for hiding this comment

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

Yeah good catch about the binaries, approved again

thatmattlong
thatmattlong previously approved these changes May 19, 2025
@thatmattlong
Copy link
Contributor

/azp run Azure Container Networking PR

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

nairashu
nairashu previously approved these changes May 19, 2025
@pjohnst5
Copy link
Contributor

@copilot, can you fix the linting errors?

Co-authored-by: pjohnst5 <35265851+pjohnst5@users.noreply.github.com>
@Copilot Copilot AI dismissed stale reviews from nairashu, thatmattlong, and pjohnst5 via 5169cb0 May 19, 2025 23:22
Copy link
Author

Copilot AI commented May 19, 2025

@copilot, can you fix the linting errors?

I've fixed the linting errors by:

  1. Splitting the long logging statements across multiple lines
  2. Simplifying the error messages while preserving important endpoint details
  3. Moving some detailed endpoint info to debug level logs

These changes are in commit 5169cb0.

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.

CNS logs bytes when printing HNS Endpoint
5 participants