@geek-fun/serverlessinsight 0.8.7 → 0.8.8
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/.serverlessinsight/state-cdn-flow-app-cdn-flow-service.json.backup +1 -1
- package/.serverlessinsight/state-iam-test-app-iam-test-service.json.backup +2 -2
- package/.serverlessinsight/state-insight-poc-app-insight-poc-tencent.json.backup +94 -0
- package/.serverlessinsight/state-insight-poc-deploy-app-insight-poc-deploy.json.backup +36 -16
- package/.serverlessinsight/state-insight-poc-destroy-app-insight-poc-destroy.json.backup +1 -1
- package/.serverlessinsight/state-insight-volc-app-insight-volc.json.backup +35 -73
- package/.serverlessinsight/state-role-reconcile-test-app-role-reconcile-test-service.json.backup +148 -0
- package/dist/package.json +1 -1
- package/dist/src/commands/deploy.js +1 -0
- package/dist/src/commands/index.js +6 -2
- package/dist/src/commands/plan.js +1 -0
- package/dist/src/common/aliyunClient/ecsOperations.js +70 -1
- package/dist/src/common/aliyunClient/nasOperations.js +21 -0
- package/dist/src/common/aliyunClient/ramOperations.js +32 -20
- package/dist/src/common/aliyunClient/slsOperations.js +16 -3
- package/dist/src/common/concurrency.js +30 -0
- package/dist/src/common/context.js +3 -0
- package/dist/src/common/dependencyGraph/graph.js +5 -0
- package/dist/src/common/index.js +5 -0
- package/dist/src/common/planCompare.js +62 -0
- package/dist/src/common/planFormatter.js +15 -3
- package/dist/src/common/refreshCache.js +32 -0
- package/dist/src/common/refreshPlanner.js +105 -0
- package/dist/src/common/tencentClient/clsOperations.js +27 -3
- package/dist/src/common/tencentClient/tdsqlcOperations.js +22 -0
- package/dist/src/common/throttleRetry.js +56 -0
- package/dist/src/common/volcengineClient/tlsOperations.js +12 -4
- package/dist/src/lang/en.js +16 -0
- package/dist/src/lang/zh-CN.js +16 -0
- package/dist/src/stack/aliyunStack/apigwPlanner.js +75 -7
- package/dist/src/stack/aliyunStack/apigwTypes.js +67 -1
- package/dist/src/stack/aliyunStack/databasePlanner.js +26 -62
- package/dist/src/stack/aliyunStack/esServerlessTypes.js +50 -1
- package/dist/src/stack/aliyunStack/fc3Executor.js +5 -3
- package/dist/src/stack/aliyunStack/fc3Planner.js +299 -12
- package/dist/src/stack/aliyunStack/fc3Resource.js +200 -30
- package/dist/src/stack/aliyunStack/fc3Types.js +61 -1
- package/dist/src/stack/aliyunStack/ossPlanner.js +21 -63
- package/dist/src/stack/aliyunStack/ossTypes.js +25 -1
- package/dist/src/stack/aliyunStack/rdsTypes.js +38 -1
- package/dist/src/stack/aliyunStack/tablestorePlanner.js +20 -74
- package/dist/src/stack/aliyunStack/tablestoreTypes.js +33 -1
- package/dist/src/stack/scfStack/cosPlanner.js +30 -50
- package/dist/src/stack/scfStack/cosTypes.js +29 -1
- package/dist/src/stack/scfStack/esServerlessPlanner.js +21 -54
- package/dist/src/stack/scfStack/esServerlessTypes.js +13 -1
- package/dist/src/stack/scfStack/scfExecutor.js +5 -3
- package/dist/src/stack/scfStack/scfPlanner.js +71 -50
- package/dist/src/stack/scfStack/scfResource.js +37 -2
- package/dist/src/stack/scfStack/scfTypes.js +35 -1
- package/dist/src/stack/scfStack/sharedLogset.js +3 -2
- package/dist/src/stack/scfStack/tdsqlcPlanner.js +37 -55
- package/dist/src/stack/scfStack/tdsqlcTypes.js +21 -1
- package/dist/src/stack/volcengineStack/apigwPlanner.js +54 -7
- package/dist/src/stack/volcengineStack/apigwTypes.js +26 -1
- package/dist/src/stack/volcengineStack/tosPlanner.js +28 -55
- package/dist/src/stack/volcengineStack/tosTypes.js +18 -1
- package/dist/src/stack/volcengineStack/vefaasExecutor.js +5 -3
- package/dist/src/stack/volcengineStack/vefaasPlanner.js +114 -6
- package/dist/src/stack/volcengineStack/vefaasResource.js +40 -5
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
|
@@ -33,7 +33,7 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
33
33
|
};
|
|
34
34
|
})();
|
|
35
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
-
exports.createEcsOperations = exports.parseSecurityGroupRule = exports.securityGroupRangeMap = void 0;
|
|
36
|
+
exports.createEcsOperations = exports.parseSecurityGroupRule = exports.canonicalSecurityGroupRule = exports.securityGroupRangeMap = void 0;
|
|
37
37
|
const ecs = __importStar(require("@alicloud/ecs20140526"));
|
|
38
38
|
const logger_1 = require("../logger");
|
|
39
39
|
exports.securityGroupRangeMap = {
|
|
@@ -50,6 +50,14 @@ const transformPortRange = (protocol, portRange) => {
|
|
|
50
50
|
return portRange.includes('/') ? portRange : `${portRange}/${portRange}`;
|
|
51
51
|
};
|
|
52
52
|
const normalizeProtocol = (protocol) => protocol.trim().toUpperCase();
|
|
53
|
+
/**
|
|
54
|
+
* Canonical rule key for config-vs-live comparison (issue #234 M2): protocol
|
|
55
|
+
* normalized, ports in Aliyun wire format, CIDR verbatim — the exact tuple an
|
|
56
|
+
* AuthorizeSecurityGroup call writes and DescribeSecurityGroupAttribute
|
|
57
|
+
* returns.
|
|
58
|
+
*/
|
|
59
|
+
/* istanbul ignore next */ const canonicalSecurityGroupRule = (protocol, portRange, cidr) => `${protocol.toUpperCase()}|${transformPortRange(protocol, portRange)}|${cidr}`;
|
|
60
|
+
exports.canonicalSecurityGroupRule = canonicalSecurityGroupRule;
|
|
53
61
|
/* istanbul ignore next */ const parseSecurityGroupRule = (rule) => {
|
|
54
62
|
const [rawProtocol, second, third, ...rest] = rule.split(':');
|
|
55
63
|
if (rest.length > 0 || !rawProtocol || !second || !third) {
|
|
@@ -159,6 +167,67 @@ const isDuplicateSecurityGroupRuleError = (error) => {
|
|
|
159
167
|
}
|
|
160
168
|
return sg;
|
|
161
169
|
},
|
|
170
|
+
authorizeSecurityGroupRules: async (securityGroupId, direction, rules) => {
|
|
171
|
+
for (const parsed of rules) {
|
|
172
|
+
try {
|
|
173
|
+
if (direction === 'ingress') {
|
|
174
|
+
const request = new ecs.AuthorizeSecurityGroupRequest({
|
|
175
|
+
regionId: context.region,
|
|
176
|
+
securityGroupId,
|
|
177
|
+
ipProtocol: parsed.protocol.toLowerCase(),
|
|
178
|
+
sourceCidrIp: parsed.cidr,
|
|
179
|
+
portRange: transformPortRange(parsed.protocol, parsed.portRange),
|
|
180
|
+
});
|
|
181
|
+
await ecsClient.authorizeSecurityGroup(request);
|
|
182
|
+
}
|
|
183
|
+
else {
|
|
184
|
+
const request = new ecs.AuthorizeSecurityGroupEgressRequest({
|
|
185
|
+
regionId: context.region,
|
|
186
|
+
securityGroupId,
|
|
187
|
+
ipProtocol: parsed.protocol.toLowerCase(),
|
|
188
|
+
destCidrIp: parsed.cidr,
|
|
189
|
+
portRange: transformPortRange(parsed.protocol, parsed.portRange),
|
|
190
|
+
});
|
|
191
|
+
await ecsClient.authorizeSecurityGroupEgress(request);
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
catch (error) {
|
|
195
|
+
if (isDuplicateSecurityGroupRuleError(error)) {
|
|
196
|
+
continue;
|
|
197
|
+
}
|
|
198
|
+
logger_1.logger.warn(`Failed to authorize ${direction} rule for ${securityGroupId}: ${String(error)}`);
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
},
|
|
202
|
+
revokeSecurityGroupRules: async (securityGroupId, direction, rules) => {
|
|
203
|
+
for (const parsed of rules) {
|
|
204
|
+
try {
|
|
205
|
+
if (direction === 'ingress') {
|
|
206
|
+
const request = new ecs.RevokeSecurityGroupRequest({
|
|
207
|
+
regionId: context.region,
|
|
208
|
+
securityGroupId,
|
|
209
|
+
ipProtocol: parsed.protocol.toLowerCase(),
|
|
210
|
+
sourceCidrIp: parsed.cidr,
|
|
211
|
+
portRange: transformPortRange(parsed.protocol, parsed.portRange),
|
|
212
|
+
});
|
|
213
|
+
await ecsClient.revokeSecurityGroup(request);
|
|
214
|
+
}
|
|
215
|
+
else {
|
|
216
|
+
const request = new ecs.RevokeSecurityGroupEgressRequest({
|
|
217
|
+
regionId: context.region,
|
|
218
|
+
securityGroupId,
|
|
219
|
+
ipProtocol: parsed.protocol.toLowerCase(),
|
|
220
|
+
destCidrIp: parsed.cidr,
|
|
221
|
+
portRange: transformPortRange(parsed.protocol, parsed.portRange),
|
|
222
|
+
});
|
|
223
|
+
await ecsClient.revokeSecurityGroupEgress(request);
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
catch (error) {
|
|
227
|
+
logger_1.logger.warn(`Failed to revoke ${direction} rule for ${securityGroupId}: ${String(error)}`);
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
},
|
|
162
231
|
getSecurityGroupRules: async (securityGroupId) => {
|
|
163
232
|
const ingressRules = [];
|
|
164
233
|
const egressRules = [];
|
|
@@ -34,6 +34,7 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
34
34
|
})();
|
|
35
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
36
|
exports.createNasOperations = void 0;
|
|
37
|
+
const logger_1 = require("../logger");
|
|
37
38
|
const nas = __importStar(require("@alicloud/nas20170626"));
|
|
38
39
|
const types_1 = require("../../types");
|
|
39
40
|
const storageClassMap = {
|
|
@@ -204,6 +205,26 @@ const createNasOperations = (nasClient) => {
|
|
|
204
205
|
accessGroupName,
|
|
205
206
|
};
|
|
206
207
|
},
|
|
208
|
+
listMountTargets: async (fileSystemId) => {
|
|
209
|
+
try {
|
|
210
|
+
const request = new nas.DescribeMountTargetsRequest({
|
|
211
|
+
fileSystemId,
|
|
212
|
+
});
|
|
213
|
+
const response = await nasClient.describeMountTargets(request);
|
|
214
|
+
const raw = response?.body?.mountTargets?.mountTarget ?? [];
|
|
215
|
+
return raw
|
|
216
|
+
.filter((mt) => mt.mountTargetDomain)
|
|
217
|
+
.map((mt) => ({
|
|
218
|
+
fileSystemId,
|
|
219
|
+
mountTargetDomain: mt.mountTargetDomain,
|
|
220
|
+
status: mt.status,
|
|
221
|
+
}));
|
|
222
|
+
}
|
|
223
|
+
catch (error) {
|
|
224
|
+
logger_1.logger.debug(`Failed to list mount targets: ${String(error)}`);
|
|
225
|
+
return [];
|
|
226
|
+
}
|
|
227
|
+
},
|
|
207
228
|
getMountTarget: async (fileSystemId, mountTargetDomain) => {
|
|
208
229
|
try {
|
|
209
230
|
const request = new nas.DescribeMountTargetsRequest({
|
|
@@ -222,6 +222,30 @@ const buildExecutionPolicy = (executionStatements, customStatements) => (0, expo
|
|
|
222
222
|
return [];
|
|
223
223
|
}
|
|
224
224
|
};
|
|
225
|
+
const readExecutionPolicyDocument = async (policyName) => {
|
|
226
|
+
try {
|
|
227
|
+
const getPolicyResponse = await ramClient.getPolicy(new ram.GetPolicyRequest({ policyName, policyType: 'Custom' }));
|
|
228
|
+
const defaultVersionId = getPolicyResponse.body?.policy?.defaultVersion;
|
|
229
|
+
if (!defaultVersionId) {
|
|
230
|
+
return { found: true };
|
|
231
|
+
}
|
|
232
|
+
const versionResponse = await ramClient.getPolicyVersion(new ram.GetPolicyVersionRequest({
|
|
233
|
+
policyName,
|
|
234
|
+
policyType: 'Custom',
|
|
235
|
+
versionId: defaultVersionId,
|
|
236
|
+
}));
|
|
237
|
+
return { found: true, document: versionResponse.body?.policyVersion?.policyDocument };
|
|
238
|
+
}
|
|
239
|
+
catch (error) {
|
|
240
|
+
if (error &&
|
|
241
|
+
typeof error === 'object' &&
|
|
242
|
+
'code' in error &&
|
|
243
|
+
error.code === 'EntityNotExist.Policy') {
|
|
244
|
+
return { found: false };
|
|
245
|
+
}
|
|
246
|
+
throw error;
|
|
247
|
+
}
|
|
248
|
+
};
|
|
225
249
|
const updateExecutionPolicyDocumentFn = async (roleName, policyDocument) => {
|
|
226
250
|
const policyName = (0, nameBuilder_1.buildRolePolicyName)(roleName);
|
|
227
251
|
const ensureAttached = async () => {
|
|
@@ -237,26 +261,8 @@ const buildExecutionPolicy = (executionStatements, customStatements) => (0, expo
|
|
|
237
261
|
}
|
|
238
262
|
}
|
|
239
263
|
};
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
const getPolicyResponse = await ramClient.getPolicy(new ram.GetPolicyRequest({ policyName, policyType: 'Custom' }));
|
|
243
|
-
const defaultVersionId = getPolicyResponse.body?.policy?.defaultVersion;
|
|
244
|
-
if (defaultVersionId) {
|
|
245
|
-
const versionResponse = await ramClient.getPolicyVersion(new ram.GetPolicyVersionRequest({
|
|
246
|
-
policyName,
|
|
247
|
-
policyType: 'Custom',
|
|
248
|
-
versionId: defaultVersionId,
|
|
249
|
-
}));
|
|
250
|
-
currentDocument = versionResponse.body?.policyVersion?.policyDocument;
|
|
251
|
-
}
|
|
252
|
-
}
|
|
253
|
-
catch (error) {
|
|
254
|
-
if (!(error &&
|
|
255
|
-
typeof error === 'object' &&
|
|
256
|
-
'code' in error &&
|
|
257
|
-
error.code === 'EntityNotExist.Policy')) {
|
|
258
|
-
throw error;
|
|
259
|
-
}
|
|
264
|
+
const readResult = await readExecutionPolicyDocument(policyName);
|
|
265
|
+
if (!readResult.found) {
|
|
260
266
|
try {
|
|
261
267
|
await ramClient.createPolicy(new ram.CreatePolicyRequest({
|
|
262
268
|
policyName,
|
|
@@ -275,6 +281,7 @@ const buildExecutionPolicy = (executionStatements, customStatements) => (0, expo
|
|
|
275
281
|
await ensureAttached();
|
|
276
282
|
return;
|
|
277
283
|
}
|
|
284
|
+
const currentDocument = readResult.document;
|
|
278
285
|
if (currentDocument === policyDocument) {
|
|
279
286
|
return;
|
|
280
287
|
}
|
|
@@ -451,6 +458,11 @@ const buildExecutionPolicy = (executionStatements, customStatements) => (0, expo
|
|
|
451
458
|
}
|
|
452
459
|
},
|
|
453
460
|
updateExecutionPolicyDocument: updateExecutionPolicyDocumentFn,
|
|
461
|
+
getExecutionPolicyDocument: async (roleName) => {
|
|
462
|
+
const policyName = (0, nameBuilder_1.buildRolePolicyName)(roleName);
|
|
463
|
+
const readResult = await readExecutionPolicyDocument(policyName);
|
|
464
|
+
return readResult.found ? readResult.document : undefined;
|
|
465
|
+
},
|
|
454
466
|
getRole: async (roleName) => {
|
|
455
467
|
try {
|
|
456
468
|
const request = new ram.GetRoleRequest({
|
|
@@ -33,10 +33,15 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
33
33
|
};
|
|
34
34
|
})();
|
|
35
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
-
exports.createSlsOperations = void 0;
|
|
36
|
+
exports.createSlsOperations = exports.SLS_LOGSTORE_SHARDS = exports.SLS_LOGSTORE_TTL = void 0;
|
|
37
37
|
const sls = __importStar(require("@alicloud/sls20201230"));
|
|
38
38
|
const logger_1 = require("../logger");
|
|
39
39
|
const polling_1 = require("../polling");
|
|
40
|
+
// The logstore attributes si creates with (issue #234 M1): `fn.log` is a
|
|
41
|
+
// boolean — these are stack constants, so live values differing from them are
|
|
42
|
+
// out-of-band drift.
|
|
43
|
+
exports.SLS_LOGSTORE_TTL = 30;
|
|
44
|
+
exports.SLS_LOGSTORE_SHARDS = 2;
|
|
40
45
|
const waitForSlsProject = async (getProject, projectName) => {
|
|
41
46
|
try {
|
|
42
47
|
const project = await (0, polling_1.pollUntil)({
|
|
@@ -149,11 +154,11 @@ const createSlsOperations = (slsClient) => {
|
|
|
149
154
|
value: tagResource.tagValue ?? '',
|
|
150
155
|
}));
|
|
151
156
|
},
|
|
152
|
-
createLogstore: async (projectName, logstoreName, ttl =
|
|
157
|
+
createLogstore: async (projectName, logstoreName, ttl = exports.SLS_LOGSTORE_TTL) => {
|
|
153
158
|
const request = new sls.CreateLogStoreRequest({
|
|
154
159
|
logstoreName,
|
|
155
160
|
ttl,
|
|
156
|
-
shardCount:
|
|
161
|
+
shardCount: exports.SLS_LOGSTORE_SHARDS,
|
|
157
162
|
});
|
|
158
163
|
await slsClient.createLogStore(projectName, request);
|
|
159
164
|
// Wait for logstore to be ready
|
|
@@ -184,6 +189,14 @@ const createSlsOperations = (slsClient) => {
|
|
|
184
189
|
throw error;
|
|
185
190
|
}
|
|
186
191
|
},
|
|
192
|
+
updateLogstore: async (projectName, logstoreName, ttl, shardCount) => {
|
|
193
|
+
const request = new sls.UpdateLogStoreRequest({
|
|
194
|
+
logstoreName,
|
|
195
|
+
ttl,
|
|
196
|
+
shardCount,
|
|
197
|
+
});
|
|
198
|
+
await slsClient.updateLogStore(projectName, logstoreName, request);
|
|
199
|
+
},
|
|
187
200
|
deleteLogstore: async (projectName, logstoreName) => {
|
|
188
201
|
await slsClient.deleteLogStore(projectName, logstoreName);
|
|
189
202
|
},
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.mapWithConcurrency = exports.PLAN_READ_CONCURRENCY = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Bounded-concurrency map for planner read fan-outs (issue #234 rate-limit
|
|
6
|
+
* mitigation): each planner probes resources concurrently, and a naive
|
|
7
|
+
* Promise.all burst can exceed provider management-API QPS (e.g. Tencent CAM
|
|
8
|
+
* GetRole at 20/s). The limit is deliberately provider-neutral and coarse —
|
|
9
|
+
* ~10 in-flight reads per planner group — since provider quota tables are
|
|
10
|
+
* partially unpublished (Volcengine, Aliyun OSS management plane).
|
|
11
|
+
*/
|
|
12
|
+
exports.PLAN_READ_CONCURRENCY = 10;
|
|
13
|
+
const mapWithConcurrency = async (items, limit, fn) => {
|
|
14
|
+
const results = new Array(items.length);
|
|
15
|
+
let nextIndex = 0;
|
|
16
|
+
const workerCount = Math.min(limit, items.length);
|
|
17
|
+
const workers = Array.from({ length: workerCount }, async () => {
|
|
18
|
+
while (true) {
|
|
19
|
+
const index = nextIndex;
|
|
20
|
+
nextIndex += 1;
|
|
21
|
+
if (index >= items.length) {
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
results[index] = await fn(items[index], index);
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
await Promise.all(workers);
|
|
28
|
+
return results;
|
|
29
|
+
};
|
|
30
|
+
exports.mapWithConcurrency = mapWithConcurrency;
|
|
@@ -9,6 +9,7 @@ const node_path_1 = __importDefault(require("node:path"));
|
|
|
9
9
|
const credentials_1 = require("./credentials");
|
|
10
10
|
const imsClient_1 = require("./imsClient");
|
|
11
11
|
const providerEnum_1 = require("./providerEnum");
|
|
12
|
+
const refreshCache_1 = require("./refreshCache");
|
|
12
13
|
let context;
|
|
13
14
|
const DEFAULT_IAC_FILES = [
|
|
14
15
|
'serverlessinsight.yml',
|
|
@@ -84,6 +85,8 @@ const setContext = async (config, reaValToken = false) => {
|
|
|
84
85
|
...acc,
|
|
85
86
|
[stage]: Object.entries(parameters).map(([key, value]) => ({ key, value })),
|
|
86
87
|
}), {}),
|
|
88
|
+
refreshCache: (0, refreshCache_1.createRefreshCache)(),
|
|
89
|
+
refresh: config.refresh ?? true,
|
|
87
90
|
};
|
|
88
91
|
if (reaValToken) {
|
|
89
92
|
const iamInfo = await (0, imsClient_1.getIamInfo)(newContext);
|
|
@@ -16,6 +16,11 @@ const RESOURCE_TYPE_PREFIX_MAP = {
|
|
|
16
16
|
SCF: 'functions',
|
|
17
17
|
COS_BUCKET: 'buckets',
|
|
18
18
|
TDSQL_C_SERVERLESS: 'databases',
|
|
19
|
+
TENCENT_ES_SERVERLESS: 'databases',
|
|
20
|
+
// Volcengine resource types (as emitted by planners)
|
|
21
|
+
VOLCENGINE_VEFAAS: 'functions',
|
|
22
|
+
VOLCENGINE_TOS_BUCKET: 'buckets',
|
|
23
|
+
VOLCENGINE_APIGW: 'events',
|
|
19
24
|
};
|
|
20
25
|
const RESOURCE_DEPENDENCY_ORDER = {
|
|
21
26
|
databases: 0,
|
package/dist/src/common/index.js
CHANGED
|
@@ -38,3 +38,8 @@ __exportStar(require("./apiClient"), exports);
|
|
|
38
38
|
__exportStar(require("./triggerMapper"), exports);
|
|
39
39
|
__exportStar(require("./nameBuilder"), exports);
|
|
40
40
|
__exportStar(require("./providerNames"), exports);
|
|
41
|
+
__exportStar(require("./refreshCache"), exports);
|
|
42
|
+
__exportStar(require("./concurrency"), exports);
|
|
43
|
+
__exportStar(require("./throttleRetry"), exports);
|
|
44
|
+
__exportStar(require("./planCompare"), exports);
|
|
45
|
+
__exportStar(require("./refreshPlanner"), exports);
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.jsonDocumentDiffers = exports.remoteDiffersFromDesired = void 0;
|
|
4
|
+
const hashUtils_1 = require("./hashUtils");
|
|
5
|
+
/**
|
|
6
|
+
* A desired value "declares" a dimension only when the executor would write it:
|
|
7
|
+
* `undefined`/`null` mean unset, and an empty plain object means the executor
|
|
8
|
+
* omits the field entirely (e.g. fc3 `environment: {}`, oss
|
|
9
|
+
* `websiteConfiguration: {}`) — so cloud-side values in that dimension can
|
|
10
|
+
* never be cleared and are not drift. Arrays and empty strings stay declared:
|
|
11
|
+
* the executor writes them explicitly.
|
|
12
|
+
*/
|
|
13
|
+
const isDeclared = (value) => {
|
|
14
|
+
if (value === undefined || value === null) {
|
|
15
|
+
return false;
|
|
16
|
+
}
|
|
17
|
+
if (typeof value === 'object' &&
|
|
18
|
+
!Array.isArray(value) &&
|
|
19
|
+
Object.keys(value).length === 0) {
|
|
20
|
+
return false;
|
|
21
|
+
}
|
|
22
|
+
return true;
|
|
23
|
+
};
|
|
24
|
+
/**
|
|
25
|
+
* One-directional live-drift check (issue #234 Phase 1 contract):
|
|
26
|
+
* compares only the attributes a cloud->definition mapper emits (remote) that
|
|
27
|
+
* the desired definition actually declares. A desired value with no matching
|
|
28
|
+
* cloud value IS drift (the executor sets it on update); a cloud-only extra
|
|
29
|
+
* the config never asked for is ignored (the executor may not clear it).
|
|
30
|
+
* Unreadable/config-only keys never appear in `remote` — so matching reality
|
|
31
|
+
* stays `noop` instead of phantom-drifting every plan.
|
|
32
|
+
*/
|
|
33
|
+
const remoteDiffersFromDesired = (remote, desired) => Object.entries(remote).some(([key]) => {
|
|
34
|
+
const desiredValue = desired[key];
|
|
35
|
+
if (!isDeclared(desiredValue)) {
|
|
36
|
+
return false;
|
|
37
|
+
}
|
|
38
|
+
return !(0, hashUtils_1.attributesEqual)({ [key]: remote[key] }, { [key]: desiredValue });
|
|
39
|
+
});
|
|
40
|
+
exports.remoteDiffersFromDesired = remoteDiffersFromDesired;
|
|
41
|
+
/**
|
|
42
|
+
* Canonical JSON document compare (issue #234 phase 3): providers return
|
|
43
|
+
* policy documents as parsed objects (or re-serialized strings) whose key
|
|
44
|
+
* order and formatting differ from what the config serialized, so byte-level
|
|
45
|
+
* string comparison false-drifts. Parses both sides and compares
|
|
46
|
+
* key-order-insensitively. Undeclared (null) desired or unreadable cloud
|
|
47
|
+
* values are not drift — only a parseable pair with different content is.
|
|
48
|
+
*/
|
|
49
|
+
const jsonDocumentDiffers = (desired, cloud) => {
|
|
50
|
+
if (desired === null || cloud === undefined || cloud === null) {
|
|
51
|
+
return false;
|
|
52
|
+
}
|
|
53
|
+
try {
|
|
54
|
+
const desiredObj = JSON.parse(desired);
|
|
55
|
+
const cloudObj = typeof cloud === 'string' ? JSON.parse(cloud) : cloud;
|
|
56
|
+
return !(0, hashUtils_1.attributesEqual)({ doc: cloudObj }, { doc: desiredObj });
|
|
57
|
+
}
|
|
58
|
+
catch {
|
|
59
|
+
return false;
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
exports.jsonDocumentDiffers = jsonDocumentDiffers;
|
|
@@ -216,8 +216,13 @@ const formatPlanItem = (item, config = DEFAULT_CONFIG) => {
|
|
|
216
216
|
const symbol = ACTION_SYMBOL[item.action] ?? ' ';
|
|
217
217
|
const symbolColor = ACTION_COLOR[item.action] ?? 'RESET';
|
|
218
218
|
const resourceLine = colorize(` ${symbol} ${item.logicalId}:`, symbolColor, config.colorize);
|
|
219
|
+
// A drifted update is caused by an out-of-config cloud edit — surface that
|
|
220
|
+
// so it doesn't read like an ordinary config change.
|
|
221
|
+
const driftedLine = item.drifted && item.action !== 'delete'
|
|
222
|
+
? [colorize(` # ${lang_1.lang.__('PLAN_DRIFTED_MARKER')}`, 'CYAN', config.colorize)]
|
|
223
|
+
: [];
|
|
219
224
|
if (!item.changes) {
|
|
220
|
-
return [headerLine, resourceLine].join('\n');
|
|
225
|
+
return [headerLine, resourceLine, ...driftedLine].join('\n');
|
|
221
226
|
}
|
|
222
227
|
const { diffs, unchangedCount } = (0, exports.computeAttributeDiffs)(item.changes.before, item.changes.after);
|
|
223
228
|
const keyWidth = Math.max(config.keyAlignWidth, computeMaxKeyWidth(diffs, config.indentSize));
|
|
@@ -229,7 +234,7 @@ const formatPlanItem = (item, config = DEFAULT_CONFIG) => {
|
|
|
229
234
|
colorize(` # ${lang_1.lang.__('PLAN_UNCHANGED_ATTRS', { count: String(unchangedCount) })}`, 'DIM', config.colorize),
|
|
230
235
|
]
|
|
231
236
|
: [];
|
|
232
|
-
return [headerLine, resourceLine, ...attrLines, ...hiddenLine].join('\n');
|
|
237
|
+
return [headerLine, resourceLine, ...driftedLine, ...attrLines, ...hiddenLine].join('\n');
|
|
233
238
|
};
|
|
234
239
|
exports.formatPlanItem = formatPlanItem;
|
|
235
240
|
/* istanbul ignore next */
|
|
@@ -257,12 +262,19 @@ const formatPlan = (items, config = DEFAULT_CONFIG) => {
|
|
|
257
262
|
'',
|
|
258
263
|
];
|
|
259
264
|
const itemLines = actionItems.flatMap((item) => [(0, exports.formatPlanItem)(item, config), '']);
|
|
265
|
+
const driftedCount = items.filter((i) => i.drifted && i.action !== 'delete').length;
|
|
266
|
+
const driftedSummary = driftedCount > 0
|
|
267
|
+
? [
|
|
268
|
+
colorize(lang_1.lang.__('PLAN_DRIFTED_SUMMARY', { driftedCount: String(driftedCount) }), 'CYAN', config.colorize),
|
|
269
|
+
'',
|
|
270
|
+
]
|
|
271
|
+
: [];
|
|
260
272
|
const summary = lang_1.lang.__('PLAN_SUMMARY', {
|
|
261
273
|
createCount: String(createItems.length),
|
|
262
274
|
updateCount: String(updateItems.length),
|
|
263
275
|
deleteCount: String(deleteItems.length),
|
|
264
276
|
});
|
|
265
|
-
return [...header, ...itemLines, summary].join('\n');
|
|
277
|
+
return [...header, ...itemLines, ...driftedSummary, summary].join('\n');
|
|
266
278
|
};
|
|
267
279
|
exports.formatPlan = formatPlan;
|
|
268
280
|
/* istanbul ignore next */
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.cachedRefreshRead = exports.createRefreshCache = void 0;
|
|
4
|
+
const logger_1 = require("./logger");
|
|
5
|
+
const lang_1 = require("../lang");
|
|
6
|
+
const throttleRetry_1 = require("./throttleRetry");
|
|
7
|
+
const createRefreshCache = () => {
|
|
8
|
+
const inflight = new Map();
|
|
9
|
+
return {
|
|
10
|
+
read: (key, load) => {
|
|
11
|
+
const existing = inflight.get(key);
|
|
12
|
+
if (existing) {
|
|
13
|
+
logger_1.logger.debug(lang_1.lang.__('REFRESH_CACHE_HIT', { key }));
|
|
14
|
+
return existing;
|
|
15
|
+
}
|
|
16
|
+
const promise = (0, throttleRetry_1.withThrottleRetry)(load).catch((error) => {
|
|
17
|
+
inflight.delete(key);
|
|
18
|
+
throw error;
|
|
19
|
+
});
|
|
20
|
+
inflight.set(key, promise);
|
|
21
|
+
return promise;
|
|
22
|
+
},
|
|
23
|
+
};
|
|
24
|
+
};
|
|
25
|
+
exports.createRefreshCache = createRefreshCache;
|
|
26
|
+
/**
|
|
27
|
+
* Read-through helper for planner call sites: uses the context-scoped cache
|
|
28
|
+
* when present, otherwise loads directly. Planners receive the context as a
|
|
29
|
+
* parameter, so tests can decide whether caching applies.
|
|
30
|
+
*/
|
|
31
|
+
const cachedRefreshRead = (context, key, load) => (context.refreshCache ? context.refreshCache.read(key, load) : load());
|
|
32
|
+
exports.cachedRefreshRead = cachedRefreshRead;
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.planRefreshedResource = exports.decideRefreshedExistsAction = void 0;
|
|
4
|
+
const hashUtils_1 = require("./hashUtils");
|
|
5
|
+
const planCompare_1 = require("./planCompare");
|
|
6
|
+
const decideRefreshedExistsAction = async (args) => {
|
|
7
|
+
const remote = await args.read();
|
|
8
|
+
if (!remote) {
|
|
9
|
+
return { action: 'create', drifted: true };
|
|
10
|
+
}
|
|
11
|
+
let attributes = args.cloudToDefinition(remote);
|
|
12
|
+
if (args.enrichRemoteAttributes) {
|
|
13
|
+
attributes = await args.enrichRemoteAttributes(remote, attributes);
|
|
14
|
+
}
|
|
15
|
+
const remoteDiffers = (0, planCompare_1.remoteDiffersFromDesired)(attributes, args.desiredDefinition);
|
|
16
|
+
if (args.definitionChanged || remoteDiffers) {
|
|
17
|
+
return { action: 'update', drifted: true };
|
|
18
|
+
}
|
|
19
|
+
const extra = await args.extraUpdate?.();
|
|
20
|
+
if (extra?.update) {
|
|
21
|
+
return { action: 'update', drifted: extra.drifted };
|
|
22
|
+
}
|
|
23
|
+
return { action: 'noop' };
|
|
24
|
+
};
|
|
25
|
+
exports.decideRefreshedExistsAction = decideRefreshedExistsAction;
|
|
26
|
+
/**
|
|
27
|
+
* Shared planner skeleton (issue #234 Phase 3): covers the uniform
|
|
28
|
+
* no-state-probe / exists-refresh decision chain of the simple planners
|
|
29
|
+
* (buckets, tables, databases). Function and gateway planners keep their
|
|
30
|
+
* custom flows (role probes, trigger reconciliation, config normalization).
|
|
31
|
+
* Read failures on the exists path degrade to a create plan — the pre-existing
|
|
32
|
+
* planner behavior, preserved verbatim.
|
|
33
|
+
*/
|
|
34
|
+
const planRefreshedResource = async (args) => {
|
|
35
|
+
const { logicalId, resourceType, currentState, desiredDefinition } = args;
|
|
36
|
+
if (!currentState || currentState.status === 'tainted') {
|
|
37
|
+
const probeRead = args.probeRead ?? args.read;
|
|
38
|
+
const remote = await probeRead();
|
|
39
|
+
if (remote && !args.isOwned(remote)) {
|
|
40
|
+
throw args.foreignError(remote);
|
|
41
|
+
}
|
|
42
|
+
return {
|
|
43
|
+
logicalId,
|
|
44
|
+
action: 'create',
|
|
45
|
+
resourceType,
|
|
46
|
+
changes: { after: desiredDefinition },
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
const normalize = args.normalizeForDisplay ?? ((d) => d);
|
|
50
|
+
const currentDefinition = currentState.definition || {};
|
|
51
|
+
const normalizedCurrent = normalize(currentDefinition);
|
|
52
|
+
const normalizedDesired = normalize(desiredDefinition);
|
|
53
|
+
const definitionChanged = !(0, hashUtils_1.attributesEqual)(normalizedCurrent, normalizedDesired);
|
|
54
|
+
const refreshEnabled = args.refresh ?? true;
|
|
55
|
+
try {
|
|
56
|
+
// --no-refresh: no cloud knowledge, so no drift claims — intent-diff only.
|
|
57
|
+
if (!refreshEnabled) {
|
|
58
|
+
if (!definitionChanged) {
|
|
59
|
+
return { logicalId, action: 'noop', resourceType };
|
|
60
|
+
}
|
|
61
|
+
return {
|
|
62
|
+
logicalId,
|
|
63
|
+
action: 'update',
|
|
64
|
+
resourceType,
|
|
65
|
+
changes: { before: normalizedCurrent, after: normalizedDesired },
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
const decision = await (0, exports.decideRefreshedExistsAction)({
|
|
69
|
+
read: args.read,
|
|
70
|
+
cloudToDefinition: args.cloudToDefinition,
|
|
71
|
+
enrichRemoteAttributes: args.enrichRemoteAttributes,
|
|
72
|
+
desiredDefinition,
|
|
73
|
+
definitionChanged,
|
|
74
|
+
extraUpdate: args.extraUpdate,
|
|
75
|
+
});
|
|
76
|
+
if (decision.action === 'noop') {
|
|
77
|
+
return { logicalId, action: 'noop', resourceType };
|
|
78
|
+
}
|
|
79
|
+
if (decision.action === 'create') {
|
|
80
|
+
return {
|
|
81
|
+
logicalId,
|
|
82
|
+
action: 'create',
|
|
83
|
+
resourceType,
|
|
84
|
+
changes: { before: normalize(currentDefinition), after: desiredDefinition },
|
|
85
|
+
drifted: true,
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
return {
|
|
89
|
+
logicalId,
|
|
90
|
+
action: 'update',
|
|
91
|
+
resourceType,
|
|
92
|
+
changes: { before: normalizedCurrent, after: normalizedDesired },
|
|
93
|
+
...(decision.drifted ? { drifted: true } : {}),
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
catch {
|
|
97
|
+
return {
|
|
98
|
+
logicalId,
|
|
99
|
+
action: 'create',
|
|
100
|
+
resourceType,
|
|
101
|
+
changes: { before: normalize(currentDefinition), after: desiredDefinition },
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
};
|
|
105
|
+
exports.planRefreshedResource = planRefreshedResource;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createClsOperations = void 0;
|
|
3
|
+
exports.createClsOperations = exports.CLS_TOPIC_STORAGE_TYPE = exports.CLS_TOPIC_PERIOD = void 0;
|
|
4
4
|
const polling_1 = require("../polling");
|
|
5
5
|
const constants_1 = require("../constants");
|
|
6
6
|
// CLS reports missing resources with `ResourceNotFound.<Kind>NotExist` codes —
|
|
@@ -23,6 +23,11 @@ const isAlreadyExists = (error) => {
|
|
|
23
23
|
code.includes('ResourceExists') ||
|
|
24
24
|
message.includes('already exist'));
|
|
25
25
|
};
|
|
26
|
+
// The topic attributes si creates with (issue #234 M3): `fn.log` is a
|
|
27
|
+
// boolean — these are stack constants, so live values differing from them are
|
|
28
|
+
// out-of-band drift.
|
|
29
|
+
exports.CLS_TOPIC_PERIOD = 30;
|
|
30
|
+
exports.CLS_TOPIC_STORAGE_TYPE = 'hot';
|
|
26
31
|
const createClsOperations = (clsClient) => {
|
|
27
32
|
const operations = {
|
|
28
33
|
createLogset: async (logsetName, tags) => {
|
|
@@ -47,6 +52,12 @@ const createClsOperations = (clsClient) => {
|
|
|
47
52
|
Tags: found.Tags,
|
|
48
53
|
};
|
|
49
54
|
},
|
|
55
|
+
getLogsetNameById: async (logsetId) => {
|
|
56
|
+
const response = await clsClient.DescribeLogsets({
|
|
57
|
+
Filters: [{ Key: 'logsetId', Values: [logsetId] }],
|
|
58
|
+
});
|
|
59
|
+
return response?.Logsets?.find((l) => l.LogsetId === logsetId)?.LogsetName ?? null;
|
|
60
|
+
},
|
|
50
61
|
listTopicsByLogset: async (logsetId) => {
|
|
51
62
|
const response = await clsClient.DescribeTopics({
|
|
52
63
|
Filters: [{ Key: 'logsetId', Values: [logsetId] }],
|
|
@@ -64,6 +75,19 @@ const createClsOperations = (clsClient) => {
|
|
|
64
75
|
});
|
|
65
76
|
return response?.Topics?.find((t) => t.TopicName === topicName) ?? null;
|
|
66
77
|
},
|
|
78
|
+
getTopicById: async (topicId) => {
|
|
79
|
+
const response = await clsClient.DescribeTopics({
|
|
80
|
+
Filters: [{ Key: 'topicId', Values: [topicId] }],
|
|
81
|
+
});
|
|
82
|
+
return response?.Topics?.find((t) => t.TopicId === topicId) ?? null;
|
|
83
|
+
},
|
|
84
|
+
modifyTopic: async (topicId, opts) => {
|
|
85
|
+
await clsClient.ModifyTopic({
|
|
86
|
+
TopicId: topicId,
|
|
87
|
+
Period: opts.period,
|
|
88
|
+
StorageType: opts.storageType,
|
|
89
|
+
});
|
|
90
|
+
},
|
|
67
91
|
waitForTopic: async (logsetId, topicName) => (0, polling_1.pollUntil)({
|
|
68
92
|
description: `CLS topic ${topicName} to become visible`,
|
|
69
93
|
fetch: () => operations.getTopicByName(logsetId, topicName),
|
|
@@ -77,8 +101,8 @@ const createClsOperations = (clsClient) => {
|
|
|
77
101
|
await clsClient.CreateTopic({
|
|
78
102
|
LogsetId: logsetId,
|
|
79
103
|
TopicName: topicName,
|
|
80
|
-
StorageType: opts.storageType ??
|
|
81
|
-
Period: opts.period ??
|
|
104
|
+
StorageType: opts.storageType ?? exports.CLS_TOPIC_STORAGE_TYPE,
|
|
105
|
+
Period: opts.period ?? exports.CLS_TOPIC_PERIOD,
|
|
82
106
|
Tags: opts.tags.map((t) => ({ Key: t.key, Value: t.value })),
|
|
83
107
|
});
|
|
84
108
|
const topic = await operations.waitForTopic(logsetId, topicName);
|
|
@@ -165,6 +165,28 @@ const createTdsqlcOperations = (cynosdbClient, context) => {
|
|
|
165
165
|
throw error;
|
|
166
166
|
}
|
|
167
167
|
},
|
|
168
|
+
getServerlessStrategy: async (clusterId) => {
|
|
169
|
+
// DescribeServerlessStrategy reports the CONFIGURED idle-pause switch
|
|
170
|
+
// (DescribeClusters only reports the running state). The dedicated API
|
|
171
|
+
// is recent — guard on SDK support and treat absence as "not readable".
|
|
172
|
+
const sdk = cynosdbClient;
|
|
173
|
+
if (typeof sdk.DescribeServerlessStrategy !== 'function') {
|
|
174
|
+
return null;
|
|
175
|
+
}
|
|
176
|
+
try {
|
|
177
|
+
const response = await sdk.DescribeServerlessStrategy({ ClusterId: clusterId });
|
|
178
|
+
if (!response) {
|
|
179
|
+
return null;
|
|
180
|
+
}
|
|
181
|
+
return {
|
|
182
|
+
autoPause: response.AutoPause === undefined ? undefined : response.AutoPause === 'yes',
|
|
183
|
+
autoPauseDelay: response.AutoPauseDelay,
|
|
184
|
+
};
|
|
185
|
+
}
|
|
186
|
+
catch {
|
|
187
|
+
return null;
|
|
188
|
+
}
|
|
189
|
+
},
|
|
168
190
|
updateCluster: async (clusterId, config) => {
|
|
169
191
|
const params = {
|
|
170
192
|
ClusterId: clusterId,
|