@oneuptime/common 14.0.104 → 14.0.105
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/Models/DatabaseModels/CloudAccount.d.mts +1 -0
- package/Models/DatabaseModels/CloudAccount.d.ts +1 -0
- package/Models/DatabaseModels/CloudAccount.js +21 -0
- package/Models/DatabaseModels/CloudBudget.d.mts +1 -0
- package/Models/DatabaseModels/CloudBudget.d.ts +1 -0
- package/Models/DatabaseModels/CloudBudget.js +38 -3
- package/Models/DatabaseModels/CloudCostRecommendation.d.mts +2 -0
- package/Models/DatabaseModels/CloudCostRecommendation.d.ts +2 -0
- package/Models/DatabaseModels/CloudCostRecommendation.js +30 -2
- package/Models/DatabaseModels/DetectionRule.js +8 -7
- package/Types/AI/ResourceAiAccessApi.d.mts +1 -0
- package/Types/AI/ResourceAiAccessApi.d.ts +1 -0
- package/Types/AI/ResourceAiAccessApi.js +6 -1
- package/Types/AI/ResourceAiAccessApi.mjs +1 -0
- package/Types/AI/ResourceAiAccessPermissions.d.mts +2 -0
- package/Types/AI/ResourceAiAccessPermissions.d.ts +2 -0
- package/Types/AI/ResourceAiAccessPermissions.js +13 -0
- package/Types/AI/ResourceAiAccessPermissions.mjs +2 -0
- package/Types/Cloud/CloudCost.d.mts +8 -0
- package/Types/Cloud/CloudCost.d.ts +8 -0
- package/Types/Cloud/CloudCost.js +37 -0
- package/Types/Cloud/CloudCost.mjs +1 -0
- package/Types/Cloud/CloudCostAnomaly.d.mts +34 -0
- package/Types/Cloud/CloudCostAnomaly.d.ts +34 -0
- package/Types/Cloud/CloudCostAnomaly.js +236 -0
- package/Types/Cloud/CloudCostAnomaly.mjs +18 -0
- package/Types/Cloud/CloudLogGroups.d.mts +6 -1
- package/Types/Cloud/CloudLogGroups.d.ts +6 -1
- package/Types/Cloud/CloudLogGroups.js +59 -3
- package/Types/Cloud/CloudLogGroups.mjs +1 -0
- package/Types/Cloud/CloudPlatform.js +9 -8
- package/Types/Cloud/CloudRightSizing.d.mts +140 -0
- package/Types/Cloud/CloudRightSizing.d.ts +140 -0
- package/Types/Cloud/CloudRightSizing.js +867 -0
- package/Types/Cloud/CloudRightSizing.mjs +53 -0
- package/Types/CloudConnection/CloudAiAgentKey.d.mts +65 -0
- package/Types/CloudConnection/CloudAiAgentKey.d.ts +65 -0
- package/Types/CloudConnection/CloudAiAgentKey.js +289 -0
- package/Types/CloudConnection/CloudAiAgentKey.mjs +18 -0
- package/Types/CloudConnection/CloudAiAgentSetupCommands.d.mts +5 -2
- package/Types/CloudConnection/CloudAiAgentSetupCommands.d.ts +5 -2
- package/Types/CloudConnection/CloudAiAgentSetupCommands.js +114 -43
- package/Types/CloudConnection/CloudAiAgentSetupCommands.mjs +4 -1
- package/Types/CloudConnection/CloudStream.d.mts +4 -0
- package/Types/CloudConnection/CloudStream.d.ts +4 -0
- package/Types/CloudConnection/CloudStream.js +18 -1
- package/Types/CloudConnection/CloudStream.mjs +4 -0
- package/Types/CloudConnection/CloudStreamTemplate.d.mts +2 -0
- package/Types/CloudConnection/CloudStreamTemplate.d.ts +2 -0
- package/Types/CloudConnection/CloudStreamTemplate.js +89 -6
- package/Types/CloudConnection/CloudStreamTemplate.mjs +2 -0
- package/Types/InstallScripts/InstallScripts.js +1 -1
- package/Types/ResourceAiAgent/CloudAiAgentNames.d.mts +6 -0
- package/Types/ResourceAiAgent/CloudAiAgentNames.d.ts +6 -0
- package/Types/ResourceAiAgent/CloudAiAgentNames.js +11 -1
- package/Types/ResourceAiAgent/CloudAiAgentNames.mjs +3 -0
- package/Types/ResourceAiAgent/ResourceAiAccess.d.mts +3 -1
- package/Types/ResourceAiAgent/ResourceAiAccess.d.ts +3 -1
- package/Types/ResourceAiAgent/ResourceAiAccess.js +13 -2
- package/Types/ResourceAiAgent/ResourceAiAccess.mjs +2 -0
- package/Types/SecurityCase/SecurityCaseContext.d.mts +2 -1
- package/Types/SecurityCase/SecurityCaseContext.d.ts +2 -1
- package/Types/SecurityCase/SecurityConnection.d.mts +2 -1
- package/Types/SecurityCase/SecurityConnection.d.ts +2 -1
- package/Types/SecurityEvent/RealTimeDetection.d.mts +14 -5
- package/Types/SecurityEvent/RealTimeDetection.d.ts +14 -5
- package/Types/SecurityEvent/RealTimeDetection.js +75 -25
- package/Types/SecurityEvent/RealTimeDetection.mjs +3 -3
- package/Types/SecurityPlaybook/SecurityPlaybookAction.d.mts +4 -2
- package/Types/SecurityPlaybook/SecurityPlaybookAction.d.ts +4 -2
- package/Types/SecurityPlaybook/SecurityPlaybookAction.js +22 -3
- package/Types/SecurityPlaybook/SecurityPlaybookStep.d.mts +7 -2
- package/Types/SecurityPlaybook/SecurityPlaybookStep.d.ts +7 -2
- package/Types/SecurityPlaybook/SecurityPlaybookStep.js +96 -39
- package/Types/SecurityPlaybook/SecurityPlaybookStep.mjs +2 -0
- package/Types/SecurityPlaybook/SecurityPlaybookStepCondition.d.mts +17 -2
- package/Types/SecurityPlaybook/SecurityPlaybookStepCondition.d.ts +17 -2
- package/Types/SecurityPlaybook/SecurityPlaybookStepCondition.js +174 -33
- package/Types/SecurityPlaybook/SecurityPlaybookStepCondition.mjs +7 -0
- package/Utils/SecurityCase/SecurityCaseMarkdown.d.mts +5 -0
- package/Utils/SecurityCase/SecurityCaseMarkdown.d.ts +5 -0
- package/Utils/SecurityCase/SecurityCaseMarkdown.js +10 -0
- package/Utils/SecurityCase/SecurityCaseMarkdown.mjs +1 -0
- package/Utils/Telemetry/CloudChangeTitle.d.mts +37 -0
- package/Utils/Telemetry/CloudChangeTitle.d.ts +37 -0
- package/Utils/Telemetry/CloudChangeTitle.js +315 -3
- package/Utils/Telemetry/CloudChangeTitle.mjs +13 -0
- package/package.json +1 -1
|
@@ -0,0 +1,867 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RIGHT_SIZING_NOT_READ = exports.RIGHT_SIZING_DAYS_READ_LABEL = exports.RIGHT_SIZING_MEMORY_PEAK_LABEL = exports.RIGHT_SIZING_CPU_MAX_LABEL = exports.RIGHT_SIZING_CPU_P95_LABEL = exports.RIGHT_SIZING_LEARNING = exports.RIGHT_SIZING_SAVING_NOT_KNOWN = exports.RIGHT_SIZING_COSTS_MORE = exports.RIGHT_SIZING_SAVES_UP_TO = exports.RIGHT_SIZING_SAVES = exports.RIGHT_SIZING_AT_NEW_SIZE_WITH_MEMORY = exports.RIGHT_SIZING_AT_NEW_SIZE = exports.RIGHT_SIZING_FITS = exports.RIGHT_SIZING_NO_LARGER_SIZE = exports.RIGHT_SIZING_NO_SMALLER_SIZE = exports.RIGHT_SIZING_TWICE_SIZE = exports.RIGHT_SIZING_QUARTER_SIZE = exports.RIGHT_SIZING_HALF_SIZE = exports.CLOUD_RIGHT_SIZING_VERDICT_LABELS = exports.RIGHT_SIZING_TITLE = exports.CloudRightSizingSkipReason = exports.CloudRightSizingVerdict = exports.CLOUD_RIGHT_SIZING_PROFILES = exports.MEMORY_NOT_REPORTED = exports.MEMORY_NEEDS_OPS_AGENT = exports.MEMORY_REPORTED_AS_FREE = exports.MEMORY_NEEDS_CLOUDWATCH_AGENT = exports.CloudSizeLadder = exports.CLOUD_SIZE_RECOMMENDATION_KINDS = exports.CLOUD_RIGHT_SIZING_RECOMMENDATION_PREFIX = exports.CLOUD_SAVINGS_SOURCE_ONEUPTIME = exports.CLOUD_DAYS_IN_AVERAGE_MONTH = exports.CLOUD_RIGHT_SIZING_MAX_STEPS_DOWN = exports.CLOUD_RIGHT_SIZING_MEMORY_HOT_PERCENT = exports.CLOUD_RIGHT_SIZING_CPU_HOT_PERCENT = exports.CLOUD_RIGHT_SIZING_MEMORY_TARGET_PERCENT = exports.CLOUD_RIGHT_SIZING_CPU_PEAK_PERCENT = exports.CLOUD_RIGHT_SIZING_CPU_TARGET_PERCENT = exports.CLOUD_RIGHT_SIZING_MIN_SAMPLES = exports.CLOUD_RIGHT_SIZING_MIN_OBSERVED_HOURS = exports.CLOUD_RIGHT_SIZING_WINDOW_DAYS = void 0;
|
|
4
|
+
exports.getCloudRightSizingRecommendationId = getCloudRightSizingRecommendationId;
|
|
5
|
+
exports.isCloudRightSizingRecommendationId = isCloudRightSizingRecommendationId;
|
|
6
|
+
exports.isRecommenderSizeRecommendation = isRecommenderSizeRecommendation;
|
|
7
|
+
exports.getCloudRightSizingProfile = getCloudRightSizingProfile;
|
|
8
|
+
exports.readCloudResourceSize = readCloudResourceSize;
|
|
9
|
+
exports.getCloudSizeSteps = getCloudSizeSteps;
|
|
10
|
+
exports.buildCloudRightSizing = buildCloudRightSizing;
|
|
11
|
+
exports.hasCloudRightSizingChange = hasCloudRightSizingChange;
|
|
12
|
+
exports.getCloudReadingsP95 = getCloudReadingsP95;
|
|
13
|
+
exports.toCloudRightSizingEvidence = toCloudRightSizingEvidence;
|
|
14
|
+
exports.readCloudRightSizingEvidence = readCloudRightSizingEvidence;
|
|
15
|
+
const Translator_1 = require("../Translator");
|
|
16
|
+
const CloudCost_1 = require("./CloudCost");
|
|
17
|
+
const CloudKeyMetrics_1 = require("./CloudKeyMetrics");
|
|
18
|
+
const CloudPlatform_1 = require("./CloudPlatform");
|
|
19
|
+
/*
|
|
20
|
+
* RIGHT-SIZING A CLOUD RESOURCE FROM ONEUPTIME'S OWN READINGS OF ITS CPU AND
|
|
21
|
+
* MEMORY.
|
|
22
|
+
*
|
|
23
|
+
* Each cloud has a recommender of its own (AWS Cost Optimization Hub, Azure
|
|
24
|
+
* Advisor, Google Cloud's Recommender), read once a day as ways to spend
|
|
25
|
+
* less. Many resources have none: a recommender that is not turned on, a
|
|
26
|
+
* type it does not cover (an ElastiCache cluster, an App Service plan, a
|
|
27
|
+
* Cloud SQL instance a recommender has nothing to say of), a resource too
|
|
28
|
+
* new for it. For those, OneUptime works it out itself, from the metrics
|
|
29
|
+
* its cloud connection reads of them, as its Kubernetes right-sizing does
|
|
30
|
+
* for workloads (Types/Kubernetes/KubernetesRightSizing): what to change,
|
|
31
|
+
* why, and what it would save once its cost is known.
|
|
32
|
+
*
|
|
33
|
+
* The rules, for the sizes a cloud doubles from one to the next:
|
|
34
|
+
*
|
|
35
|
+
* - Over-provisioned: the size half as big (or a quarter) would still
|
|
36
|
+
* have room - its CPU's 95th percentile at most 60% and its highest
|
|
37
|
+
* reading at most 100% of the smaller size, and its memory's peak at
|
|
38
|
+
* most 70% of it, when its memory is read. A size is never cut more
|
|
39
|
+
* than twice (to a quarter) at once.
|
|
40
|
+
* - Under-provisioned: its CPU's 95th percentile at 85% or more, or its
|
|
41
|
+
* memory's peak at 90% or more: the size twice as big.
|
|
42
|
+
* - Right-sized: neither.
|
|
43
|
+
*
|
|
44
|
+
* Over a window of 14 days, and only once it has at least 6 days and 288
|
|
45
|
+
* readings: a quiet weekend or a nightly batch alone never sizes it. A
|
|
46
|
+
* memory that is not read as a share (EC2 without the CloudWatch agent, a
|
|
47
|
+
* database that reports the memory left) sizes by CPU only, and says so.
|
|
48
|
+
*
|
|
49
|
+
* What a change saves is its share of what the resource cost a day, over
|
|
50
|
+
* the days its cloud billed it in the last 30, made a month: a size half as
|
|
51
|
+
* big costs half as much on every cloud's list price. A database's bill
|
|
52
|
+
* also holds its storage, so for those it is "up to". Burstable sizes (t3,
|
|
53
|
+
* B-series, e2-micro) are sized by their CPU credits, never here.
|
|
54
|
+
*
|
|
55
|
+
* Shared by the server (a cloud connection's daily read writes the
|
|
56
|
+
* over-provisioned as ways to spend less) and the Dashboard (a resource's
|
|
57
|
+
* Overview). React-free and server-safe.
|
|
58
|
+
*/
|
|
59
|
+
// The days the readings are taken from.
|
|
60
|
+
exports.CLOUD_RIGHT_SIZING_WINDOW_DAYS = 14;
|
|
61
|
+
// The least history a resource is sized from: almost a week.
|
|
62
|
+
exports.CLOUD_RIGHT_SIZING_MIN_OBSERVED_HOURS = 6 * 24;
|
|
63
|
+
// And at least a day of five-minute readings.
|
|
64
|
+
exports.CLOUD_RIGHT_SIZING_MIN_SAMPLES = 288;
|
|
65
|
+
// The 95th percentile of CPU a smaller size may run at.
|
|
66
|
+
exports.CLOUD_RIGHT_SIZING_CPU_TARGET_PERCENT = 60;
|
|
67
|
+
// The highest CPU reading a smaller size may reach.
|
|
68
|
+
exports.CLOUD_RIGHT_SIZING_CPU_PEAK_PERCENT = 100;
|
|
69
|
+
// The memory peak a smaller size may run at.
|
|
70
|
+
exports.CLOUD_RIGHT_SIZING_MEMORY_TARGET_PERCENT = 70;
|
|
71
|
+
// A 95th percentile of CPU from which a size is too small.
|
|
72
|
+
exports.CLOUD_RIGHT_SIZING_CPU_HOT_PERCENT = 85;
|
|
73
|
+
// A memory peak from which a size is too small.
|
|
74
|
+
exports.CLOUD_RIGHT_SIZING_MEMORY_HOT_PERCENT = 90;
|
|
75
|
+
// A size is cut at most twice at once: to a quarter.
|
|
76
|
+
exports.CLOUD_RIGHT_SIZING_MAX_STEPS_DOWN = 2;
|
|
77
|
+
// The days in a month, on average: what a day's cost is made a month by.
|
|
78
|
+
exports.CLOUD_DAYS_IN_AVERAGE_MONTH = 365.25 / 12;
|
|
79
|
+
// The source a right-sizing OneUptime worked out is kept as.
|
|
80
|
+
exports.CLOUD_SAVINGS_SOURCE_ONEUPTIME = "OneUptime";
|
|
81
|
+
/*
|
|
82
|
+
* What a right-sizing OneUptime worked out is kept as among the ways to
|
|
83
|
+
* spend less: "oneuptime-rightsize:<the resource's id>".
|
|
84
|
+
*/
|
|
85
|
+
exports.CLOUD_RIGHT_SIZING_RECOMMENDATION_PREFIX = "oneuptime-rightsize:";
|
|
86
|
+
function getCloudRightSizingRecommendationId(cloudResourceId) {
|
|
87
|
+
return `${exports.CLOUD_RIGHT_SIZING_RECOMMENDATION_PREFIX}${cloudResourceId}`;
|
|
88
|
+
}
|
|
89
|
+
function isCloudRightSizingRecommendationId(recommendationId) {
|
|
90
|
+
return (recommendationId || "").startsWith(exports.CLOUD_RIGHT_SIZING_RECOMMENDATION_PREFIX);
|
|
91
|
+
}
|
|
92
|
+
/*
|
|
93
|
+
* The kinds of a cloud's recommendation that speak for a resource's size: a
|
|
94
|
+
* resource its cloud's recommender would resize, stop or move to a newer
|
|
95
|
+
* generation is left to it. A commitment says nothing of one resource.
|
|
96
|
+
*/
|
|
97
|
+
exports.CLOUD_SIZE_RECOMMENDATION_KINDS = [
|
|
98
|
+
CloudCost_1.CloudSavingKind.Rightsize,
|
|
99
|
+
CloudCost_1.CloudSavingKind.Idle,
|
|
100
|
+
CloudCost_1.CloudSavingKind.Upgrade,
|
|
101
|
+
];
|
|
102
|
+
// Whether a recommendation is a cloud recommender's word on a resource's size.
|
|
103
|
+
function isRecommenderSizeRecommendation(data) {
|
|
104
|
+
return (!isCloudRightSizingRecommendationId(data.recommendationId) &&
|
|
105
|
+
exports.CLOUD_SIZE_RECOMMENDATION_KINDS.includes(data.kind));
|
|
106
|
+
}
|
|
107
|
+
/*
|
|
108
|
+
* ---------------------------------------------------------------------------
|
|
109
|
+
* The resources it sizes
|
|
110
|
+
* ---------------------------------------------------------------------------
|
|
111
|
+
*/
|
|
112
|
+
// How a cloud names its sizes, and so how one is a step from another.
|
|
113
|
+
var CloudSizeLadder;
|
|
114
|
+
(function (CloudSizeLadder) {
|
|
115
|
+
// m5.2xlarge, db.r6g.xlarge, cache.r6g.large.
|
|
116
|
+
CloudSizeLadder["Aws"] = "aws";
|
|
117
|
+
// Standard_D8s_v5 - and a flexible server's SKU, Standard_D4ds_v4.
|
|
118
|
+
CloudSizeLadder["AzureVm"] = "azure-vm";
|
|
119
|
+
// An App Service plan's SKU: P1v3, S2.
|
|
120
|
+
CloudSizeLadder["AzureAppServicePlan"] = "azure-app-service-plan";
|
|
121
|
+
// n2-standard-16, n2-custom-8-32768.
|
|
122
|
+
CloudSizeLadder["GcpMachine"] = "gcp-machine";
|
|
123
|
+
// db-custom-4-16384, db-n1-standard-4.
|
|
124
|
+
CloudSizeLadder["GcpCloudSql"] = "gcp-cloud-sql";
|
|
125
|
+
})(CloudSizeLadder || (exports.CloudSizeLadder = CloudSizeLadder = {}));
|
|
126
|
+
// An Azure Monitor metric under each aggregation it may be stored with.
|
|
127
|
+
function azureStoredNames(metricName) {
|
|
128
|
+
return ["Average", "Maximum", "Minimum", "Total"].map((aggregation) => {
|
|
129
|
+
return (0, CloudKeyMetrics_1.getAzureStoredMetricName)(metricName, aggregation);
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
function awsStoredName(namespace, metricName) {
|
|
133
|
+
return [(0, CloudKeyMetrics_1.getAwsStoredMetricName)(namespace, metricName).toLowerCase()];
|
|
134
|
+
}
|
|
135
|
+
exports.MEMORY_NEEDS_CLOUDWATCH_AGENT = (0, Translator_1.translationKey)("CloudWatch reads an instance's memory only with its agent. Check it uses less than half its memory before you change its size.");
|
|
136
|
+
exports.MEMORY_REPORTED_AS_FREE = (0, Translator_1.translationKey)("Its cloud reports the memory left, not the share used. Check it uses less than half its memory before you change its size.");
|
|
137
|
+
exports.MEMORY_NEEDS_OPS_AGENT = (0, Translator_1.translationKey)("Cloud Monitoring reads an instance's memory only with the Ops Agent. Check it uses less than half its memory before you change its size.");
|
|
138
|
+
exports.MEMORY_NOT_REPORTED = (0, Translator_1.translationKey)("No memory readings came in over these days. Check it uses less than half its memory before you change its size.");
|
|
139
|
+
exports.CLOUD_RIGHT_SIZING_PROFILES = [
|
|
140
|
+
{
|
|
141
|
+
provider: CloudPlatform_1.CloudProvider.AWS,
|
|
142
|
+
type: "AWS::EC2::Instance",
|
|
143
|
+
savingResourceType: "EC2 instance",
|
|
144
|
+
sizeProperty: "InstanceType",
|
|
145
|
+
ladder: CloudSizeLadder.Aws,
|
|
146
|
+
cpu: { names: awsStoredName("AWS/EC2", "CPUUtilization"), toPercent: 1 },
|
|
147
|
+
memory: null,
|
|
148
|
+
memoryNotRead: exports.MEMORY_NEEDS_CLOUDWATCH_AGENT,
|
|
149
|
+
billHoldsMoreThanSize: false,
|
|
150
|
+
},
|
|
151
|
+
{
|
|
152
|
+
provider: CloudPlatform_1.CloudProvider.AWS,
|
|
153
|
+
type: "AWS::RDS::DBInstance",
|
|
154
|
+
savingResourceType: "RDS DB instance",
|
|
155
|
+
sizeProperty: "DBInstanceClass",
|
|
156
|
+
ladder: CloudSizeLadder.Aws,
|
|
157
|
+
cpu: { names: awsStoredName("AWS/RDS", "CPUUtilization"), toPercent: 1 },
|
|
158
|
+
memory: null,
|
|
159
|
+
memoryNotRead: exports.MEMORY_REPORTED_AS_FREE,
|
|
160
|
+
billHoldsMoreThanSize: true,
|
|
161
|
+
},
|
|
162
|
+
{
|
|
163
|
+
provider: CloudPlatform_1.CloudProvider.AWS,
|
|
164
|
+
type: "AWS::ElastiCache::CacheCluster",
|
|
165
|
+
savingResourceType: "ElastiCache cluster",
|
|
166
|
+
sizeProperty: "CacheNodeType",
|
|
167
|
+
ladder: CloudSizeLadder.Aws,
|
|
168
|
+
cpu: {
|
|
169
|
+
names: awsStoredName("AWS/ElastiCache", "CPUUtilization"),
|
|
170
|
+
toPercent: 1,
|
|
171
|
+
},
|
|
172
|
+
memory: {
|
|
173
|
+
names: awsStoredName("AWS/ElastiCache", "DatabaseMemoryUsagePercentage"),
|
|
174
|
+
toPercent: 1,
|
|
175
|
+
},
|
|
176
|
+
billHoldsMoreThanSize: false,
|
|
177
|
+
},
|
|
178
|
+
{
|
|
179
|
+
provider: CloudPlatform_1.CloudProvider.AWS,
|
|
180
|
+
type: "AWS::ElastiCache::ReplicationGroup",
|
|
181
|
+
savingResourceType: "ElastiCache replication group",
|
|
182
|
+
sizeProperty: "CacheNodeType",
|
|
183
|
+
ladder: CloudSizeLadder.Aws,
|
|
184
|
+
cpu: {
|
|
185
|
+
names: awsStoredName("AWS/ElastiCache", "CPUUtilization"),
|
|
186
|
+
toPercent: 1,
|
|
187
|
+
},
|
|
188
|
+
memory: {
|
|
189
|
+
names: awsStoredName("AWS/ElastiCache", "DatabaseMemoryUsagePercentage"),
|
|
190
|
+
toPercent: 1,
|
|
191
|
+
},
|
|
192
|
+
billHoldsMoreThanSize: false,
|
|
193
|
+
},
|
|
194
|
+
{
|
|
195
|
+
provider: CloudPlatform_1.CloudProvider.Azure,
|
|
196
|
+
type: "Microsoft.Compute/virtualMachines",
|
|
197
|
+
savingResourceType: "Virtual machine",
|
|
198
|
+
sizeProperty: "vmSize",
|
|
199
|
+
ladder: CloudSizeLadder.AzureVm,
|
|
200
|
+
cpu: { names: azureStoredNames("Percentage CPU"), toPercent: 1 },
|
|
201
|
+
memory: null,
|
|
202
|
+
memoryNotRead: exports.MEMORY_REPORTED_AS_FREE,
|
|
203
|
+
billHoldsMoreThanSize: false,
|
|
204
|
+
},
|
|
205
|
+
{
|
|
206
|
+
provider: CloudPlatform_1.CloudProvider.Azure,
|
|
207
|
+
type: "Microsoft.DBforPostgreSQL/flexibleServers",
|
|
208
|
+
savingResourceType: "PostgreSQL flexible server",
|
|
209
|
+
sizeProperty: "skuName",
|
|
210
|
+
ladder: CloudSizeLadder.AzureVm,
|
|
211
|
+
cpu: { names: azureStoredNames("cpu_percent"), toPercent: 1 },
|
|
212
|
+
memory: { names: azureStoredNames("memory_percent"), toPercent: 1 },
|
|
213
|
+
billHoldsMoreThanSize: true,
|
|
214
|
+
},
|
|
215
|
+
{
|
|
216
|
+
provider: CloudPlatform_1.CloudProvider.Azure,
|
|
217
|
+
type: "Microsoft.DBforMySQL/flexibleServers",
|
|
218
|
+
savingResourceType: "MySQL flexible server",
|
|
219
|
+
sizeProperty: "skuName",
|
|
220
|
+
ladder: CloudSizeLadder.AzureVm,
|
|
221
|
+
cpu: { names: azureStoredNames("cpu_percent"), toPercent: 1 },
|
|
222
|
+
memory: { names: azureStoredNames("memory_percent"), toPercent: 1 },
|
|
223
|
+
billHoldsMoreThanSize: true,
|
|
224
|
+
},
|
|
225
|
+
{
|
|
226
|
+
provider: CloudPlatform_1.CloudProvider.Azure,
|
|
227
|
+
type: "Microsoft.Web/serverfarms",
|
|
228
|
+
savingResourceType: "App Service plan",
|
|
229
|
+
sizeProperty: "skuName",
|
|
230
|
+
ladder: CloudSizeLadder.AzureAppServicePlan,
|
|
231
|
+
cpu: { names: azureStoredNames("CpuPercentage"), toPercent: 1 },
|
|
232
|
+
memory: { names: azureStoredNames("MemoryPercentage"), toPercent: 1 },
|
|
233
|
+
billHoldsMoreThanSize: false,
|
|
234
|
+
},
|
|
235
|
+
{
|
|
236
|
+
provider: CloudPlatform_1.CloudProvider.GCP,
|
|
237
|
+
type: "gce_instance",
|
|
238
|
+
savingResourceType: "Compute Engine instance",
|
|
239
|
+
sizeProperty: "machineType",
|
|
240
|
+
ladder: CloudSizeLadder.GcpMachine,
|
|
241
|
+
cpu: {
|
|
242
|
+
names: ["compute.googleapis.com/instance/cpu/utilization"],
|
|
243
|
+
toPercent: 100,
|
|
244
|
+
},
|
|
245
|
+
memory: null,
|
|
246
|
+
memoryNotRead: exports.MEMORY_NEEDS_OPS_AGENT,
|
|
247
|
+
billHoldsMoreThanSize: false,
|
|
248
|
+
},
|
|
249
|
+
{
|
|
250
|
+
provider: CloudPlatform_1.CloudProvider.GCP,
|
|
251
|
+
type: "cloudsql_database",
|
|
252
|
+
savingResourceType: "Cloud SQL instance",
|
|
253
|
+
sizeProperty: "settings.tier",
|
|
254
|
+
ladder: CloudSizeLadder.GcpCloudSql,
|
|
255
|
+
cpu: {
|
|
256
|
+
names: ["cloudsql.googleapis.com/database/cpu/utilization"],
|
|
257
|
+
toPercent: 100,
|
|
258
|
+
},
|
|
259
|
+
memory: {
|
|
260
|
+
names: ["cloudsql.googleapis.com/database/memory/utilization"],
|
|
261
|
+
toPercent: 100,
|
|
262
|
+
},
|
|
263
|
+
billHoldsMoreThanSize: true,
|
|
264
|
+
},
|
|
265
|
+
];
|
|
266
|
+
const PROFILES_BY_TYPE = new Map(exports.CLOUD_RIGHT_SIZING_PROFILES.map((profile) => {
|
|
267
|
+
return [`${profile.provider}|${profile.type.toLowerCase()}`, profile];
|
|
268
|
+
}));
|
|
269
|
+
// How a resource of this type is sized; null for a type that is not.
|
|
270
|
+
function getCloudRightSizingProfile(provider, type) {
|
|
271
|
+
return (PROFILES_BY_TYPE.get(`${(provider || "").trim().toLowerCase()}|${(type || "").trim().toLowerCase()}`) || null);
|
|
272
|
+
}
|
|
273
|
+
/*
|
|
274
|
+
* A resource's size, from what its inventory keeps: "m5.2xlarge",
|
|
275
|
+
* "Standard_D8s_v5", "n2-standard-16" (a Compute Engine machine type is
|
|
276
|
+
* kept as its URL: the last part is its name). Null when none is kept.
|
|
277
|
+
*/
|
|
278
|
+
function readCloudResourceSize(profile, properties) {
|
|
279
|
+
if (!properties ||
|
|
280
|
+
typeof properties !== "object" ||
|
|
281
|
+
Array.isArray(properties)) {
|
|
282
|
+
return null;
|
|
283
|
+
}
|
|
284
|
+
const value = properties[profile.sizeProperty];
|
|
285
|
+
if (typeof value !== "string") {
|
|
286
|
+
return null;
|
|
287
|
+
}
|
|
288
|
+
const text = value.trim();
|
|
289
|
+
const lastSlash = text.lastIndexOf("/");
|
|
290
|
+
const name = (lastSlash >= 0 ? text.slice(lastSlash + 1) : text).trim();
|
|
291
|
+
return name.length > 0 && name.length <= 100 ? name : null;
|
|
292
|
+
}
|
|
293
|
+
const NOT_SIZED = {
|
|
294
|
+
isKnown: false,
|
|
295
|
+
isBurstable: false,
|
|
296
|
+
smaller: null,
|
|
297
|
+
larger: null,
|
|
298
|
+
};
|
|
299
|
+
/*
|
|
300
|
+
* AWS: "[db.|cache.]<family>.<size>". Each of these sizes is half the next
|
|
301
|
+
* in every family that has both - the 2x chain from large up, and the
|
|
302
|
+
* pairs the families that leave it keep (12xlarge and 24xlarge, 9xlarge and
|
|
303
|
+
* 18xlarge). A size outside them (3xlarge, metal) is not stepped from.
|
|
304
|
+
*/
|
|
305
|
+
const AWS_SIZE = /^((?:db|cache)\.)?([a-z][a-z0-9-]*)\.([a-z0-9-]+)$/;
|
|
306
|
+
const AWS_BURSTABLE_FAMILY = /^t\d/;
|
|
307
|
+
const AWS_HALF_OF = {
|
|
308
|
+
xlarge: "large",
|
|
309
|
+
"2xlarge": "xlarge",
|
|
310
|
+
"4xlarge": "2xlarge",
|
|
311
|
+
"8xlarge": "4xlarge",
|
|
312
|
+
"16xlarge": "8xlarge",
|
|
313
|
+
"32xlarge": "16xlarge",
|
|
314
|
+
"24xlarge": "12xlarge",
|
|
315
|
+
"48xlarge": "24xlarge",
|
|
316
|
+
"18xlarge": "9xlarge",
|
|
317
|
+
};
|
|
318
|
+
// Twice each, and a medium's large (every family with a medium has one).
|
|
319
|
+
const AWS_TWICE_OF = Object.assign(Object.assign({}, Object.fromEntries(Object.entries(AWS_HALF_OF).map(([larger, smaller]) => {
|
|
320
|
+
return [smaller, larger];
|
|
321
|
+
}))), { medium: "large" });
|
|
322
|
+
const AWS_KNOWN_SIZES = new Set([
|
|
323
|
+
"nano",
|
|
324
|
+
"micro",
|
|
325
|
+
"small",
|
|
326
|
+
"medium",
|
|
327
|
+
...Object.keys(AWS_HALF_OF),
|
|
328
|
+
...Object.values(AWS_HALF_OF),
|
|
329
|
+
"3xlarge",
|
|
330
|
+
"6xlarge",
|
|
331
|
+
"10xlarge",
|
|
332
|
+
"56xlarge",
|
|
333
|
+
"96xlarge",
|
|
334
|
+
"112xlarge",
|
|
335
|
+
]);
|
|
336
|
+
function awsSteps(size) {
|
|
337
|
+
const match = size.toLowerCase().match(AWS_SIZE);
|
|
338
|
+
if (!match) {
|
|
339
|
+
return NOT_SIZED;
|
|
340
|
+
}
|
|
341
|
+
const prefix = match[1] || "";
|
|
342
|
+
const family = match[2] || "";
|
|
343
|
+
const step = match[3] || "";
|
|
344
|
+
if (!AWS_KNOWN_SIZES.has(step)) {
|
|
345
|
+
return NOT_SIZED;
|
|
346
|
+
}
|
|
347
|
+
if (AWS_BURSTABLE_FAMILY.test(family)) {
|
|
348
|
+
return { isKnown: true, isBurstable: true, smaller: null, larger: null };
|
|
349
|
+
}
|
|
350
|
+
const smaller = AWS_HALF_OF[step];
|
|
351
|
+
const larger = AWS_TWICE_OF[step];
|
|
352
|
+
return {
|
|
353
|
+
isKnown: true,
|
|
354
|
+
isBurstable: false,
|
|
355
|
+
smaller: smaller ? `${prefix}${family}.${smaller}` : null,
|
|
356
|
+
larger: larger ? `${prefix}${family}.${larger}` : null,
|
|
357
|
+
};
|
|
358
|
+
}
|
|
359
|
+
/*
|
|
360
|
+
* Azure: "Standard_<series><vCPUs><features>_v<version>", the vCPUs halved
|
|
361
|
+
* or doubled within their chain: D, E, F, L and the confidential DC and EC
|
|
362
|
+
* series, from the generations whose number is the vCPU count (D and E from
|
|
363
|
+
* v3, F and L from v2). Constrained sizes (E16-4s_v5) and other series are
|
|
364
|
+
* not stepped from; B-series is burstable.
|
|
365
|
+
*/
|
|
366
|
+
const AZURE_VM_SIZE = /^standard_([a-z]+)(\d+)([a-z]*)_v(\d+)$/i;
|
|
367
|
+
const AZURE_BURSTABLE_SIZE = /^standard_b\d/i;
|
|
368
|
+
const AZURE_VM_HALF_OF = {
|
|
369
|
+
4: 2,
|
|
370
|
+
8: 4,
|
|
371
|
+
16: 8,
|
|
372
|
+
32: 16,
|
|
373
|
+
64: 32,
|
|
374
|
+
96: 48,
|
|
375
|
+
};
|
|
376
|
+
const AZURE_VM_TWICE_OF = {
|
|
377
|
+
2: 4,
|
|
378
|
+
4: 8,
|
|
379
|
+
8: 16,
|
|
380
|
+
16: 32,
|
|
381
|
+
32: 64,
|
|
382
|
+
48: 96,
|
|
383
|
+
};
|
|
384
|
+
const AZURE_VM_SERIES_FROM_VERSION = {
|
|
385
|
+
d: 3,
|
|
386
|
+
e: 3,
|
|
387
|
+
dc: 3,
|
|
388
|
+
ec: 5,
|
|
389
|
+
f: 2,
|
|
390
|
+
l: 2,
|
|
391
|
+
};
|
|
392
|
+
function azureVmSteps(size) {
|
|
393
|
+
if (AZURE_BURSTABLE_SIZE.test(size)) {
|
|
394
|
+
return { isKnown: true, isBurstable: true, smaller: null, larger: null };
|
|
395
|
+
}
|
|
396
|
+
const match = size.match(AZURE_VM_SIZE);
|
|
397
|
+
if (!match) {
|
|
398
|
+
return NOT_SIZED;
|
|
399
|
+
}
|
|
400
|
+
const series = match[1] || "";
|
|
401
|
+
const vcpus = Number(match[2]);
|
|
402
|
+
const features = match[3] || "";
|
|
403
|
+
const version = Number(match[4]);
|
|
404
|
+
const fromVersion = AZURE_VM_SERIES_FROM_VERSION[series.toLowerCase()];
|
|
405
|
+
if (fromVersion === undefined || version < fromVersion) {
|
|
406
|
+
return NOT_SIZED;
|
|
407
|
+
}
|
|
408
|
+
const smaller = AZURE_VM_HALF_OF[vcpus];
|
|
409
|
+
const larger = AZURE_VM_TWICE_OF[vcpus];
|
|
410
|
+
if (smaller === undefined && larger === undefined) {
|
|
411
|
+
return NOT_SIZED;
|
|
412
|
+
}
|
|
413
|
+
const name = (count) => {
|
|
414
|
+
return `Standard_${series}${count}${features}_v${version}`;
|
|
415
|
+
};
|
|
416
|
+
return {
|
|
417
|
+
isKnown: true,
|
|
418
|
+
isBurstable: false,
|
|
419
|
+
smaller: smaller !== undefined ? name(smaller) : null,
|
|
420
|
+
larger: larger !== undefined ? name(larger) : null,
|
|
421
|
+
};
|
|
422
|
+
}
|
|
423
|
+
/*
|
|
424
|
+
* An App Service plan's SKU: each tier's sizes double from one to the next
|
|
425
|
+
* (S1, S2, S3; P0v3 to P3v3; P1mv3 to P5mv3). Free, Shared, Elastic and
|
|
426
|
+
* consumption plans are not stepped from.
|
|
427
|
+
*/
|
|
428
|
+
const APP_SERVICE_PLAN_TIERS = [
|
|
429
|
+
["B1", "B2", "B3"],
|
|
430
|
+
["S1", "S2", "S3"],
|
|
431
|
+
["P1v2", "P2v2", "P3v2"],
|
|
432
|
+
["P0v3", "P1v3", "P2v3", "P3v3"],
|
|
433
|
+
["P1mv3", "P2mv3", "P3mv3", "P4mv3", "P5mv3"],
|
|
434
|
+
["I1v2", "I2v2", "I3v2"],
|
|
435
|
+
];
|
|
436
|
+
function appServicePlanSteps(size) {
|
|
437
|
+
const wanted = size.trim().toLowerCase();
|
|
438
|
+
for (const tier of APP_SERVICE_PLAN_TIERS) {
|
|
439
|
+
const index = tier.findIndex((sku) => {
|
|
440
|
+
return sku.toLowerCase() === wanted;
|
|
441
|
+
});
|
|
442
|
+
if (index >= 0) {
|
|
443
|
+
return {
|
|
444
|
+
isKnown: true,
|
|
445
|
+
isBurstable: false,
|
|
446
|
+
smaller: index > 0 ? tier[index - 1] : null,
|
|
447
|
+
larger: index < tier.length - 1 ? tier[index + 1] : null,
|
|
448
|
+
};
|
|
449
|
+
}
|
|
450
|
+
}
|
|
451
|
+
return NOT_SIZED;
|
|
452
|
+
}
|
|
453
|
+
/*
|
|
454
|
+
* Compute Engine: "<family>-<standard|highmem|highcpu>-<vCPUs>", the vCPUs
|
|
455
|
+
* halved or doubled within what the family offers, and custom machine types
|
|
456
|
+
* ("<family>-custom-<vCPUs>-<MB>") halved or doubled whole. Shared-core
|
|
457
|
+
* types (e2-micro, f1-micro, g1-small) are burstable.
|
|
458
|
+
*/
|
|
459
|
+
const GCP_PREDEFINED_TYPE = /^([a-z][a-z0-9]*)-(standard|highmem|highcpu)-(\d+)$/;
|
|
460
|
+
const GCP_CUSTOM_TYPE = /^([a-z][a-z0-9]*)-custom-(\d+)-(\d+)$/;
|
|
461
|
+
const GCP_SHARED_CORE_TYPES = new Set([
|
|
462
|
+
"e2-micro",
|
|
463
|
+
"e2-small",
|
|
464
|
+
"e2-medium",
|
|
465
|
+
"f1-micro",
|
|
466
|
+
"g1-small",
|
|
467
|
+
]);
|
|
468
|
+
// The vCPU counts each family offers on the 2x chain: [smallest, largest].
|
|
469
|
+
const GCP_FAMILY_VCPUS = {
|
|
470
|
+
n1: [1, 64],
|
|
471
|
+
n2: [2, 128],
|
|
472
|
+
n2d: [2, 128],
|
|
473
|
+
n4: [2, 64],
|
|
474
|
+
e2: [2, 32],
|
|
475
|
+
t2d: [1, 32],
|
|
476
|
+
c2d: [2, 32],
|
|
477
|
+
};
|
|
478
|
+
const GCP_CUSTOM_FAMILY_VCPUS = {
|
|
479
|
+
n1: [2, 64],
|
|
480
|
+
n2: [2, 80],
|
|
481
|
+
n2d: [2, 96],
|
|
482
|
+
e2: [2, 32],
|
|
483
|
+
};
|
|
484
|
+
function isPowerOfTwo(value) {
|
|
485
|
+
return Number.isInteger(value) && value > 0 && (value & (value - 1)) === 0;
|
|
486
|
+
}
|
|
487
|
+
function gcpMachineSteps(size) {
|
|
488
|
+
const name = size.trim().toLowerCase();
|
|
489
|
+
if (GCP_SHARED_CORE_TYPES.has(name)) {
|
|
490
|
+
return { isKnown: true, isBurstable: true, smaller: null, larger: null };
|
|
491
|
+
}
|
|
492
|
+
const predefined = name.match(GCP_PREDEFINED_TYPE);
|
|
493
|
+
if (predefined) {
|
|
494
|
+
const family = predefined[1] || "";
|
|
495
|
+
const kind = predefined[2] || "";
|
|
496
|
+
const vcpus = Number(predefined[3]);
|
|
497
|
+
const range = GCP_FAMILY_VCPUS[family];
|
|
498
|
+
if (!range ||
|
|
499
|
+
!isPowerOfTwo(vcpus) ||
|
|
500
|
+
vcpus < range[0] ||
|
|
501
|
+
vcpus > range[1]) {
|
|
502
|
+
return NOT_SIZED;
|
|
503
|
+
}
|
|
504
|
+
// e2's high-memory types stop at 16 vCPUs.
|
|
505
|
+
const largest = family === "e2" && kind === "highmem" ? 16 : range[1];
|
|
506
|
+
return {
|
|
507
|
+
isKnown: true,
|
|
508
|
+
isBurstable: false,
|
|
509
|
+
smaller: vcpus / 2 >= range[0] ? `${family}-${kind}-${vcpus / 2}` : null,
|
|
510
|
+
larger: vcpus * 2 <= largest ? `${family}-${kind}-${vcpus * 2}` : null,
|
|
511
|
+
};
|
|
512
|
+
}
|
|
513
|
+
const custom = name.match(GCP_CUSTOM_TYPE);
|
|
514
|
+
if (custom) {
|
|
515
|
+
const family = custom[1] || "";
|
|
516
|
+
const vcpus = Number(custom[2]);
|
|
517
|
+
const megabytes = Number(custom[3]);
|
|
518
|
+
const range = GCP_CUSTOM_FAMILY_VCPUS[family];
|
|
519
|
+
if (!range || vcpus % 2 !== 0 || megabytes % 256 !== 0) {
|
|
520
|
+
return NOT_SIZED;
|
|
521
|
+
}
|
|
522
|
+
// Half of each, still whole vCPUs in twos and memory in 256 MB steps.
|
|
523
|
+
const canHalve = vcpus / 2 >= range[0] && (vcpus / 2) % 2 === 0 && megabytes % 512 === 0;
|
|
524
|
+
return {
|
|
525
|
+
isKnown: true,
|
|
526
|
+
isBurstable: false,
|
|
527
|
+
smaller: canHalve
|
|
528
|
+
? `${family}-custom-${vcpus / 2}-${megabytes / 2}`
|
|
529
|
+
: null,
|
|
530
|
+
larger: vcpus * 2 <= range[1]
|
|
531
|
+
? `${family}-custom-${vcpus * 2}-${megabytes * 2}`
|
|
532
|
+
: null,
|
|
533
|
+
};
|
|
534
|
+
}
|
|
535
|
+
return NOT_SIZED;
|
|
536
|
+
}
|
|
537
|
+
/*
|
|
538
|
+
* Cloud SQL: "db-custom-<vCPUs>-<MB>" halved or doubled whole (one vCPU, or
|
|
539
|
+
* an even number of them), and the older "db-n1-standard-<vCPUs>" and
|
|
540
|
+
* "db-n1-highmem-<vCPUs>" on the 2x chain. Shared-core tiers (db-f1-micro,
|
|
541
|
+
* db-g1-small) are burstable.
|
|
542
|
+
*/
|
|
543
|
+
const CLOUD_SQL_CUSTOM_TIER = /^db-custom-(\d+)-(\d+)$/;
|
|
544
|
+
const CLOUD_SQL_N1_TIER = /^db-n1-(standard|highmem)-(\d+)$/;
|
|
545
|
+
const CLOUD_SQL_SHARED_TIERS = new Set([
|
|
546
|
+
"db-f1-micro",
|
|
547
|
+
"db-g1-small",
|
|
548
|
+
]);
|
|
549
|
+
const CLOUD_SQL_MAX_VCPUS = 96;
|
|
550
|
+
function isCloudSqlVcpuCount(vcpus) {
|
|
551
|
+
return vcpus === 1 || (vcpus >= 2 && vcpus % 2 === 0);
|
|
552
|
+
}
|
|
553
|
+
function cloudSqlSteps(size) {
|
|
554
|
+
const tier = size.trim().toLowerCase();
|
|
555
|
+
if (CLOUD_SQL_SHARED_TIERS.has(tier)) {
|
|
556
|
+
return { isKnown: true, isBurstable: true, smaller: null, larger: null };
|
|
557
|
+
}
|
|
558
|
+
const custom = tier.match(CLOUD_SQL_CUSTOM_TIER);
|
|
559
|
+
if (custom) {
|
|
560
|
+
const vcpus = Number(custom[1]);
|
|
561
|
+
const megabytes = Number(custom[2]);
|
|
562
|
+
if (!isCloudSqlVcpuCount(vcpus) || megabytes % 256 !== 0) {
|
|
563
|
+
return NOT_SIZED;
|
|
564
|
+
}
|
|
565
|
+
const canHalve = vcpus >= 2 && isCloudSqlVcpuCount(vcpus / 2) && megabytes % 512 === 0;
|
|
566
|
+
return {
|
|
567
|
+
isKnown: true,
|
|
568
|
+
isBurstable: false,
|
|
569
|
+
smaller: canHalve ? `db-custom-${vcpus / 2}-${megabytes / 2}` : null,
|
|
570
|
+
larger: vcpus * 2 <= CLOUD_SQL_MAX_VCPUS
|
|
571
|
+
? `db-custom-${vcpus * 2}-${megabytes * 2}`
|
|
572
|
+
: null,
|
|
573
|
+
};
|
|
574
|
+
}
|
|
575
|
+
const n1 = tier.match(CLOUD_SQL_N1_TIER);
|
|
576
|
+
if (n1) {
|
|
577
|
+
const kind = n1[1] || "";
|
|
578
|
+
const vcpus = Number(n1[2]);
|
|
579
|
+
if (!isPowerOfTwo(vcpus) || vcpus > 64) {
|
|
580
|
+
return NOT_SIZED;
|
|
581
|
+
}
|
|
582
|
+
return {
|
|
583
|
+
isKnown: true,
|
|
584
|
+
isBurstable: false,
|
|
585
|
+
smaller: vcpus >= 2 ? `db-n1-${kind}-${vcpus / 2}` : null,
|
|
586
|
+
larger: vcpus * 2 <= 64 ? `db-n1-${kind}-${vcpus * 2}` : null,
|
|
587
|
+
};
|
|
588
|
+
}
|
|
589
|
+
return NOT_SIZED;
|
|
590
|
+
}
|
|
591
|
+
// The sizes a step from this one, along its ladder.
|
|
592
|
+
function getCloudSizeSteps(ladder, size) {
|
|
593
|
+
const name = (size || "").trim();
|
|
594
|
+
if (!name) {
|
|
595
|
+
return NOT_SIZED;
|
|
596
|
+
}
|
|
597
|
+
switch (ladder) {
|
|
598
|
+
case CloudSizeLadder.Aws:
|
|
599
|
+
return awsSteps(name);
|
|
600
|
+
case CloudSizeLadder.AzureVm:
|
|
601
|
+
return azureVmSteps(name);
|
|
602
|
+
case CloudSizeLadder.AzureAppServicePlan:
|
|
603
|
+
return appServicePlanSteps(name);
|
|
604
|
+
case CloudSizeLadder.GcpMachine:
|
|
605
|
+
return gcpMachineSteps(name);
|
|
606
|
+
case CloudSizeLadder.GcpCloudSql:
|
|
607
|
+
return cloudSqlSteps(name);
|
|
608
|
+
default:
|
|
609
|
+
return NOT_SIZED;
|
|
610
|
+
}
|
|
611
|
+
}
|
|
612
|
+
/*
|
|
613
|
+
* ---------------------------------------------------------------------------
|
|
614
|
+
* The verdict
|
|
615
|
+
* ---------------------------------------------------------------------------
|
|
616
|
+
*/
|
|
617
|
+
var CloudRightSizingVerdict;
|
|
618
|
+
(function (CloudRightSizingVerdict) {
|
|
619
|
+
// A smaller size would do: money on the table.
|
|
620
|
+
CloudRightSizingVerdict["Overprovisioned"] = "overprovisioned";
|
|
621
|
+
// Its size runs out: a larger one would keep up.
|
|
622
|
+
CloudRightSizingVerdict["Underprovisioned"] = "underprovisioned";
|
|
623
|
+
CloudRightSizingVerdict["RightSized"] = "right-sized";
|
|
624
|
+
// Too few readings yet to say.
|
|
625
|
+
CloudRightSizingVerdict["NotEnoughHistory"] = "not-enough-history";
|
|
626
|
+
// Not sized here: its size is not known, burstable, or on no ladder.
|
|
627
|
+
CloudRightSizingVerdict["NotSized"] = "not-sized";
|
|
628
|
+
})(CloudRightSizingVerdict || (exports.CloudRightSizingVerdict = CloudRightSizingVerdict = {}));
|
|
629
|
+
var CloudRightSizingSkipReason;
|
|
630
|
+
(function (CloudRightSizingSkipReason) {
|
|
631
|
+
CloudRightSizingSkipReason["SizeNotKnown"] = "size-not-known";
|
|
632
|
+
CloudRightSizingSkipReason["Burstable"] = "burstable";
|
|
633
|
+
CloudRightSizingSkipReason["SizeNotOnLadder"] = "size-not-on-ladder";
|
|
634
|
+
})(CloudRightSizingSkipReason || (exports.CloudRightSizingSkipReason = CloudRightSizingSkipReason = {}));
|
|
635
|
+
function finite(value) {
|
|
636
|
+
return value === null || value === undefined || !Number.isFinite(value)
|
|
637
|
+
? null
|
|
638
|
+
: Math.max(0, value);
|
|
639
|
+
}
|
|
640
|
+
function roundMoney(amount) {
|
|
641
|
+
return Math.round(amount * 100) / 100;
|
|
642
|
+
}
|
|
643
|
+
// Whether a size this many times smaller still has room.
|
|
644
|
+
function fitsSmaller(data) {
|
|
645
|
+
if (data.cpuP95 * data.factor > exports.CLOUD_RIGHT_SIZING_CPU_TARGET_PERCENT) {
|
|
646
|
+
return false;
|
|
647
|
+
}
|
|
648
|
+
if (data.cpuMax !== null &&
|
|
649
|
+
data.cpuMax * data.factor > exports.CLOUD_RIGHT_SIZING_CPU_PEAK_PERCENT) {
|
|
650
|
+
return false;
|
|
651
|
+
}
|
|
652
|
+
if (data.memoryPeak !== null &&
|
|
653
|
+
data.memoryPeak * data.factor > exports.CLOUD_RIGHT_SIZING_MEMORY_TARGET_PERCENT) {
|
|
654
|
+
return false;
|
|
655
|
+
}
|
|
656
|
+
return true;
|
|
657
|
+
}
|
|
658
|
+
/*
|
|
659
|
+
* One resource's right-sizing, from its type, its size, OneUptime's
|
|
660
|
+
* readings of it and, when its cloud bills it by name, what it costs.
|
|
661
|
+
*/
|
|
662
|
+
function buildCloudRightSizing(data) {
|
|
663
|
+
const cpuP95 = finite(data.observation.cpuP95Percent);
|
|
664
|
+
const cpuMax = finite(data.observation.cpuMaxPercent);
|
|
665
|
+
const memoryPeak = data.profile.memory
|
|
666
|
+
? finite(data.observation.memoryPeakPercent)
|
|
667
|
+
: null;
|
|
668
|
+
const samples = Math.max(0, Math.floor(Number(data.observation.samples) || 0));
|
|
669
|
+
const observedHours = Math.max(0, Number(data.observation.observedHours) || 0);
|
|
670
|
+
const cost = data.dailyCost &&
|
|
671
|
+
Number.isFinite(data.dailyCost.amount) &&
|
|
672
|
+
data.dailyCost.amount > 0 &&
|
|
673
|
+
data.dailyCost.days > 0
|
|
674
|
+
? data.dailyCost
|
|
675
|
+
: null;
|
|
676
|
+
const monthlyCost = cost
|
|
677
|
+
? roundMoney(cost.amount * exports.CLOUD_DAYS_IN_AVERAGE_MONTH)
|
|
678
|
+
: null;
|
|
679
|
+
const result = {
|
|
680
|
+
verdict: CloudRightSizingVerdict.NotSized,
|
|
681
|
+
currentSize: data.size,
|
|
682
|
+
recommendedSize: null,
|
|
683
|
+
factor: 1,
|
|
684
|
+
cpuP95Percent: cpuP95,
|
|
685
|
+
cpuMaxPercent: cpuMax,
|
|
686
|
+
memoryPeakPercent: memoryPeak,
|
|
687
|
+
isMemoryRead: memoryPeak !== null,
|
|
688
|
+
/*
|
|
689
|
+
* Why it is sized by CPU only: its cloud reports no share of memory
|
|
690
|
+
* used, or - for a type whose cloud does - none came in.
|
|
691
|
+
*/
|
|
692
|
+
memoryNotRead: memoryPeak === null
|
|
693
|
+
? data.profile.memory
|
|
694
|
+
? exports.MEMORY_NOT_REPORTED
|
|
695
|
+
: data.profile.memoryNotRead || exports.MEMORY_REPORTED_AS_FREE
|
|
696
|
+
: undefined,
|
|
697
|
+
observedDays: Math.floor(observedHours / 24),
|
|
698
|
+
samples,
|
|
699
|
+
projectedCpuP95Percent: null,
|
|
700
|
+
projectedMemoryPeakPercent: null,
|
|
701
|
+
monthlyCost,
|
|
702
|
+
currency: cost ? cost.currency : null,
|
|
703
|
+
monthlySavings: 0,
|
|
704
|
+
monthlyIncrease: 0,
|
|
705
|
+
isSavingUpperBound: data.profile.billHoldsMoreThanSize,
|
|
706
|
+
};
|
|
707
|
+
if (!data.size) {
|
|
708
|
+
return Object.assign(Object.assign({}, result), { skipReason: CloudRightSizingSkipReason.SizeNotKnown });
|
|
709
|
+
}
|
|
710
|
+
const steps = getCloudSizeSteps(data.profile.ladder, data.size);
|
|
711
|
+
if (steps.isBurstable) {
|
|
712
|
+
return Object.assign(Object.assign({}, result), { skipReason: CloudRightSizingSkipReason.Burstable });
|
|
713
|
+
}
|
|
714
|
+
if (!steps.isKnown) {
|
|
715
|
+
return Object.assign(Object.assign({}, result), { skipReason: CloudRightSizingSkipReason.SizeNotOnLadder });
|
|
716
|
+
}
|
|
717
|
+
if (cpuP95 === null ||
|
|
718
|
+
samples < exports.CLOUD_RIGHT_SIZING_MIN_SAMPLES ||
|
|
719
|
+
observedHours < exports.CLOUD_RIGHT_SIZING_MIN_OBSERVED_HOURS) {
|
|
720
|
+
return Object.assign(Object.assign({}, result), { verdict: CloudRightSizingVerdict.NotEnoughHistory });
|
|
721
|
+
}
|
|
722
|
+
const isHot = cpuP95 >= exports.CLOUD_RIGHT_SIZING_CPU_HOT_PERCENT ||
|
|
723
|
+
(memoryPeak !== null &&
|
|
724
|
+
memoryPeak >= exports.CLOUD_RIGHT_SIZING_MEMORY_HOT_PERCENT);
|
|
725
|
+
if (isHot) {
|
|
726
|
+
return Object.assign(Object.assign({}, result), { verdict: CloudRightSizingVerdict.Underprovisioned, recommendedSize: steps.larger, factor: steps.larger ? 2 : 1, projectedCpuP95Percent: steps.larger ? cpuP95 / 2 : null, projectedMemoryPeakPercent: steps.larger && memoryPeak !== null ? memoryPeak / 2 : null, monthlyIncrease: steps.larger && monthlyCost !== null ? monthlyCost : 0 });
|
|
727
|
+
}
|
|
728
|
+
// The smallest size along the ladder that still has room, at most a quarter.
|
|
729
|
+
let recommended = null;
|
|
730
|
+
let factor = 1;
|
|
731
|
+
let current = steps;
|
|
732
|
+
for (let step = 1; step <= exports.CLOUD_RIGHT_SIZING_MAX_STEPS_DOWN; step++) {
|
|
733
|
+
if (!current.smaller ||
|
|
734
|
+
!fitsSmaller({ factor: factor * 2, cpuP95, cpuMax, memoryPeak })) {
|
|
735
|
+
break;
|
|
736
|
+
}
|
|
737
|
+
recommended = current.smaller;
|
|
738
|
+
factor = factor * 2;
|
|
739
|
+
current = getCloudSizeSteps(data.profile.ladder, current.smaller);
|
|
740
|
+
}
|
|
741
|
+
if (!recommended) {
|
|
742
|
+
/*
|
|
743
|
+
* Room to spare at half its size, but no smaller size to name: still
|
|
744
|
+
* over-provisioned, said without a change to make.
|
|
745
|
+
*/
|
|
746
|
+
if (!steps.smaller &&
|
|
747
|
+
fitsSmaller({ factor: 2, cpuP95, cpuMax, memoryPeak })) {
|
|
748
|
+
return Object.assign(Object.assign({}, result), { verdict: CloudRightSizingVerdict.Overprovisioned });
|
|
749
|
+
}
|
|
750
|
+
return Object.assign(Object.assign({}, result), { verdict: CloudRightSizingVerdict.RightSized });
|
|
751
|
+
}
|
|
752
|
+
return Object.assign(Object.assign({}, result), { verdict: CloudRightSizingVerdict.Overprovisioned, recommendedSize: recommended, factor, projectedCpuP95Percent: cpuP95 * factor, projectedMemoryPeakPercent: memoryPeak !== null ? memoryPeak * factor : null, monthlySavings: monthlyCost !== null ? roundMoney(monthlyCost * (1 - 1 / factor)) : 0 });
|
|
753
|
+
}
|
|
754
|
+
// Whether a right-sizing has a change to make.
|
|
755
|
+
function hasCloudRightSizingChange(sizing) {
|
|
756
|
+
return ((sizing.verdict === CloudRightSizingVerdict.Overprovisioned ||
|
|
757
|
+
sizing.verdict === CloudRightSizingVerdict.Underprovisioned) &&
|
|
758
|
+
Boolean(sizing.recommendedSize));
|
|
759
|
+
}
|
|
760
|
+
/*
|
|
761
|
+
* ---------------------------------------------------------------------------
|
|
762
|
+
* Reading the readings
|
|
763
|
+
* ---------------------------------------------------------------------------
|
|
764
|
+
*/
|
|
765
|
+
/*
|
|
766
|
+
* The 95th percentile of a set of readings, as ClickHouse's quantileExact
|
|
767
|
+
* reads it (the reading at or above 95% of the others): for a resource's
|
|
768
|
+
* page and the tests, which work from readings rather than a query.
|
|
769
|
+
*/
|
|
770
|
+
function getCloudReadingsP95(readings) {
|
|
771
|
+
const values = readings
|
|
772
|
+
.filter((value) => {
|
|
773
|
+
return Number.isFinite(value);
|
|
774
|
+
})
|
|
775
|
+
.sort((a, b) => {
|
|
776
|
+
return a - b;
|
|
777
|
+
});
|
|
778
|
+
if (values.length === 0) {
|
|
779
|
+
return null;
|
|
780
|
+
}
|
|
781
|
+
const index = Math.min(values.length - 1, Math.floor(0.95 * values.length));
|
|
782
|
+
return values[index];
|
|
783
|
+
}
|
|
784
|
+
function toCloudRightSizingEvidence(sizing) {
|
|
785
|
+
const round = (value) => {
|
|
786
|
+
return value === null ? null : Math.round(value * 10) / 10;
|
|
787
|
+
};
|
|
788
|
+
return {
|
|
789
|
+
cpuP95Percent: round(sizing.cpuP95Percent),
|
|
790
|
+
cpuMaxPercent: round(sizing.cpuMaxPercent),
|
|
791
|
+
memoryPeakPercent: round(sizing.memoryPeakPercent),
|
|
792
|
+
observedDays: sizing.observedDays,
|
|
793
|
+
factor: sizing.factor,
|
|
794
|
+
isSavingUpperBound: sizing.isSavingUpperBound,
|
|
795
|
+
};
|
|
796
|
+
}
|
|
797
|
+
function readPercent(value) {
|
|
798
|
+
if (value === null || value === undefined || value === "") {
|
|
799
|
+
return null;
|
|
800
|
+
}
|
|
801
|
+
const number = Number(value);
|
|
802
|
+
return Number.isFinite(number) && number >= 0 ? number : null;
|
|
803
|
+
}
|
|
804
|
+
// Stored evidence, read back: null when there is none or it is malformed.
|
|
805
|
+
function readCloudRightSizingEvidence(value) {
|
|
806
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) {
|
|
807
|
+
return null;
|
|
808
|
+
}
|
|
809
|
+
const record = value;
|
|
810
|
+
const cpuP95Percent = readPercent(record["cpuP95Percent"]);
|
|
811
|
+
const observedDays = Math.max(0, Math.floor(Number(record["observedDays"]) || 0));
|
|
812
|
+
if (cpuP95Percent === null || observedDays <= 0) {
|
|
813
|
+
return null;
|
|
814
|
+
}
|
|
815
|
+
const factor = Number(record["factor"]);
|
|
816
|
+
return {
|
|
817
|
+
cpuP95Percent,
|
|
818
|
+
cpuMaxPercent: readPercent(record["cpuMaxPercent"]),
|
|
819
|
+
memoryPeakPercent: readPercent(record["memoryPeakPercent"]),
|
|
820
|
+
observedDays,
|
|
821
|
+
factor: Number.isFinite(factor) && factor >= 1 ? factor : 1,
|
|
822
|
+
isSavingUpperBound: record["isSavingUpperBound"] === true,
|
|
823
|
+
};
|
|
824
|
+
}
|
|
825
|
+
/*
|
|
826
|
+
* ---------------------------------------------------------------------------
|
|
827
|
+
* Words
|
|
828
|
+
* ---------------------------------------------------------------------------
|
|
829
|
+
*/
|
|
830
|
+
exports.RIGHT_SIZING_TITLE = (0, Translator_1.translationKey)("Right-sizing");
|
|
831
|
+
exports.CLOUD_RIGHT_SIZING_VERDICT_LABELS = {
|
|
832
|
+
[CloudRightSizingVerdict.Overprovisioned]: (0, Translator_1.translationKey)("Over-provisioned"),
|
|
833
|
+
[CloudRightSizingVerdict.Underprovisioned]: (0, Translator_1.translationKey)("Under-provisioned"),
|
|
834
|
+
[CloudRightSizingVerdict.RightSized]: (0, Translator_1.translationKey)("Right-sized"),
|
|
835
|
+
[CloudRightSizingVerdict.NotEnoughHistory]: (0, Translator_1.translationKey)("Not enough readings yet"),
|
|
836
|
+
[CloudRightSizingVerdict.NotSized]: (0, Translator_1.translationKey)("Not sized"),
|
|
837
|
+
};
|
|
838
|
+
// What to change to, by how much smaller or larger it is.
|
|
839
|
+
exports.RIGHT_SIZING_HALF_SIZE = (0, Translator_1.translationKey)("A size half as big would do.");
|
|
840
|
+
exports.RIGHT_SIZING_QUARTER_SIZE = (0, Translator_1.translationKey)("A size a quarter as big would do.");
|
|
841
|
+
exports.RIGHT_SIZING_TWICE_SIZE = (0, Translator_1.translationKey)("A size twice as big would keep up.");
|
|
842
|
+
exports.RIGHT_SIZING_NO_SMALLER_SIZE = (0, Translator_1.translationKey)("It has room to spare, and already has the smallest size of its family.");
|
|
843
|
+
exports.RIGHT_SIZING_NO_LARGER_SIZE = (0, Translator_1.translationKey)("It runs out of room, and already has the largest size of its family that OneUptime names.");
|
|
844
|
+
exports.RIGHT_SIZING_FITS = (0, Translator_1.translationKey)("Its size fits what it uses.");
|
|
845
|
+
/*
|
|
846
|
+
* Why the change works: its readings at the new size. Its readings now are
|
|
847
|
+
* the card's figures, so they are not said again in words.
|
|
848
|
+
*/
|
|
849
|
+
exports.RIGHT_SIZING_AT_NEW_SIZE = (0, Translator_1.translationKey)("At {{size}}, 95% of the time its CPU would be at or under {{p95}}.");
|
|
850
|
+
exports.RIGHT_SIZING_AT_NEW_SIZE_WITH_MEMORY = (0, Translator_1.translationKey)("At {{size}}, 95% of the time its CPU would be at or under {{p95}}, and its memory would peak at {{memory}}.");
|
|
851
|
+
// What it would save, or cost: a month at its cost of the last 30 days.
|
|
852
|
+
exports.RIGHT_SIZING_SAVES = (0, Translator_1.translationKey)("Saves about {{amount}} a month, at its cost over the last 30 days.");
|
|
853
|
+
exports.RIGHT_SIZING_SAVES_UP_TO = (0, Translator_1.translationKey)("Saves up to {{amount}} a month, at its cost over the last 30 days: its bill also holds its storage, which stays the same.");
|
|
854
|
+
exports.RIGHT_SIZING_COSTS_MORE = (0, Translator_1.translationKey)("Costs about {{amount}} a month more, at its cost over the last 30 days.");
|
|
855
|
+
/*
|
|
856
|
+
* Its cloud bills it under its service only (AWS Cost Explorer, a Google
|
|
857
|
+
* Cloud standard export): no cost of its own to say a saving from.
|
|
858
|
+
*/
|
|
859
|
+
exports.RIGHT_SIZING_SAVING_NOT_KNOWN = (0, Translator_1.translationKey)("What it would save is not known yet: its cloud's bill does not name it.");
|
|
860
|
+
// Not enough readings: how far it has come.
|
|
861
|
+
exports.RIGHT_SIZING_LEARNING = (0, Translator_1.translationKey)("Right-sizing needs {{needed}} days of its CPU readings. It has {{read}} so far.");
|
|
862
|
+
// What the readings are, as the card's figures name them.
|
|
863
|
+
exports.RIGHT_SIZING_CPU_P95_LABEL = (0, Translator_1.translationKey)("CPU (95th percentile)");
|
|
864
|
+
exports.RIGHT_SIZING_CPU_MAX_LABEL = (0, Translator_1.translationKey)("CPU (highest)");
|
|
865
|
+
exports.RIGHT_SIZING_MEMORY_PEAK_LABEL = (0, Translator_1.translationKey)("Memory (highest)");
|
|
866
|
+
exports.RIGHT_SIZING_DAYS_READ_LABEL = (0, Translator_1.translationKey)("Days read");
|
|
867
|
+
exports.RIGHT_SIZING_NOT_READ = (0, Translator_1.translationKey)("Not read");
|