Skip to content

Conversation

Copy link
Contributor

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

github-actions bot commented Jul 4, 2025

This pull request is stale because it has been open for 2 weeks with no activity. Remove stale label or comment or this will be closed in 7 days

@github-actions github-actions bot added the stale Stale due to inactivity. label Jul 4, 2025
@github-actions
Copy link

Pull request closed due to inactivity.

@github-actions github-actions bot closed this Jul 12, 2025
@github-actions github-actions bot deleted the copilot/fix-3746 branch July 12, 2025 00:01
@rbtr rbtr restored the copilot/fix-3746 branch July 14, 2025 19:28
@rbtr rbtr reopened this Jul 14, 2025
@rbtr rbtr added exempt-stale Keep this fresh and removed stale Stale due to inactivity. labels Jul 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

exempt-stale Keep this fresh

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Fix logging response from NMAgent in syncHostNCVersion function

3 participants