Skip to content

perf(azure database): batched per-server lookup to populate AZConfig + Deployment in DatabaseDetails #149

@cristim

Description

@cristim

Summary

Follow-up to PR #81. PR #81 wired the lazy SKU catalogue lookup for Azure SQL Database, populating DatabaseDetails.EngineVersion from armsql.CapabilitiesClient.ListByLocation. Two other deferred fields on DatabaseDetailsAZConfig and Deployment — were intentionally left empty because they require a different SDK pattern (per-server lookups, not per-region capabilities).

Current behaviour

providers/azure/services/database/client.go::convertAzureSQLRecommendation (post-#81) populates:

Leaves empty:

  • AZConfig — Availability Zone configuration (zoneRedundant / zonePinned / none).
  • Deployment — server deployment shape (single server / managed instance / serverless).

Why deferred from #81

  • AZConfig is a per-server attribute (armsql.ServersClient.Get(rg, server).Properties.IsZoneRedundant-equivalent), not derivable from LocationCapabilities.
  • Deployment similarly comes from per-server armsql.Server.Kind / armsql.ManagedInstance resource type — different SDK calls per shape.
  • A reservation recommendation does not name a specific server, so the converter cannot pick "the right" server to enrich from.
  • Mirrors the cosmosdb cachedAPIType pattern ("dominant single-value across the subscription, else empty"): we could fetch all SQL servers in the subscription once and use the dominant zone-redundancy / deployment shape, but this is a different code path from the LocationCapabilities one and was out of scope for the perf change.

Proposed fix

Add a second cached lookup alongside the SKU catalogue:

  1. cachedDominantAZConfig(ctx)sync.Once-gated, hits armsql.ServersClient.NewListPager (subscription-wide), reduces IsZoneRedundant across all servers to a single dominant value or empty when ambiguous. Mirrors the cosmosdb cachedAPIType pattern.
  2. cachedDominantDeployment(ctx) — same shape, derives from server Kind / managed-instance presence.
  3. Update convertAzureSQLRecommendation to write both into Details when non-empty.
  4. Add three new tests per field: _PopulatesAZConfig, _AmbiguousAZConfig, _AZConfigPagerErrorFallsBack (and the same trio for Deployment).

No new struct fields required — DatabaseDetails.AZConfig + Deployment already exist on pkg/common.

Test plan

  • Single-server subscription with IsZoneRedundant=trueDetails.AZConfig = "zoneRedundant".
  • Mixed subscription (one zoneRedundant, one zonePinned) → AZConfig empty (ambiguous).
  • Pager failure → AZConfig empty, conversion still succeeds.
  • _FetchedOnce invariant pinned (one call per client lifetime regardless of converter call count).
  • Same matrix for Deployment.

References

Severity

Low-Medium — UI degrades to "unknown" for two presentation-only fields. Functional but loses signal.

Effort

Small — ~80 LOC + ~6 unit tests, all in the database service package. Pattern is already established by #81.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions