azure-container-networking icon indicating copy to clipboard operation
azure-container-networking copied to clipboard

Fix CNS logs bytes when printing HNS Endpoint

Open Copilot opened this issue 5 months ago • 29 comments

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 avatar May 19 '25 20:05 Copilot