@geek-fun/serverlessinsight 0.8.7 → 0.8.9
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/index.js +44 -35
- 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/constants.js +5 -1
- package/dist/src/common/context.js +3 -0
- package/dist/src/common/dependencyGraph/graph.js +5 -0
- package/dist/src/common/imsClient.js +2 -2
- 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 +221 -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 = [];
|
|
@@ -76,6 +76,15 @@ __exportStar(require("./tablestoreOperations"), exports);
|
|
|
76
76
|
__exportStar(require("./dnsOperations"), exports);
|
|
77
77
|
__exportStar(require("./casOperations"), exports);
|
|
78
78
|
__exportStar(require("./cdnOperations"), exports);
|
|
79
|
+
// Non-fc3 aliyun clients are synchronous management-plane RPCs — they share
|
|
80
|
+
// the short query-tier timeout budget (issue #234: sls ran on the SDK default
|
|
81
|
+
// 3s read timeout and a cold read aborted whole deploys; the deploy-tier
|
|
82
|
+
// budget would instead let a hung call stall a deploy for minutes).
|
|
83
|
+
const applyAliyunQueryTimeouts = (config) => {
|
|
84
|
+
config.connectTimeout = constants_1.ALIYUN_QUERY_CONNECT_TIMEOUT_MS;
|
|
85
|
+
config.readTimeout = constants_1.ALIYUN_QUERY_READ_TIMEOUT_MS;
|
|
86
|
+
return config;
|
|
87
|
+
};
|
|
79
88
|
const initializeSdkClients = (context) => {
|
|
80
89
|
const baseConfig = {
|
|
81
90
|
accessKeyId: context.accessKeyId,
|
|
@@ -83,47 +92,47 @@ const initializeSdkClients = (context) => {
|
|
|
83
92
|
regionId: context.region,
|
|
84
93
|
securityToken: context.securityToken,
|
|
85
94
|
};
|
|
86
|
-
const
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
const
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
const
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
const
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
const
|
|
101
|
-
|
|
102
|
-
|
|
95
|
+
const fc3Client = new fc20230330_1.default(Object.assign(new $OpenApi.Config(baseConfig), {
|
|
96
|
+
endpoint: `${context.accountId}.${context.region}.fc.aliyuncs.com`,
|
|
97
|
+
connectTimeout: constants_1.ALIYUN_FC3_CONNECT_TIMEOUT_MS,
|
|
98
|
+
readTimeout: constants_1.ALIYUN_FC3_READ_TIMEOUT_MS,
|
|
99
|
+
}));
|
|
100
|
+
const slsClient = new sls20201230_1.default(applyAliyunQueryTimeouts(Object.assign(new $OpenApi.Config(baseConfig), {
|
|
101
|
+
endpoint: `${context.region}.log.aliyuncs.com`,
|
|
102
|
+
})));
|
|
103
|
+
const ramClient = new ram20150501_1.default(applyAliyunQueryTimeouts(Object.assign(new $OpenApi.Config(baseConfig), {
|
|
104
|
+
endpoint: 'ram.aliyuncs.com',
|
|
105
|
+
})));
|
|
106
|
+
const ecsClient = new ecs20140526_1.default(applyAliyunQueryTimeouts(Object.assign(new $OpenApi.Config(baseConfig), {
|
|
107
|
+
endpoint: `ecs.${context.region}.aliyuncs.com`,
|
|
108
|
+
})));
|
|
109
|
+
const nasClient = new nas20170626_1.default(applyAliyunQueryTimeouts(Object.assign(new $OpenApi.Config(baseConfig), {
|
|
110
|
+
endpoint: `nas.${context.region}.aliyuncs.com`,
|
|
111
|
+
})));
|
|
103
112
|
const ossClient = new ali_oss_1.default({
|
|
104
113
|
accessKeyId: context.accessKeyId,
|
|
105
114
|
accessKeySecret: context.accessKeySecret,
|
|
106
115
|
region: `oss-${context.region}`,
|
|
107
116
|
stsToken: context.securityToken,
|
|
108
117
|
});
|
|
109
|
-
const
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
const
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
const
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
const
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
const
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
const
|
|
125
|
-
|
|
126
|
-
|
|
118
|
+
const apigwClient = new cloudapi20160714_1.default(applyAliyunQueryTimeouts(Object.assign(new $OpenApi.Config(baseConfig), {
|
|
119
|
+
endpoint: `apigateway.${context.region}.aliyuncs.com`,
|
|
120
|
+
})));
|
|
121
|
+
const rdsClient = new rds20140815_1.default(applyAliyunQueryTimeouts(Object.assign(new $OpenApi.Config(baseConfig), {
|
|
122
|
+
endpoint: `rds.aliyuncs.com`,
|
|
123
|
+
})));
|
|
124
|
+
const esClient = new es_serverless20230627_1.default(applyAliyunQueryTimeouts(Object.assign(new $OpenApi.Config(baseConfig), {
|
|
125
|
+
endpoint: `elasticsearch-serverless.${context.region}.aliyuncs.com`,
|
|
126
|
+
})));
|
|
127
|
+
const dnsClient = new alidns20150109_1.default(applyAliyunQueryTimeouts(Object.assign(new $OpenApi.Config(baseConfig), {
|
|
128
|
+
endpoint: `alidns.aliyuncs.com`,
|
|
129
|
+
})));
|
|
130
|
+
const casClient = new cas20200407_1.default(applyAliyunQueryTimeouts(Object.assign(new $OpenApi.Config(baseConfig), {
|
|
131
|
+
endpoint: `cas.aliyuncs.com`,
|
|
132
|
+
})));
|
|
133
|
+
const cdnClient = new cdn20180510_1.default(applyAliyunQueryTimeouts(Object.assign(new $OpenApi.Config(baseConfig), {
|
|
134
|
+
endpoint: `cdn.aliyuncs.com`,
|
|
135
|
+
})));
|
|
127
136
|
return {
|
|
128
137
|
fc3: fc3Client,
|
|
129
138
|
sls: slsClient,
|
|
@@ -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;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.CLS_TOPIC_POLL_MAX_ATTEMPTS = exports.CLS_TOPIC_POLL_INTERVAL_MS = exports.SCF_STATUS_POLL_MAX_ATTEMPTS = exports.SCF_STATUS_POLL_INTERVAL_MS = exports.RAM_ROLE_PROPAGATION_DELAY_MS = exports.APIGW_DNS_PUBLIC_RESOLUTION_DELAY_MS = exports.APIGW_DNS_PUBLIC_RESOLUTION_MAX_ATTEMPTS = exports.APIGW_DOMAIN_BIND_RETRY_DELAY_MS = exports.APIGW_DOMAIN_BIND_MAX_RETRIES = exports.DNS_PROPAGATION_DELAY_MS = exports.DNS_PROPAGATION_MAX_ATTEMPTS = exports.DOMAIN_BIND_RETRY_DELAY_MS = exports.DOMAIN_BIND_MAX_RETRIES = exports.STALE_LOCK_THRESHOLD = exports.DEFAULT_LOCK_RETRY_DELAY = exports.DEFAULT_LOCK_TIMEOUT = exports.LOCK_FILE_SUFFIX = exports.OSS_STATE_REQUEST_TIMEOUT_MS = exports.OSS_STATE_CONNECT_TIMEOUT_MS = exports.FC3_CODE_INLINE_SIZE_LIMIT = exports.ALIYUN_FC3_READ_TIMEOUT_MS = exports.ALIYUN_FC3_CONNECT_TIMEOUT_MS = exports.SI_LOCALSTACK_SERVER_PORT = exports.SI_BOOTSTRAP_BUCKET_PREFIX = exports.SI_BOOTSTRAP_FC_PREFIX = exports.OSS_DEPLOYMENT_TIMEOUT = exports.CODE_ZIP_SIZE_LIMIT = void 0;
|
|
3
|
+
exports.CLS_TOPIC_POLL_MAX_ATTEMPTS = exports.CLS_TOPIC_POLL_INTERVAL_MS = exports.SCF_STATUS_POLL_MAX_ATTEMPTS = exports.SCF_STATUS_POLL_INTERVAL_MS = exports.RAM_ROLE_PROPAGATION_DELAY_MS = exports.APIGW_DNS_PUBLIC_RESOLUTION_DELAY_MS = exports.APIGW_DNS_PUBLIC_RESOLUTION_MAX_ATTEMPTS = exports.APIGW_DOMAIN_BIND_RETRY_DELAY_MS = exports.APIGW_DOMAIN_BIND_MAX_RETRIES = exports.DNS_PROPAGATION_DELAY_MS = exports.DNS_PROPAGATION_MAX_ATTEMPTS = exports.DOMAIN_BIND_RETRY_DELAY_MS = exports.DOMAIN_BIND_MAX_RETRIES = exports.STALE_LOCK_THRESHOLD = exports.DEFAULT_LOCK_RETRY_DELAY = exports.DEFAULT_LOCK_TIMEOUT = exports.LOCK_FILE_SUFFIX = exports.OSS_STATE_REQUEST_TIMEOUT_MS = exports.OSS_STATE_CONNECT_TIMEOUT_MS = exports.FC3_CODE_INLINE_SIZE_LIMIT = exports.ALIYUN_QUERY_READ_TIMEOUT_MS = exports.ALIYUN_QUERY_CONNECT_TIMEOUT_MS = exports.ALIYUN_FC3_READ_TIMEOUT_MS = exports.ALIYUN_FC3_CONNECT_TIMEOUT_MS = exports.SI_LOCALSTACK_SERVER_PORT = exports.SI_BOOTSTRAP_BUCKET_PREFIX = exports.SI_BOOTSTRAP_FC_PREFIX = exports.OSS_DEPLOYMENT_TIMEOUT = exports.CODE_ZIP_SIZE_LIMIT = void 0;
|
|
4
4
|
exports.CODE_ZIP_SIZE_LIMIT = 300 * 1000; // 300 KB - code package size limit for inline deployment
|
|
5
5
|
exports.OSS_DEPLOYMENT_TIMEOUT = 3000; // in seconds
|
|
6
6
|
exports.SI_BOOTSTRAP_FC_PREFIX = 'si-bootstrap-api';
|
|
@@ -8,6 +8,10 @@ exports.SI_BOOTSTRAP_BUCKET_PREFIX = 'si-bootstrap-artifacts';
|
|
|
8
8
|
exports.SI_LOCALSTACK_SERVER_PORT = 4567;
|
|
9
9
|
exports.ALIYUN_FC3_CONNECT_TIMEOUT_MS = 120000;
|
|
10
10
|
exports.ALIYUN_FC3_READ_TIMEOUT_MS = 600000;
|
|
11
|
+
// Query-tier budget for synchronous management-plane RPCs (all non-fc3 aliyun
|
|
12
|
+
// clients): fast fail beats long hang — long waits are polling loops, not calls.
|
|
13
|
+
exports.ALIYUN_QUERY_CONNECT_TIMEOUT_MS = 10000; // 10 seconds
|
|
14
|
+
exports.ALIYUN_QUERY_READ_TIMEOUT_MS = 30000; // 30 seconds
|
|
11
15
|
exports.FC3_CODE_INLINE_SIZE_LIMIT = 70 * 1024 * 1024; // 70MB threshold for OSS upload
|
|
12
16
|
// OSS state backend timeouts
|
|
13
17
|
exports.OSS_STATE_CONNECT_TIMEOUT_MS = 10000; // 10 seconds
|
|
@@ -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,
|
|
@@ -48,8 +48,8 @@ const getIamInfo = async (context) => {
|
|
|
48
48
|
regionId: context.region,
|
|
49
49
|
endpoint: 'ims.aliyuncs.com',
|
|
50
50
|
});
|
|
51
|
-
imsConfig.connectTimeout = constants_1.
|
|
52
|
-
imsConfig.readTimeout = constants_1.
|
|
51
|
+
imsConfig.connectTimeout = constants_1.ALIYUN_QUERY_CONNECT_TIMEOUT_MS;
|
|
52
|
+
imsConfig.readTimeout = constants_1.ALIYUN_QUERY_READ_TIMEOUT_MS;
|
|
53
53
|
const imsClient = new ims20190815_1.default(imsConfig);
|
|
54
54
|
const { body } = await imsClient.getUser(new ims20190815.GetUserRequest({ userAccessKeyId: context.accessKeyId }));
|
|
55
55
|
return body?.user
|
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;
|