Skip to content

Fix logging response from NMAgent in syncHostNCVersion function #3747

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

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented Jun 19, 2025

Problem

The syncHostNCVersion function logged a generic error message when some NCs couldn't be updated:

if len(outdatedNCs) > 0 {
    return len(programmedNCs), errors.Errorf("unabled to update some NCs: %v, missing or bad response from NMA", outdatedNCs)
}

This message was not useful because it didn't distinguish between:

  1. NCs that are completely missing from the NMAgent response
  2. NCs that are present in the NMAgent response but programmed to older versions

Solution

Enhanced the error logging to separately track and report missing vs outdated NCs with detailed version information:

  • Missing NCs: Shows NC IDs and their expected versions for NCs completely absent from NMAgent response
  • Outdated NCs: Shows NC IDs with both expected and actual versions for NCs present but outdated in NMAgent response

Changes

Core Implementation (cns/restserver/internalapi.go)

  • Added separate tracking maps during NC processing:
    • missingNCs: Maps NC ID → expected version
    • outdatedNMaNCs: Maps NC ID → "expected:X,actual:Y"
  • Enhanced processing logic to categorize NCs correctly based on NMAgent response
  • Replaced generic error with structured message showing both categories with version details

Test Coverage (cns/restserver/internalapi_test.go)

  • Added comprehensive test TestSyncHostNCVersionErrorMessages covering both scenarios
  • Validates error message content and programmed NC count behavior
  • Ensures existing functionality remains unchanged

Example Output

Before:

"unabled to update some NCs: [nc-id-1 nc-id-2], missing or bad response from NMA"

After:

Missing only: "missing NCs from NMAgent response: map[nc-id-1:2]"
Outdated only: "outdated NCs in NMAgent response: map[nc-id-1:expected:2,actual:1]"
Combined: "unable to update some NCs - missing NCs from NMAgent response: map[nc-id-1:2]; outdated NCs in NMAgent response: map[nc-id-2:expected:3,actual:1]"

This provides operators with actionable information to distinguish between missing NCs (potential NMAgent issues) and outdated NCs (version synchronization issues), along with specific version details for effective troubleshooting.

Fixes #3746.


💡 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 changed the title [WIP] Fix logging response from NMAgent in syncHostNCVersion function Fix logging response from NMAgent in syncHostNCVersion function Jun 19, 2025
@Copilot Copilot AI requested a review from thatmattlong June 19, 2025 17:41
Copilot finished work on behalf of thatmattlong June 19, 2025 17:41

// Track NCs missing from NMAgent response and outdated NCs for better error reporting
missingNCs := make(map[string]string) // ncID -> expected version
outdatedNMaNCs := make(map[string]string) // ncID -> "expected:actual" version info
Copy link
Contributor

Choose a reason for hiding this comment

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

you should define a new struct for this instead of using a string. You should name the struct ncVersionInfo and it should have two fields, an expected field and an actual field

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Implemented as requested. Created ncVersionInfo struct with expected and actual fields to replace the formatted string approach. This provides better type safety and clearer separation of version information. b35be04

@Copilot Copilot AI requested a review from thatmattlong June 19, 2025 19:12
Copilot finished work on behalf of thatmattlong June 19, 2025 19:12
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.

Fix logging response from NMAgent in syncHostNCVersion function
2 participants