Skip to content

fix(fleetcontrol): improve error handling and enforce exact value matching#1827

Open
pranav-new-relic wants to merge 2 commits intomainfrom
fix/fleetcontrol-error-handling-exact-value-matching
Open

fix(fleetcontrol): improve error handling and enforce exact value matching#1827
pranav-new-relic wants to merge 2 commits intomainfrom
fix/fleetcontrol-error-handling-exact-value-matching

Conversation

@pranav-new-relic
Copy link
Copy Markdown
Member

Summary

This PR addresses two issues reported by the fleet team:

  1. Misleading error messages: When organization ID retrieval fails (e.g., due to "Unauthorized IP address"), the CLI showed a generic "failed to determine organization ID" message without revealing the underlying cause.

  2. Inconsistent validation: The original implementation used case_insensitive: true in YAML configs but didn't properly normalize values before sending to the API, leading to confusion about which values were actually accepted.

Changes

Error Handling

  • Modified GetOrganizationID() to return the actual API error, providing users with clear information about what went wrong (e.g., "Unauthorized IP address")
  • Updated all 7 callers of GetOrganizationID() to properly handle the new error return value

Exact Value Matching

  • Removed all case_insensitive: true from YAML config files - values must now match exactly as specified
  • Removed case normalization (ToUpper/ToLower) from all Map* functions to enforce exact matching
  • Added explicit validation for agent types in:
    • ParseAgentSpec() - validates --agent flag format (e.g., "NRInfra:1.70.0:version1")
    • fleet_deployment_create.go - validates legacy --agent-type flag
  • Updated README documentation to reflect case-sensitive validation requirements

Required Values

Users must now provide exact values as specified:

  • Agent types: NRInfra, NRDOT, FluentBit, NRPrometheusAgent (not "nrinfra" or "NRINFRA")
  • Managed entity types: HOST, KUBERNETESCLUSTER (not "host" or "kubernetescluster")
  • Operating systems: LINUX, WINDOWS (not "linux" or "windows")
  • Configuration modes: ConfigEntity, ConfigVersionEntity (not "configentity")

Testing

Verified that:

  • Lowercase values like "nrinfra", "host", etc. are now properly rejected with clear error messages
  • Correct values like "NRInfra", "HOST" work as expected
  • Organization ID errors now display the underlying API error
  • All code compiles successfully

…ching

- Modified GetOrganizationID() to return underlying API errors instead of
  generic "failed to determine organization ID" message
- Removed all case-insensitive validation - values must now match exactly
  as specified in allowed_values lists
- Removed case normalization from all Map* functions (MapManagedEntityType,
  MapOperatingSystemType, MapConfigurationMode, MapScopeType)
- Added strict validation for agent types in ParseAgentSpec and legacy
  deployment syntax to ensure exact matches
- Updated README to reflect case-sensitive validation requirements
- Updated all GetOrganizationID() callers to properly handle error returns
- Added validation block to legacy --agent-type flag in deployment create YAML
- Removed redundant code validation from fleet_deployment_create.go
- Follows YAML-first validation approach: framework validates before handlers run
- Code validation only remains in ParseAgentSpec for complex spec format parsing
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