@pagopa/dx-savemoney 0.2.5 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +33 -27
- package/dist/azure/analyzer.d.ts +49 -21
- package/dist/azure/analyzer.d.ts.map +1 -1
- package/dist/azure/analyzer.js +369 -93
- package/dist/azure/analyzer.js.map +1 -1
- package/dist/azure/analyzers/advisor.d.ts +68 -0
- package/dist/azure/analyzers/advisor.d.ts.map +1 -0
- package/dist/azure/analyzers/advisor.js +234 -0
- package/dist/azure/analyzers/advisor.js.map +1 -0
- package/dist/azure/analyzers/index.d.ts +8 -0
- package/dist/azure/analyzers/index.d.ts.map +1 -0
- package/dist/azure/analyzers/index.js +6 -0
- package/dist/azure/analyzers/index.js.map +1 -0
- package/dist/azure/analyzers/registry.d.ts +29 -0
- package/dist/azure/analyzers/registry.d.ts.map +1 -0
- package/dist/azure/analyzers/registry.js +79 -0
- package/dist/azure/analyzers/registry.js.map +1 -0
- package/dist/azure/analyzers/subscription.d.ts +53 -0
- package/dist/azure/analyzers/subscription.d.ts.map +1 -0
- package/dist/azure/analyzers/subscription.js +18 -0
- package/dist/azure/analyzers/subscription.js.map +1 -0
- package/dist/azure/analyzers/types.d.ts +62 -0
- package/dist/azure/analyzers/types.d.ts.map +1 -0
- package/dist/azure/analyzers/types.js +15 -0
- package/dist/azure/analyzers/types.js.map +1 -0
- package/dist/azure/config.d.ts.map +1 -1
- package/dist/azure/config.js +2 -0
- package/dist/azure/config.js.map +1 -1
- package/dist/azure/index.d.ts +1 -0
- package/dist/azure/index.d.ts.map +1 -1
- package/dist/azure/index.js +1 -0
- package/dist/azure/index.js.map +1 -1
- package/dist/azure/report.d.ts.map +1 -1
- package/dist/azure/report.js +178 -29
- package/dist/azure/report.js.map +1 -1
- package/dist/azure/resources/app-service.d.ts +2 -1
- package/dist/azure/resources/app-service.d.ts.map +1 -1
- package/dist/azure/resources/app-service.js +3 -3
- package/dist/azure/resources/app-service.js.map +1 -1
- package/dist/azure/resources/container-app.d.ts +2 -1
- package/dist/azure/resources/container-app.d.ts.map +1 -1
- package/dist/azure/resources/container-app.js +9 -9
- package/dist/azure/resources/container-app.js.map +1 -1
- package/dist/azure/resources/public-ip.d.ts +2 -1
- package/dist/azure/resources/public-ip.d.ts.map +1 -1
- package/dist/azure/resources/public-ip.js +2 -2
- package/dist/azure/resources/public-ip.js.map +1 -1
- package/dist/azure/resources/static-web-app.d.ts +2 -1
- package/dist/azure/resources/static-web-app.d.ts.map +1 -1
- package/dist/azure/resources/static-web-app.js +3 -3
- package/dist/azure/resources/static-web-app.js.map +1 -1
- package/dist/azure/resources/storage.d.ts +2 -1
- package/dist/azure/resources/storage.d.ts.map +1 -1
- package/dist/azure/resources/storage.js +2 -2
- package/dist/azure/resources/storage.js.map +1 -1
- package/dist/azure/resources/vm.d.ts +2 -1
- package/dist/azure/resources/vm.d.ts.map +1 -1
- package/dist/azure/resources/vm.js +3 -3
- package/dist/azure/resources/vm.js.map +1 -1
- package/dist/azure/types.d.ts +34 -1
- package/dist/azure/types.d.ts.map +1 -1
- package/dist/azure/utils.d.ts +35 -3
- package/dist/azure/utils.d.ts.map +1 -1
- package/dist/azure/utils.js +70 -29
- package/dist/azure/utils.js.map +1 -1
- package/dist/finding.d.ts +114 -0
- package/dist/finding.d.ts.map +1 -0
- package/dist/finding.js +51 -0
- package/dist/finding.js.map +1 -0
- package/dist/index.d.ts +4 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -1
- package/dist/schema.d.ts +5 -0
- package/dist/schema.d.ts.map +1 -1
- package/dist/schema.js +14 -0
- package/dist/schema.js.map +1 -1
- package/package.json +4 -1
- package/src/__tests__/finding.test.ts +149 -0
- package/src/azure/__tests__/analyzer-tags.test.ts +74 -0
- package/src/azure/__tests__/report.test.ts +27 -0
- package/src/azure/__tests__/utils.test.ts +164 -2
- package/src/azure/analyzer.ts +513 -182
- package/src/azure/analyzers/__tests__/advisor.test.ts +367 -0
- package/src/azure/analyzers/advisor.ts +324 -0
- package/src/azure/analyzers/index.ts +14 -0
- package/src/azure/analyzers/registry.ts +196 -0
- package/src/azure/analyzers/subscription.ts +56 -0
- package/src/azure/analyzers/types.ts +66 -0
- package/src/azure/config.ts +2 -0
- package/src/azure/index.ts +1 -0
- package/src/azure/report.ts +206 -35
- package/src/azure/resources/app-service.ts +4 -0
- package/src/azure/resources/container-app.ts +10 -0
- package/src/azure/resources/public-ip.ts +3 -0
- package/src/azure/resources/static-web-app.ts +4 -0
- package/src/azure/resources/storage.ts +3 -0
- package/src/azure/resources/vm.ts +4 -0
- package/src/azure/types.ts +35 -1
- package/src/azure/utils.ts +110 -39
- package/src/finding.ts +152 -0
- package/src/index.ts +19 -1
- package/src/schema.ts +14 -0
package/dist/azure/analyzer.js
CHANGED
|
@@ -1,5 +1,22 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Azure resource analyzer - Main orchestration logic
|
|
3
|
+
*
|
|
4
|
+
* Iterates every resource in every configured subscription, dispatches it
|
|
5
|
+
* to the registered analyzers (see `./analyzers/registry.ts`), and feeds
|
|
6
|
+
* the resulting findings into the report generator.
|
|
7
|
+
*
|
|
8
|
+
* Phase 0 refactor:
|
|
9
|
+
* - Resources are dispatched through a plugin-style `Analyzer` registry
|
|
10
|
+
* instead of a hard-coded `switch` statement.
|
|
11
|
+
* - Per-subscription resources are analyzed in parallel via a small
|
|
12
|
+
* in-process limiter (default concurrency 8, configurable via
|
|
13
|
+
* `AzureConfig.concurrency`).
|
|
14
|
+
* - Azure Monitor metric calls are memoized for the duration of a run via
|
|
15
|
+
* a per-run `MetricsCache` passed through `AnalyzerContext`, so concurrent
|
|
16
|
+
* calls to `analyzeAzureResources` stay fully isolated.
|
|
17
|
+
*
|
|
18
|
+
* The output schema (`AzureDetailedResourceReport`) is unchanged so the
|
|
19
|
+
* existing report formats keep working untouched.
|
|
3
20
|
*/
|
|
4
21
|
import { ContainerAppsAPIClient } from "@azure/arm-appcontainers";
|
|
5
22
|
import { WebSiteManagementClient } from "@azure/arm-appservice";
|
|
@@ -9,73 +26,143 @@ import { NetworkManagementClient } from "@azure/arm-network";
|
|
|
9
26
|
import * as armResources from "@azure/arm-resources";
|
|
10
27
|
import { DefaultAzureCredential } from "@azure/identity";
|
|
11
28
|
import { getLogger } from "@logtape/logtape";
|
|
29
|
+
import pLimit from "p-limit";
|
|
30
|
+
import { findingsFromAnalysisResult } from "../finding.js";
|
|
12
31
|
import { DEFAULT_THRESHOLDS, mergeResults, } from "../types.js";
|
|
13
|
-
import {
|
|
14
|
-
import { analyzeAppServicePlan, analyzeContainerApp, analyzeDisk, analyzeNic, analyzePrivateEndpoint, analyzePublicIp, analyzeStaticSite, analyzeStorageAccount, analyzeVM, } from "./resources/index.js";
|
|
32
|
+
import { createDefaultAnalyzers, createDefaultSubscriptionAnalyzers, } from "./analyzers/index.js";
|
|
15
33
|
import { matchesTags } from "./utils.js";
|
|
34
|
+
const DEFAULT_CONCURRENCY = 8;
|
|
35
|
+
const DEFAULT_SOURCES = ["advisor", "custom"];
|
|
36
|
+
const RISK_ORDER = { high: 0, low: 2, medium: 1 };
|
|
16
37
|
/**
|
|
17
|
-
* Analyzes resources in
|
|
38
|
+
* Analyzes resources in every configured Azure subscription and returns
|
|
39
|
+
* the structured report.
|
|
40
|
+
*
|
|
41
|
+
* Phase 1 change: this function no longer emits a report to stdout. The
|
|
42
|
+
* orchestrator returns `AzureDetailedResourceReport[]` and the caller
|
|
43
|
+
* (the CLI today, future GUI / API consumers tomorrow) chooses how to
|
|
44
|
+
* render it via `generateReport`.
|
|
18
45
|
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
46
|
+
* Each entry carries both the legacy `analysis` summary and the unified
|
|
47
|
+
* `findings: Finding[]` so consumers can pick the level of detail they
|
|
48
|
+
* need. Azure Advisor recommendations and per-resource analyzer outputs
|
|
49
|
+
* are merged into the same entry when they refer to the same resource.
|
|
50
|
+
*
|
|
51
|
+
* @param config - Azure configuration with subscription IDs and settings.
|
|
52
|
+
* `config.sources` controls which analyzers run.
|
|
21
53
|
*/
|
|
22
|
-
export async function analyzeAzureResources(config
|
|
54
|
+
export async function analyzeAzureResources(config) {
|
|
23
55
|
const logger = getLogger(["savemoney", "azure"]);
|
|
24
56
|
const credential = new DefaultAzureCredential();
|
|
25
57
|
const allReports = [];
|
|
58
|
+
const sources = config.sources ?? DEFAULT_SOURCES;
|
|
59
|
+
const customEnabled = sources.includes("custom");
|
|
60
|
+
const advisorEnabled = sources.includes("advisor");
|
|
61
|
+
const analyzers = createDefaultAnalyzers();
|
|
62
|
+
const subscriptionAnalyzers = advisorEnabled
|
|
63
|
+
? createDefaultSubscriptionAnalyzers()
|
|
64
|
+
: [];
|
|
65
|
+
const thresholds = config.thresholds ?? DEFAULT_THRESHOLDS;
|
|
66
|
+
// Normalise concurrency the same way p-limit does to keep maxInFlight
|
|
67
|
+
// consistent. A raw value of 0/NaN would produce maxInFlight = 0/NaN and
|
|
68
|
+
// either deadlock or silently disable backpressure.
|
|
69
|
+
const rawConcurrency = config.concurrency ?? DEFAULT_CONCURRENCY;
|
|
70
|
+
const concurrency = Number.isFinite(rawConcurrency)
|
|
71
|
+
? Math.max(1, Math.floor(rawConcurrency))
|
|
72
|
+
: 1;
|
|
73
|
+
const limit = pLimit(concurrency);
|
|
74
|
+
// Bound the in-flight Set to `2 × concurrency` so memory stays proportional
|
|
75
|
+
// to the limiter width, not the total resource count in a subscription.
|
|
76
|
+
const maxInFlight = concurrency * 2;
|
|
26
77
|
for (const subscriptionId of config.subscriptionIds) {
|
|
27
78
|
logger.info(`Analyzing subscription: ${subscriptionId}`);
|
|
28
|
-
const
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
const
|
|
33
|
-
const
|
|
34
|
-
|
|
35
|
-
//
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
79
|
+
const sid = subscriptionId.trim();
|
|
80
|
+
// Per-subscription index keyed by lowercased resourceId so subscription-
|
|
81
|
+
// level analyzers (Advisor, future quotas, …) can merge their findings
|
|
82
|
+
// back into the matching resource report.
|
|
83
|
+
const reportsById = new Map();
|
|
84
|
+
const taggedResourceIds = new Set();
|
|
85
|
+
// Fresh cache per subscription — bounds peak memory to one subscription's
|
|
86
|
+
// worth of metrics and keeps concurrent analyzeAzureResources calls isolated.
|
|
87
|
+
const runCache = new Map();
|
|
88
|
+
const clients = {
|
|
89
|
+
compute: new ComputeManagementClient(credential, sid),
|
|
90
|
+
containerApps: new ContainerAppsAPIClient(credential, sid),
|
|
91
|
+
monitor: new MonitorClient(credential, sid),
|
|
92
|
+
network: new NetworkManagementClient(credential, sid),
|
|
93
|
+
webSite: new WebSiteManagementClient(credential, sid),
|
|
94
|
+
};
|
|
95
|
+
if (customEnabled) {
|
|
96
|
+
await runPerResourceAnalysis({
|
|
97
|
+
analyzers,
|
|
98
|
+
clients,
|
|
99
|
+
config,
|
|
100
|
+
credential,
|
|
101
|
+
limit,
|
|
102
|
+
logger,
|
|
103
|
+
maxInFlight,
|
|
104
|
+
reports: allReports,
|
|
105
|
+
reportsById,
|
|
106
|
+
runCache,
|
|
107
|
+
sid,
|
|
108
|
+
taggedResourceIds,
|
|
109
|
+
thresholds,
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
if (!customEnabled && advisorEnabled && hasTagFilter(config.filterTags)) {
|
|
113
|
+
await collectTaggedResourceIds({
|
|
114
|
+
config,
|
|
115
|
+
credential,
|
|
116
|
+
sid,
|
|
117
|
+
taggedResourceIds,
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
if (advisorEnabled && subscriptionAnalyzers.length > 0) {
|
|
121
|
+
await runSubscriptionAnalyzers({
|
|
122
|
+
analyzers: subscriptionAnalyzers,
|
|
123
|
+
credential,
|
|
124
|
+
logger,
|
|
125
|
+
reports: allReports,
|
|
126
|
+
reportsById,
|
|
127
|
+
sid,
|
|
128
|
+
tagFilterActive: hasTagFilter(config.filterTags),
|
|
129
|
+
taggedResourceIds,
|
|
130
|
+
verbose: config.verbose ?? false,
|
|
131
|
+
});
|
|
52
132
|
}
|
|
53
133
|
}
|
|
54
|
-
// Sort to make the output more readable
|
|
134
|
+
// Sort to make the output more readable:
|
|
135
|
+
// - Subscription-scoped findings (Reserved Instances, savings plans, ...)
|
|
136
|
+
// sink to the bottom: they aggregate many recommendations into a single
|
|
137
|
+
// fat row and are easier to consume after the per-resource rows.
|
|
138
|
+
// - Within each group, sort by cost risk then by resource name.
|
|
55
139
|
allReports.sort((a, b) => {
|
|
140
|
+
const aSub = isSubscriptionScopedReport(a);
|
|
141
|
+
const bSub = isSubscriptionScopedReport(b);
|
|
142
|
+
if (aSub !== bSub)
|
|
143
|
+
return aSub ? 1 : -1;
|
|
56
144
|
if (a.analysis.costRisk === b.analysis.costRisk)
|
|
57
145
|
return (a.resource.name ?? "").localeCompare(b.resource.name ?? "");
|
|
58
|
-
|
|
59
|
-
return order[a.analysis.costRisk] - order[b.analysis.costRisk];
|
|
146
|
+
return RISK_ORDER[a.analysis.costRisk] - RISK_ORDER[b.analysis.costRisk];
|
|
60
147
|
});
|
|
61
|
-
|
|
148
|
+
return allReports;
|
|
62
149
|
}
|
|
63
150
|
/**
|
|
64
|
-
* Analyzes a single Azure resource
|
|
151
|
+
* Analyzes a single Azure resource by dispatching it to every registered
|
|
152
|
+
* analyzer that supports it. Generic checks (missing tags, location
|
|
153
|
+
* mismatch) are applied around the analyzer-specific logic.
|
|
65
154
|
*
|
|
66
|
-
* @param resource
|
|
67
|
-
* @param
|
|
68
|
-
* @param
|
|
69
|
-
* @param
|
|
70
|
-
* @param
|
|
71
|
-
* @param
|
|
72
|
-
* @param
|
|
73
|
-
* @param
|
|
74
|
-
* @param verbose - Whether verbose logging is enabled
|
|
155
|
+
* @param resource The Azure resource to analyze
|
|
156
|
+
* @param analyzers Registered analyzers (typically `createDefaultAnalyzers()`)
|
|
157
|
+
* @param clients Bundle of Azure SDK clients shared across analyzers
|
|
158
|
+
* @param metricsCache Run-scoped metrics cache to pass through to analyzers
|
|
159
|
+
* @param preferredLocation Preferred Azure region (resources elsewhere are flagged)
|
|
160
|
+
* @param timespanDays Look-back window for Azure Monitor metrics
|
|
161
|
+
* @param thresholds Numeric thresholds used during analysis
|
|
162
|
+
* @param verbose Whether verbose logging is enabled
|
|
75
163
|
* @returns Analysis result with cost risk and reason
|
|
76
164
|
*/
|
|
77
|
-
export async function analyzeResource(resource,
|
|
78
|
-
const type = resource.type?.toLowerCase() || "";
|
|
165
|
+
export async function analyzeResource(resource, analyzers, clients, metricsCache = new Map(), preferredLocation, timespanDays, thresholds, verbose = false) {
|
|
79
166
|
let result = {
|
|
80
167
|
costRisk: "low",
|
|
81
168
|
reason: "",
|
|
@@ -86,62 +173,251 @@ export async function analyzeResource(resource, monitorClient, computeClient, ne
|
|
|
86
173
|
result.suspectedUnused = true;
|
|
87
174
|
result.reason += "No tags found. ";
|
|
88
175
|
}
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
176
|
+
const ctx = {
|
|
177
|
+
clients,
|
|
178
|
+
metricsCache,
|
|
179
|
+
preferredLocation,
|
|
180
|
+
resource,
|
|
181
|
+
thresholds,
|
|
182
|
+
timespanDays,
|
|
183
|
+
verbose,
|
|
184
|
+
};
|
|
185
|
+
let matched = false;
|
|
186
|
+
for (const analyzer of analyzers) {
|
|
187
|
+
if (!analyzer.supports(resource)) {
|
|
188
|
+
continue;
|
|
100
189
|
}
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
190
|
+
matched = true;
|
|
191
|
+
const specific = await analyzer.analyze(ctx);
|
|
192
|
+
result = mergeResults(result, specific);
|
|
193
|
+
}
|
|
194
|
+
if (!matched) {
|
|
195
|
+
result.reason += "No specific analysis for this resource type. ";
|
|
196
|
+
}
|
|
197
|
+
// Generic check for location
|
|
198
|
+
if (resource.location &&
|
|
199
|
+
!resource.location.toLowerCase().includes(preferredLocation.toLowerCase())) {
|
|
200
|
+
result.reason += `Resource not in preferred location (${preferredLocation}). `;
|
|
201
|
+
}
|
|
202
|
+
return { ...result, reason: result.reason.trim() };
|
|
203
|
+
}
|
|
204
|
+
export function shouldIncludeAdvisorFindingForTags(finding, taggedResourceIds, tagFilterActive) {
|
|
205
|
+
if (!tagFilterActive) {
|
|
206
|
+
return true;
|
|
207
|
+
}
|
|
208
|
+
if (finding.source !== "advisor") {
|
|
209
|
+
return true;
|
|
210
|
+
}
|
|
211
|
+
if (!isResourceScopedFinding(finding.resourceId)) {
|
|
212
|
+
// Subscription-level findings are intentionally always global.
|
|
213
|
+
return true;
|
|
214
|
+
}
|
|
215
|
+
return taggedResourceIds.has(normalizeResourceId(finding.resourceId));
|
|
216
|
+
}
|
|
217
|
+
/**
|
|
218
|
+
* Derives a legacy `AnalysisResult` summary from a `Finding`, so the
|
|
219
|
+
* existing report formats keep working untouched on Advisor-only
|
|
220
|
+
* resources.
|
|
221
|
+
*/
|
|
222
|
+
function analysisFromFinding(finding) {
|
|
223
|
+
const trimmed = finding.reason.trim();
|
|
224
|
+
const reason = trimmed.endsWith(".") ? trimmed : `${trimmed}.`;
|
|
225
|
+
return {
|
|
226
|
+
costRisk: finding.severity,
|
|
227
|
+
reason,
|
|
228
|
+
suspectedUnused: true,
|
|
229
|
+
};
|
|
230
|
+
}
|
|
231
|
+
/**
|
|
232
|
+
* Builds a minimal `GenericResource` from a resource ID. Used when a
|
|
233
|
+
* subscription-level analyzer surfaces a resource the per-resource pass
|
|
234
|
+
* did not see — we have neither tags nor location, but `name` and `type`
|
|
235
|
+
* can be parsed deterministically from the resource ID structure.
|
|
236
|
+
*
|
|
237
|
+
* Handles three shapes:
|
|
238
|
+
* - Fully qualified: /subscriptions/{sub}/resourceGroups/{rg}/providers/{provider}/{type}/{name}
|
|
239
|
+
* - Resource-group-scoped: /subscriptions/{sub}/resourceGroups/{rg}
|
|
240
|
+
* - Subscription-scoped: /subscriptions/{sub}
|
|
241
|
+
*/
|
|
242
|
+
function buildResourceStub(resourceId) {
|
|
243
|
+
const parts = resourceId.split("/").filter((s) => s.length > 0);
|
|
244
|
+
const providersIdx = parts.indexOf("providers");
|
|
245
|
+
if (providersIdx >= 0 && parts.length > providersIdx + 2) {
|
|
246
|
+
// Fully qualified resource ID.
|
|
247
|
+
const provider = parts[providersIdx + 1];
|
|
248
|
+
const tail = parts.slice(providersIdx + 2); // [type, name, subtype, subname, ...]
|
|
249
|
+
const typeSegments = [provider];
|
|
250
|
+
for (let i = 0; i < tail.length; i += 2) {
|
|
251
|
+
typeSegments.push(tail[i]);
|
|
105
252
|
}
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
253
|
+
return {
|
|
254
|
+
id: resourceId,
|
|
255
|
+
name: tail[tail.length - 1],
|
|
256
|
+
type: typeSegments.join("/"),
|
|
257
|
+
};
|
|
258
|
+
}
|
|
259
|
+
const rgIdx = parts.indexOf("resourceGroups");
|
|
260
|
+
if (rgIdx >= 0 && parts.length > rgIdx + 1) {
|
|
261
|
+
// Resource-group-scoped ID.
|
|
262
|
+
return {
|
|
263
|
+
id: resourceId,
|
|
264
|
+
name: parts[rgIdx + 1],
|
|
265
|
+
type: "Microsoft.Resources/resourceGroups",
|
|
266
|
+
};
|
|
267
|
+
}
|
|
268
|
+
const subIdx = parts.indexOf("subscriptions");
|
|
269
|
+
if (subIdx >= 0 && parts.length > subIdx + 1) {
|
|
270
|
+
// Subscription-scoped ID (e.g. Reserved Instance recommendations).
|
|
271
|
+
return {
|
|
272
|
+
id: resourceId,
|
|
273
|
+
name: parts[subIdx + 1],
|
|
274
|
+
type: "Microsoft.Subscription",
|
|
275
|
+
};
|
|
276
|
+
}
|
|
277
|
+
// Fallback for completely unknown shapes.
|
|
278
|
+
return { id: resourceId, name: parts[parts.length - 1], type: undefined };
|
|
279
|
+
}
|
|
280
|
+
async function collectTaggedResourceIds(args) {
|
|
281
|
+
const { config, credential, sid, taggedResourceIds } = args;
|
|
282
|
+
const resourceClient = new armResources.ResourceManagementClient(credential, sid);
|
|
283
|
+
for await (const resource of resourceClient.resources.list()) {
|
|
284
|
+
if (!matchesTags(resource, config.filterTags)) {
|
|
285
|
+
continue;
|
|
110
286
|
}
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
break;
|
|
287
|
+
const resourceId = normalizeResourceId(resource.id);
|
|
288
|
+
if (resourceId) {
|
|
289
|
+
taggedResourceIds.add(resourceId);
|
|
115
290
|
}
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
function hasTagFilter(filterTags) {
|
|
294
|
+
return Boolean(filterTags && filterTags.size > 0);
|
|
295
|
+
}
|
|
296
|
+
function isResourceScopedFinding(resourceId) {
|
|
297
|
+
return /\/providers\//i.test(resourceId);
|
|
298
|
+
}
|
|
299
|
+
function isSubscriptionScopedReport(r) {
|
|
300
|
+
return r.resource.type === "Microsoft.Subscription";
|
|
301
|
+
}
|
|
302
|
+
/**
|
|
303
|
+
* Inserts a `Finding` into the right report entry, creating a stub
|
|
304
|
+
* resource entry on the fly when the finding refers to a resource that
|
|
305
|
+
* the per-resource pass did not analyze.
|
|
306
|
+
*/
|
|
307
|
+
function mergeFinding(finding, reports, reportsById) {
|
|
308
|
+
const idKey = finding.resourceId.toLowerCase();
|
|
309
|
+
const existing = reportsById.get(idKey);
|
|
310
|
+
if (existing) {
|
|
311
|
+
existing.findings = [...(existing.findings ?? []), finding];
|
|
312
|
+
const added = analysisFromFinding(finding);
|
|
313
|
+
// Use max costRisk (not last-wins) and join reasons with a space so we
|
|
314
|
+
// don't produce "Sentence one.Sentence two." when the existing reason is
|
|
315
|
+
// already trimmed (i.e. has no trailing separator space).
|
|
316
|
+
existing.analysis = {
|
|
317
|
+
costRisk: RISK_ORDER[existing.analysis.costRisk] <= RISK_ORDER[added.costRisk]
|
|
318
|
+
? existing.analysis.costRisk
|
|
319
|
+
: added.costRisk,
|
|
320
|
+
reason: existing.analysis.reason && added.reason
|
|
321
|
+
? `${existing.analysis.reason.trimEnd()} ${added.reason.trimStart()}`
|
|
322
|
+
: existing.analysis.reason || added.reason,
|
|
323
|
+
suspectedUnused: existing.analysis.suspectedUnused || added.suspectedUnused,
|
|
324
|
+
};
|
|
325
|
+
return;
|
|
326
|
+
}
|
|
327
|
+
const stub = buildResourceStub(finding.resourceId);
|
|
328
|
+
const report = {
|
|
329
|
+
analysis: analysisFromFinding(finding),
|
|
330
|
+
findings: [finding],
|
|
331
|
+
resource: stub,
|
|
332
|
+
};
|
|
333
|
+
reports.push(report);
|
|
334
|
+
reportsById.set(idKey, report);
|
|
335
|
+
}
|
|
336
|
+
function normalizeResourceId(resourceId) {
|
|
337
|
+
return (resourceId ?? "").trim().toLowerCase();
|
|
338
|
+
}
|
|
339
|
+
/**
|
|
340
|
+
* Runs the per-resource analyzer plugins against every resource in the
|
|
341
|
+
* given subscription. Extracted from `analyzeAzureResources` to keep that
|
|
342
|
+
* function readable now that subscription-level analyzers were added.
|
|
343
|
+
*/
|
|
344
|
+
async function runPerResourceAnalysis(args) {
|
|
345
|
+
const { analyzers, clients, config, credential, limit, logger, maxInFlight, reports, reportsById, runCache, sid, taggedResourceIds, thresholds, } = args;
|
|
346
|
+
const resourceClient = new armResources.ResourceManagementClient(credential, sid);
|
|
347
|
+
const inFlight = new Set();
|
|
348
|
+
// Use the async iterator to avoid loading all resources into memory at once.
|
|
349
|
+
for await (const resource of resourceClient.resources.list()) {
|
|
350
|
+
if (!matchesTags(resource, config.filterTags)) {
|
|
351
|
+
continue;
|
|
120
352
|
}
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
break;
|
|
353
|
+
const taggedId = normalizeResourceId(resource.id);
|
|
354
|
+
if (taggedId) {
|
|
355
|
+
taggedResourceIds.add(taggedId);
|
|
125
356
|
}
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
357
|
+
// Backpressure: wait for a slot before enqueuing the next task so that
|
|
358
|
+
// the inFlight Set stays bounded by maxInFlight instead of growing to the
|
|
359
|
+
// total resource count in the subscription.
|
|
360
|
+
while (inFlight.size >= maxInFlight) {
|
|
361
|
+
await Promise.race(inFlight).catch(() => undefined);
|
|
130
362
|
}
|
|
131
|
-
|
|
132
|
-
const
|
|
133
|
-
|
|
134
|
-
|
|
363
|
+
const task = limit(async () => {
|
|
364
|
+
const analysis = await analyzeResource(resource, analyzers, clients, runCache, config.preferredLocation, config.timespanDays, thresholds, config.verbose || false);
|
|
365
|
+
if (analysis.suspectedUnused) {
|
|
366
|
+
const reason = analysis.reason || "No specific findings.";
|
|
367
|
+
const report = {
|
|
368
|
+
analysis: { ...analysis, reason },
|
|
369
|
+
findings: findingsFromAnalysisResult({
|
|
370
|
+
reason,
|
|
371
|
+
resourceId: resource.id ?? "",
|
|
372
|
+
severity: analysis.costRisk,
|
|
373
|
+
source: "custom",
|
|
374
|
+
}),
|
|
375
|
+
resource,
|
|
376
|
+
};
|
|
377
|
+
reports.push(report);
|
|
378
|
+
const idKey = (resource.id ?? "").toLowerCase();
|
|
379
|
+
if (idKey)
|
|
380
|
+
reportsById.set(idKey, report);
|
|
381
|
+
}
|
|
382
|
+
});
|
|
383
|
+
inFlight.add(task);
|
|
384
|
+
// Suppress the unhandled-rejection that would occur between task creation
|
|
385
|
+
// and the Promise.allSettled drain below. The .catch() handler is a no-op
|
|
386
|
+
// because the actual error is still visible to allSettled (which logs it)
|
|
387
|
+
// via the original `task` reference kept in inFlight.
|
|
388
|
+
void task.catch(() => undefined).finally(() => inFlight.delete(task));
|
|
389
|
+
}
|
|
390
|
+
// Drain remaining tasks; surface any unexpected errors so they don't
|
|
391
|
+
// disappear silently and produce an incomplete report without a signal.
|
|
392
|
+
const results = await Promise.allSettled(inFlight);
|
|
393
|
+
for (const result of results) {
|
|
394
|
+
if (result.status === "rejected") {
|
|
395
|
+
logger.error(`Resource analysis failed: ${String(result.reason)}`);
|
|
135
396
|
}
|
|
136
|
-
default:
|
|
137
|
-
result.reason += "No specific analysis for this resource type. ";
|
|
138
|
-
break;
|
|
139
397
|
}
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
398
|
+
}
|
|
399
|
+
/**
|
|
400
|
+
* Runs every subscription-level analyzer in parallel and merges their
|
|
401
|
+
* findings into the per-resource reports. Findings about resources that
|
|
402
|
+
* the per-resource pass did not surface (typical for Advisor, which
|
|
403
|
+
* reaches SQL DBs, Front Doors, etc.) produce new report entries with a
|
|
404
|
+
* minimal `GenericResource` stub derived from the resource ID.
|
|
405
|
+
*/
|
|
406
|
+
async function runSubscriptionAnalyzers(args) {
|
|
407
|
+
const { analyzers, credential, logger, reports, reportsById, sid, tagFilterActive, taggedResourceIds, verbose, } = args;
|
|
408
|
+
const allFindings = await Promise.all(analyzers.map((a) => a
|
|
409
|
+
.analyze({ credential, subscriptionId: sid, verbose })
|
|
410
|
+
.catch((err) => {
|
|
411
|
+
logger.error(`Subscription analyzer ${a.id} failed: ${String(err)}`);
|
|
412
|
+
return [];
|
|
413
|
+
})));
|
|
414
|
+
for (const findings of allFindings) {
|
|
415
|
+
for (const finding of findings) {
|
|
416
|
+
if (!shouldIncludeAdvisorFindingForTags(finding, taggedResourceIds, tagFilterActive)) {
|
|
417
|
+
continue;
|
|
418
|
+
}
|
|
419
|
+
mergeFinding(finding, reports, reportsById);
|
|
420
|
+
}
|
|
144
421
|
}
|
|
145
|
-
return { ...result, reason: result.reason.trim() };
|
|
146
422
|
}
|
|
147
423
|
//# sourceMappingURL=analyzer.js.map
|
|
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AK,UAAU,wBAAwB,CAAC,IAUvC;IACC,MAAM,EACJ,SAAS,EACT,UAAU,EACV,MAAM,EACN,OAAO,EACP,WAAW,EACX,GAAG,EACH,eAAe,EACf,iBAAiB,EACjB,OAAO,GACR,GAAG,IAAI,CAAC;IAET,MAAM,WAAW,GAAG,MAAM,OAAO,CAAC,GAAG,CACnC,SAAS,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAClB,CAAC;SACE,OAAO,CAAC,EAAE,UAAU,EAAE,cAAc,EAAE,GAAG,EAAE,OAAO,EAAE,CAAC;SACrD,KAAK,CAAC,CAAC,GAAY,EAAE,EAAE;QACtB,MAAM,CAAC,KAAK,CAAC,yBAAyB,CAAC,CAAC,EAAE,YAAY,MAAM,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;QACrE,OAAO,EAAe,CAAC;IACzB,CAAC,CAAC,CACL,CACF,CAAC;IAEF,KAAK,MAAM,QAAQ,IAAI,WAAW,EAAE,CAAC;QACnC,KAAK,MAAM,OAAO,IAAI,QAAQ,EAAE,CAAC;YAC/B,IACE,CAAC,kCAAkC,CACjC,OAAO,EACP,iBAAiB,EACjB,eAAe,CAChB,EACD,CAAC;gBACD,SAAS;YACX,CAAC;YACD,YAAY,CAAC,OAAO,EAAE,OAAO,EAAE,WAAW,CAAC,CAAC;QAC9C,CAAC;IACH,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Azure Advisor analyzer.
|
|
3
|
+
*
|
|
4
|
+
* Fetches all `Cost` recommendations for the target subscription via the
|
|
5
|
+
* `@azure/arm-advisor` SDK and normalises them into the unified `Finding`
|
|
6
|
+
* model.
|
|
7
|
+
*
|
|
8
|
+
* ## Two kinds of Advisor cost recommendations
|
|
9
|
+
*
|
|
10
|
+
* ### Resource-specific (resourceMetadata.resourceId contains /providers/)
|
|
11
|
+
* Recommendations about a particular Azure resource (e.g. "right-size this
|
|
12
|
+
* VM"). Each is emitted as a separate Finding so it appears next to the
|
|
13
|
+
* resource in the per-resource section of the report. `enrichReason` adds
|
|
14
|
+
* SKU / region / term context from `extendedProperties` so findings for
|
|
15
|
+
* the same recommendation type on different resources are distinguishable.
|
|
16
|
+
*
|
|
17
|
+
* ### Subscription-scoped (no resourceId, or resourceId without /providers/)
|
|
18
|
+
* Reserved Instance and Savings Plan recommendations. The Advisor API
|
|
19
|
+
* returns **one entry per qualifying combination** (term, scope, quantity,
|
|
20
|
+
* etc.) but the Azure Portal **groups them by `recommendationTypeId`** and
|
|
21
|
+
* shows a single entry for the best option — matching the mental model
|
|
22
|
+
* a user has when deciding whether to buy a commitment.
|
|
23
|
+
*
|
|
24
|
+
* Different amounts within the same `recommendationTypeId` represent
|
|
25
|
+
* **mutually exclusive purchase options** (e.g. different DB sizes or
|
|
26
|
+
* quantities); the user would choose one, not buy all. We therefore report
|
|
27
|
+
* the **maximum** savings amount across all unique configurations, matching
|
|
28
|
+
* the portal's behaviour. Scope variants (Shared / Single / ResourceGroup)
|
|
29
|
+
* that carry the same amount are deduplicated so they do not count more
|
|
30
|
+
* than once. True duplicates — recommendations with the same ARM ID —
|
|
31
|
+
* are also removed before taking the maximum.
|
|
32
|
+
*/
|
|
33
|
+
import type { SubscriptionAnalyzer, SubscriptionContext } from "./subscription.js";
|
|
34
|
+
/** Minimal client shape used by the analyzer (and injectable in tests). */
|
|
35
|
+
type AdvisorClientLike = {
|
|
36
|
+
recommendations: {
|
|
37
|
+
list(options?: {
|
|
38
|
+
filter?: string;
|
|
39
|
+
}): AsyncIterable<RecommendationInfo>;
|
|
40
|
+
};
|
|
41
|
+
};
|
|
42
|
+
/** Minimal shape of a recommendation entry needed by the helpers. */
|
|
43
|
+
type RecommendationInfo = {
|
|
44
|
+
category?: string;
|
|
45
|
+
extendedProperties?: Record<string, unknown>;
|
|
46
|
+
id?: string;
|
|
47
|
+
impact?: string;
|
|
48
|
+
recommendationTypeId?: string;
|
|
49
|
+
resourceMetadata?: {
|
|
50
|
+
resourceId?: string;
|
|
51
|
+
};
|
|
52
|
+
shortDescription?: {
|
|
53
|
+
problem?: string;
|
|
54
|
+
solution?: string;
|
|
55
|
+
};
|
|
56
|
+
};
|
|
57
|
+
/**
|
|
58
|
+
* Builds the Advisor subscription-level analyzer.
|
|
59
|
+
*
|
|
60
|
+
* @param clientFactory Optional override to inject a mock client in tests.
|
|
61
|
+
* In production the default factory builds a real
|
|
62
|
+
* `AdvisorManagementClient` from the credential.
|
|
63
|
+
*/
|
|
64
|
+
export declare function createAdvisorAnalyzer(clientFactory?: {
|
|
65
|
+
build(credential: SubscriptionContext["credential"], subscriptionId: string): AdvisorClientLike;
|
|
66
|
+
}): SubscriptionAnalyzer;
|
|
67
|
+
export {};
|
|
68
|
+
//# sourceMappingURL=advisor.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"advisor.d.ts","sourceRoot":"","sources":["../../../src/azure/analyzers/advisor.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AAOH,OAAO,KAAK,EACV,oBAAoB,EACpB,mBAAmB,EACpB,MAAM,mBAAmB,CAAC;AAE3B,2EAA2E;AAC3E,KAAK,iBAAiB,GAAG;IACvB,eAAe,EAAE;QACf,IAAI,CAAC,OAAO,CAAC,EAAE;YAAE,MAAM,CAAC,EAAE,MAAM,CAAA;SAAE,GAAG,aAAa,CAAC,kBAAkB,CAAC,CAAC;KACxE,CAAC;CACH,CAAC;AAEF,qEAAqE;AACrE,KAAK,kBAAkB,GAAG;IACxB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,kBAAkB,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC7C,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,oBAAoB,CAAC,EAAE,MAAM,CAAC;IAC9B,gBAAgB,CAAC,EAAE;QAAE,UAAU,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;IAC3C,gBAAgB,CAAC,EAAE;QAAE,OAAO,CAAC,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;CAC5D,CAAC;AAuBF;;;;;;GAMG;AACH,wBAAgB,qBAAqB,CAAC,aAAa,CAAC,EAAE;IACpD,KAAK,CACH,UAAU,EAAE,mBAAmB,CAAC,YAAY,CAAC,EAC7C,cAAc,EAAE,MAAM,GACrB,iBAAiB,CAAC;CACtB,GAAG,oBAAoB,CAwCvB"}
|