maproom 0.2.0__py3-none-any.whl
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.
- maproom/__init__.py +14 -0
- maproom/__main__.py +10 -0
- maproom/analyze/__init__.py +1 -0
- maproom/analyze/accel_families.py +45 -0
- maproom/analyze/account_azure_activity.py +260 -0
- maproom/analyze/account_azure_quota_requests.py +177 -0
- maproom/analyze/account_cloudtrail.py +316 -0
- maproom/analyze/account_quota_requests.py +180 -0
- maproom/analyze/analyze_v1_orchestration.py +1194 -0
- maproom/analyze/catalog.py +353 -0
- maproom/analyze/change_detection.py +652 -0
- maproom/analyze/context_client.py +99 -0
- maproom/analyze/context_lookup.py +142 -0
- maproom/analyze/cover_analyze.py +344 -0
- maproom/analyze/cover_client.py +65 -0
- maproom/analyze/cover_lookup.py +242 -0
- maproom/analyze/engine.py +644 -0
- maproom/analyze/fleetfit_endpoints.py +217 -0
- maproom/analyze/fleetfit_policy.py +66 -0
- maproom/analyze/instance_price_analyze.py +221 -0
- maproom/analyze/instance_price_client.py +108 -0
- maproom/analyze/instance_price_lookup.py +60 -0
- maproom/analyze/local_reads.py +484 -0
- maproom/analyze/lookup_http.py +280 -0
- maproom/analyze/metric_format.py +20 -0
- maproom/analyze/migration_method.py +130 -0
- maproom/analyze/move_list.py +93 -0
- maproom/analyze/operator_context.py +156 -0
- maproom/analyze/performance_rank.py +97 -0
- maproom/analyze/primary_recommendation.py +422 -0
- maproom/analyze/provider_comparison.py +401 -0
- maproom/analyze/quota_analyze.py +481 -0
- maproom/analyze/quota_client.py +75 -0
- maproom/analyze/quota_lookup.py +110 -0
- maproom/analyze/quota_outcome_steer.py +105 -0
- maproom/analyze/recommend_batch.py +199 -0
- maproom/analyze/recommend_client.py +362 -0
- maproom/analyze/recommend_share.py +118 -0
- maproom/analyze/recommendation.py +591 -0
- maproom/analyze/reservation_pack.py +883 -0
- maproom/analyze/reservation_read.py +461 -0
- maproom/analyze/safe_analyze.py +1134 -0
- maproom/analyze/safe_move.py +195 -0
- maproom/analyze/safe_moves.py +571 -0
- maproom/analyze/safe_moves_catalog.py +127 -0
- maproom/analyze/safe_moves_client.py +70 -0
- maproom/analyze/series_analyze.py +491 -0
- maproom/analyze/series_client.py +106 -0
- maproom/analyze/series_lookup.py +663 -0
- maproom/analyze/shape.py +254 -0
- maproom/analyze/size_analyze.py +883 -0
- maproom/analyze/size_client.py +81 -0
- maproom/analyze/size_keep.py +409 -0
- maproom/analyze/size_lookup.py +368 -0
- maproom/analyze/specs.py +325 -0
- maproom/analyze/spot_analyze.py +392 -0
- maproom/analyze/spot_client.py +74 -0
- maproom/analyze/spot_lookup.py +213 -0
- maproom/analyze/token_client.py +97 -0
- maproom/analyze/utilization.py +190 -0
- maproom/analyze/workload.py +104 -0
- maproom/analyze/workset.py +762 -0
- maproom/aws_region.py +78 -0
- maproom/cache/__init__.py +1 -0
- maproom/cache/catalog.py +372 -0
- maproom/cache/commands.py +215 -0
- maproom/cache/instances.py +460 -0
- maproom/cli.py +2084 -0
- maproom/cli_argv.py +329 -0
- maproom/cli_floors.py +89 -0
- maproom/cliio/__init__.py +1 -0
- maproom/cliio/registry.py +377 -0
- maproom/cliio/runner.py +489 -0
- maproom/consent/__init__.py +33 -0
- maproom/consent/gate.py +238 -0
- maproom/consent/policy.py +20 -0
- maproom/consent/prompt.py +61 -0
- maproom/consent/service_upload_gate.py +318 -0
- maproom/consent/service_upload_prompt.py +62 -0
- maproom/consent/stdin.py +45 -0
- maproom/consent/storage.py +24 -0
- maproom/consent/write_token.py +29 -0
- maproom/contracts/__init__.py +6 -0
- maproom/contracts/schema_diff.py +119 -0
- maproom/contracts/validate.py +113 -0
- maproom/data/__init__.py +1 -0
- maproom/data/clear.py +76 -0
- maproom/data/commands.py +14 -0
- maproom/doctor/__init__.py +1 -0
- maproom/doctor/aws_session.py +226 -0
- maproom/doctor/checks.py +701 -0
- maproom/doctor/context.py +32 -0
- maproom/doctor/display.py +96 -0
- maproom/doctor/inventory_display.py +377 -0
- maproom/doctor/runner.py +1467 -0
- maproom/errors.py +43 -0
- maproom/exitcodes.py +70 -0
- maproom/inventory/__init__.py +1 -0
- maproom/inventory/account_identity.py +79 -0
- maproom/inventory/accounts.py +155 -0
- maproom/inventory/command.py +961 -0
- maproom/inventory/messages.py +264 -0
- maproom/inventory/reservations_refresh.py +37 -0
- maproom/mock_environment/__init__.py +28 -0
- maproom/mock_environment/load.py +241 -0
- maproom/mock_environment/runner.py +387 -0
- maproom/output/__init__.py +1 -0
- maproom/output/json_envelope.py +241 -0
- maproom/output/redact.py +11 -0
- maproom/output/terminal.py +129 -0
- maproom/parsers.py +284 -0
- maproom/paths.py +105 -0
- maproom/plan/__init__.py +1 -0
- maproom/plan/accept.py +59 -0
- maproom/plan/analysis_context.py +78 -0
- maproom/plan/analyze_selection.py +279 -0
- maproom/plan/commands.py +586 -0
- maproom/plan/current.py +59 -0
- maproom/plan/errors.py +10 -0
- maproom/plan/export.py +36 -0
- maproom/plan/formatting.py +91 -0
- maproom/plan/ids.py +13 -0
- maproom/plan/migration_options.py +75 -0
- maproom/plan/model.py +265 -0
- maproom/plan/names.py +24 -0
- maproom/plan/store.py +193 -0
- maproom/plan/tty.py +34 -0
- maproom/pricing/__init__.py +5 -0
- maproom/pricing/prices.py +119 -0
- maproom/privacy/__init__.py +6 -0
- maproom/privacy/commands.py +159 -0
- maproom/privacy/delete_uploads.py +204 -0
- maproom/privacy/fleetfit_policy.py +125 -0
- maproom/privacy/fleetfit_statement.py +104 -0
- maproom/privacy/format.py +76 -0
- maproom/privacy/manifests.py +342 -0
- maproom/privacy/statement.py +58 -0
- maproom/quotas/__init__.py +21 -0
- maproom/quotas/aws.py +204 -0
- maproom/quotas/azure.py +75 -0
- maproom/quotas/commands.py +240 -0
- maproom/quotas/family_coverage.py +122 -0
- maproom/quotas/fetch.py +124 -0
- maproom/quotas/load.py +41 -0
- maproom/quotas/model.py +178 -0
- maproom/quotas/outcome_ledger.py +245 -0
- maproom/quotas/quota_request_sync.py +221 -0
- maproom/quotas/show.py +73 -0
- maproom/quotas/status.py +206 -0
- maproom/quotas/store.py +161 -0
- maproom/redaction.py +157 -0
- maproom/reference_data/__init__.py +1 -0
- maproom/reference_data/aws/aws_prices.csv +25562 -0
- maproom/reference_data/aws/capabilities.csv +1346 -0
- maproom/reference_data/aws/instance_types.csv +1346 -0
- maproom/reference_data/azure/azure_prices.csv +1 -0
- maproom/reference_data/azure/vm_types.csv +1 -0
- maproom/reference_data/benchmarks/cpu-lscpu-v2-instances.json +27 -0
- maproom/reference_data/benchmarks/safe-moves-v1.json +328 -0
- maproom/reference_data/manifest.json +174 -0
- maproom/reference_data/manifest.py +69 -0
- maproom/reservations/__init__.py +17 -0
- maproom/reservations/aws.py +76 -0
- maproom/reservations/azure.py +36 -0
- maproom/reservations/commands.py +149 -0
- maproom/reservations/load.py +41 -0
- maproom/reservations/model.py +316 -0
- maproom/reservations/show.py +64 -0
- maproom/reservations/status.py +181 -0
- maproom/reservations/store.py +391 -0
- maproom/resources.py +54 -0
- maproom/root_help.py +251 -0
- maproom/saving_plans/__init__.py +15 -0
- maproom/saving_plans/aws.py +73 -0
- maproom/saving_plans/commands.py +122 -0
- maproom/saving_plans/load.py +41 -0
- maproom/saving_plans/model.py +101 -0
- maproom/saving_plans/show.py +64 -0
- maproom/saving_plans/status.py +118 -0
- maproom/saving_plans/store.py +173 -0
- maproom/secret_egress_gate.py +108 -0
- maproom/service/install_id.py +60 -0
- maproom/settings/__init__.py +1 -0
- maproom/settings/defaults.py +73 -0
- maproom/settings/init.py +143 -0
- maproom/settings/model.py +105 -0
- maproom/settings/product_version_change.py +343 -0
- maproom/settings/product_versions.py +68 -0
- maproom/settings/set.py +347 -0
- maproom/settings/show.py +227 -0
- maproom/settings/write.py +273 -0
- maproom/snapshot_time.py +27 -0
- maproom-0.2.0.dist-info/METADATA +263 -0
- maproom-0.2.0.dist-info/RECORD +199 -0
- maproom-0.2.0.dist-info/WHEEL +5 -0
- maproom-0.2.0.dist-info/entry_points.txt +2 -0
- maproom-0.2.0.dist-info/licenses/LICENSE +201 -0
- maproom-0.2.0.dist-info/licenses/NOTICE +72 -0
- maproom-0.2.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
"""GUID tokens for the recommendation upload, held in process memory only.
|
|
2
|
+
|
|
3
|
+
POST {authorize}/v1/tokens returns a batch of GUIDs. Bearer authorization
|
|
4
|
+
headers on recommend POSTs spend one GUID at a time. A new batch is fetched only
|
|
5
|
+
when the queue is empty, so the queue never holds more than one batch. GUIDs
|
|
6
|
+
are never written to disk, to settings.toml, or into a message.
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
from __future__ import annotations
|
|
10
|
+
|
|
11
|
+
import re
|
|
12
|
+
import threading
|
|
13
|
+
import urllib.error
|
|
14
|
+
from collections import deque
|
|
15
|
+
from typing import Any
|
|
16
|
+
|
|
17
|
+
MAX_QUEUED_TOKENS = 10
|
|
18
|
+
TOKEN_EXPIRED = "token_expired"
|
|
19
|
+
|
|
20
|
+
_GUID = re.compile(
|
|
21
|
+
r"[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}"
|
|
22
|
+
)
|
|
23
|
+
|
|
24
|
+
_LOCK = threading.Lock()
|
|
25
|
+
_QUEUE: deque[str] = deque()
|
|
26
|
+
_QUEUE_SOURCE: str | None = None
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
class TokenFetchError(Exception):
|
|
30
|
+
"""The authorize host did not return a usable batch of tokens."""
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
def queued_token_count() -> int:
|
|
34
|
+
with _LOCK:
|
|
35
|
+
return len(_QUEUE)
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
def clear_tokens() -> None:
|
|
39
|
+
"""Drop every queued GUID."""
|
|
40
|
+
global _QUEUE_SOURCE
|
|
41
|
+
with _LOCK:
|
|
42
|
+
_QUEUE.clear()
|
|
43
|
+
_QUEUE_SOURCE = None
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
def take_token(tokens_url: str) -> str:
|
|
47
|
+
"""Pop one GUID. Fetch one batch first when the queue is empty."""
|
|
48
|
+
global _QUEUE_SOURCE
|
|
49
|
+
with _LOCK:
|
|
50
|
+
if _QUEUE_SOURCE != tokens_url:
|
|
51
|
+
_QUEUE.clear()
|
|
52
|
+
if not _QUEUE:
|
|
53
|
+
_QUEUE_SOURCE = None
|
|
54
|
+
from maproom.analyze.workset import note_progress
|
|
55
|
+
|
|
56
|
+
note_progress("Asking FleetFit for a one-time token...")
|
|
57
|
+
batch = _fetch_batch(tokens_url)
|
|
58
|
+
_QUEUE.extend(batch)
|
|
59
|
+
_QUEUE_SOURCE = tokens_url
|
|
60
|
+
return _QUEUE.popleft()
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
def _fetch_batch(tokens_url: str) -> list[str]:
|
|
64
|
+
from maproom.analyze.lookup_http import LookupRedirectError, post_lookup_json
|
|
65
|
+
from maproom.paths import settings_file
|
|
66
|
+
from maproom.settings.model import load_effective_settings
|
|
67
|
+
|
|
68
|
+
settings, _ = load_effective_settings(settings_file())
|
|
69
|
+
try:
|
|
70
|
+
payload = post_lookup_json(
|
|
71
|
+
tokens_url,
|
|
72
|
+
{},
|
|
73
|
+
lookup_label="token request",
|
|
74
|
+
settings=settings,
|
|
75
|
+
)
|
|
76
|
+
except LookupRedirectError as exc:
|
|
77
|
+
raise TokenFetchError(str(exc)) from exc
|
|
78
|
+
except urllib.error.HTTPError as exc:
|
|
79
|
+
raise TokenFetchError(f"token request HTTP {exc.code}") from exc
|
|
80
|
+
except urllib.error.URLError as exc:
|
|
81
|
+
detail = exc.reason if isinstance(exc.reason, str) else "token request failed"
|
|
82
|
+
raise TokenFetchError(detail) from exc
|
|
83
|
+
except (TimeoutError, ValueError) as exc:
|
|
84
|
+
raise TokenFetchError(str(exc)) from exc
|
|
85
|
+
return _require_tokens(payload)
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
def _require_tokens(payload: dict[str, Any]) -> list[str]:
|
|
89
|
+
tokens = payload.get("tokens")
|
|
90
|
+
if not isinstance(tokens, list) or not tokens:
|
|
91
|
+
raise TokenFetchError("token request returned no tokens")
|
|
92
|
+
batch: list[str] = []
|
|
93
|
+
for token in tokens:
|
|
94
|
+
if not isinstance(token, str) or _GUID.fullmatch(token.strip()) is None:
|
|
95
|
+
raise TokenFetchError("token request returned a token that is not a GUID")
|
|
96
|
+
batch.append(token.strip())
|
|
97
|
+
return batch[:MAX_QUEUED_TOKENS]
|
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
"""CloudWatch CPU utilization reads for analyze (fixture-replayable)."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import json
|
|
6
|
+
import statistics
|
|
7
|
+
from datetime import datetime, timedelta, timezone
|
|
8
|
+
from typing import Any, Sequence
|
|
9
|
+
|
|
10
|
+
UTILIZATION_LOOKBACK_DAYS = 14
|
|
11
|
+
SAMPLE_PERIOD_MINUTES = 5
|
|
12
|
+
METRIC_NAMES = (
|
|
13
|
+
"cpu",
|
|
14
|
+
"memory",
|
|
15
|
+
"disk_iops_per_second",
|
|
16
|
+
"disk_throughput_per_second",
|
|
17
|
+
"net_iops_per_second",
|
|
18
|
+
"net_throughput_per_second",
|
|
19
|
+
)
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def utilization_window(
|
|
23
|
+
now: datetime | None = None,
|
|
24
|
+
*,
|
|
25
|
+
lookback_days: int = UTILIZATION_LOOKBACK_DAYS,
|
|
26
|
+
) -> tuple[datetime, datetime]:
|
|
27
|
+
end = (now or datetime.now(timezone.utc)).astimezone(timezone.utc).replace(microsecond=0)
|
|
28
|
+
start = end - timedelta(days=lookback_days)
|
|
29
|
+
return start, end
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
def _iso_z(dt: datetime) -> str:
|
|
33
|
+
return dt.astimezone(timezone.utc).strftime("%Y-%m-%dT%H:%M:%SZ")
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
def build_cpu_utilization_argv(
|
|
37
|
+
instance_id: str,
|
|
38
|
+
*,
|
|
39
|
+
start: datetime,
|
|
40
|
+
end: datetime,
|
|
41
|
+
period: int = 300,
|
|
42
|
+
) -> list[str]:
|
|
43
|
+
query = [
|
|
44
|
+
{
|
|
45
|
+
"Id": "m1",
|
|
46
|
+
"MetricStat": {
|
|
47
|
+
"Metric": {
|
|
48
|
+
"Namespace": "AWS/EC2",
|
|
49
|
+
"MetricName": "CPUUtilization",
|
|
50
|
+
"Dimensions": [{"Name": "InstanceId", "Value": instance_id}],
|
|
51
|
+
},
|
|
52
|
+
"Period": period,
|
|
53
|
+
"Stat": "Average",
|
|
54
|
+
},
|
|
55
|
+
"ReturnData": True,
|
|
56
|
+
}
|
|
57
|
+
]
|
|
58
|
+
return [
|
|
59
|
+
"cloudwatch",
|
|
60
|
+
"get-metric-data",
|
|
61
|
+
"--metric-data-queries",
|
|
62
|
+
json.dumps(query, separators=(",", ":")),
|
|
63
|
+
"--start-time",
|
|
64
|
+
_iso_z(start),
|
|
65
|
+
"--end-time",
|
|
66
|
+
_iso_z(end),
|
|
67
|
+
"--output",
|
|
68
|
+
"json",
|
|
69
|
+
]
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
def percentile(values: Sequence[float], pct: float) -> float:
|
|
73
|
+
if not values:
|
|
74
|
+
raise ValueError("empty values")
|
|
75
|
+
if len(values) == 1:
|
|
76
|
+
return float(values[0])
|
|
77
|
+
return float(statistics.quantiles(sorted(values), n=100)[int(pct) - 1])
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
def cpu_percentiles_from_values(values: Sequence[float]) -> dict[str, float]:
|
|
81
|
+
cleaned = [float(v) for v in values if v is not None]
|
|
82
|
+
if not cleaned:
|
|
83
|
+
return {}
|
|
84
|
+
return {
|
|
85
|
+
"p50": round(percentile(cleaned, 50), 2),
|
|
86
|
+
"p95": round(percentile(cleaned, 95), 2),
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
def percentile_field(metric: str, period_minutes: int) -> str:
|
|
91
|
+
"""Field name for one p99. The period is 1 or 5 minutes."""
|
|
92
|
+
if period_minutes not in (1, 5):
|
|
93
|
+
raise ValueError("sample period must be 1 or 5 minutes")
|
|
94
|
+
if metric not in METRIC_NAMES:
|
|
95
|
+
raise ValueError("unknown size metric")
|
|
96
|
+
return f"{metric}_{period_minutes}minute_p99"
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
def p99_from_values(values: Sequence[float]) -> float | None:
|
|
100
|
+
cleaned = [float(v) for v in values if v is not None]
|
|
101
|
+
if not cleaned:
|
|
102
|
+
return None
|
|
103
|
+
return round(percentile(cleaned, 99), 2)
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
def cpu_p99_from_values(values: Sequence[float]) -> float | None:
|
|
107
|
+
return p99_from_values(values)
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
def sum_aligned_rates(
|
|
111
|
+
series: Sequence[Sequence[tuple[datetime, float]]],
|
|
112
|
+
*,
|
|
113
|
+
period_seconds: int,
|
|
114
|
+
) -> list[float]:
|
|
115
|
+
"""Sum samples that share a timestamp, then divide by the period in seconds."""
|
|
116
|
+
if period_seconds <= 0:
|
|
117
|
+
raise ValueError("period_seconds must be positive")
|
|
118
|
+
totals: dict[datetime, float] = {}
|
|
119
|
+
for pairs in series:
|
|
120
|
+
for ts, value in pairs:
|
|
121
|
+
totals[ts] = totals.get(ts, 0.0) + float(value)
|
|
122
|
+
if not totals:
|
|
123
|
+
return []
|
|
124
|
+
return [totals[ts] / period_seconds for ts in sorted(totals)]
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
def build_size_metric_argv(
|
|
128
|
+
instance_id: str,
|
|
129
|
+
*,
|
|
130
|
+
start: datetime,
|
|
131
|
+
end: datetime,
|
|
132
|
+
period_seconds: int = SAMPLE_PERIOD_MINUTES * 60,
|
|
133
|
+
) -> list[str]:
|
|
134
|
+
"""One GetMetricData call for the same-type size-change readings.
|
|
135
|
+
|
|
136
|
+
CPU is percent. Memory is the CloudWatch agent used-percent, empty when
|
|
137
|
+
that agent is not publishing. Disk and network sums are later divided by
|
|
138
|
+
the period to make a per-second rate.
|
|
139
|
+
"""
|
|
140
|
+
dimensions = [{"Name": "InstanceId", "Value": instance_id}]
|
|
141
|
+
|
|
142
|
+
def _query(query_id: str, namespace: str, metric: str, stat: str) -> dict[str, Any]:
|
|
143
|
+
return {
|
|
144
|
+
"Id": query_id,
|
|
145
|
+
"MetricStat": {
|
|
146
|
+
"Metric": {
|
|
147
|
+
"Namespace": namespace,
|
|
148
|
+
"MetricName": metric,
|
|
149
|
+
"Dimensions": dimensions,
|
|
150
|
+
},
|
|
151
|
+
"Period": period_seconds,
|
|
152
|
+
"Stat": stat,
|
|
153
|
+
},
|
|
154
|
+
"ReturnData": True,
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
queries = [
|
|
158
|
+
_query("cpu", "AWS/EC2", "CPUUtilization", "Average"),
|
|
159
|
+
_query("memory", "CWAgent", "mem_used_percent", "Average"),
|
|
160
|
+
_query("ebs_read_ops", "AWS/EC2", "EBSReadOps", "Sum"),
|
|
161
|
+
_query("ebs_write_ops", "AWS/EC2", "EBSWriteOps", "Sum"),
|
|
162
|
+
_query("ebs_read_bytes", "AWS/EC2", "EBSReadBytes", "Sum"),
|
|
163
|
+
_query("ebs_write_bytes", "AWS/EC2", "EBSWriteBytes", "Sum"),
|
|
164
|
+
_query("net_in_bytes", "AWS/EC2", "NetworkIn", "Sum"),
|
|
165
|
+
_query("net_out_bytes", "AWS/EC2", "NetworkOut", "Sum"),
|
|
166
|
+
_query("net_in_pkts", "AWS/EC2", "NetworkPacketsIn", "Sum"),
|
|
167
|
+
_query("net_out_pkts", "AWS/EC2", "NetworkPacketsOut", "Sum"),
|
|
168
|
+
]
|
|
169
|
+
return [
|
|
170
|
+
"cloudwatch",
|
|
171
|
+
"get-metric-data",
|
|
172
|
+
"--metric-data-queries",
|
|
173
|
+
json.dumps(queries, separators=(",", ":")),
|
|
174
|
+
"--start-time",
|
|
175
|
+
_iso_z(start),
|
|
176
|
+
"--end-time",
|
|
177
|
+
_iso_z(end),
|
|
178
|
+
"--output",
|
|
179
|
+
"json",
|
|
180
|
+
]
|
|
181
|
+
|
|
182
|
+
|
|
183
|
+
def summarize_cpu_utilization(metric_result: dict[str, Any] | None) -> dict[str, Any] | None:
|
|
184
|
+
if not metric_result:
|
|
185
|
+
return None
|
|
186
|
+
values = metric_result.get("Values") or []
|
|
187
|
+
stats = cpu_percentiles_from_values(values)
|
|
188
|
+
if not stats:
|
|
189
|
+
return None
|
|
190
|
+
return stats
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
"""Workload profile assembly for analyze (FB-3 / alternative_candidate section 1 subset)."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from typing import Any
|
|
6
|
+
|
|
7
|
+
from maproom.analyze.utilization import UTILIZATION_LOOKBACK_DAYS, summarize_cpu_utilization
|
|
8
|
+
from maproom.resources import Ec2Target
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
def build_workload_profile(
|
|
12
|
+
*,
|
|
13
|
+
target: Ec2Target,
|
|
14
|
+
instance: dict[str, Any],
|
|
15
|
+
cpu_metric_result: dict[str, Any] | None,
|
|
16
|
+
account_id: str,
|
|
17
|
+
reservation_coverage_missing: bool = True,
|
|
18
|
+
quota_headroom_missing: bool = True,
|
|
19
|
+
) -> tuple[dict[str, Any], list[str]]:
|
|
20
|
+
instance_type = instance.get("InstanceType")
|
|
21
|
+
cpu_stats = summarize_cpu_utilization(cpu_metric_result)
|
|
22
|
+
|
|
23
|
+
utilization: dict[str, Any] = {
|
|
24
|
+
"lookback_days": UTILIZATION_LOOKBACK_DAYS,
|
|
25
|
+
"cpu": cpu_stats,
|
|
26
|
+
"memory": None,
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
missing: list[str] = []
|
|
30
|
+
if reservation_coverage_missing:
|
|
31
|
+
missing.append("reservation_coverage")
|
|
32
|
+
if quota_headroom_missing:
|
|
33
|
+
missing.append("quota_headroom")
|
|
34
|
+
if instance_type:
|
|
35
|
+
missing.append("instance_type_specs")
|
|
36
|
+
if cpu_stats is None:
|
|
37
|
+
missing.append("cpu_utilization")
|
|
38
|
+
missing.append("memory_utilization")
|
|
39
|
+
|
|
40
|
+
profile = {
|
|
41
|
+
"cloud": target.cloud,
|
|
42
|
+
"account_id": account_id,
|
|
43
|
+
"region": target.region,
|
|
44
|
+
"instance_id": target.instance_id,
|
|
45
|
+
"instance_type": instance_type,
|
|
46
|
+
"state": (instance.get("State") or {}).get("Name"),
|
|
47
|
+
"az": (instance.get("Placement") or {}).get("AvailabilityZone"),
|
|
48
|
+
"vcpu": None,
|
|
49
|
+
"memory_gib": None,
|
|
50
|
+
"utilization": utilization,
|
|
51
|
+
}
|
|
52
|
+
return profile, missing
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
def reconcile_instance_specs_evidence(
|
|
56
|
+
profile: dict[str, Any],
|
|
57
|
+
missing_evidence: list[str],
|
|
58
|
+
spec_catalog: Any | None,
|
|
59
|
+
) -> tuple[dict[str, Any], list[str]]:
|
|
60
|
+
"""Align profile vCPU/memory and missing_evidence with the resolved spec catalog."""
|
|
61
|
+
profile_out = dict(profile)
|
|
62
|
+
missing = list(missing_evidence)
|
|
63
|
+
instance_type = profile_out.get("instance_type")
|
|
64
|
+
if not instance_type:
|
|
65
|
+
return profile_out, missing
|
|
66
|
+
|
|
67
|
+
from maproom.analyze.specs import catalog_has_specs
|
|
68
|
+
|
|
69
|
+
if (
|
|
70
|
+
catalog_has_specs(spec_catalog)
|
|
71
|
+
and instance_type in spec_catalog.specs
|
|
72
|
+
):
|
|
73
|
+
spec = spec_catalog.specs[instance_type]
|
|
74
|
+
if spec.vcpus > 0:
|
|
75
|
+
profile_out["vcpu"] = spec.vcpus
|
|
76
|
+
if spec.memory_mib > 0:
|
|
77
|
+
profile_out["memory_gib"] = spec.memory_mib // 1024
|
|
78
|
+
if "instance_type_specs" in missing:
|
|
79
|
+
missing.remove("instance_type_specs")
|
|
80
|
+
elif "instance_type_specs" not in missing:
|
|
81
|
+
missing.append("instance_type_specs")
|
|
82
|
+
|
|
83
|
+
return profile_out, missing
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
def format_input_quality(missing_evidence: list[str]) -> str:
|
|
87
|
+
lines = ["Input quality:"]
|
|
88
|
+
if not missing_evidence:
|
|
89
|
+
lines.append(" complete")
|
|
90
|
+
return "\n".join(lines)
|
|
91
|
+
lines.append(" missing: " + ", ".join(missing_evidence))
|
|
92
|
+
if "reservation_coverage" in missing_evidence:
|
|
93
|
+
lines.append(
|
|
94
|
+
" reservation coverage unknown: savings estimates would use on-demand pricing"
|
|
95
|
+
)
|
|
96
|
+
if "quota_headroom" in missing_evidence:
|
|
97
|
+
lines.append(
|
|
98
|
+
" quota headroom unknown: launchability not evaluated for candidates"
|
|
99
|
+
)
|
|
100
|
+
if "cpu_utilization" in missing_evidence:
|
|
101
|
+
lines.append(" cpu utilization unavailable: confidence for rightsizing is reduced")
|
|
102
|
+
if "memory_utilization" in missing_evidence:
|
|
103
|
+
lines.append(" memory utilization unavailable: memory-bound moves cannot be ruled out")
|
|
104
|
+
return "\n".join(lines)
|