diff --git a/l10n/bundle.l10n.json b/l10n/bundle.l10n.json index 2a1594007..e909d61b5 100644 --- a/l10n/bundle.l10n.json +++ b/l10n/bundle.l10n.json @@ -87,6 +87,8 @@ "{victim} throttles at `{victimRate}%` despite using only `{victimShare}%` of the pool. It is being starved.": "{victim} throttles at `{victimRate}%` despite using only `{victimShare}%` of the pool. It is being starved.", "`{pct}%` of query executions fan out across partitions (the container has `~{partitions} physical partitions`).": "`{pct}%` of query executions fan out across partitions (the container has `~{partitions} physical partitions`).", "`{pct}%` of this container's query executions fan out across `~{partitions} physical partitions`.": "`{pct}%` of this container's query executions fan out across `~{partitions} physical partitions`.", + "`{rate}%` of `{total} requests` returned status ≥400 excluding 429. The most frequent error was `{status}`. Account-level counts do not identify an application, container, operation or item, or prove an application defect.": "`{rate}%` of `{total} requests` returned status ≥400 excluding 429. The most frequent error was `{status}`. Account-level counts do not identify an application, container, operation or item, or prove an application defect.", + "`{rate}%` of `{total} requests` were throttled. `{operation}` is the most frequent throttled operation, representing `{share}%` of status-reported 429s. Independent metric breakdowns can differ in completeness; operation mix does not prove a root cause.": "`{rate}%` of `{total} requests` were throttled. `{operation}` is the most frequent throttled operation, representing `{share}%` of status-reported 429s. Independent metric breakdowns can differ in completeness; operation mix does not prove a root cause.", "× items ~{n}": "× items ~{n}", "< 100 — low": "< 100 — low", "~{ru} RU / point read": "~{ru} RU / point read", @@ -171,7 +173,9 @@ "Account overview sections": "Account overview sections", "Account Overview update finished.": "Account Overview update finished.", "Account provisioned successfully.": "Account provisioned successfully.", + "Account request errors excluding 429 warrant investigation. Status counts alone do not establish an application defect or identify its source.": "Account request errors excluding 429 warrant investigation. Status counts alone do not establish an application defect or identify its source.", "Account throughput is low and sporadic: peak `{peak} RU/s`, average `{avg} RU/s` (a `{ratio}%` average-to-peak with long idle stretches).": "Account throughput is low and sporadic: peak `{peak} RU/s`, average `{avg} RU/s` (a `{ratio}%` average-to-peak with long idle stretches).", + "Account-level status counts alone do not identify an operation or item or establish a read-404-then-insert sequence. Investigate request-level evidence before selecting a remediation.": "Account-level status counts alone do not identify an operation or item or establish a read-404-then-insert sequence. Investigate request-level evidence before selecting a remediation.", "Account-wide": "Account-wide", "Account-wide 429 responses exceeded {percent}% for at least {duration} in the last {window}.": "Account-wide 429 responses exceeded {percent}% for at least {duration} in the last {window}.", "Account-wide request health over the last {window} could not be assessed: {reason}.": "Account-wide request health over the last {window} could not be assessed: {reason}.", @@ -358,6 +362,8 @@ "Chat & Sessions": "Chat & Sessions", "Chat sessions, AI assistants, helpdesks": "Chat sessions, AI assistants, helpdesks", "Check Chat": "Check Chat", + "Check expected missing-item lookups, id and partition-key context. Only if code or traces confirm existence-check-before-create, review SDK-appropriate atomic create and 409 handling. Upsert can overwrite data; a 404 supplies no ETag. Do not assume .NET IfNoneMatchEtag protects writes.": "Check expected missing-item lookups, id and partition-key context. Only if code or traces confirm existence-check-before-create, review SDK-appropriate atomic create and 409 handling. Upsert can overwrite data; a 404 supplies no ETag. Do not assume .NET IfNoneMatchEtag protects writes.", + "Check partition saturation and key distribution to distinguish hotspots from uniform capacity pressure.": "Check partition saturation and key distribution to distinguish hotspots from uniform capacity pressure.", "Check that DataPlaneRequests5M or DataPlaneRequests, and QueryRuntimeStatistics, are exported to Log Analytics in resource-specific mode, not only AzureDiagnostics. Query RU evidence requires raw DataPlaneRequests.": "Check that DataPlaneRequests5M or DataPlaneRequests, and QueryRuntimeStatistics, are exported to Log Analytics in resource-specific mode, not only AzureDiagnostics. Query RU evidence requires raw DataPlaneRequests.", "Check the signed-in identity, resource log permissions, and the workspace access-control mode and table permissions.": "Check the signed-in identity, resource log permissions, and the workspace access-control mode and table permissions.", "Checking": "Checking", @@ -405,6 +411,7 @@ "Confirm the application genuinely needs this consistency level.": "Confirm the application genuinely needs this consistency level.", "Confirm the partition key spreads new data across partitions, and archive or delete cold data.": "Confirm the partition key spreads new data across partitions, and archive or delete cold data.", "Confirm this inferred environment and its availability requirements with the account owner.": "Confirm this inferred environment and its availability requirements with the account owner.", + "Confirm throughput mode, current feature eligibility and regional/partition demand. If autoscale is used and demand is uneven, evaluate independent scaling. This does not fix a skewed logical key, and savings are not established.": "Confirm throughput mode, current feature eligibility and regional/partition demand. If autoscale is used and demand is uneven, evaluate independent scaling. This does not fix a skewed logical key, and savings are not established.", "Connect to {0}": "Connect to {0}", "Connect to a container first": "Connect to a container first", "Connect to a container to generate a schema": "Connect to a container to generate a schema", @@ -619,6 +626,7 @@ "Discovery input must be relative to the migration folder and remain inside the workspace.": "Discovery input must be relative to the migration folder and remain inside the workspace.", "Dismiss": "Dismiss", "Dismiss advisory for {scope}": "Dismiss advisory for {scope}", + "Distinct provisioned offers total `{ru} RU/s` (manual allocations plus autoscale maxima). This is a configuration proxy, not a measured stable billable baseline. Low severity describes the review advisory, not utilization or potential savings.": "Distinct provisioned offers total `{ru} RU/s` (manual allocations plus autoscale maxima). This is a configuration proxy, not a measured stable billable baseline. Low severity describes the review advisory, not utilization or potential savings.", "Do you mind taking a quick feedback survey about Azure Cosmos DB for VS Code?": "Do you mind taking a quick feedback survey about Azure Cosmos DB for VS Code?", "Document count": "Document count", "Document ID strategy": "Document ID strategy", @@ -983,6 +991,8 @@ "Input must be a number": "Input must be a number", "Inserted {0} document(s). See output for more details.": "Inserted {0} document(s). See output for more details.", "Inserts / sec": "Inserts / sec", + "Inspect query diagnostics, partition-key filters and indexing requirements before attributing throttling to fan-out or increasing RU/s.": "Inspect query diagnostics, partition-key filters and indexing requirements before attributing throttling to fan-out or increasing RU/s.", + "Inspect the actual operation and ETag/precondition handling. A 412 can be expected concurrency protection, not proof of missing control or a hot item. For confirmed read-modify-write, re-read state and ETag, reapply the update and retry with bounded attempts. Surface unresolved conflicts; do not drop preconditions.": "Inspect the actual operation and ETag/precondition handling. A 412 can be expected concurrency protection, not proof of missing control or a hot item. For confirmed read-modify-write, re-read state and ETag, reapply the update and retry with bounded attempts. Surface unresolved conflicts; do not drop preconditions.", "Install": "Install", "Install .NET Install Tool": "Install .NET Install Tool", "Install .NET SDK": "Install .NET SDK", @@ -1010,6 +1020,7 @@ "Invalid semver \"{0}\".": "Invalid semver \"{0}\".", "Invalid: {count}": "Invalid: {count}", "Inventory & Supply Chain": "Inventory & Supply Chain", + "Investigate request validation, access, configuration, SDK retries or service health as appropriate for the status. Status counts do not identify a missing role or firewall setting; 5xx can be service-side. Increasing throughput is not a general remedy for non-429 failures.": "Investigate request validation, access, configuration, SDK retries or service health as appropriate for the status. Status counts do not identify a missing role or firewall setting; 5xx can be service-side. Increasing throughput is not a general remedy for non-429 failures.", "Investigate this container urgently: archive or delete cold data and add TTL where appropriate.": "Investigate this container urgently: archive or delete cold data and add TTL where appropriate.", "IoT Device Telemetry": "IoT Device Telemetry", "It does not remove the throttling on a single hot key.": "It does not remove the throttling on a single hot key.", @@ -1135,6 +1146,7 @@ "More items": "More items", "More…": "More…", "Move the monopolizing collection (or the starved one) to dedicated throughput, or migrate collections off the shared pool.": "Move the monopolizing collection (or the starved one) to dedicated throughput, or migrate collections off the shared pool.", + "Multi-region provisioned accounts with independent scaling disabled may benefit if autoscale usage and uneven demand justify it.": "Multi-region provisioned accounts with independent scaling disabled may benefit if autoscale usage and uneven demand justify it.", "Multi-region write antipattern": "Multi-region write antipattern", "Multi-region writes are enabled across `{regions} write regions` on a non-production account, which does not need RTO=0 write failover.": "Multi-region writes are enabled across `{regions} write regions` on a non-production account, which does not need RTO=0 write failover.", "Multi-region writes are enabled but the account has a single write region.": "Multi-region writes are enabled but the account has a single write region.", @@ -1212,6 +1224,8 @@ "No telemetry available for this selection yet.": "No telemetry available for this selection yet.", "No throughput reduction is available under this model. Validate the service minimum and workload needs; do not apply an unchanged target.": "No throughput reduction is available under this model. Validate the service minimum and workload needs; do not apply an unchanged target.", "No total throughput limit": "No total throughput limit", + "Non-throttling errors": "Non-throttling errors", + "Non-throttling request errors": "Non-throttling request errors", "None of these fit": "None of these fit", "Normalized RU": "Normalized RU", "Normalized RU is not applicable to serverless accounts because they do not have provisioned throughput.": "Normalized RU is not applicable to serverless accounts because they do not have provisioned throughput.", @@ -1284,6 +1298,8 @@ "Page {page} of {count}": "Page {page} of {count}", "Page {page} of {pages}. Containers {start} to {end} of {total}.": "Page {page} of {pages}. Containers {start} to {end} of {total}.", "Page through results": "Page through results", + "Paid continuous backup": "Paid continuous backup", + "Paid continuous backup on a non-production account": "Paid continuous backup on a non-production account", "Parameters": "Parameters", "Partial coverage": "Partial coverage", "Partial data": "Partial data", @@ -1320,6 +1336,7 @@ "per physical partition": "per physical partition", "Per-partition or per-region autoscale can soften the cost of feeding the hot partition while you redesign.": "Per-partition or per-region autoscale can soften the cost of feeding the hot partition while you redesign.", "Per-query fixes cannot resolve a fundamentally mismatched key, and the cost grows as the container adds partitions.": "Per-query fixes cannot resolve a fundamentally mismatched key, and the cost grows as the container adds partitions.", + "Per-region autoscale review": "Per-region autoscale review", "Periods use the alert start time and current condition. Azure Monitor retains alert instances for 30 days.": "Periods use the alert start time and current condition. Azure Monitor retains alert instances for 30 days.", "Phase 1: Source Discovery": "Phase 1: Source Discovery", "Phase 2: Domain Assessment": "Phase 2: Domain Assessment", @@ -1394,6 +1411,7 @@ "Provision New Account": "Provision New Account", "Provision new Azure Cosmos DB Account": "Provision new Azure Cosmos DB Account", "Provisioned (100%)": "Provisioned (100%)", + "Provisioned capacity warrants reviewing eligible usage and existing reservations. This is not a savings estimate or a purchase recommendation.": "Provisioned capacity warrants reviewing eligible usage and existing reservations. This is not a savings estimate or a purchase recommendation.", "Provisioned containers or shared database offers serve almost no traffic. Review recoverable manual capacity or the autoscale idle floor.": "Provisioned containers or shared database offers serve almost no traffic. Review recoverable manual capacity or the autoscale idle floor.", "Provisioned offer looks idle": "Provisioned offer looks idle", "Provisioned RU/s stays well above observed demand, so you are paying for capacity the workload never uses.": "Provisioned RU/s stays well above observed demand, so you are paying for capacity the workload never uses.", @@ -1515,6 +1533,7 @@ "Required log tables are unavailable. Check diagnostic categories, resource-specific export mode, ingestion, and Log Analytics access.": "Required log tables are unavailable. Check diagnostic categories, resource-specific export mode, ingestion, and Log Analytics access.", "Required prerequisite: {phase}. Regenerate this phase first.": "Required prerequisite: {phase}. Regenerate this phase first.", "Required table unavailable": "Required table unavailable", + "Reserved-capacity review": "Reserved-capacity review", "Reset": "Reset", "Reset model to workload defaults?": "Reset model to workload defaults?", "Reset Project": "Reset Project", @@ -1557,10 +1576,18 @@ "Review and copy or download the configuration, then initialize, plan, and apply it with Terraform.": "Review and copy or download the configuration, then initialize, plan, and apply it with Terraform.", "Review and copy or download the template, then deploy it with your Bicep tooling.": "Review and copy or download the template, then deploy it with your Bicep tooling.", "Review and Fix": "Review and Fix", + "Review Continuous7Days only if seven days of restore history meets the recovery policy. Older restore points would be lost and restores remain separately chargeable. Do not revert to periodic backup solely for this advisory.": "Review Continuous7Days only if seven days of restore history meets the recovery policy. Older restore points would be lost and restores remain separately chargeable. Do not revert to periodic backup solely for this advisory.", "Review disabling multi-region writes if active-active availability is unnecessary. Separately assess whether extra regions can be removed; toggling multi-write alone does not recover regional capacity.": "Review disabling multi-region writes if active-active availability is unnecessary. Separately assess whether extra regions can be removed; toggling multi-write alone does not recover regional capacity.", + "Review eligible usage, existing reservation coverage, negotiated rates and future demand in Cost Management before considering a one- or three-year commitment. This check does not establish that reservations are absent or quantify a discount.": "Review eligible usage, existing reservation coverage, negotiated rates and future demand in Cost Management before considering a one- or three-year commitment. This check does not establish that reservations are absent or quantify a discount.", + "Review ingestion pacing, bulk execution and client-side throughput control before changing capacity.": "Review ingestion pacing, bulk execution and client-side throughput control before changing capacity.", "Review lowering the autoscale max on \"{container}\" toward the analytical target `~{recommended} RU/s`.": "Review lowering the autoscale max on \"{container}\" toward the analytical target `~{recommended} RU/s`.", "Review multi-region-write compatibility and availability requirements before changing the flag. Disabling multi-write while keeping all regions does not remove their provisioned capacity.": "Review multi-region-write compatibility and availability requirements before changing the flag. Disabling multi-write while keeping all regions does not remove their provisioned capacity.", + "Review paid restore-history retention on positively inferred non-production accounts without compromising recovery requirements.": "Review paid restore-history retention on positively inferred non-production accounts without compromising recovery requirements.", + "Review per-region and per-partition autoscale": "Review per-region and per-partition autoscale", + "Review reserved-capacity coverage": "Review reserved-capacity coverage", + "Review stored-procedure/server-side execution RU cost and call rate.": "Review stored-procedure/server-side execution RU cost and call rate.", "Review stronger consistency requirements": "Review stronger consistency requirements", + "Review the dominant operation, its call rate, RU cost and SDK retry behavior.": "Review the dominant operation, its call rate, RU cost and SDK retry behavior.", "Review the partition key for a higher-cardinality choice so data spreads evenly.": "Review the partition key for a higher-cardinality choice so data spreads evenly.", "Review the shared database offer and all its member workloads before decommissioning or changing capacity. An idle member alone does not make the shared offer recoverable.": "Review the shared database offer and all its member workloads before decommissioning or changing capacity. An idle member alone does not make the shared offer recoverable.", "Review the shared database offer and member workloads for partition skew. Identify the affected containers before changing a partition key or isolating throughput.": "Review the shared database offer and member workloads for partition skew. Identify the affected containers before changing a partition key or isolating throughput.", @@ -1610,6 +1637,7 @@ "Search published content across sites": "Search published content across sites", "second partition key e.g., /UserId": "second partition key e.g., /UserId", "See the extension Output channel for the HTTP status, service error details, and request ID.": "See the extension Output channel for the HTTP status, service error details, and request ID.", + "See which operation contributes the most 429s. Operation mix guides investigation but does not prove a root cause.": "See which operation contributes the most 429s. Operation mix guides investigation but does not prove a root cause.", "Select": "Select", "Select {0}": "Select {0}", "Select a container": "Select a container", @@ -1787,6 +1815,7 @@ "The {api} drivers cannot use Cosmos DB's multi-region-write failover, so the RTO=0 HA benefit never materialises.": "The {api} drivers cannot use Cosmos DB's multi-region-write failover, so the RTO=0 HA benefit never materialises.", "The account action could not be completed. Retry or use the Azure Resources view.": "The account action could not be completed. Retry or use the Azure Resources view.", "The account consumption pattern is intermittent enough that serverless may cost less than provisioned throughput.": "The account consumption pattern is intermittent enough that serverless may cost less than provisioned throughput.", + "The account has `{regions} regions` and per-region/per-partition autoscale is reported as disabled. This configuration check does not establish autoscale usage or uneven regional demand.": "The account has `{regions} regions` and per-region/per-partition autoscale is reported as disabled. This configuration check does not establish autoscale usage or uneven regional demand.", "The account has one default consistency level. For load-balanced applications, pass the Cosmos response SessionToken through the web tier to the end-user client in a cookie or equivalent client context.": "The account has one default consistency level. For load-balanced applications, pass the Cosmos response SessionToken through the web tier to the end-user client in a cookie or equivalent client context.", "The account-wide active alert check is unavailable. The filtered list is shown below.": "The account-wide active alert check is unavailable. The filtered list is shown below.", "The active alert count is unavailable for the selected window.": "The active alert count is unavailable for the selected window.", @@ -1899,6 +1928,7 @@ "This account has no databases or containers yet.": "This account has no databases or containers yet.", "This account has no databases. Choose New database to create one.": "This account has no databases. Choose New database to create one.", "This account has no databases. Create a database before adding a container.": "This account has no databases. Create a database before adding a container.", + "This account has paid continuous-backup retention and is inferred to be non-production. Confirm the environment and recovery requirements with the account owner.": "This account has paid continuous-backup retention and is inferred to be non-production. Confirm the environment and recovery requirements with the account owner.", "This account uses {level} consistency across `{regions} regions`.": "This account uses {level} consistency across `{regions} regions`.", "This account-wide cap limits throughput allocation, not consumed RU or available performance. Autoscale resources count at their configured maximum.": "This account-wide cap limits throughput allocation, not consumed RU or available performance. Autoscale resources count at their configured maximum.", "This cannot be undone.": "This cannot be undone.", @@ -1934,10 +1964,15 @@ "This workspace is not under version control. It is strongly recommended to initialize a Git repository before starting the migration.": "This workspace is not under version control. It is strongly recommended to initialize a Git repository before starting the migration.", "Threshold: ≥ `{pct}%` fan-out share across ≥ `{partitions} partitions`, and ≥ `0.1 fan-out queries/s`": "Threshold: ≥ `{pct}%` fan-out share across ≥ `{partitions} partitions`, and ≥ `0.1 fan-out queries/s`", "Threshold: ≥ `{pct}%` fan-out share, avg ≥ `{fanout} partitions/query`, and ≥ `0.1 fan-out queries/s`": "Threshold: ≥ `{pct}%` fan-out share, avg ≥ `{fanout} partitions/query`, and ≥ `0.1 fan-out queries/s`", + "Threshold: ≥`1,000 requests` and ≥`1%` non-429 errors; Medium ≥`5%`, High ≥`10%` over seven days": "Threshold: ≥`1,000 requests` and ≥`1%` non-429 errors; Medium ≥`5%`, High ≥`10%` over seven days", + "Threshold: ≥`1,000 requests`, ≥`1%` 429s and a positive operation breakdown; Medium ≥`5%`, High ≥`20%` over seven days": "Threshold: ≥`1,000 requests`, ≥`1%` 429s and a positive operation breakdown; Medium ≥`5%`, High ≥`20%` over seven days", "Threshold: 429 rate ≥ `{rate}%` over at least `{requests} requests`": "Threshold: 429 rate ≥ `{rate}%` over at least `{requests} requests`", "Threshold: 429 rate ≥ `{rate}%`, busiest partition p99 ≥ `{saturation}%`, coolest partition p99 ≥ `{headroom}%`": "Threshold: 429 rate ≥ `{rate}%`, busiest partition p99 ≥ `{saturation}%`, coolest partition p99 ≥ `{headroom}%`", + "Threshold: at least `{ru} RU/s` of provisioned capacity; constant Low severity": "Threshold: at least `{ru} RU/s` of provisioned capacity; constant Low severity", + "Threshold: at least `2 regions`, provisioned account and per-region/per-partition autoscale explicitly disabled": "Threshold: at least `2 regions`, provisioned account and per-region/per-partition autoscale explicitly disabled", "Threshold: average ≥ `{avg}%` of max and peak/average ≤ `{ratio}×`": "Threshold: average ≥ `{avg}%` of max and peak/average ≤ `{ratio}×`", "Threshold: busiest partition p99 ≥ `{saturation}%` while another < `{headroom}%`": "Threshold: busiest partition p99 ≥ `{saturation}%` while another < `{headroom}%`", + "Threshold: Continuous30Days or Continuous35Days on a positively inferred non-production account": "Threshold: Continuous30Days or Continuous35Days on a positively inferred non-production account", "Threshold: current partition size ≥ `50 GiB`": "Threshold: current partition size ≥ `50 GiB`", "Threshold: index/data storage > `{threshold}%`": "Threshold: index/data storage > `{threshold}%`", "Threshold: min/max partition size < `{threshold}×` with busiest ≥ `1 GiB`": "Threshold: min/max partition size < `{threshold}×` with busiest ≥ `1 GiB`", @@ -1956,6 +1991,7 @@ "Threshold: write-RU ≥ `{writePct}%` and 429 rate ≥ `{throttlePct}%`": "Threshold: write-RU ≥ `{writePct}%` and 429 rate ≥ `{throttlePct}%`", "Throttled: {count}": "Throttled: {count}", "Throttling": "Throttling", + "Throttling by operation": "Throttling by operation", "Throughput": "Throughput", "Throughput Bucket": "Throughput Bucket", "Throughput may be over-provisioned": "Throughput may be over-provisioned", diff --git a/specs/account-overview.md b/specs/account-overview.md index e0ef6e4a2..784f90e97 100644 --- a/specs/account-overview.md +++ b/specs/account-overview.md @@ -538,6 +538,8 @@ over observed hourly buckets. Missing buckets do not become zero samples in eith | AutoscaledRU | 30 days / 1 hour | Dedicated and shared database autoscale offers | | Consumed-RU shape | 30 days / 1 hour | Non-Serverless account, no database filter | | Serverless request-rate totals | 7 days / 1 hour | Serverless containers | +| Account status counts | 7 days / 1 hour, Count TotalRequests | Account, one shared input for DX-020/021 | +| Throttled operation counts | Same window / grain, StatusCode=429 | Account; only after DX-021 volume/rate gates pass | | Log query fan-out evidence | Last 24 hours, raw event aggregation | Dedicated and Serverless containers | | Log ingestion evidence | 24 hours, five-minute aggregates or raw events | Dedicated containers | | Log shared-pool evidence | Same selected request-log source/window | Shared-throughput database offers | @@ -615,6 +617,20 @@ The result exposes metric and log coverage separately. An empty finding list doe Some empty successful sources abstain via sample gates without marking a failure; coverage flags are not a complete inventory of every insufficient-evidence case. +DX-019/022 use the existing ARM snapshot, including continuous retention tier and the explicit +per-region/per-partition autoscale flag. Missing backup mode, unknown tier on non-production, and missing +applicable autoscale configuration are reported in workload coverage, not interpreted as disabled/free. +DX-020 and DX-021 do not require Log Analytics or inventory. Status parsing accepts finite positive counts +with numeric integer status codes; hard errors are codes >=400 excluding 429. All parsed requests, including +429s, remain in the denominator. One status read feeds both rules; a failed/empty operation breakdown at a +qualifying throttle rate marks DX-021 incomplete without removing a successful DX-020 finding. +Both split queries request up to 1,000 series and reject a response at that cap as potentially truncated. +DX-023 uses the same distinct-offer total as materiality, not replicated container rows or regional copies. +Unavailable, incomplete, invalid or duplicate inventory withholds its baseline and records incomplete coverage. +The inventory-completeness flag is checked before summing returned numeric offers: an omitted unknown-throughput +offer is not zero capacity. Incomplete inventory also withholds DX-008 regional quantification and account/manual +materiality totals, while known per-offer workload findings and configuration-only DX-008 findings remain available. + Known age below a rule's minimum suppresses that rule; unknown/non-finite age does not. Collector age derives from resource/offer creation metadata with account creation as fallback. Manual/autoscale utilization rules require at least 24 finite observations; this is not 24 days or complete coverage. @@ -672,6 +688,29 @@ not entries in the derived-detector registry. | AO-D20 `SharedThroughputStarvation` / DX-003 | Known shared members; >=2 active members each with >=100 requests; their pool rate >=5%, total RU >0, largest RU share >=60%, and a different member has rate >=5% and RU share <=20% | High | | AO-D21 `ServerlessThrottling` / DX-018 | Serverless container; >=1,000 requests; rate >=1%; no normalized-RU prerequisite | High rate >=20%; Medium >=5%; otherwise Low | | AO-D3 `StorageSkewRisk` / DX-015 | Age not known <1 day; >=2 valid non-negative partition peaks; busiest >=1 GiB; coolest/busiest <0.7 | High busiest >=40 GiB; Medium >=25 GiB; otherwise Low | +| `PaidContinuousBackup` / DX-019 | Continuous30Days/Continuous35Days, case-insensitive, and positively classified non-production | Medium | +| `NonThrottlingErrors` / DX-020 | >=1,000 account requests and >=1% hard non-429 errors | High >=10%; Medium >=5%; otherwise Low | +| `ThrottlingByOperation` / DX-021 | >=1,000 account requests, >=1% 429s and a positive operation breakdown | High >=20%; Medium >=5%; otherwise Low | +| `PerRegionAutoscaleCandidate` / DX-022 | Known provisioned account, >=2 regions and independent autoscale explicitly disabled; an autoscale offer is not required for this review | Low | +| `ReservedCapacityCandidate` / DX-023 | Known provisioned account and complete distinct-offer baseline >=3,000 RU/s | Always Low, including very large accounts | + +The proposed CODA DX-020/021/023 thresholds above were explicitly adopted for native advisories. +They remain ranking heuristics, separate from Account Health and user settings. +DX-019 advises reviewing seven-day continuous retention only if recovery requirements allow losing older restore +points; it never recommends switching to Periodic. Monetary estimates are not collected. +DX-020 uses the most frequent individual hard-error status. Only dominant 404/409 map to +`sdk-conditional-create-etag`, only 412 maps to `sdk-etag-concurrency`; other statuses map to null. +These are conditional investigations, not proof of existence-check-before-create, a missing ETag or a hot item. +SDK-specific atomic-create semantics matter: unconditional upsert can overwrite, and .NET IfNoneMatchEtag is +not write protection. Expected 412s may show concurrency protection working. +DX-021 selects the most frequent individual throttled operation, not the largest combined category. +Category shares use status-reported total 429s; independent breakdowns may differ in completeness. +Write/read/query/execute/other map respectively to `sdk-ingestion-rate-control`, `partition-avoid-hotspots`, +`query-avoid-cross-partition`, `monitoring-ru-consumption`, `monitoring-throttling`. +The nullable `agentKitRule` field preserves these mappings for consumers; it does not execute a skill. +DX-022 requires throughput/feature/demand review and quantifies no savings. +DX-023 does not establish a stable billable baseline, absent reservations, future demand or a discount. +Its constant Low severity describes a reservation-review advisory, not low utilization or small potential savings. **Storage-skew classification:** match CODA's observed-data ordering: no usable histories is `insufficient_data`; one usable history is `single_partition`; multiple histories below the 1 GiB diff --git a/src/panels/accountOverview/services/advisories/collect.ts b/src/panels/accountOverview/services/advisories/collect.ts index 8edbea4d5..50255bec1 100644 --- a/src/panels/accountOverview/services/advisories/collect.ts +++ b/src/panels/accountOverview/services/advisories/collect.ts @@ -20,10 +20,12 @@ import { import { getContainerCreatedAt, getKnownResourceAgeDays, getSystemCreatedAt } from '../resourceAge'; import { getRuTrends, getThrottleRate } from '../ruTrends'; import { classifyUnavailable, containerKey } from '../shared'; -import { offerScope } from './core/helpers'; +import { configurationFailures, offerScope } from './core/helpers'; +import { summarizeRequestStatuses } from './core/requestMetrics'; import { DIAGNOSTIC_POLICY } from './core/thresholds'; import { type AccountConfigInput, + type AccountRequestMetricsInput, type CrossPartitionInput, type ConsistencyReadRuInput, type DerivedAdvisory, @@ -56,11 +58,13 @@ import { import { type LogsDiagnostic, type LogsDiagnosticReporter } from './fetchers/logsDiagnostics'; import { getAccountConsumedRuShape, + getAccountRequestStatusCounts, getAutoscaleUtilization, getContainerIdlePeak, getContainerIndexingUsage, getContainerMergeStoragePeak, getContainerPartitionCount, + getThrottledOperationCounts, } from './fetchers/metrics'; // ─── Server-side orchestration ────────────────────────────────────────────────── @@ -227,8 +231,9 @@ export async function collectDerivedAdvisories( const now = Date.now(); const effectiveAccountConfig = accountConfig && { ...accountConfig, isServerless }; - const metricFailures: MetricSourceStatus['failures'] = []; + const metricFailures = configurationFailures(effectiveAccountConfig); const accountCreatedAtPromise = capture(getAccountCreatedAt(cosmosClient, resourceGroup, accountName)); + const accountRequestsPromise = capture(getAccountRequestStatusCounts(monitorClient, accountId, now)); let rows: InventoryContainerRow[] = []; let offers: InventoryThroughputOffer[] = []; @@ -306,6 +311,33 @@ export async function collectDerivedAdvisories( inventory.value?.throughputInventoryComplete !== true || invalidOfferScopes.size > 0 ? undefined : offerTargets.reduce((sum, offer) => sum + offer.throughputRU, 0); + if (!isServerless && scopeProvisionedRuTotal === undefined) { + addMetricFailure(metricFailures, 'ReservedCapacityCandidate', inventory.reason ?? 'noData'); + } + + const statusResult = await accountRequestsPromise; + const statuses = statusResult.value && summarizeRequestStatuses(statusResult.value); + let accountRequests: AccountRequestMetricsInput | undefined; + if (!statusResult.value || !statuses || !Number.isFinite(statuses.totalRequests) || statuses.totalRequests === 0) { + for (const rule of ['NonThrottlingErrors', 'ThrottlingByOperation'] as const) { + addMetricFailure(metricFailures, rule, statusResult.reason ?? 'noData'); + } + } else { + accountRequests = { statusCounts: statusResult.value }; + if ( + statuses.totalRequests >= DIAGNOSTIC_POLICY.accountRequests.minRequests && + (100 * statuses.totalThrottled) / statuses.totalRequests >= + DIAGNOSTIC_POLICY.throttlingByOperation.ratePercent + ) { + const operations = await capture(getThrottledOperationCounts(monitorClient, accountId, now)); + if (!operations.value || Object.keys(operations.value).length === 0) { + addMetricFailure(metricFailures, 'ThrottlingByOperation', operations.reason ?? 'noData'); + } else { + accountRequests.throttledOperationCounts = operations.value; + } + } + } + const manualObservation = DIAGNOSTIC_POLICY.overProvisioning.observation; const saturationObservation = DIAGNOSTIC_POLICY.partitionSaturation.observation; const storageObservation = DIAGNOSTIC_POLICY.storageGrowth.observation; @@ -698,6 +730,7 @@ export async function collectDerivedAdvisories( : undefined, accountConfig: effectiveAccountConfig, consistencyReadRu: logs.consistencyReadRu, + accountRequests, crossPartition: logs.crossPartition, ingestion: logs.ingestion, sharedThroughput: logs.sharedThroughput, diff --git a/src/panels/accountOverview/services/advisories/collectParity.test.ts b/src/panels/accountOverview/services/advisories/collectParity.test.ts index 0f67fc110..673244fab 100644 --- a/src/panels/accountOverview/services/advisories/collectParity.test.ts +++ b/src/panels/accountOverview/services/advisories/collectParity.test.ts @@ -55,7 +55,7 @@ vi.mock('./fetchers/metrics', () => ({ getContainerPartitionCount: vi.fn(), })); -import { CosmosDBManagementClient } from '@azure/arm-cosmosdb'; +import { CosmosDBManagementClient, type ThroughputSettingsGetResults } from '@azure/arm-cosmosdb'; import { MonitorClient, type Response as MetricsResponse } from '@azure/arm-monitor'; import { getSqlInventoryDetails } from '../inventory'; import { getPartitionHealth, getPartitionStorageSeries } from '../partitionHealth'; @@ -75,14 +75,17 @@ import { } from './fetchers/logs'; import { getAccountConsumedRuShape, + getAccountRequestStatusCounts, getAutoscaleUtilization, getContainerIdlePeak, getContainerIndexingUsage, getContainerMergeStoragePeak, getContainerPartitionCount, + getThrottledOperationCounts, } from './fetchers/metrics'; beforeEach(() => { + vi.mocked(getAccountRequestStatusCounts).mockResolvedValue({ 200: 1000 }); vi.mocked(selectDataPlaneSource).mockResolvedValue('CDBDataPlaneRequests'); vi.mocked(probeCdbLogs).mockResolvedValue({ available: false, reason: 'noData' }); }); @@ -134,6 +137,20 @@ function params(overrides: Partial[0 } describe('collectDerivedAdvisories parity wiring', () => { + it.each([true, false])( + 'reports reservation inventory failure only for provisioned accounts (serverless=%s)', + async (isServerless) => { + vi.mocked(getSqlInventoryDetails).mockRejectedValue({ statusCode: 403 }); + vi.mocked(computeDerivedAdvisories).mockReturnValue([]); + const result = await collectDerivedAdvisories(params({ isServerless, logsClient: undefined })); + const failures = result.metricSource.failures.filter( + (failure) => failure.rule === 'ReservedCapacityCandidate', + ); + expect(failures).toEqual(isServerless ? [] : [{ rule: 'ReservedCapacityCandidate', reason: 'rbac' }]); + expect(vi.mocked(computeDerivedAdvisories).mock.calls[0][0].scopeProvisionedRuTotal).toBeUndefined(); + }, + ); + it.each([true, false])( 'uses the account capacity baseline only for complete throughput inventory (complete=%s)', async (throughputInventoryComplete) => { @@ -325,6 +342,247 @@ describe('collectDerivedAdvisories parity wiring', () => { }, ); + it('shares one account status read between DX-020/021 even when inventory is denied', async () => { + const engine = await vi.importActual('./engine'); + vi.mocked(computeDerivedAdvisories).mockImplementation(engine.computeDerivedAdvisories); + vi.mocked(getSqlInventoryDetails).mockRejectedValue({ statusCode: 403 }); + vi.mocked(getAccountRequestStatusCounts).mockResolvedValue({ 200: 800, 404: 100, 429: 100 }); + vi.mocked(getThrottledOperationCounts).mockResolvedValue({ Create: 100 }); + + const result = await collectDerivedAdvisories(params({ logsClient: undefined })); + expect(result.advisories.map((item) => item.rule)).toEqual(['NonThrottlingErrors', 'ThrottlingByOperation']); + expect(getAccountRequestStatusCounts).toHaveBeenCalledOnce(); + expect(getThrottledOperationCounts).toHaveBeenCalledOnce(); + expect(vi.mocked(getAccountRequestStatusCounts).mock.calls[0][2]).toBe( + vi.mocked(getThrottledOperationCounts).mock.calls[0][2], + ); + expect(result.metricSource.failures).toContainEqual({ rule: 'ReservedCapacityCandidate', reason: 'rbac' }); + expect(result.logSource.available).toBe(false); + }); + + it.each<{ statusCounts: Record }>([ + { statusCounts: { 200: 899, 429: 100 } }, + { statusCounts: { 200: 9991, 429: 9 } }, + { statusCounts: { 200: 1000 } }, + ])('does not request an operation split below the DX-021 gates: %j', async ({ statusCounts }) => { + vi.mocked(getSqlInventoryDetails).mockResolvedValue({ + rows: [], + offers: [], + databases: [], + throughputInventoryComplete: true, + }); + vi.mocked(getAccountRequestStatusCounts).mockResolvedValue(statusCounts); + vi.mocked(computeDerivedAdvisories).mockReturnValue([]); + await collectDerivedAdvisories(params({ logsClient: undefined })); + expect(getThrottledOperationCounts).not.toHaveBeenCalled(); + }); + + it.each(['denied', 'empty'] as const)( + 'preserves errors while reporting %s throttled-operation evidence as incomplete', + async (scenario) => { + const engine = await vi.importActual('./engine'); + vi.mocked(computeDerivedAdvisories).mockImplementation(engine.computeDerivedAdvisories); + vi.mocked(getSqlInventoryDetails).mockResolvedValue({ + rows: [], + offers: [], + databases: [], + throughputInventoryComplete: true, + }); + vi.mocked(getAccountRequestStatusCounts).mockResolvedValue({ 200: 800, 500: 100, 429: 100 }); + if (scenario === 'denied') { + vi.mocked(getThrottledOperationCounts).mockRejectedValue({ statusCode: 403 }); + } else { + vi.mocked(getThrottledOperationCounts).mockResolvedValue({}); + } + const result = await collectDerivedAdvisories(params({ logsClient: undefined })); + expect(result.advisories.map((item) => item.rule)).toEqual(['NonThrottlingErrors']); + expect(result.metricSource.failures).toContainEqual({ + rule: 'ThrottlingByOperation', + reason: scenario === 'denied' ? 'rbac' : 'noData', + scope: undefined, + }); + }, + ); + + it('reports both account rules when status collection fails, without attempting operations', async () => { + vi.mocked(getSqlInventoryDetails).mockResolvedValue({ + rows: [], + offers: [], + databases: [], + throughputInventoryComplete: true, + }); + vi.mocked(getAccountRequestStatusCounts).mockRejectedValue({ statusCode: 403 }); + vi.mocked(computeDerivedAdvisories).mockReturnValue([]); + const result = await collectDerivedAdvisories(params({ logsClient: undefined })); + expect(result.metricSource.failures).toEqual([ + { rule: 'NonThrottlingErrors', reason: 'rbac', scope: undefined }, + { rule: 'ThrottlingByOperation', reason: 'rbac', scope: undefined }, + ]); + expect(getThrottledOperationCounts).not.toHaveBeenCalled(); + }); + + it.each([false, true])( + 'uses one authoritative shared offer for reservation review; duplicate=%s', + async (duplicate) => { + const engine = await vi.importActual('./engine'); + vi.mocked(computeDerivedAdvisories).mockImplementation(engine.computeDerivedAdvisories); + const offer = { + databaseId: 'db', + throughputRU: 3000, + offerLevel: 'database', + throughputMode: 'shared', + offerThroughputMode: 'manual', + resourceCreatedAt: '2020-01-01T00:00:00.000Z', + } as const; + vi.mocked(getSqlInventoryDetails).mockResolvedValue({ + rows: [], + offers: duplicate ? [offer, offer] : [offer], + databases: ['db'], + throughputInventoryComplete: true, + }); + vi.mocked(getRuTrends).mockResolvedValue({ + available: false, + points: [], + provisionedPercent: 100, + timeRange: '7D', + generatedAt: 0, + }); + const result = await collectDerivedAdvisories(params({ logsClient: undefined })); + const reservations = result.advisories.filter((item) => item.rule === 'ReservedCapacityCandidate'); + expect(reservations).toHaveLength(duplicate ? 0 : 1); + const inputs = vi.mocked(computeDerivedAdvisories).mock.calls[0][0]; + expect(inputs.scopeProvisionedRuTotal).toBe(duplicate ? undefined : 3000); + expect(inputs.manualRegionalCapacityRu).toBe(duplicate ? undefined : 3000); + expect(result.metricSource.failures.some((failure) => failure.rule === 'ReservedCapacityCandidate')).toBe( + duplicate, + ); + }, + ); + + it.each<{ + scope: + | 'container' + | 'shared database' + | 'empty database' + | 'unresolved container' + | 'container on shared database'; + response?: ThroughputSettingsGetResults; + total?: number; + }>([ + { scope: 'container', response: { resource: {} } }, + { scope: 'container', response: {} }, + { scope: 'shared database', response: { resource: {} } }, + { scope: 'shared database', response: {} }, + { scope: 'empty database', response: { resource: {} } }, + { scope: 'empty database', response: {} }, + { scope: 'unresolved container' }, + { scope: 'container on shared database', response: {} }, + { scope: 'container on shared database', response: { resource: {} } }, + { scope: 'container', response: { resource: { throughput: 1000 } }, total: 4000 }, + { scope: 'shared database', response: { resource: { throughput: 1000 } }, total: 4000 }, + { scope: 'empty database', response: { resource: { throughput: 1000 } }, total: 4000 }, + { scope: 'empty database', total: 3000 }, + ])('requires complete ARM inventory for DX-023 and DX-008: %j', async ({ scope, response, total }) => { + const inventory = await vi.importActual('../inventory'); + const engine = await vi.importActual('./engine'); + vi.mocked(getSqlInventoryDetails).mockImplementation(inventory.getSqlInventoryDetails); + vi.mocked(computeDerivedAdvisories).mockImplementation(engine.computeDerivedAdvisories); + const missingOffer = Object.assign(new Error('Not found'), { statusCode: 404 }); + const cosmosClient = new CosmosDBManagementClient({ getToken: async () => null }, 'sub'); + vi.spyOn(cosmosClient.databaseAccounts, 'get').mockResolvedValue({ + systemData: { createdAt: new Date('2020-01-01T00:00:00.000Z') }, + }); + vi.spyOn(cosmosClient.sqlResources, 'listSqlDatabases').mockImplementation(() => + pagedItems([{ resource: { id: 'known-db' } }, { resource: { id: 'target-db' } }]), + ); + vi.spyOn(cosmosClient.sqlResources, 'getSqlDatabaseThroughput').mockImplementation( + async (_rg, _account, database) => { + if (database !== 'target-db' || scope === 'container' || scope === 'unresolved container') { + throw missingOffer; + } + if (scope === 'container on shared database') { + return { resource: { throughput: 1000 } }; + } + if (response === undefined) { + throw missingOffer; + } + return response; + }, + ); + vi.spyOn(cosmosClient.sqlResources, 'listSqlContainers').mockImplementation((_rg, _account, database) => + pagedItems( + database === 'known-db' || scope !== 'empty database' + ? [ + { + resource: { id: database === 'known-db' ? 'known' : 'target' }, + systemData: { createdAt: new Date('2020-01-01T00:00:00.000Z') }, + }, + ] + : [], + ), + ); + vi.spyOn(cosmosClient.sqlResources, 'getSqlContainerThroughput').mockImplementation( + async (_rg, _account, database) => { + if (database === 'known-db') { + return { resource: { throughput: 3000 } }; + } + if ((scope === 'container' || scope === 'container on shared database') && response !== undefined) { + return response; + } + throw missingOffer; + }, + ); + vi.mocked(getRuTrends).mockResolvedValue({ + available: true, + points: Array.from({ length: 24 }, (_, timestamp) => ({ timestamp, ruPercent: 10, throttled: false })), + peakPercent: 10, + provisionedPercent: 100, + timeRange: '7D', + generatedAt: 0, + }); + vi.mocked(getContainerIdlePeak).mockResolvedValue(1000); + const result = await collectDerivedAdvisories( + params({ + cosmosClient, + logsClient: undefined, + accountConfig: { + accountName: 'acct-dev', + regionCount: 2, + writeRegionCount: 2, + multiRegionWritesEnabled: true, + api: API.Core, + backupPolicy: { type: 'Periodic' }, + perRegionPerPartitionAutoscaleEnabled: true, + }, + }), + ); + const collectedInventory = await vi.mocked(getSqlInventoryDetails).mock.results[0].value; + expect(collectedInventory.throughputInventoryComplete).toBe(total !== undefined); + const inputs = vi.mocked(computeDerivedAdvisories).mock.calls[0][0]; + expect(inputs.scopeProvisionedRuTotal).toBe(total); + expect(inputs.manualProvisionedRuTotal).toBe(total); + expect(inputs.manualRegionalCapacityRu).toBe(total); + expect(result.advisories.some((item) => item.rule === 'ReservedCapacityCandidate')).toBe(total !== undefined); + expect( + result.advisories.filter((item) => item.rule === 'OverProvisioning').map((item) => item.scope), + ).toContain('known-db/known'); + const regional = result.advisories.find((item) => item.rule === 'MultiRegionWriteAntipattern'); + expect(regional?.severity).toBe('Medium'); + expect(regional?.evidence).toEqual( + total === undefined + ? undefined + : { + regionalCapacityQuantified: true, + configuredPerRegionRu: total, + globalRegionalFootprintRu: total * 2, + removableExtraRegionRu: total, + }, + ); + expect(result.metricSource.failures.filter((failure) => failure.rule === 'ReservedCapacityCandidate')).toEqual( + total === undefined ? [{ rule: 'ReservedCapacityCandidate', reason: 'noData', scope: undefined }] : [], + ); + }); + it.each(['none', 'NoNe', 'NONE'])( 'skips DX-024 metric acquisition and coverage failures for %s indexing', async (indexingMode) => { diff --git a/src/panels/accountOverview/services/advisories/core/helpers.ts b/src/panels/accountOverview/services/advisories/core/helpers.ts index e3826ada2..05d781581 100644 --- a/src/panels/accountOverview/services/advisories/core/helpers.ts +++ b/src/panels/accountOverview/services/advisories/core/helpers.ts @@ -3,8 +3,16 @@ * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ +import { classifyEnvironment } from '../../environmentClassifier'; import { DIAGNOSTIC_POLICY } from './thresholds'; -import { type DerivedAdvisory, type DerivedAdvisorySeverity, type UtilizationBand } from './types'; +import { + type AccountConfigInput, + type AdvisoryEvaluation, + type DerivedAdvisory, + type DerivedAdvisorySeverity, + type MetricSourceStatus, + type UtilizationBand, +} from './types'; export function utilizationBand(value: number, moderateUpperPercent: number): UtilizationBand { return value < DIAGNOSTIC_POLICY.overProvisioning.idleBandPercent @@ -16,6 +24,88 @@ export function utilizationBand(value: number, moderateUpperPercent: number): Ut : 'ok'; } +function continuousBackupTier(config: AccountConfigInput) { + const tier = config.backupPolicy?.continuousTier?.trim().toLowerCase(); + return tier === 'continuous7days' || tier === 'continuous30days' || tier === 'continuous35days' ? tier : undefined; +} + +type PaidBackupClassification = + | { + rootCause: Exclude['rootCause'], 'nonprod_paid_continuous_backup'>; + hasRequiredInputs: boolean; + } + | { + rootCause: 'nonprod_paid_continuous_backup'; + hasRequiredInputs: true; + tier: 'continuous30days' | 'continuous35days'; + inferredEnvironment: string; + }; + +export function classifyPaidContinuousBackup(config: AccountConfigInput | undefined): PaidBackupClassification { + if (config === undefined) { + return { rootCause: 'unknown', hasRequiredInputs: false }; + } + const mode = config.backupPolicy?.type?.toLowerCase(); + if (mode === 'periodic') { + return { rootCause: 'periodic_backup', hasRequiredInputs: true }; + } + if (mode !== 'continuous') { + return { rootCause: 'unknown', hasRequiredInputs: false }; + } + const tier = continuousBackupTier(config); + if (tier === 'continuous7days') { + return { rootCause: 'uncharged_7day_backup', hasRequiredInputs: true }; + } + const environment = classifyEnvironment(config.accountName, config.tags, config.subscriptionName); + if (tier === undefined) { + return { rootCause: 'unknown_continuous_tier', hasRequiredInputs: !environment.isNonProd }; + } + if (!environment.isNonProd) { + return { rootCause: 'legitimate_prod_backup', hasRequiredInputs: true }; + } + return { + rootCause: 'nonprod_paid_continuous_backup', + hasRequiredInputs: true, + tier, + inferredEnvironment: environment.inferredEnv, + }; +} + +export function classifyPerRegionAutoscale(config: AccountConfigInput | undefined): { + rootCause: AdvisoryEvaluation<'PerRegionAutoscaleCandidate'>['rootCause']; + hasRequiredInputs: boolean; +} { + if (config?.isServerless === true) { + return { rootCause: 'serverless', hasRequiredInputs: true }; + } + const validRegions = config !== undefined && Number.isInteger(config.regionCount) && config.regionCount >= 1; + if (config?.isServerless !== false || !validRegions) { + return { rootCause: 'unknown', hasRequiredInputs: validRegions && config.regionCount === 1 }; + } + if (config.regionCount < 2) { + return { rootCause: 'single_region', hasRequiredInputs: true }; + } + if (config.perRegionPerPartitionAutoscaleEnabled === true) { + return { rootCause: 'already_enabled', hasRequiredInputs: true }; + } + if (config.perRegionPerPartitionAutoscaleEnabled !== false) { + return { rootCause: 'unknown', hasRequiredInputs: false }; + } + return { rootCause: 'prpa_candidate', hasRequiredInputs: true }; +} + +/** Configuration-only checks can still report missing inputs when workload collection is unavailable. */ +export function configurationFailures(config: AccountConfigInput | undefined): MetricSourceStatus['failures'] { + const failures: MetricSourceStatus['failures'] = []; + if (!classifyPaidContinuousBackup(config).hasRequiredInputs) { + failures.push({ rule: 'PaidContinuousBackup', reason: 'noData' }); + } + if (!classifyPerRegionAutoscale(config).hasRequiredInputs) { + failures.push({ rule: 'PerRegionAutoscaleCandidate', reason: 'noData' }); + } + return failures; +} + const ADVISORY_SEVERITY_ORDER: Record = { High: 0, Medium: 1, Low: 2 }; /** Shared throughput belongs to the database offer; it must never be recovered once per member. */ diff --git a/src/panels/accountOverview/services/advisories/core/requestMetrics.ts b/src/panels/accountOverview/services/advisories/core/requestMetrics.ts new file mode 100644 index 000000000..ca893cb69 --- /dev/null +++ b/src/panels/accountOverview/services/advisories/core/requestMetrics.ts @@ -0,0 +1,50 @@ +/*--------------------------------------------------------------------------------------------- + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for license information. + *--------------------------------------------------------------------------------------------*/ + +export function summarizeRequestStatuses(counts: Readonly>) { + let totalRequests = 0; + let totalThrottled = 0; + let totalErrors = 0; + const errors = new Map(); + for (const [rawStatus, count] of Object.entries(counts)) { + const status = Number(rawStatus.trim()); + if (!/^\d+$/.test(rawStatus.trim()) || !Number.isSafeInteger(status) || !Number.isFinite(count) || count <= 0) { + continue; + } + totalRequests += count; + if (status === 429) { + totalThrottled += count; + } else if (status >= 400) { + totalErrors += count; + errors.set(status, (errors.get(status) ?? 0) + count); + } + } + return { totalRequests, totalThrottled, totalErrors, errors }; +} + +export type OperationCategory = 'write' | 'read' | 'query' | 'execute' | 'other'; + +const OPERATION_CATEGORIES: Readonly> = { + create: 'write', + upsert: 'write', + replace: 'write', + delete: 'write', + patch: 'write', + batch: 'write', + executebatch: 'write', + read: 'read', + head: 'read', + query: 'query', + queryplan: 'query', + readfeed: 'query', + execute: 'execute', + executejavascript: 'execute', + executestoredprocedure: 'execute', +}; + +export function operationCategory(operation: string): OperationCategory { + const key = operation.trim().toLowerCase(); + return Object.hasOwn(OPERATION_CATEGORIES, key) ? OPERATION_CATEGORIES[key] : 'other'; +} diff --git a/src/panels/accountOverview/services/advisories/core/thresholds.ts b/src/panels/accountOverview/services/advisories/core/thresholds.ts index eef0efd2b..e6db93216 100644 --- a/src/panels/accountOverview/services/advisories/core/thresholds.ts +++ b/src/panels/accountOverview/services/advisories/core/thresholds.ts @@ -176,6 +176,24 @@ export const DIAGNOSTIC_POLICY = { multiRegionWrite: { minWriteRegions: 2, }, + // CODA's proposed DX-020/021/023 ranking policies, explicitly adopted for native advisories. + accountRequests: { + minRequests: 1000, + observation: { windowMs: 7 * DAY, interval: 'PT1H', bucketMs: HOUR } satisfies RangeConfig, + }, + nonThrottlingErrors: { + ratePercent: 1, + mediumPercent: 5, + highPercent: 10, + }, + throttlingByOperation: { + ratePercent: 1, + mediumPercent: 5, + highPercent: 20, + }, + reservedCapacity: { + minBaselineRu: 3000, + }, } as const; /** Flat detector inputs derived only from the internal policy, never from VS Code settings. */ diff --git a/src/panels/accountOverview/services/advisories/core/types.ts b/src/panels/accountOverview/services/advisories/core/types.ts index 06f154320..32df07431 100644 --- a/src/panels/accountOverview/services/advisories/core/types.ts +++ b/src/panels/accountOverview/services/advisories/core/types.ts @@ -8,6 +8,7 @@ import { type ThroughputMode } from '../../inventory'; import { type PartitionStorageSeries } from '../../partitionHealth'; import { type UnavailableReason } from '../../shared'; import { type LogsFailureKind, type LogsOperation } from '../fetchers/logsDiagnostics'; +import { type OperationCategory } from './requestMetrics'; // ─── Client-side derived advisories ────────────────────────────────────────────── // @@ -38,7 +39,12 @@ export type DerivedAdvisoryRule = | 'CrossPartitionQuery' | 'ShardKeyMisalignment' | 'UncontrolledIngestion' - | 'SharedThroughputStarvation'; + | 'SharedThroughputStarvation' + | 'PaidContinuousBackup' + | 'NonThrottlingErrors' + | 'ThrottlingByOperation' + | 'PerRegionAutoscaleCandidate' + | 'ReservedCapacityCandidate'; export type DerivedAdvisorySeverity = 'High' | 'Medium' | 'Low'; @@ -52,6 +58,13 @@ export interface ProvisioningEvaluation { advisory?: DerivedAdvisory; } +export interface RequestErrorEvaluation { + rootCause: 'too_few_requests' | 'clean' | 'has_errors'; + errorRatePercent: number; + dominantStatus?: number; + advisory?: DerivedAdvisory; +} + type EvaluationOutcome = { rootCause: RootCause } & ([ Observations, ] extends [never] @@ -99,6 +112,14 @@ interface AdvisoryEvaluationResults { removableExtraRegionRu: number | null; }; }; + PaidContinuousBackup: EvaluationOutcome< + | 'periodic_backup' + | 'unknown' + | 'uncharged_7day_backup' + | 'unknown_continuous_tier' + | 'legitimate_prod_backup' + | 'nonprod_paid_continuous_backup' + >; PartitionMergeCandidate: | EvaluationOutcome<'insufficient_data' | 'single_partition' | 'right_sized'> | EvaluationOutcome< @@ -111,6 +132,10 @@ interface AdvisoryEvaluationResults { | 'unknown'; } >; + PerRegionAutoscaleCandidate: EvaluationOutcome< + 'serverless' | 'unknown' | 'single_region' | 'already_enabled' | 'prpa_candidate' + >; + ReservedCapacityCandidate: EvaluationOutcome<'serverless' | 'unknown' | 'below_baseline' | 'reserved_candidate'>; ServerlessCandidate: EvaluationOutcome< | 'already_serverless' | 'insufficient_data' @@ -135,6 +160,19 @@ interface AdvisoryEvaluationResults { SustainedThrottlingInRegion: EvaluationOutcome< 'insufficient_data' | 'not_throttling' | 'skew_suspected' | 'global_under_provisioning' >; + ThrottlingByOperation: + | EvaluationOutcome<'too_few_requests' | 'not_throttling'> + | EvaluationOutcome< + 'decomposed', + { + totalRequests: number; + totalThrottled: number; + throttleRatePercent: number; + dominantOperation: string; + dominantCategory: OperationCategory; + dominantSharePercent: number; + } & Partial> + >; UncontrolledIngestion: EvaluationOutcome<'insufficient_data' | 'not_uncontrolled' | 'uncontrolled_ingestion'>; } @@ -165,6 +203,8 @@ export interface DerivedAdvisory { evidence?: Record; /** Structural findings can remain visible while a proposed action is blocked or unverified. */ actionEligibility?: 'requiresValidation' | 'blocked' | 'unknown'; + /** Conditional investigation guidance, not a confirmed application antipattern or authorization to remediate. */ + agentKitRule?: string | null; } /** @@ -582,6 +622,13 @@ export interface SharedThroughputThresholds { victimSharePct: number; } +/** Account-level Count TotalRequests over one common seven-day observation, not Log Analytics events. */ +export interface AccountRequestMetricsInput { + statusCounts: Readonly>; + /** 429 counts split by OperationType; absent when unavailable, not an observed zero. */ + throttledOperationCounts?: Readonly>; +} + /** Already-fetched telemetry the derived-advisory engine consumes. */ export interface DerivedAdvisoryInputs { manualThroughput?: readonly ManualThroughputInput[]; @@ -624,4 +671,5 @@ export interface DerivedAdvisoryInputs { ingestion?: readonly UncontrolledIngestionInput[]; /** Per-shared-database collection traffic (Log Analytics) for the shared-throughput-starvation rule (DX-003). */ sharedThroughput?: readonly SharedThroughputInput[]; + accountRequests?: AccountRequestMetricsInput; } diff --git a/src/panels/accountOverview/services/advisories/detectors/NonThrottlingErrorsDetector.ts b/src/panels/accountOverview/services/advisories/detectors/NonThrottlingErrorsDetector.ts new file mode 100644 index 000000000..a3ddc3934 --- /dev/null +++ b/src/panels/accountOverview/services/advisories/detectors/NonThrottlingErrorsDetector.ts @@ -0,0 +1,92 @@ +/*--------------------------------------------------------------------------------------------- + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for license information. + *--------------------------------------------------------------------------------------------*/ + +import * as l10n from '@vscode/l10n'; +import { Detector, type DetectorContext } from '../core/Detector'; +import { summarizeRequestStatuses } from '../core/requestMetrics'; +import { DIAGNOSTIC_POLICY } from '../core/thresholds'; +import { type AccountRequestMetricsInput, type DerivedAdvisory, type RequestErrorEvaluation } from '../core/types'; + +export class NonThrottlingErrorsDetector extends Detector { + readonly rule = 'NonThrottlingErrors' as const; + + evaluateResult(input: AccountRequestMetricsInput): RequestErrorEvaluation { + const { totalRequests, totalErrors, errors } = summarizeRequestStatuses(input.statusCounts); + const policy = DIAGNOSTIC_POLICY.nonThrottlingErrors; + const rate = totalRequests > 0 ? (100 * totalErrors) / totalRequests : 0; + const observed = { errorRatePercent: Number(rate.toFixed(2)) }; + if (!Number.isFinite(totalRequests) || totalRequests < DIAGNOSTIC_POLICY.accountRequests.minRequests) { + return { ...observed, rootCause: 'too_few_requests' }; + } + if (!Number.isFinite(rate) || rate < policy.ratePercent) { + return { ...observed, rootCause: 'clean' }; + } + const dominant = [...errors].sort(([codeA, countA], [codeB, countB]) => countB - countA || codeA - codeB)[0]; + if (!dominant) { + return { ...observed, rootCause: 'clean' }; + } + const [status] = dominant; + const conditionalCreate = status === 404 || status === 409; + const agentKitRule = conditionalCreate + ? 'sdk-conditional-create-etag' + : status === 412 + ? 'sdk-etag-concurrency' + : null; + const investigation = l10n.t( + 'Account-level status counts alone do not identify an operation or item or establish a read-404-then-insert sequence. Investigate request-level evidence before selecting a remediation.', + ); + const specificAction = conditionalCreate + ? l10n.t( + 'Check expected missing-item lookups, id and partition-key context. Only if code or traces confirm existence-check-before-create, review SDK-appropriate atomic create and 409 handling. Upsert can overwrite data; a 404 supplies no ETag. Do not assume .NET IfNoneMatchEtag protects writes.', + ) + : status === 412 + ? l10n.t( + 'Inspect the actual operation and ETag/precondition handling. A 412 can be expected concurrency protection, not proof of missing control or a hot item. For confirmed read-modify-write, re-read state and ETag, reapply the update and retry with bounded attempts. Surface unresolved conflicts; do not drop preconditions.', + ) + : l10n.t( + 'Investigate request validation, access, configuration, SDK retries or service health as appropriate for the status. Status counts do not identify a missing role or firewall setting; 5xx can be service-side. Increasing throughput is not a general remedy for non-429 failures.', + ); + const suggestedAction = investigation + ' ' + specificAction; + const evidence: NonNullable = { + totalRequests, + totalErrors, + errorRatePercent: rate, + dominantStatus: status, + guidance: suggestedAction, + }; + for (const [code, count] of errors) { + evidence[`status${code}Count`] = count; + evidence[`status${code}RatePercent`] = (100 * count) / totalRequests; + } + const advisory: DerivedAdvisory = { + id: this.rule, + rule: this.rule, + severity: rate >= policy.highPercent ? 'High' : rate >= policy.mediumPercent ? 'Medium' : 'Low', + title: l10n.t('Non-throttling request errors'), + rationale: l10n.t( + '`{rate}%` of `{total} requests` returned status ≥400 excluding 429. The most frequent error was `{status}`. Account-level counts do not identify an application, container, operation or item, or prove an application defect.', + { rate: rate.toFixed(2), total: totalRequests, status }, + ), + suggestedAction, + thresholdReference: l10n.t( + 'Threshold: ≥`1,000 requests` and ≥`1%` non-429 errors; Medium ≥`5%`, High ≥`10%` over seven days', + ), + evidence, + agentKitRule, + }; + return { ...observed, rootCause: 'has_errors', dominantStatus: status, advisory }; + } + + evaluate(input: AccountRequestMetricsInput): DerivedAdvisory | undefined { + return this.evaluateResult(input).advisory; + } + + run(ctx: DetectorContext): DerivedAdvisory[] { + const finding = ctx.inputs.accountRequests && this.evaluate(ctx.inputs.accountRequests); + return finding ? [finding] : []; + } +} + +export const nonThrottlingErrorsDetector = new NonThrottlingErrorsDetector(); diff --git a/src/panels/accountOverview/services/advisories/detectors/PaidContinuousBackupDetector.ts b/src/panels/accountOverview/services/advisories/detectors/PaidContinuousBackupDetector.ts new file mode 100644 index 000000000..ca885bc11 --- /dev/null +++ b/src/panels/accountOverview/services/advisories/detectors/PaidContinuousBackupDetector.ts @@ -0,0 +1,48 @@ +/*--------------------------------------------------------------------------------------------- + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for license information. + *--------------------------------------------------------------------------------------------*/ + +import * as l10n from '@vscode/l10n'; +import { Detector, type DetectorContext } from '../core/Detector'; +import { classifyPaidContinuousBackup } from '../core/helpers'; +import { type AccountConfigInput, type AdvisoryEvaluation, type DerivedAdvisory } from '../core/types'; + +export class PaidContinuousBackupDetector extends Detector { + readonly rule = 'PaidContinuousBackup' as const; + + evaluateResult = (config: AccountConfigInput): AdvisoryEvaluation<'PaidContinuousBackup'> => { + const classification = classifyPaidContinuousBackup(config); + if (classification.rootCause !== 'nonprod_paid_continuous_backup') { + return { rootCause: classification.rootCause }; + } + const advisory: DerivedAdvisory = { + id: this.rule, + rule: this.rule, + severity: 'Medium', + title: l10n.t('Paid continuous backup on a non-production account'), + rationale: l10n.t( + 'This account has paid continuous-backup retention and is inferred to be non-production. Confirm the environment and recovery requirements with the account owner.', + ), + suggestedAction: l10n.t( + 'Review Continuous7Days only if seven days of restore history meets the recovery policy. Older restore points would be lost and restores remain separately chargeable. Do not revert to periodic backup solely for this advisory.', + ), + thresholdReference: l10n.t( + 'Threshold: Continuous30Days or Continuous35Days on a positively inferred non-production account', + ), + evidence: { continuousTier: classification.tier, inferredEnvironment: classification.inferredEnvironment }, + actionEligibility: 'requiresValidation', + agentKitRule: null, + }; + return { rootCause: 'nonprod_paid_continuous_backup', advisory }; + }; + + evaluate = (config: AccountConfigInput) => this.evaluateResult(config).advisory; + + run(ctx: DetectorContext): DerivedAdvisory[] { + const finding = ctx.inputs.accountConfig && this.evaluate(ctx.inputs.accountConfig); + return finding ? [finding] : []; + } +} + +export const paidContinuousBackupDetector = new PaidContinuousBackupDetector(); diff --git a/src/panels/accountOverview/services/advisories/detectors/PerRegionAutoscaleCandidateDetector.ts b/src/panels/accountOverview/services/advisories/detectors/PerRegionAutoscaleCandidateDetector.ts new file mode 100644 index 000000000..372a55c01 --- /dev/null +++ b/src/panels/accountOverview/services/advisories/detectors/PerRegionAutoscaleCandidateDetector.ts @@ -0,0 +1,49 @@ +/*--------------------------------------------------------------------------------------------- + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for license information. + *--------------------------------------------------------------------------------------------*/ + +import * as l10n from '@vscode/l10n'; +import { Detector, type DetectorContext } from '../core/Detector'; +import { classifyPerRegionAutoscale } from '../core/helpers'; +import { type AccountConfigInput, type AdvisoryEvaluation, type DerivedAdvisory } from '../core/types'; + +export class PerRegionAutoscaleCandidateDetector extends Detector { + readonly rule = 'PerRegionAutoscaleCandidate' as const; + + evaluateResult = (config: AccountConfigInput): AdvisoryEvaluation<'PerRegionAutoscaleCandidate'> => { + const classification = classifyPerRegionAutoscale(config); + if (classification.rootCause !== 'prpa_candidate') { + return { rootCause: classification.rootCause }; + } + const advisory: DerivedAdvisory = { + id: this.rule, + rule: this.rule, + severity: 'Low', + title: l10n.t('Review per-region and per-partition autoscale'), + rationale: l10n.t( + 'The account has `{regions} regions` and per-region/per-partition autoscale is reported as disabled. This configuration check does not establish autoscale usage or uneven regional demand.', + { regions: config.regionCount }, + ), + suggestedAction: l10n.t( + 'Confirm throughput mode, current feature eligibility and regional/partition demand. If autoscale is used and demand is uneven, evaluate independent scaling. This does not fix a skewed logical key, and savings are not established.', + ), + thresholdReference: l10n.t( + 'Threshold: at least `2 regions`, provisioned account and per-region/per-partition autoscale explicitly disabled', + ), + evidence: { regionCount: config.regionCount, perRegionPerPartitionAutoscaleEnabled: false }, + actionEligibility: 'requiresValidation', + agentKitRule: null, + }; + return { rootCause: 'prpa_candidate', advisory }; + }; + + evaluate = (config: AccountConfigInput) => this.evaluateResult(config).advisory; + + run(ctx: DetectorContext): DerivedAdvisory[] { + const finding = ctx.inputs.accountConfig && this.evaluate(ctx.inputs.accountConfig); + return finding ? [finding] : []; + } +} + +export const perRegionAutoscaleCandidateDetector = new PerRegionAutoscaleCandidateDetector(); diff --git a/src/panels/accountOverview/services/advisories/detectors/ReservedCapacityCandidateDetector.ts b/src/panels/accountOverview/services/advisories/detectors/ReservedCapacityCandidateDetector.ts new file mode 100644 index 000000000..8e9bc9096 --- /dev/null +++ b/src/panels/accountOverview/services/advisories/detectors/ReservedCapacityCandidateDetector.ts @@ -0,0 +1,61 @@ +/*--------------------------------------------------------------------------------------------- + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for license information. + *--------------------------------------------------------------------------------------------*/ + +import * as l10n from '@vscode/l10n'; +import { Detector, type DetectorContext } from '../core/Detector'; +import { DIAGNOSTIC_POLICY } from '../core/thresholds'; +import { type AdvisoryEvaluation, type DerivedAdvisory } from '../core/types'; + +export class ReservedCapacityCandidateDetector extends Detector { + readonly rule = 'ReservedCapacityCandidate' as const; + + evaluateResult = ( + provisionedRu: number | undefined, + isServerless: boolean | undefined, + ): AdvisoryEvaluation<'ReservedCapacityCandidate'> => { + if (isServerless === true) { + return { rootCause: 'serverless' }; + } + if (isServerless !== false || provisionedRu === undefined || !Number.isFinite(provisionedRu)) { + return { rootCause: 'unknown' }; + } + if (provisionedRu < DIAGNOSTIC_POLICY.reservedCapacity.minBaselineRu) { + return { rootCause: 'below_baseline' }; + } + const advisory: DerivedAdvisory = { + id: this.rule, + rule: this.rule, + severity: 'Low', + title: l10n.t('Review reserved-capacity coverage'), + rationale: l10n.t( + 'Distinct provisioned offers total `{ru} RU/s` (manual allocations plus autoscale maxima). This is a configuration proxy, not a measured stable billable baseline. Low severity describes the review advisory, not utilization or potential savings.', + { ru: provisionedRu }, + ), + suggestedAction: l10n.t( + 'Review eligible usage, existing reservation coverage, negotiated rates and future demand in Cost Management before considering a one- or three-year commitment. This check does not establish that reservations are absent or quantify a discount.', + ), + thresholdReference: l10n.t( + 'Threshold: at least `{ru} RU/s` of provisioned capacity; constant Low severity', + { + ru: DIAGNOSTIC_POLICY.reservedCapacity.minBaselineRu, + }, + ), + evidence: { provisionedRu }, + actionEligibility: 'requiresValidation', + agentKitRule: null, + }; + return { rootCause: 'reserved_candidate', advisory }; + }; + + evaluate = (provisionedRu: number | undefined, isServerless: boolean | undefined) => + this.evaluateResult(provisionedRu, isServerless).advisory; + + run(ctx: DetectorContext): DerivedAdvisory[] { + const finding = this.evaluate(ctx.inputs.scopeProvisionedRuTotal, ctx.inputs.accountConfig?.isServerless); + return finding ? [finding] : []; + } +} + +export const reservedCapacityCandidateDetector = new ReservedCapacityCandidateDetector(); diff --git a/src/panels/accountOverview/services/advisories/detectors/ThrottlingByOperationDetector.ts b/src/panels/accountOverview/services/advisories/detectors/ThrottlingByOperationDetector.ts new file mode 100644 index 000000000..a6594ba1a --- /dev/null +++ b/src/panels/accountOverview/services/advisories/detectors/ThrottlingByOperationDetector.ts @@ -0,0 +1,114 @@ +/*--------------------------------------------------------------------------------------------- + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for license information. + *--------------------------------------------------------------------------------------------*/ + +import * as l10n from '@vscode/l10n'; +import { escapeAdvisoryText } from '../../../advisoryText'; +import { Detector, type DetectorContext } from '../core/Detector'; +import { clampRationale } from '../core/helpers'; +import { operationCategory, summarizeRequestStatuses, type OperationCategory } from '../core/requestMetrics'; +import { DIAGNOSTIC_POLICY } from '../core/thresholds'; +import { type AccountRequestMetricsInput, type AdvisoryEvaluation, type DerivedAdvisory } from '../core/types'; + +const CATEGORY_RULE: Record = { + write: 'sdk-ingestion-rate-control', + read: 'partition-avoid-hotspots', + query: 'query-avoid-cross-partition', + execute: 'monitoring-ru-consumption', + other: 'monitoring-throttling', +}; + +function categoryAction(category: OperationCategory): string { + switch (category) { + case 'write': + return l10n.t( + 'Review ingestion pacing, bulk execution and client-side throughput control before changing capacity.', + ); + case 'read': + return l10n.t( + 'Check partition saturation and key distribution to distinguish hotspots from uniform capacity pressure.', + ); + case 'query': + return l10n.t( + 'Inspect query diagnostics, partition-key filters and indexing requirements before attributing throttling to fan-out or increasing RU/s.', + ); + case 'execute': + return l10n.t('Review stored-procedure/server-side execution RU cost and call rate.'); + case 'other': + return l10n.t('Review the dominant operation, its call rate, RU cost and SDK retry behavior.'); + } +} + +export class ThrottlingByOperationDetector extends Detector { + readonly rule = 'ThrottlingByOperation' as const; + + evaluateResult = (input: AccountRequestMetricsInput): AdvisoryEvaluation<'ThrottlingByOperation'> => { + const { totalRequests, totalThrottled } = summarizeRequestStatuses(input.statusCounts); + const rate = (100 * totalThrottled) / totalRequests; + const policy = DIAGNOSTIC_POLICY.throttlingByOperation; + const operations = Object.entries(input.throttledOperationCounts ?? {}) + .filter(([operation, count]) => operation.trim().length > 0 && Number.isFinite(count) && count > 0) + .sort(([opA, countA], [opB, countB]) => countB - countA || opA.localeCompare(opB)); + if (!Number.isFinite(totalRequests) || totalRequests < DIAGNOSTIC_POLICY.accountRequests.minRequests) { + return { rootCause: 'too_few_requests' }; + } + if (!Number.isFinite(rate) || rate < policy.ratePercent || operations.length === 0) { + return { rootCause: 'not_throttling' }; + } + const [operation, count] = operations[0]; + const category = operationCategory(operation); + const evidence: Extract< + AdvisoryEvaluation<'ThrottlingByOperation'>, + { rootCause: 'decomposed' } + >['observations'] = { + totalRequests, + totalThrottled, + throttleRatePercent: rate, + dominantOperation: operation, + dominantCategory: category, + dominantSharePercent: (100 * count) / totalThrottled, + }; + const categoryCounts = new Map(); + for (const [op, opCount] of operations) { + const opCategory = operationCategory(op); + categoryCounts.set(opCategory, (categoryCounts.get(opCategory) ?? 0) + opCount); + } + for (const [key, categoryCount] of categoryCounts) { + evidence[`${key}SharePercent`] = (100 * categoryCount) / totalThrottled; + } + const advisory: DerivedAdvisory = { + id: this.rule, + rule: this.rule, + severity: rate >= policy.highPercent ? 'High' : rate >= policy.mediumPercent ? 'Medium' : 'Low', + title: l10n.t('Throttling by operation'), + rationale: clampRationale( + l10n.t( + '`{rate}%` of `{total} requests` were throttled. `{operation}` is the most frequent throttled operation, representing `{share}%` of status-reported 429s. Independent metric breakdowns can differ in completeness; operation mix does not prove a root cause.', + { + rate: rate.toFixed(2), + total: totalRequests, + operation: escapeAdvisoryText(operation), + share: ((100 * count) / totalThrottled).toFixed(2), + }, + ), + ), + suggestedAction: categoryAction(category), + thresholdReference: l10n.t( + 'Threshold: ≥`1,000 requests`, ≥`1%` 429s and a positive operation breakdown; Medium ≥`5%`, High ≥`20%` over seven days', + ), + evidence, + agentKitRule: CATEGORY_RULE[category], + }; + return { rootCause: 'decomposed', advisory, observations: evidence }; + }; + + evaluate = (input: AccountRequestMetricsInput) => this.evaluateResult(input).advisory; + + run(ctx: DetectorContext): DerivedAdvisory[] { + const finding = ctx.inputs.accountRequests && this.evaluate(ctx.inputs.accountRequests); + return finding ? [finding] : []; + } +} + +export const throttlingByOperationDetector = new ThrottlingByOperationDetector(); diff --git a/src/panels/accountOverview/services/advisories/fetchers/accountRequests.test.ts b/src/panels/accountOverview/services/advisories/fetchers/accountRequests.test.ts new file mode 100644 index 000000000..33e0d4dea --- /dev/null +++ b/src/panels/accountOverview/services/advisories/fetchers/accountRequests.test.ts @@ -0,0 +1,126 @@ +/*--------------------------------------------------------------------------------------------- + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for license information. + *--------------------------------------------------------------------------------------------*/ + +import { describe, expect, it, vi } from 'vitest'; +import { mockClient, throwingClient } from '../../testFixtures'; +import { getAccountRequestStatusCounts, getThrottledOperationCounts } from './metrics'; + +const now = Date.parse('2026-11-09T12:00:00.000Z'); +const timeStamp = '2026-11-09T11:00:00.000Z'; +const series = (dimension: string, value: string, count: number) => ({ + metadatavalues: [{ name: { value: dimension }, value }], + data: [{ timeStamp, count }], +}); + +describe('account request metric collection', () => { + it('reads one account-only seven-day hourly status breakdown and sums regional/bucket counts', async () => { + const client = mockClient({ + TotalRequests: { + value: [ + { + timeseries: [ + series('StatusCode', '200', 900), + series('statuscode', '200', 100), + series('StatusCode', '429', 50), + { + ...series('StatusCode', '404', 10), + data: [ + { timeStamp, count: 10 }, + { timeStamp: '2026-11-09T10:00:00.000Z', count: 20 }, + ], + }, + ], + }, + ], + }, + }); + const list = vi.spyOn(client.metrics, 'list'); + expect(await getAccountRequestStatusCounts(client, 'account', now)).toEqual({ 200: 1000, 429: 50, 404: 30 }); + expect(list).toHaveBeenCalledExactlyOnceWith('account', { + metricnames: 'TotalRequests', + aggregation: 'Count', + interval: 'PT1H', + timespan: '2026-11-02T12:00:00.000Z/2026-11-09T12:00:00.000Z', + filter: "StatusCode eq '*'", + top: 1000, + }); + }); + + it('uses the same observation for the 429-only operation split', async () => { + const client = mockClient({ + TotalRequests: { + value: [{ timeseries: [series('OperationType', 'Create', 30), series('OperationType', 'Read', 20)] }], + }, + }); + const list = vi.spyOn(client.metrics, 'list'); + expect(await getThrottledOperationCounts(client, 'account', now)).toEqual({ Create: 30, Read: 20 }); + expect(list).toHaveBeenCalledExactlyOnceWith( + 'account', + expect.objectContaining({ + filter: "StatusCode eq '429' and OperationType eq '*'", + timespan: '2026-11-02T12:00:00.000Z/2026-11-09T12:00:00.000Z', + interval: 'PT1H', + aggregation: 'Count', + }), + ); + }); + + it('does not turn absent, malformed or nonpositive samples into measured counts', async () => { + const client = mockClient({ + TotalRequests: { + value: [ + { + timeseries: [ + series('StatusCode', '200', -1), + series('StatusCode', '404', Infinity), + series('StatusCode', '429', NaN), + series('StatusCode', '500', 0), + series('OperationType', 'Create', 100), + { + ...series('StatusCode', '403', 10), + data: [ + { timeStamp: 'invalid', count: 10 }, + { timeStamp, total: 10 }, + ], + }, + { data: [{ timeStamp, count: 1000 }] }, + ], + }, + ], + }, + }); + expect(await getAccountRequestStatusCounts(client, 'account', now)).toEqual({}); + expect(await getAccountRequestStatusCounts(mockClient({}), 'account', now)).toEqual({}); + }); + + it.each([getAccountRequestStatusCounts, getThrottledOperationCounts])( + 'propagates denied and metric-level failures from %s', + async (read) => { + await expect(read(throwingClient({ statusCode: 403 }), 'account', now)).rejects.toMatchObject({ + statusCode: 403, + }); + const response = { + value: [ + { + errorCode: 'InternalServerError', + errorMessage: 'Incomplete response', + timeseries: [series('StatusCode', '200', 1000)], + }, + ], + }; + const client = mockClient({ TotalRequests: response }); + await expect(read(client, 'account', now)).rejects.toThrow('Incomplete response'); + }, + ); + + it('rejects potentially truncated responses instead of claiming complete totals', async () => { + const client = mockClient({ + TotalRequests: { + value: [{ timeseries: Array.from({ length: 1000 }, () => series('OperationType', 'Create', 1)) }], + }, + }); + await expect(getThrottledOperationCounts(client, 'account', now)).rejects.toThrow('may be truncated'); + }); +}); diff --git a/src/panels/accountOverview/services/advisories/fetchers/metrics.ts b/src/panels/accountOverview/services/advisories/fetchers/metrics.ts index 0349517dd..5d5cf06c8 100644 --- a/src/panels/accountOverview/services/advisories/fetchers/metrics.ts +++ b/src/panels/accountOverview/services/advisories/fetchers/metrics.ts @@ -31,6 +31,62 @@ function advisoryTimespan(observation: RangeConfig, now = Date.now()): string { return `${new Date(start).toISOString()}/${new Date(now).toISOString()}`; } +/** Split only one low-cardinality account dimension, never database/container inventory discovery. */ +async function getAccountRequestDimension( + client: MonitorClient, + resourceUri: string, + dimension: 'StatusCode' | 'OperationType', + now: number, +): Promise> { + const observation = DIAGNOSTIC_POLICY.accountRequests.observation; + const seriesLimit = 1000; + const response = await client.metrics.list(resourceUri, { + metricnames: 'TotalRequests', + aggregation: 'Count', + timespan: advisoryTimespan(observation, now), + interval: observation.interval, + filter: dimension === 'StatusCode' ? "StatusCode eq '*'" : "StatusCode eq '429' and OperationType eq '*'", + top: seriesLimit, + }); + const counts = new Map(); + for (const metric of response.value ?? []) { + if (metric.errorCode && metric.errorCode !== 'Success') { + throw new Error(metric.errorMessage ?? metric.errorCode); + } + if ((metric.timeseries?.length ?? 0) >= seriesLimit) { + throw new Error('Account request metric series may be truncated.'); + } + for (const series of metric.timeseries ?? []) { + const key = series.metadatavalues + ?.find((value) => value.name?.value?.toLowerCase() === dimension.toLowerCase()) + ?.value?.trim(); + if (!key) { + continue; + } + for (const point of series.data ?? []) { + const count = pickPointValue(point, 'Count'); + if (count === undefined || count <= 0 || parseMonitorTimestamp(point.timeStamp) === undefined) { + continue; + } + const total = (counts.get(key) ?? 0) + count; + if (!Number.isFinite(total)) { + throw new Error('Account request metric count is not finite.'); + } + counts.set(key, total); + } + } + } + return Object.fromEntries(counts); +} + +export function getAccountRequestStatusCounts(client: MonitorClient, resourceUri: string, now = Date.now()) { + return getAccountRequestDimension(client, resourceUri, 'StatusCode', now); +} + +export function getThrottledOperationCounts(client: MonitorClient, resourceUri: string, now = Date.now()) { + return getAccountRequestDimension(client, resourceUri, 'OperationType', now); +} + /** Account-total consumed-RU shape over the 30-day window (DX-014 serverless-candidate signal). */ export interface AccountConsumedRuShape { /** Account-total average consumed RU/s across the sampled buckets. */ diff --git a/src/panels/accountOverview/services/advisories/index.ts b/src/panels/accountOverview/services/advisories/index.ts index 33c544b1b..b7409b9bb 100644 --- a/src/panels/accountOverview/services/advisories/index.ts +++ b/src/panels/accountOverview/services/advisories/index.ts @@ -35,6 +35,11 @@ export * from './detectors/CrossPartitionQueryDetector'; export * from './detectors/ShardKeyMisalignmentDetector'; export * from './detectors/UncontrolledIngestionDetector'; export * from './detectors/SharedThroughputStarvationDetector'; +export * from './detectors/PaidContinuousBackupDetector'; +export * from './detectors/NonThrottlingErrorsDetector'; +export * from './detectors/ThrottlingByOperationDetector'; +export * from './detectors/PerRegionAutoscaleCandidateDetector'; +export * from './detectors/ReservedCapacityCandidateDetector'; export * from './fetchers/metrics'; export * from './fetchers/logs'; diff --git a/src/panels/accountOverview/services/advisories/missingDetectors.test.ts b/src/panels/accountOverview/services/advisories/missingDetectors.test.ts new file mode 100644 index 000000000..b1836324e --- /dev/null +++ b/src/panels/accountOverview/services/advisories/missingDetectors.test.ts @@ -0,0 +1,378 @@ +/*--------------------------------------------------------------------------------------------- + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for license information. + *--------------------------------------------------------------------------------------------*/ + +import { describe, expect, it } from 'vitest'; +import { API } from '../../../../AzureDBExperiences'; +import { configurationFailures } from './core/helpers'; +import { DEFAULT_ADVISORY_THRESHOLDS } from './core/thresholds'; +import { type AccountConfigInput } from './core/types'; +import { nonThrottlingErrorsDetector } from './detectors/NonThrottlingErrorsDetector'; +import { paidContinuousBackupDetector } from './detectors/PaidContinuousBackupDetector'; +import { perRegionAutoscaleCandidateDetector } from './detectors/PerRegionAutoscaleCandidateDetector'; +import { reservedCapacityCandidateDetector } from './detectors/ReservedCapacityCandidateDetector'; +import { throttlingByOperationDetector } from './detectors/ThrottlingByOperationDetector'; +import { computeDerivedAdvisories } from './engine'; +import { DETECTORS } from './registry'; + +const config: AccountConfigInput = { + accountName: 'account-dev', + regionCount: 2, + multiRegionWritesEnabled: false, + writeRegionCount: 1, + api: API.Core, + isServerless: false, + perRegionPerPartitionAutoscaleEnabled: false, + backupPolicy: { type: 'Continuous', continuousTier: 'Continuous30Days' }, +}; + +describe('native DX-019 paid continuous retention', () => { + it.each<{ + overrides: Partial; + rootCause: string; + missing: boolean; + }>([ + { overrides: { backupPolicy: undefined }, rootCause: 'unknown', missing: true }, + { overrides: { backupPolicy: { type: 'Unknown' } }, rootCause: 'unknown', missing: true }, + { overrides: { backupPolicy: { type: 'pErIoDiC' } }, rootCause: 'periodic_backup', missing: false }, + { + overrides: { backupPolicy: { type: 'Continuous', continuousTier: ' Continuous7Days ' } }, + rootCause: 'uncharged_7day_backup', + missing: false, + }, + { + overrides: { backupPolicy: { type: 'Continuous', continuousTier: 'Unknown' } }, + rootCause: 'unknown_continuous_tier', + missing: true, + }, + { + overrides: { accountName: 'account-prod', backupPolicy: { type: 'Continuous' } }, + rootCause: 'unknown_continuous_tier', + missing: false, + }, + { + overrides: { accountName: 'account', backupPolicy: { type: 'Continuous' } }, + rootCause: 'unknown_continuous_tier', + missing: false, + }, + { overrides: { accountName: 'account-prod' }, rootCause: 'legitimate_prod_backup', missing: false }, + { overrides: { accountName: 'account' }, rootCause: 'legitimate_prod_backup', missing: false }, + { overrides: {}, rootCause: 'nonprod_paid_continuous_backup', missing: false }, + ])('preserves classification and coverage for $overrides', ({ overrides, rootCause, missing }) => { + const input = { ...config, ...overrides }; + expect(paidContinuousBackupDetector.evaluateResult(input).rootCause).toBe(rootCause); + expect(configurationFailures(input).some((failure) => failure.rule === 'PaidContinuousBackup')).toBe(missing); + }); + + it.each<[string | undefined, string | undefined]>([ + ['Continuous30Days', 'Medium'], + ['cOnTiNuOuS35DaYs', 'Medium'], + ['Continuous7Days', undefined], + ['Unknown', undefined], + [undefined, undefined], + ])('evaluates tier %s without inventing a paid tier', (continuousTier, severity) => { + const result = paidContinuousBackupDetector.evaluate({ + ...config, + backupPolicy: { type: 'Continuous', continuousTier }, + }); + expect(result?.severity).toBe(severity); + }); + + it.each([ + { accountName: 'account-prod' }, + { accountName: 'account' }, + { accountName: 'account-dev', tags: { environment: 'production' } }, + { backupPolicy: { type: 'Periodic', continuousTier: 'Continuous30Days' } }, + { backupPolicy: undefined }, + ])('does not infer non-production paid retention: %j', (overrides) => { + expect(paidContinuousBackupDetector.evaluate({ ...config, ...overrides })).toBeUndefined(); + }); + + it('keeps retention review separate from a savings estimate or disabling PITR', () => { + const result = paidContinuousBackupDetector.evaluate(config); + expect(result).toMatchObject({ + severity: 'Medium', + agentKitRule: null, + actionEligibility: 'requiresValidation', + evidence: { continuousTier: 'continuous30days', inferredEnvironment: 'dev' }, + }); + expect(result?.suggestedAction).toContain('Older restore points would be lost'); + expect(result?.suggestedAction).toContain('Do not revert to periodic'); + expect(result?.evidence).not.toHaveProperty('savings'); + }); +}); + +describe('native DX-020 non-429 errors', () => { + it.each<[number, string | undefined]>([ + [9, undefined], + [10, 'Low'], + [49, 'Low'], + [50, 'Medium'], + [99, 'Medium'], + [100, 'High'], + ])('grades %s hard errors in 1,000 requests without rounding before gates', (errors, severity) => { + const result = nonThrottlingErrorsDetector.evaluate({ statusCounts: { 200: 1000 - errors, 500: errors } }); + expect(result?.severity).toBe(severity); + }); + + it('includes 429s in the denominator but not the hard-error numerator', () => { + const result = nonThrottlingErrorsDetector.evaluate({ statusCounts: { 200: 590, 429: 400, 404: 10 } }); + expect(result?.evidence).toMatchObject({ + totalRequests: 1000, + totalErrors: 10, + errorRatePercent: 1, + status404RatePercent: 1, + }); + expect(nonThrottlingErrorsDetector.evaluate({ statusCounts: { 200: 600, 429: 400 } })).toBeUndefined(); + }); + + it.each>([ + { 200: 899, 500: 100 }, + { 200: 100_000, 500: 1009 }, + { broken: 100_000, 500: 10 }, + { 200: NaN, 500: 10 }, + { 200: Infinity, 500: -1 }, + {}, + ])('abstains for insufficient/invalid observations: %j', (statusCounts) => { + expect(nonThrottlingErrorsDetector.evaluate({ statusCounts })).toBeUndefined(); + }); + + it.each<[number, string | null, string]>([ + [404, 'sdk-conditional-create-etag', 'Only if code or traces confirm'], + [409, 'sdk-conditional-create-etag', 'Upsert can overwrite'], + [412, 'sdk-etag-concurrency', 'expected concurrency protection'], + [401, null, 'Increasing throughput is not a general remedy'], + [403, null, 'do not identify a missing role'], + [500, null, '5xx can be service-side'], + ])('uses only conditional guidance for dominant %s', (status, agentKitRule, action) => { + const result = nonThrottlingErrorsDetector.evaluate({ statusCounts: { 200: 900, [status]: 100 } }); + expect(result).toMatchObject({ agentKitRule, evidence: { dominantStatus: status } }); + expect(result?.suggestedAction).toContain(action); + expect(result?.rationale).toContain('do not identify an application, container, operation or item'); + }); + + it('does not select a minority mapped error over a dominant service failure', () => { + expect( + nonThrottlingErrorsDetector.evaluate({ + statusCounts: { 200: 800, 500: 150, 404: 30, 409: 10, 412: 10, invalid: 50, 201: -10 }, + }), + ).toMatchObject({ + severity: 'High', + agentKitRule: null, + evidence: { totalRequests: 1000, dominantStatus: 500 }, + }); + }); +}); + +describe('native DX-021 throttled operation investigation', () => { + it.each<[number, string | undefined]>([ + [99, undefined], + [100, 'Low'], + [499, 'Low'], + [500, 'Medium'], + [1999, 'Medium'], + [2000, 'High'], + ])('grades %s throttles in 10,000 requests', (throttles, severity) => { + const result = throttlingByOperationDetector.evaluate({ + statusCounts: { 200: 10_000 - throttles, 429: throttles }, + throttledOperationCounts: { Create: throttles }, + }); + expect(result?.severity).toBe(severity); + }); + + it.each([ + ['Create', 'write', 'sdk-ingestion-rate-control'], + ['ExecuteBatch', 'write', 'sdk-ingestion-rate-control'], + [' head ', 'read', 'partition-avoid-hotspots'], + ['Read', 'read', 'partition-avoid-hotspots'], + ['ReadFeed', 'query', 'query-avoid-cross-partition'], + ['QueryPlan', 'query', 'query-avoid-cross-partition'], + ['ExecuteStoredProcedure', 'execute', 'monitoring-ru-consumption'], + ['ExecuteJavaScript', 'execute', 'monitoring-ru-consumption'], + ['NewOperation', 'other', 'monitoring-throttling'], + ['constructor', 'other', 'monitoring-throttling'], + ])('classifies %s without claiming root cause', (operation, category, agentKitRule) => { + const result = throttlingByOperationDetector.evaluate({ + statusCounts: { 200: 900, 429: 100 }, + throttledOperationCounts: { [operation]: 100 }, + }); + expect(result).toMatchObject({ + agentKitRule, + evidence: { dominantCategory: category, dominantSharePercent: 100 }, + }); + expect(result?.rationale).toContain('does not prove a root cause'); + }); + + it('selects the dominant individual operation, not the combined category', () => { + const result = throttlingByOperationDetector.evaluate({ + statusCounts: { 200: 8700, 429: 1300 }, + throttledOperationCounts: { Create: 400, Upsert: 400, Read: 500, invalid: NaN, zero: 0 }, + }); + expect(result).toMatchObject({ + agentKitRule: 'partition-avoid-hotspots', + evidence: { dominantOperation: 'Read', dominantCategory: 'read' }, + }); + expect(result?.evidence?.writeSharePercent).toBeCloseTo((800 / 1300) * 100); + expect(result?.evidence?.readSharePercent).toBeCloseTo((500 / 1300) * 100); + }); + + it.each<{ counts: Record | undefined }>([ + { counts: undefined }, + { counts: {} }, + { counts: { Create: 0 } }, + { counts: { Create: NaN } }, + { counts: { ' ': 100 } }, + ])('does not invent an operation breakdown: %j', ({ counts: throttledOperationCounts }) => { + expect( + throttlingByOperationDetector.evaluate({ + statusCounts: { 200: 800, 429: 200 }, + throttledOperationCounts, + }), + ).toBeUndefined(); + }); + + it('preserves independent-source share semantics rather than normalizing missing operations to 100%', () => { + const result = throttlingByOperationDetector.evaluate({ + statusCounts: { 200: 900, 429: 100 }, + throttledOperationCounts: { Query: 50 }, + }); + expect(result?.evidence).toMatchObject({ querySharePercent: 50, dominantSharePercent: 50 }); + }); + + it('requires 1,000 requests and escapes literal operation markup', () => { + expect( + throttlingByOperationDetector.evaluate({ + statusCounts: { 200: 899, 429: 100 }, + throttledOperationCounts: { Create: 100 }, + }), + ).toBeUndefined(); + const result = throttlingByOperationDetector.evaluate({ + statusCounts: { 200: 900, 429: 100 }, + throttledOperationCounts: { 'op`name': 100 }, + }); + expect(result?.rationale).toContain('op\\`name'); + }); +}); + +describe('native DX-022 and DX-023 configuration reviews', () => { + it.each([ + { regions: 0, serverless: true, enabled: undefined, rootCause: 'serverless', missing: false }, + { regions: 1, serverless: false, enabled: undefined, rootCause: 'single_region', missing: false }, + { regions: 1, serverless: undefined, enabled: undefined, rootCause: 'unknown', missing: false }, + { regions: 2, serverless: undefined, enabled: false, rootCause: 'unknown', missing: true }, + { regions: 2, serverless: false, enabled: undefined, rootCause: 'unknown', missing: true }, + { regions: 2, serverless: false, enabled: true, rootCause: 'already_enabled', missing: false }, + { regions: 2, serverless: false, enabled: false, rootCause: 'prpa_candidate', missing: false }, + { regions: 0, serverless: false, enabled: true, rootCause: 'unknown', missing: true }, + { regions: 1.5, serverless: false, enabled: false, rootCause: 'unknown', missing: true }, + { regions: NaN, serverless: false, enabled: false, rootCause: 'unknown', missing: true }, + ])( + 'preserves regional classification and coverage for %j', + ({ regions, serverless, enabled, rootCause, missing }) => { + const input = { + ...config, + regionCount: regions, + isServerless: serverless, + perRegionPerPartitionAutoscaleEnabled: enabled, + }; + expect(perRegionAutoscaleCandidateDetector.evaluateResult(input).rootCause).toBe(rootCause); + expect(configurationFailures(input).some((failure) => failure.rule === 'PerRegionAutoscaleCandidate')).toBe( + missing, + ); + }, + ); + + it('reports both configuration checks as missing when account metadata is unavailable', () => { + expect(configurationFailures(undefined)).toEqual([ + { rule: 'PaidContinuousBackup', reason: 'noData' }, + { rule: 'PerRegionAutoscaleCandidate', reason: 'noData' }, + ]); + }); + + it.each<[number, boolean | undefined, boolean | undefined, string | undefined]>([ + [1, false, false, undefined], + [2, false, false, 'Low'], + [3, false, false, 'Low'], + [2, true, false, undefined], + [2, false, true, undefined], + [2, false, undefined, undefined], + [0, false, false, undefined], + [NaN, false, false, undefined], + [1.5, false, false, undefined], + [2, undefined, false, undefined], + ])('evaluates regions=%s, serverless=%s, feature=%s', (regionCount, isServerless, enabled, severity) => { + expect( + perRegionAutoscaleCandidateDetector.evaluate({ + ...config, + regionCount, + isServerless, + perRegionPerPartitionAutoscaleEnabled: enabled, + })?.severity, + ).toBe(severity); + }); + + it.each<[number | undefined, string | undefined]>([ + [undefined, undefined], + [NaN, undefined], + [Infinity, undefined], + [-1, undefined], + [2999, undefined], + [3000, 'Low'], + [250_000, 'Low'], + ])('keeps baseline %s unknown/below-threshold or constant Low', (baseline, severity) => { + expect(reservedCapacityCandidateDetector.evaluate(baseline, false)?.severity).toBe(severity); + expect(reservedCapacityCandidateDetector.evaluate(baseline, true)).toBeUndefined(); + expect(reservedCapacityCandidateDetector.evaluate(baseline, undefined)).toBeUndefined(); + }); + + it('reports missing configuration without treating missing feature state as off', () => { + expect( + configurationFailures({ + ...config, + backupPolicy: { type: 'Continuous' }, + perRegionPerPartitionAutoscaleEnabled: undefined, + }), + ).toEqual([ + { rule: 'PaidContinuousBackup', reason: 'noData' }, + { rule: 'PerRegionAutoscaleCandidate', reason: 'noData' }, + ]); + expect(configurationFailures(config)).toEqual([]); + expect( + configurationFailures({ + ...config, + accountName: 'account-prod', + backupPolicy: { type: 'Continuous' }, + }), + ).toEqual([]); + }); + + it('registers all five new rules and evaluates independent native inputs together', () => { + expect(DETECTORS).toHaveLength(24); + expect(new Set(DETECTORS.map((detector) => detector.rule)).size).toBe(24); + const results = computeDerivedAdvisories( + { + weeklyRuPercents: [], + hasManualThroughput: false, + partitions: [], + storage: [], + indexing: [], + accountConfig: config, + scopeProvisionedRuTotal: 5000, + accountRequests: { + statusCounts: { 200: 800, 404: 100, 429: 100 }, + throttledOperationCounts: { Create: 70 }, + }, + }, + DEFAULT_ADVISORY_THRESHOLDS, + ); + expect(results.map((result) => result.rule).sort()).toEqual([ + 'NonThrottlingErrors', + 'PaidContinuousBackup', + 'PerRegionAutoscaleCandidate', + 'ReservedCapacityCandidate', + 'ThrottlingByOperation', + ]); + expect(results.every((result) => result.scope === undefined && result.rationale.length <= 500)).toBe(true); + }); +}); diff --git a/src/panels/accountOverview/services/advisories/registry.ts b/src/panels/accountOverview/services/advisories/registry.ts index a5e03ff45..47983000a 100644 --- a/src/panels/accountOverview/services/advisories/registry.ts +++ b/src/panels/accountOverview/services/advisories/registry.ts @@ -13,14 +13,19 @@ import { hotPartitionRiskDetector } from './detectors/HotPartitionRiskDetector'; import { idleContainerDetector } from './detectors/IdleContainerDetector'; import { indexingCostRiskDetector } from './detectors/IndexingCostRiskDetector'; import { multiRegionWriteAntipatternDetector } from './detectors/MultiRegionWriteAntipatternDetector'; +import { nonThrottlingErrorsDetector } from './detectors/NonThrottlingErrorsDetector'; import { overProvisioningDetector } from './detectors/OverProvisioningDetector'; +import { paidContinuousBackupDetector } from './detectors/PaidContinuousBackupDetector'; import { partitionMergeCandidateDetector } from './detectors/PartitionMergeCandidateDetector'; +import { perRegionAutoscaleCandidateDetector } from './detectors/PerRegionAutoscaleCandidateDetector'; +import { reservedCapacityCandidateDetector } from './detectors/ReservedCapacityCandidateDetector'; import { serverlessCandidateDetector } from './detectors/ServerlessCandidateDetector'; import { serverlessThrottlingDetector } from './detectors/ServerlessThrottlingDetector'; import { shardKeyMisalignmentDetector } from './detectors/ShardKeyMisalignmentDetector'; import { sharedThroughputStarvationDetector } from './detectors/SharedThroughputStarvationDetector'; import { storageGrowthRiskDetector } from './detectors/StorageGrowthRiskDetector'; import { storageSkewRiskDetector } from './detectors/StorageSkewRiskDetector'; +import { throttlingByOperationDetector } from './detectors/ThrottlingByOperationDetector'; import { uncontrolledIngestionDetector } from './detectors/UncontrolledIngestionDetector'; import { underProvisioningDetector } from './detectors/UnderProvisioningDetector'; @@ -49,4 +54,9 @@ export const DETECTORS: readonly Detector[] = [ crossPartitionQueryDetector, uncontrolledIngestionDetector, sharedThroughputStarvationDetector, + paidContinuousBackupDetector, + nonThrottlingErrorsDetector, + throttlingByOperationDetector, + perRegionAutoscaleCandidateDetector, + reservedCapacityCandidateDetector, ]; diff --git a/src/panels/trpc/routers/accountOverview/derivedAdvisoriesRouter.test.ts b/src/panels/trpc/routers/accountOverview/derivedAdvisoriesRouter.test.ts index ae5f020f2..cddb96889 100644 --- a/src/panels/trpc/routers/accountOverview/derivedAdvisoriesRouter.test.ts +++ b/src/panels/trpc/routers/accountOverview/derivedAdvisoriesRouter.test.ts @@ -85,6 +85,63 @@ describe('account advisory acquisition', () => { }, ); + it('retains the new ARM-only findings when Monitor acquisition is denied', async () => { + const input = metadata({ + tags: { environment: 'dev' }, + backupPolicy: { type: 'Continuous', continuousModeProperties: { tier: 'Continuous30Days' } }, + enablePerRegionPerPartitionAutoscale: false, + }); + input.getMonitorClient.mockRejectedValue({ statusCode: 403 }); + const result = await getDerivedAdvisoriesForAccount(input); + expect(result.advisories.map((item) => item.rule)).toEqual([ + 'ExpensiveConsistency', + 'PaidContinuousBackup', + 'PerRegionAutoscaleCandidate', + ]); + expect(result.metricSource?.failures.map((failure) => failure.rule)).not.toContain('PaidContinuousBackup'); + expect(result.metricSource?.failures.map((failure) => failure.rule)).not.toContain( + 'PerRegionAutoscaleCandidate', + ); + expect(input.getClient).not.toHaveBeenCalled(); + expect(input.getLogsQueryClient).not.toHaveBeenCalled(); + }); + + it('passes continuous tier and explicit independent-autoscale state from the existing snapshot', async () => { + vi.mocked(collectDerivedAdvisories).mockResolvedValueOnce({ + advisories: [], + logSource: { available: true }, + metricSource: { available: true, failures: [] }, + }); + await getDerivedAdvisoriesForAccount( + metadata({ + backupPolicy: { type: 'Continuous', continuousModeProperties: { tier: 'Continuous35Days' } }, + enablePerRegionPerPartitionAutoscale: false, + }), + ); + expect(collectDerivedAdvisories).toHaveBeenCalledWith( + expect.objectContaining({ + accountConfig: expect.objectContaining({ + isServerless: false, + perRegionPerPartitionAutoscaleEnabled: false, + backupPolicy: expect.objectContaining({ type: 'Continuous', continuousTier: 'Continuous35Days' }), + }), + }), + ); + }); + + it('reports unknown configuration rather than interpreting absent ARM fields as off', async () => { + const input = metadata({ backupPolicy: undefined, enablePerRegionPerPartitionAutoscale: undefined }); + input.getMonitorClient.mockResolvedValue(undefined); + const result = await getDerivedAdvisoriesForAccount(input); + expect(result.metricSource?.failures).toEqual( + expect.arrayContaining([ + { rule: 'PaidContinuousBackup', reason: 'noData' }, + { rule: 'PerRegionAutoscaleCandidate', reason: 'noData' }, + ]), + ); + expect(result.advisories.map((item) => item.rule)).toEqual(['ExpensiveConsistency']); + }); + it('passes existing ARM backup and migration metadata without acquiring another identity', async () => { const backupPolicy = { type: 'Periodic', migrationState: { status: 'InProgress', targetType: 'Continuous' } }; const input = metadata({ backupPolicy }); @@ -115,12 +172,14 @@ describe('account advisory acquisition', () => { const result = await getDerivedAdvisoriesForAccount(input); expect(result.metricSource?.available).toBe(false); - expect(result.metricSource?.failures).toHaveLength(13); + expect(result.metricSource?.failures).toHaveLength(16); expect(result.metricSource?.failures.every((failure) => failure.reason === reason)).toBe(true); const failedRules = result.metricSource?.failures.map((failure) => failure.rule); for (const rule of [ 'ExpensiveConsistency', 'MultiRegionWriteAntipattern', + 'PaidContinuousBackup', + 'PerRegionAutoscaleCandidate', 'CrossPartitionQuery', 'ShardKeyMisalignment', 'UncontrolledIngestion', diff --git a/src/panels/trpc/routers/accountOverview/derivedAdvisoriesRouter.ts b/src/panels/trpc/routers/accountOverview/derivedAdvisoriesRouter.ts index df8c40b0b..2fdcee2b8 100644 --- a/src/panels/trpc/routers/accountOverview/derivedAdvisoriesRouter.ts +++ b/src/panels/trpc/routers/accountOverview/derivedAdvisoriesRouter.ts @@ -10,6 +10,7 @@ import { createLogsOutputReporter } from '../../../accountOverview/logsOutput'; import { collectDerivedAdvisories, computeDerivedAdvisories, + configurationFailures, type AccountConfigInput, type DerivedAdvisoriesResult, } from '../../../accountOverview/services/advisories'; @@ -91,15 +92,21 @@ export async function getDerivedAdvisoriesForAccount( ), metricSource: { available: false, - failures: DETECTORS.filter( - ({ rule }) => - rule !== 'ExpensiveConsistency' && - rule !== 'MultiRegionWriteAntipattern' && - rule !== 'CrossPartitionQuery' && - rule !== 'ShardKeyMisalignment' && - rule !== 'UncontrolledIngestion' && - rule !== 'SharedThroughputStarvation', - ).map(({ rule }) => ({ rule, reason })), + failures: [ + ...configurationFailures(accountConfig), + ...DETECTORS.filter( + ({ rule }) => + rule !== 'ExpensiveConsistency' && + rule !== 'MultiRegionWriteAntipattern' && + rule !== 'PaidContinuousBackup' && + rule !== 'PerRegionAutoscaleCandidate' && + !(rule === 'ReservedCapacityCandidate' && metadata.isServerless) && + rule !== 'CrossPartitionQuery' && + rule !== 'ShardKeyMisalignment' && + rule !== 'UncontrolledIngestion' && + rule !== 'SharedThroughputStarvation', + ).map(({ rule }) => ({ rule, reason })), + ], }, logSource: { available: false, reason }, generatedAt: Date.now(), diff --git a/src/webviews/cosmosdb/AccountOverview/DerivedAdvisories.test.tsx b/src/webviews/cosmosdb/AccountOverview/DerivedAdvisories.test.tsx index 8808669d3..ce274af52 100644 --- a/src/webviews/cosmosdb/AccountOverview/DerivedAdvisories.test.tsx +++ b/src/webviews/cosmosdb/AccountOverview/DerivedAdvisories.test.tsx @@ -19,7 +19,7 @@ import { cleanup, fireEvent, render, screen, waitFor, within } from '@testing-li import userEvent from '@testing-library/user-event'; import { useState } from 'react'; import { afterEach, describe, expect, it, vi } from 'vitest'; -import { type DerivedAdvisoriesResult } from '../../api/types'; +import { type DerivedAdvisoriesResult, type DerivedAdvisoryRule } from '../../api/types'; import { DashboardActionsProvider } from './DashboardChrome'; import { DerivedAdvisories } from './DerivedAdvisories'; @@ -178,6 +178,41 @@ describe('log coverage guidance', () => { }); describe('metric coverage and actionable findings', () => { + it.each<{ rule: DerivedAdvisoryRule; name: string }>([ + { rule: 'PaidContinuousBackup', name: 'Paid continuous backup' }, + { rule: 'NonThrottlingErrors', name: 'Non-throttling errors' }, + { rule: 'ThrottlingByOperation', name: 'Throttling by operation' }, + { rule: 'PerRegionAutoscaleCandidate', name: 'Per-region autoscale review' }, + { rule: 'ReservedCapacityCandidate', name: 'Reserved-capacity review' }, + ])('renders an accessible account-wide $rule review and opens its details by keyboard', async ({ rule, name }) => { + const user = userEvent.setup(); + showCoverage( + { available: true }, + { + advisories: [ + { + id: rule, + rule, + severity: 'Low', + title: name, + rationale: 'Account observation.', + suggestedAction: 'Review requirements.', + thresholdReference: 'Internal policy.', + }, + ], + }, + ); + const button = screen.getByRole('button', { name: new RegExp(`^${name}\\.`) }); + expect(button).toHaveTextContent(name); + expect(button).toHaveAccessibleName(new RegExp(`^${name}\\.`)); + expect(button).toHaveAttribute('aria-haspopup', 'dialog'); + button.focus(); + await user.keyboard('{Enter}'); + const dialog = screen.getByRole('dialog', { name }); + expect(dialog).toHaveTextContent('Account observation.'); + expect(dialog).toHaveTextContent('Review requirements.'); + }); + it('announces incomplete metric checks without claiming a clean result or blaming Log Analytics', () => { showCoverage( { available: true }, diff --git a/src/webviews/cosmosdb/AccountOverview/DerivedAdvisories.tsx b/src/webviews/cosmosdb/AccountOverview/DerivedAdvisories.tsx index e0be7111d..6237b1ccc 100644 --- a/src/webviews/cosmosdb/AccountOverview/DerivedAdvisories.tsx +++ b/src/webviews/cosmosdb/AccountOverview/DerivedAdvisories.tsx @@ -373,6 +373,41 @@ function ruleMeta(rule: DerivedAdvisoryRule): { name: string; description: strin 'Containers in a shared-throughput database compete for one RU pool and starve each other under load.', ), }; + case 'PaidContinuousBackup': + return { + name: l10n.t('Paid continuous backup'), + description: l10n.t( + 'Review paid restore-history retention on positively inferred non-production accounts without compromising recovery requirements.', + ), + }; + case 'NonThrottlingErrors': + return { + name: l10n.t('Non-throttling errors'), + description: l10n.t( + 'Account request errors excluding 429 warrant investigation. Status counts alone do not establish an application defect or identify its source.', + ), + }; + case 'ThrottlingByOperation': + return { + name: l10n.t('Throttling by operation'), + description: l10n.t( + 'See which operation contributes the most 429s. Operation mix guides investigation but does not prove a root cause.', + ), + }; + case 'PerRegionAutoscaleCandidate': + return { + name: l10n.t('Per-region autoscale review'), + description: l10n.t( + 'Multi-region provisioned accounts with independent scaling disabled may benefit if autoscale usage and uneven demand justify it.', + ), + }; + case 'ReservedCapacityCandidate': + return { + name: l10n.t('Reserved-capacity review'), + description: l10n.t( + 'Provisioned capacity warrants reviewing eligible usage and existing reservations. This is not a savings estimate or a purchase recommendation.', + ), + }; } }