Skip to content

Fix EventHubs Tool Issues.#2678

Draft
g2vinay wants to merge 1 commit into
microsoft:mainfrom
g2vinay:fix-eventhubs-issues
Draft

Fix EventHubs Tool Issues.#2678
g2vinay wants to merge 1 commit into
microsoft:mainfrom
g2vinay:fix-eventhubs-issues

Conversation

@g2vinay
Copy link
Copy Markdown
Contributor

@g2vinay g2vinay commented May 20, 2026

Fix EventHubs bugs: correctness, reliability, and performance

What changed

Correctness

  • DeleteNamespaceAsync now returns false for 404 instead of true. NamespaceDeleteCommand reports "not found" rather than "deleted successfully" when the namespace never existed.
  • EventHubUpdateCommand--status option is now forwarded to the service and applied. Previously it was accepted but silently discarded, leaving the hub unchanged.
  • Invalid SKU tier now throws a clear ArgumentException instead of silently defaulting to Standard.

Reliability

  • CreateOrUpdateConsumerGroupAsync now validates parent resources (resource group → namespace → event hub) before proceeding, throwing KeyNotFoundException with an actionable message at each level instead of an unhandled NullReferenceException.
  • GetNamespaceAsync now validates namespaceName and resourceGroup before making any ARM call.
  • All not-found conditions now throw KeyNotFoundException → HTTP 404, not InvalidOperationException → HTTP 500.

Performance

  • GetNamespacesAsync (no resource group filter) replaced an N+1 per-resource-group loop with a single GetEventHubsNamespacesAsync subscription-scoped call.

Polish

  • SKU tier and Event Hub status inputs are now matched case-insensitively.
  • EventHubGetCommand error log messages were swapped between the single-get and list-all paths — corrected.
  • EventHubsService is now sealed.

- EH-07: DeleteNamespaceAsync returns false (not true) for 404
- EH-01: NamespaceDeleteCommand shows correct not-found message when success=false
- EH-02: GetNamespacesAsync uses subscriptionResource.GetEventHubsNamespacesAsync()
         instead of N+1 per-resource-group calls
- EH-03: GetNamespaceAsync validates namespaceName and resourceGroup parameters
- EH-04: Invalid SKU tier throws ArgumentException instead of silently defaulting to Standard
- EH-06: EventHubUpdateCommand passes status option to CreateOrUpdateEventHubAsync;
         service applies EventHubEntityStatus with validation
- EH-08: CreateOrUpdateConsumerGroupAsync adds null guards on resourceGroup,
         namespace and eventHub lookups; throws KeyNotFoundException on missing parent
- EH-09: EventHubGetCommand error log messages corrected (were swapped)
- EH-11: Not-found resource paths throw KeyNotFoundException (HTTP 404)
         instead of InvalidOperationException (HTTP 500)
- EH-13: EventHubsService is now sealed

Tests: added ExecuteAsync_PassesStatusOptionToService and
       ExecuteAsync_WhenNamespaceNotFound_ReturnsNotFoundMessage;
       updated all existing mocks to match new service signatures
"STANDARD" => EventHubsSkuTier.Standard,
"PREMIUM" => EventHubsSkuTier.Premium,
null or "" => EventHubsSkuTier.Standard,
_ => throw new ArgumentException(
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This will need to be listed as a breaking change

{
_logger.LogInformation(
"Event Hubs namespace '{NamespaceName}' not found in resource group '{ResourceGroup}'",
_logger.LogWarning(
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I don't think this warrants being a warning level log.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

tools-EventHubs Event Hubs MCP tools

Projects

Status: Untriaged

Development

Successfully merging this pull request may close these issues.

2 participants