@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
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.withThrottleRetry = exports.isThrottlingError = void 0;
|
|
4
|
+
const retryUtils_1 = require("./retryUtils");
|
|
5
|
+
/**
|
|
6
|
+
* Provider management-API throttling recognition (issue #234). Error shapes
|
|
7
|
+
* differ across SDKs: Alibaba/Volcengine/Tencent expose `code`, Volcengine TLS
|
|
8
|
+
* nests it under `response.data.Error.Code`, and Tencent scopes the frequency
|
|
9
|
+
* limit as `RequestLimitExceeded.UinLimitExceeded` etc. All three families map
|
|
10
|
+
* onto one recognizer because none of the SDKs retry throttling by default.
|
|
11
|
+
*/
|
|
12
|
+
const isThrottlingCode = (code) => {
|
|
13
|
+
if (typeof code === 'string') {
|
|
14
|
+
return (code.startsWith('Throttling') ||
|
|
15
|
+
code.startsWith('RequestLimitExceeded') ||
|
|
16
|
+
code === 'FlowLimitExceeded' ||
|
|
17
|
+
code === 'SlowDown' ||
|
|
18
|
+
code === 'TooManyRequests');
|
|
19
|
+
}
|
|
20
|
+
return code === 100018; // Volcengine FlowLimitExceeded numeric code
|
|
21
|
+
};
|
|
22
|
+
const isThrottlingError = (error) => {
|
|
23
|
+
if (!error || typeof error !== 'object') {
|
|
24
|
+
return false;
|
|
25
|
+
}
|
|
26
|
+
const candidate = error;
|
|
27
|
+
if (isThrottlingCode(candidate.code)) {
|
|
28
|
+
return true;
|
|
29
|
+
}
|
|
30
|
+
return isThrottlingCode(candidate.response?.data?.Error?.Code);
|
|
31
|
+
};
|
|
32
|
+
exports.isThrottlingError = isThrottlingError;
|
|
33
|
+
const RETRY_DELAY_BASE_MS = 250;
|
|
34
|
+
const RETRY_JITTER_MAX_MS = 150;
|
|
35
|
+
const jitteredBackoff = (attempt) => RETRY_DELAY_BASE_MS * 2 ** attempt + Math.floor(Math.random() * RETRY_JITTER_MAX_MS);
|
|
36
|
+
/**
|
|
37
|
+
* Retries a load only on recognized throttling errors with exponential backoff
|
|
38
|
+
* + jitter. Used on the refresh/plan read path; write operations must not be
|
|
39
|
+
* auto-retried through this helper (idempotency is their caller's concern).
|
|
40
|
+
*/
|
|
41
|
+
const withThrottleRetry = async (load, maxAttempts = 3) => {
|
|
42
|
+
let attempt = 0;
|
|
43
|
+
for (;;) {
|
|
44
|
+
try {
|
|
45
|
+
return await load();
|
|
46
|
+
}
|
|
47
|
+
catch (error) {
|
|
48
|
+
attempt += 1;
|
|
49
|
+
if (!(0, exports.isThrottlingError)(error) || attempt >= maxAttempts) {
|
|
50
|
+
throw error;
|
|
51
|
+
}
|
|
52
|
+
await (0, retryUtils_1.sleep)(jitteredBackoff(attempt - 1));
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
exports.withThrottleRetry = withThrottleRetry;
|
|
@@ -1,11 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createTlsOperations = void 0;
|
|
3
|
+
exports.createTlsOperations = exports.TLS_TOPIC_SHARDS = exports.TLS_TOPIC_TTL = void 0;
|
|
4
4
|
const logger_1 = require("../logger");
|
|
5
5
|
const lang_1 = require("../../lang");
|
|
6
6
|
const polling_1 = require("../polling");
|
|
7
7
|
const WAIT_INTERVAL_MS = 5000;
|
|
8
8
|
const MAX_WAIT_ATTEMPTS = 30;
|
|
9
|
+
// The topic attributes si creates with (issue #234 M5): `fn.log` is a
|
|
10
|
+
// boolean — these are stack constants, so live values differing from them are
|
|
11
|
+
// out-of-band drift. ModifyTopic cannot change shard count (create-only).
|
|
12
|
+
exports.TLS_TOPIC_TTL = 30;
|
|
13
|
+
exports.TLS_TOPIC_SHARDS = 1;
|
|
9
14
|
const waitForProjectReady = async (getProject, projectName) => {
|
|
10
15
|
try {
|
|
11
16
|
await (0, polling_1.pollUntil)({
|
|
@@ -195,8 +200,8 @@ const createTlsOperations = (tlsClient) => {
|
|
|
195
200
|
ProjectId: project.projectId,
|
|
196
201
|
TopicName: config.topicName,
|
|
197
202
|
Description: config.description,
|
|
198
|
-
Ttl: config.ttl ??
|
|
199
|
-
ShardCount:
|
|
203
|
+
Ttl: config.ttl ?? exports.TLS_TOPIC_TTL,
|
|
204
|
+
ShardCount: exports.TLS_TOPIC_SHARDS,
|
|
200
205
|
});
|
|
201
206
|
logger_1.logger.info(lang_1.lang.__('TLS_TOPIC_CREATED', { topicName: config.topicName }));
|
|
202
207
|
return {
|
|
@@ -204,7 +209,7 @@ const createTlsOperations = (tlsClient) => {
|
|
|
204
209
|
topicName: config.topicName,
|
|
205
210
|
projectName: config.projectName,
|
|
206
211
|
description: config.description,
|
|
207
|
-
ttl: config.ttl ??
|
|
212
|
+
ttl: config.ttl ?? exports.TLS_TOPIC_TTL,
|
|
208
213
|
status: 'Active',
|
|
209
214
|
};
|
|
210
215
|
}
|
|
@@ -259,6 +264,9 @@ const createTlsOperations = (tlsClient) => {
|
|
|
259
264
|
throw error;
|
|
260
265
|
}
|
|
261
266
|
},
|
|
267
|
+
modifyTopic: async (topicId, ttl) => {
|
|
268
|
+
await tlsClient.ModifyTopic({ TopicId: topicId, Ttl: ttl });
|
|
269
|
+
},
|
|
262
270
|
listTopics: async (projectName) => {
|
|
263
271
|
try {
|
|
264
272
|
const project = await operations.getProject(projectName);
|
package/dist/src/lang/en.js
CHANGED
|
@@ -118,6 +118,8 @@ exports.en = {
|
|
|
118
118
|
PLAN_SUMMARY: 'Plan: {{createCount}} to add, {{updateCount}} to change, {{deleteCount}} to destroy.',
|
|
119
119
|
PLAN_UNCHANGED_ATTRS: '({{count}} unchanged attributes hidden)',
|
|
120
120
|
PLAN_COMPUTED_VALUE: '(known after deploy)',
|
|
121
|
+
PLAN_DRIFTED_MARKER: '(drifted — cloud changed outside of this config, will be reconciled)',
|
|
122
|
+
PLAN_DRIFTED_SUMMARY: 'Drift: {{driftedCount}} resource(s) changed in the cloud outside of this config.',
|
|
121
123
|
// TDSQL-C database messages
|
|
122
124
|
TDSQL_CLUSTER_CREATION_INITIATED: 'TDSQL-C cluster creation initiated',
|
|
123
125
|
TDSQL_CLUSTER_CREATION_FAILED: 'Failed to create TDSQL-C cluster',
|
|
@@ -230,6 +232,20 @@ exports.en = {
|
|
|
230
232
|
SLS_LOGSTORE_WAITING: 'Waiting for SLS logstore {{project}}/{{logstore}} to be ready...',
|
|
231
233
|
SHARED_SLS_PROJECT_IN_USE: '{{count}} logstore(s) still reference shared SLS project {{projectName}}; retaining it',
|
|
232
234
|
SHARED_SLS_PROJECT_ADOPTED: 'Adopting existing shared SLS project {{projectName}} owned by this app',
|
|
235
|
+
REFRESH_CACHE_HIT: 'Refresh read cache hit: {{key}}',
|
|
236
|
+
PLAN_FUNCTION_ROLE_MISSING: 'Function {{functionName}} role {{roleName}} is missing in the provider; it will be recreated and rebound on deploy',
|
|
237
|
+
PLAN_FUNCTION_ROLE_PROBE_FAILED: 'Live role policy check for function {{functionName}} (role {{roleName}}) failed: {{error}}; skipping role drift detection for this plan',
|
|
238
|
+
PLAN_FUNCTION_NESTED_PROBE_FAILED: 'Nested resource probe for function {{functionName}} failed: {{error}}; skipping nested drift detection for this plan',
|
|
239
|
+
NESTED_LOGSTORE_RECREATED: 'Logstore {{logstoreName}} was deleted out-of-band; recreating it',
|
|
240
|
+
NESTED_LOGSTORE_UPDATED: 'Logstore {{logstoreName}} attributes drifted; updating to match si defaults',
|
|
241
|
+
NESTED_TLS_TOPIC_UPDATED: 'TLS topic {{topicId}} ttl drifted; updating to match si defaults',
|
|
242
|
+
NESTED_MOUNT_TARGET_RECREATED: 'NAS mount target for file system {{fileSystemId}} was deleted out-of-band; recreating it',
|
|
243
|
+
NESTED_TOPIC_RECREATED: 'CLS topic {{topicId}} was deleted out-of-band; recreating it under the shared logset',
|
|
244
|
+
NESTED_TOPIC_UPDATED: 'CLS topic {{topicId}} attributes drifted; updating to match si defaults',
|
|
245
|
+
NESTED_SG_RULES_REPAIRED: 'Security group {{securityGroupId}} rule set drifted; authorizing {{added}} and revoking {{removed}} rules',
|
|
246
|
+
NESTED_INDEX_RECREATED: 'Logstore index {{logstoreName}} was deleted out-of-band; recreating it',
|
|
247
|
+
PLAN_EVENT_TRIGGER_PROBE_FAILED: 'Live trigger check for API Gateway {{eventName}} failed: {{error}}; skipping trigger drift detection for this plan',
|
|
248
|
+
RAM_ROLE_MISSING_RECREATE: 'RAM role {{roleName}} is missing in the provider; recreating it with the union of all functions that share it',
|
|
233
249
|
SLS_PROJECT_FOREIGN_OWNED: 'SLS project {{projectName}} exists but is not owned by this app; refusing to adopt',
|
|
234
250
|
APIGW_LOG_CONFIG_STILL_REFERENCES_STORE: 'Regional PROVIDER gateway log config still references {{slsLogStore}}; retaining logstore',
|
|
235
251
|
APIGW_DOMAIN_BINDING_FAILED: 'Failed to bind custom domain: {{error}}',
|
package/dist/src/lang/zh-CN.js
CHANGED
|
@@ -118,6 +118,8 @@ exports.zhCN = {
|
|
|
118
118
|
PLAN_SUMMARY: '计划: 新增 {{createCount}} 个,变更 {{updateCount}} 个,销毁 {{deleteCount}} 个。',
|
|
119
119
|
PLAN_UNCHANGED_ATTRS: '({{count}} 个未变更属性已隐藏)',
|
|
120
120
|
PLAN_COMPUTED_VALUE: '(部署后可知)',
|
|
121
|
+
PLAN_DRIFTED_MARKER: '(云端已漂移——与本配置不一致,将按配置纠正)',
|
|
122
|
+
PLAN_DRIFTED_SUMMARY: '漂移: {{driftedCount}} 个资源在云端被本配置之外的变更修改。',
|
|
121
123
|
// TDSQL-C 数据库消息
|
|
122
124
|
TDSQL_CLUSTER_CREATION_INITIATED: 'TDSQL-C 集群创建已启动',
|
|
123
125
|
TDSQL_CLUSTER_CREATION_FAILED: '创建 TDSQL-C 集群失败',
|
|
@@ -230,6 +232,20 @@ exports.zhCN = {
|
|
|
230
232
|
SLS_LOGSTORE_WAITING: '等待 SLS 日志库 {{project}}/{{logstore}} 就绪...',
|
|
231
233
|
SHARED_SLS_PROJECT_IN_USE: '仍有 {{count}} 个日志库引用共享 SLS 项目 {{projectName}},予以保留',
|
|
232
234
|
SHARED_SLS_PROJECT_ADOPTED: '采用当前应用已有的共享 SLS 项目 {{projectName}}',
|
|
235
|
+
REFRESH_CACHE_HIT: '刷新读缓存命中:{{key}}',
|
|
236
|
+
PLAN_FUNCTION_ROLE_MISSING: '函数 {{functionName}} 的角色 {{roleName}} 在云端不存在;部署时将重建并重新绑定',
|
|
237
|
+
PLAN_FUNCTION_ROLE_PROBE_FAILED: '函数 {{functionName}}(角色 {{roleName}})的实时角色策略检查失败:{{error}};本次计划跳过角色漂移检测',
|
|
238
|
+
PLAN_FUNCTION_NESTED_PROBE_FAILED: '函数 {{functionName}} 的嵌套资源探测失败:{{error}};本次计划跳过嵌套漂移检测',
|
|
239
|
+
NESTED_LOGSTORE_RECREATED: '日志库 {{logstoreName}} 被带外删除,正在重建',
|
|
240
|
+
NESTED_LOGSTORE_UPDATED: '日志库 {{logstoreName}} 属性已漂移,正在按 si 默认值更新',
|
|
241
|
+
NESTED_TLS_TOPIC_UPDATED: 'TLS 日志主题 {{topicId}} 的 ttl 已漂移,正在按 si 默认值更新',
|
|
242
|
+
NESTED_MOUNT_TARGET_RECREATED: '文件系统 {{fileSystemId}} 的 NAS 挂载点被带外删除,正在重建',
|
|
243
|
+
NESTED_TOPIC_RECREATED: '日志主题 {{topicId}} 被带外删除,正在共享日志集下重建',
|
|
244
|
+
NESTED_TOPIC_UPDATED: '日志主题 {{topicId}} 属性已漂移,正在按 si 默认值更新',
|
|
245
|
+
NESTED_SG_RULES_REPAIRED: '安全组 {{securityGroupId}} 规则集已漂移;新增 {{added}} 条、撤销 {{removed}} 条',
|
|
246
|
+
NESTED_INDEX_RECREATED: '日志库 {{logstoreName}} 的索引被带外删除,正在重建',
|
|
247
|
+
PLAN_EVENT_TRIGGER_PROBE_FAILED: 'API 网关 {{eventName}} 的实时触发器检查失败:{{error}};本次计划跳过触发器漂移检测',
|
|
248
|
+
RAM_ROLE_MISSING_RECREATE: 'RAM 角色 {{roleName}} 在云端不存在;将以共享该角色的所有函数的并集权限重建',
|
|
233
249
|
SLS_PROJECT_FOREIGN_OWNED: 'SLS 项目 {{projectName}} 已存在但不属于当前应用,拒绝采用',
|
|
234
250
|
APIGW_LOG_CONFIG_STILL_REFERENCES_STORE: '区域级 PROVIDER 网关日志配置仍引用 {{slsLogStore}},保留该日志库',
|
|
235
251
|
APIGW_DOMAIN_BINDING_FAILED: '绑定自定义域名失败:{{error}}',
|
|
@@ -5,6 +5,10 @@ const aliyunClient_1 = require("../../common/aliyunClient");
|
|
|
5
5
|
const apigwTypes_1 = require("./apigwTypes");
|
|
6
6
|
const stateManager_1 = require("../../common/stateManager");
|
|
7
7
|
const hashUtils_1 = require("../../common/hashUtils");
|
|
8
|
+
const iacHelper_1 = require("../../common/iacHelper");
|
|
9
|
+
const planCompare_1 = require("../../common/planCompare");
|
|
10
|
+
const refreshCache_1 = require("../../common/refreshCache");
|
|
11
|
+
const concurrency_1 = require("../../common/concurrency");
|
|
8
12
|
const ownershipTag_1 = require("../ownershipTag");
|
|
9
13
|
const DNS_SUB_RESOURCE_SUFFIXES = ['.dns_verification', '.dns_txt_verification'];
|
|
10
14
|
const isDnsSubResource = (logicalId) => DNS_SUB_RESOURCE_SUFFIXES.some((suffix) => logicalId.endsWith(suffix));
|
|
@@ -14,6 +18,17 @@ const planEventDeletion = (logicalId, definition) => ({
|
|
|
14
18
|
resourceType: 'ALIYUN_APIGW',
|
|
15
19
|
changes: { before: definition },
|
|
16
20
|
});
|
|
21
|
+
const buildDesiredTriggerApiName = (event, trigger, stage) => (0, apigwTypes_1.buildAliyunApigwApiName)(event.name, stage, (0, apigwTypes_1.generateApiKey)(trigger.method, trigger.path));
|
|
22
|
+
const resolveTriggerBackend = (iac, backendRef) => {
|
|
23
|
+
if (!iac) {
|
|
24
|
+
return backendRef;
|
|
25
|
+
}
|
|
26
|
+
const functionDef = (0, iacHelper_1.getIacDefinition)(iac, backendRef);
|
|
27
|
+
if (!functionDef || !(0, iacHelper_1.isFunctionDomain)(functionDef)) {
|
|
28
|
+
return backendRef;
|
|
29
|
+
}
|
|
30
|
+
return functionDef.name;
|
|
31
|
+
};
|
|
17
32
|
/**
|
|
18
33
|
* Generate plan for API Gateway events
|
|
19
34
|
*/
|
|
@@ -27,7 +42,7 @@ const generateApigwPlan = async (context, state, events, serviceName) => {
|
|
|
27
42
|
return { items };
|
|
28
43
|
}
|
|
29
44
|
const desiredLogicalIds = new Set(events.map((e) => `events.${e.key}`));
|
|
30
|
-
const eventItems = await
|
|
45
|
+
const eventItems = await (0, concurrency_1.mapWithConcurrency)(events, concurrency_1.PLAN_READ_CONCURRENCY, async (event) => {
|
|
31
46
|
const logicalId = `events.${event.key}`;
|
|
32
47
|
const currentState = (0, stateManager_1.getResource)(state, logicalId);
|
|
33
48
|
const groupConfig = (0, apigwTypes_1.eventToApigwGroupConfig)(event, serviceName, context.stage);
|
|
@@ -50,7 +65,7 @@ const generateApigwPlan = async (context, state, events, serviceName) => {
|
|
|
50
65
|
// If a same-named group already exists WITHOUT our ownership tag it
|
|
51
66
|
// may belong to another project — fail fast in the plan instead of
|
|
52
67
|
// letting the executor discover it mid-deploy.
|
|
53
|
-
const remoteGroup = await client.apigw.findApiGroupByName(groupConfig.groupName);
|
|
68
|
+
const remoteGroup = await (0, refreshCache_1.cachedRefreshRead)(context, `apigw.findApiGroupByName:${groupConfig.groupName}`, () => client.apigw.findApiGroupByName(groupConfig.groupName));
|
|
54
69
|
if (remoteGroup?.groupId) {
|
|
55
70
|
if (!(0, ownershipTag_1.isOwnedByStack)(context, logicalId, remoteGroup.tags)) {
|
|
56
71
|
throw new Error(`API group ${groupConfig.groupName} already exists in provider but is not owned by this stack (missing ${ownershipTag_1.OWNERSHIP_TAG_KEY} tag). Refusing to create — resolve manually.`);
|
|
@@ -77,8 +92,12 @@ const generateApigwPlan = async (context, state, events, serviceName) => {
|
|
|
77
92
|
// State exists, check for changes
|
|
78
93
|
try {
|
|
79
94
|
const groupInstance = currentState.instances.find((i) => i.type === 'ALIYUN_APIGW_GROUP');
|
|
95
|
+
const currentDefinition = currentState.definition || {};
|
|
96
|
+
const definitionChanged = !(0, hashUtils_1.attributesEqual)(currentDefinition, desiredDefinition);
|
|
97
|
+
let groupRemoteDiffers = false;
|
|
98
|
+
let triggersDiffer = false;
|
|
80
99
|
if (groupInstance) {
|
|
81
|
-
const remoteGroup = await client.apigw.getApiGroup(groupInstance.id);
|
|
100
|
+
const remoteGroup = await (0, refreshCache_1.cachedRefreshRead)(context, `apigw.getApiGroup:${groupInstance.id}`, () => client.apigw.getApiGroup(groupInstance.id));
|
|
82
101
|
if (!remoteGroup) {
|
|
83
102
|
// Resource in state but not remotely - needs recreate
|
|
84
103
|
return {
|
|
@@ -89,15 +108,64 @@ const generateApigwPlan = async (context, state, events, serviceName) => {
|
|
|
89
108
|
drifted: true,
|
|
90
109
|
};
|
|
91
110
|
}
|
|
111
|
+
// Issue #234 Phase 1: a local config change already forces update, so
|
|
112
|
+
// the live cloud is only probed when state == config — a console edit
|
|
113
|
+
// to the group/trigger then surfaces as update + drifted, and a read
|
|
114
|
+
// failure cannot degrade a config-driven update into a create.
|
|
115
|
+
// Domain/log stay existence-only in Phase 0-2 — never compared live.
|
|
116
|
+
if (!definitionChanged) {
|
|
117
|
+
const remoteGroupAttrs = (0, apigwTypes_1.cloudApigwGroupToDefinition)(remoteGroup);
|
|
118
|
+
groupRemoteDiffers = (0, planCompare_1.remoteDiffersFromDesired)(remoteGroupAttrs, desiredDefinition);
|
|
119
|
+
if (event.triggers.length > 0) {
|
|
120
|
+
const desiredApis = new Map(event.triggers.map((trigger) => {
|
|
121
|
+
const apiName = buildDesiredTriggerApiName(event, trigger, context.stage);
|
|
122
|
+
return [
|
|
123
|
+
apiName,
|
|
124
|
+
{
|
|
125
|
+
method: trigger.method,
|
|
126
|
+
path: trigger.path,
|
|
127
|
+
backend: resolveTriggerBackend(context.iac, String(trigger.backend)),
|
|
128
|
+
},
|
|
129
|
+
];
|
|
130
|
+
}));
|
|
131
|
+
const cloudSummaries = ((await (0, refreshCache_1.cachedRefreshRead)(context, `apigw.listApisByGroup:${groupInstance.id}`, () => client.apigw.listApisByGroup(groupInstance.id))) ?? []);
|
|
132
|
+
const cloudApis = new Map();
|
|
133
|
+
for (const summary of cloudSummaries) {
|
|
134
|
+
// Only reconcile expected APIs — the executor never touches
|
|
135
|
+
// same-group APIs outside our derived name set (buildCloudInstance
|
|
136
|
+
// in apigwResource), so foreign/console-added APIs are ignored.
|
|
137
|
+
if (!desiredApis.has(summary.apiName)) {
|
|
138
|
+
continue;
|
|
139
|
+
}
|
|
140
|
+
const apiInfo = await (0, refreshCache_1.cachedRefreshRead)(context, `apigw.getApi:${groupInstance.id}:${summary.apiId}`, () => client.apigw.getApi(groupInstance.id, summary.apiId));
|
|
141
|
+
if (apiInfo) {
|
|
142
|
+
const attrs = (0, apigwTypes_1.cloudApigwApiToTriggerAttributes)(apiInfo);
|
|
143
|
+
if (attrs.apiName) {
|
|
144
|
+
cloudApis.set(attrs.apiName, attrs);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
// A desired API absent from the cloud is recreated by the executor.
|
|
149
|
+
triggersDiffer = [...desiredApis.keys()].sort().some((apiName) => {
|
|
150
|
+
const desired = desiredApis.get(apiName);
|
|
151
|
+
const cloud = cloudApis.get(apiName);
|
|
152
|
+
if (!desired || !cloud) {
|
|
153
|
+
return true;
|
|
154
|
+
}
|
|
155
|
+
return (desired.method !== cloud.method ||
|
|
156
|
+
desired.path !== cloud.path ||
|
|
157
|
+
desired.backend !== cloud.backend);
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
}
|
|
92
161
|
}
|
|
93
|
-
|
|
94
|
-
const definitionChanged = !(0, hashUtils_1.attributesEqual)(currentDefinition, desiredDefinition);
|
|
95
|
-
if (definitionChanged) {
|
|
162
|
+
if (definitionChanged || groupRemoteDiffers || triggersDiffer) {
|
|
96
163
|
return {
|
|
97
164
|
logicalId,
|
|
98
165
|
action: 'update',
|
|
99
166
|
resourceType: 'ALIYUN_APIGW',
|
|
100
167
|
changes: { before: currentDefinition, after: desiredDefinition },
|
|
168
|
+
drifted: true,
|
|
101
169
|
};
|
|
102
170
|
}
|
|
103
171
|
return { logicalId, action: 'noop', resourceType: 'ALIYUN_APIGW' };
|
|
@@ -110,7 +178,7 @@ const generateApigwPlan = async (context, state, events, serviceName) => {
|
|
|
110
178
|
changes: { before: currentState.definition, after: desiredDefinition },
|
|
111
179
|
};
|
|
112
180
|
}
|
|
113
|
-
})
|
|
181
|
+
});
|
|
114
182
|
// Find resources in state that are no longer in config
|
|
115
183
|
const allStates = (0, stateManager_1.getAllResources)(state);
|
|
116
184
|
const deletionItems = Object.entries(allStates)
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.extractEventDomainDefinition = exports.buildEventLogSnapshot = exports.inferProtocolConfig = exports.extractApigwDeploymentDefinition = exports.extractApigwApiDefinition = exports.extractApigwGroupDefinition = exports.triggerToApigwApiConfig = exports.eventToApigwGroupConfig = exports.normalizeRoleArnResolver = exports.generateApiKey = exports.buildAliyunApigwApiName = void 0;
|
|
3
|
+
exports.cloudGatewayLogToLogConfig = exports.cloudApigwCustomDomainToDefinition = exports.cloudApigwApiToTriggerAttributes = exports.cloudApigwGroupToDefinition = exports.extractEventDomainDefinition = exports.buildEventLogSnapshot = exports.inferProtocolConfig = exports.extractApigwDeploymentDefinition = exports.extractApigwApiDefinition = exports.extractApigwGroupDefinition = exports.triggerToApigwApiConfig = exports.eventToApigwGroupConfig = exports.normalizeRoleArnResolver = exports.generateApiKey = exports.buildAliyunApigwApiName = void 0;
|
|
4
4
|
const common_1 = require("../../common");
|
|
5
5
|
const lang_1 = require("../../lang");
|
|
6
6
|
const ownershipTag_1 = require("../ownershipTag");
|
|
@@ -269,3 +269,69 @@ const extractEventDomainDefinition = (domain) => {
|
|
|
269
269
|
return definition;
|
|
270
270
|
};
|
|
271
271
|
exports.extractEventDomainDefinition = extractEventDomainDefinition;
|
|
272
|
+
// Cloud response normalizers (issue #234): pure field mappings from already
|
|
273
|
+
// fetched cloud objects back to the desired/config extract shapes. Never call a
|
|
274
|
+
// client API; Wave C diffs these against the desired definitions and only
|
|
275
|
+
// compares keys both sides declare, so omitting config-only or unreadable keys
|
|
276
|
+
// here prevents phantom drift.
|
|
277
|
+
/**
|
|
278
|
+
* Cloud-side counterpart of extractApigwGroupDefinition: maps an ApigwGroupInfo
|
|
279
|
+
* to the same {groupName, description, basePath} shape the planner diffs.
|
|
280
|
+
*/
|
|
281
|
+
const cloudApigwGroupToDefinition = (group) => {
|
|
282
|
+
return {
|
|
283
|
+
groupName: group.groupName ?? null,
|
|
284
|
+
description: group.description ?? null,
|
|
285
|
+
basePath: group.basePath ?? null,
|
|
286
|
+
};
|
|
287
|
+
};
|
|
288
|
+
exports.cloudApigwGroupToDefinition = cloudApigwGroupToDefinition;
|
|
289
|
+
/**
|
|
290
|
+
* Cloud-side counterpart of a desired trigger {method, path, backend}: the API's
|
|
291
|
+
* recorded apiName plus the request method/path and the FunctionCompute backend
|
|
292
|
+
* name. Fields with no clear cloud value stay undefined (never invented).
|
|
293
|
+
*/
|
|
294
|
+
const cloudApigwApiToTriggerAttributes = (api) => {
|
|
295
|
+
return {
|
|
296
|
+
apiName: api.apiName ?? '',
|
|
297
|
+
method: api.requestConfig?.requestHttpMethod,
|
|
298
|
+
path: api.requestConfig?.requestPath,
|
|
299
|
+
backend: api.serviceConfig?.functionComputeConfig?.functionName,
|
|
300
|
+
};
|
|
301
|
+
};
|
|
302
|
+
exports.cloudApigwApiToTriggerAttributes = cloudApigwApiToTriggerAttributes;
|
|
303
|
+
/**
|
|
304
|
+
* Cloud-side counterpart of extractEventDomainDefinition restricted to the keys
|
|
305
|
+
* the cloud reliably reports (domainName + certificateId). wwwBindApex,
|
|
306
|
+
* protocol, certificate bodies and cdn* have no cloud source and are omitted so
|
|
307
|
+
* they can never trigger phantom drift. Undefined when the item has no
|
|
308
|
+
* domainName to key on.
|
|
309
|
+
*/
|
|
310
|
+
const cloudApigwCustomDomainToDefinition = (domain) => {
|
|
311
|
+
if (!domain.domainName) {
|
|
312
|
+
return undefined;
|
|
313
|
+
}
|
|
314
|
+
return {
|
|
315
|
+
domainName: domain.domainName,
|
|
316
|
+
certificateId: domain.certificateId ?? null,
|
|
317
|
+
};
|
|
318
|
+
};
|
|
319
|
+
exports.cloudApigwCustomDomainToDefinition = cloudApigwCustomDomainToDefinition;
|
|
320
|
+
/**
|
|
321
|
+
* Cloud-side counterpart of buildEventLogSnapshot: maps the region-wide PROVIDER
|
|
322
|
+
* gateway log config into the snapshot shape. Undefined when no PROVIDER config
|
|
323
|
+
* exists (describeGatewayLogConfig returned null or an empty config).
|
|
324
|
+
*/
|
|
325
|
+
const cloudGatewayLogToLogConfig = (log) => {
|
|
326
|
+
if (!log || log.logType == null || log.logType === '') {
|
|
327
|
+
return undefined;
|
|
328
|
+
}
|
|
329
|
+
return {
|
|
330
|
+
logEnabled: log.logType === 'PROVIDER',
|
|
331
|
+
logConfig: {
|
|
332
|
+
project: log.slsProject ?? '',
|
|
333
|
+
logstore: log.slsLogStore ?? '',
|
|
334
|
+
},
|
|
335
|
+
};
|
|
336
|
+
};
|
|
337
|
+
exports.cloudGatewayLogToLogConfig = cloudGatewayLogToLogConfig;
|
|
@@ -2,10 +2,12 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.generateDatabasePlan = void 0;
|
|
4
4
|
const aliyunClient_1 = require("../../common/aliyunClient");
|
|
5
|
+
const refreshCache_1 = require("../../common/refreshCache");
|
|
6
|
+
const concurrency_1 = require("../../common/concurrency");
|
|
5
7
|
const rdsTypes_1 = require("./rdsTypes");
|
|
6
8
|
const esServerlessTypes_1 = require("./esServerlessTypes");
|
|
7
9
|
const stateManager_1 = require("../../common/stateManager");
|
|
8
|
-
const
|
|
10
|
+
const refreshPlanner_1 = require("../../common/refreshPlanner");
|
|
9
11
|
const ownershipTag_1 = require("../ownershipTag");
|
|
10
12
|
const toOwnershipTagShape = (tags) => tags?.map((t) => ({ Key: t.key, Value: t.value }));
|
|
11
13
|
const planDatabaseDeletion = (logicalId, definition, resourceType) => ({
|
|
@@ -61,71 +63,33 @@ const generateDatabasePlan = async (context, state, databases) => {
|
|
|
61
63
|
}
|
|
62
64
|
const desiredLogicalIds = new Set(aliyunDatabases.map((db) => `databases.${db.key}`));
|
|
63
65
|
const client = (0, aliyunClient_1.createAliyunClient)(context);
|
|
64
|
-
const databaseItems = await
|
|
66
|
+
const databaseItems = await (0, concurrency_1.mapWithConcurrency)(aliyunDatabases, concurrency_1.PLAN_READ_CONCURRENCY, async (database) => {
|
|
65
67
|
const logicalId = `databases.${database.key}`;
|
|
66
68
|
const currentState = (0, stateManager_1.getResource)(state, logicalId);
|
|
67
69
|
const resourceType = getResourceType(database);
|
|
68
70
|
const desiredDefinition = getDesiredDefinition(database);
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
let remoteInstance = null;
|
|
92
|
-
if (resourceType === 'ALIYUN_ES_SERVERLESS') {
|
|
93
|
-
remoteInstance = instanceId ? await client.es.getApp(instanceId) : null;
|
|
94
|
-
}
|
|
95
|
-
else if (resourceType === 'ALIYUN_RDS_SERVERLESS') {
|
|
96
|
-
remoteInstance = instanceId ? await client.rds.getInstance(instanceId) : null;
|
|
97
|
-
}
|
|
98
|
-
if (!remoteInstance) {
|
|
99
|
-
return {
|
|
100
|
-
logicalId,
|
|
101
|
-
action: 'create',
|
|
102
|
-
resourceType,
|
|
103
|
-
changes: { before: currentState.definition, after: desiredDefinition },
|
|
104
|
-
drifted: true,
|
|
105
|
-
};
|
|
106
|
-
}
|
|
107
|
-
const currentDefinition = currentState.definition || {};
|
|
108
|
-
const definitionChanged = !(0, hashUtils_1.attributesEqual)(currentDefinition, desiredDefinition);
|
|
109
|
-
if (definitionChanged) {
|
|
110
|
-
return {
|
|
111
|
-
logicalId,
|
|
112
|
-
action: 'update',
|
|
113
|
-
resourceType,
|
|
114
|
-
changes: { before: currentDefinition, after: desiredDefinition },
|
|
115
|
-
drifted: true,
|
|
116
|
-
};
|
|
117
|
-
}
|
|
118
|
-
return { logicalId, action: 'noop', resourceType };
|
|
119
|
-
}
|
|
120
|
-
catch {
|
|
121
|
-
return {
|
|
122
|
-
logicalId,
|
|
123
|
-
action: 'create',
|
|
124
|
-
resourceType,
|
|
125
|
-
changes: { before: currentState.definition, after: desiredDefinition },
|
|
126
|
-
};
|
|
127
|
-
}
|
|
128
|
-
}));
|
|
71
|
+
const instanceId = currentState?.metadata?.instanceId ||
|
|
72
|
+
currentState?.instances?.[0]?.id;
|
|
73
|
+
const isEs = resourceType === 'ALIYUN_ES_SERVERLESS';
|
|
74
|
+
return (0, refreshPlanner_1.planRefreshedResource)({
|
|
75
|
+
logicalId,
|
|
76
|
+
resourceType,
|
|
77
|
+
currentState,
|
|
78
|
+
desiredDefinition,
|
|
79
|
+
probeRead: () => isEs
|
|
80
|
+
? (0, refreshCache_1.cachedRefreshRead)(context, `es.getApp:${database.name}`, () => client.es.getApp(database.name))
|
|
81
|
+
: (0, refreshCache_1.cachedRefreshRead)(context, `rds.getInstanceByName:${database.name}`, () => client.rds.getInstanceByName(database.name)),
|
|
82
|
+
read: () => !instanceId
|
|
83
|
+
? Promise.resolve(null)
|
|
84
|
+
: isEs
|
|
85
|
+
? (0, refreshCache_1.cachedRefreshRead)(context, `es.getApp:${instanceId}`, () => client.es.getApp(instanceId))
|
|
86
|
+
: (0, refreshCache_1.cachedRefreshRead)(context, `rds.getInstance:${instanceId}`, () => client.rds.getInstance(instanceId)),
|
|
87
|
+
isOwned: (remote) => (0, ownershipTag_1.isOwnedByStack)(context, logicalId, toOwnershipTagShape(remote.tags)),
|
|
88
|
+
foreignError: () => new Error(`${resourceType} ${database.name} already exists in provider but is not owned by this stack (missing ${ownershipTag_1.OWNERSHIP_TAG_KEY} tag). Refusing to create — resolve manually.`),
|
|
89
|
+
cloudToDefinition: (remote) => isEs ? (0, esServerlessTypes_1.cloudEsToDefinition)(remote) : (0, rdsTypes_1.cloudRdsToDefinition)(remote),
|
|
90
|
+
refresh: context.refresh,
|
|
91
|
+
});
|
|
92
|
+
});
|
|
129
93
|
const allStates = (0, stateManager_1.getAllResources)(state);
|
|
130
94
|
const deletionItems = Object.entries(allStates)
|
|
131
95
|
.filter(([logicalId, resourceState]) => {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.extractEsDefinition = exports.databaseToEsConfig = void 0;
|
|
3
|
+
exports.cloudEsToDefinition = exports.extractEsDefinition = exports.databaseToEsConfig = void 0;
|
|
4
4
|
// Map database versions to ES versions
|
|
5
5
|
const esVersionMap = new Map([
|
|
6
6
|
[
|
|
@@ -139,3 +139,52 @@ const extractEsDefinition = (config) => {
|
|
|
139
139
|
};
|
|
140
140
|
};
|
|
141
141
|
exports.extractEsDefinition = extractEsDefinition;
|
|
142
|
+
const cloudEsToDefinition = (info) => ({
|
|
143
|
+
...(info.appName === undefined ? {} : { appName: info.appName }),
|
|
144
|
+
...(info.version === undefined ? {} : { appVersion: info.version }),
|
|
145
|
+
...(info.description === undefined ? {} : { description: info.description }),
|
|
146
|
+
...(info.chargeType === undefined ? {} : { chargeType: info.chargeType }),
|
|
147
|
+
...(info.network === undefined
|
|
148
|
+
? {}
|
|
149
|
+
: {
|
|
150
|
+
network: info.network.map((network) => ({
|
|
151
|
+
type: network.type ?? null,
|
|
152
|
+
enabled: network.enabled ?? null,
|
|
153
|
+
domain: network.domain ?? null,
|
|
154
|
+
port: network.port ?? null,
|
|
155
|
+
whiteIpGroup: network.whiteIpGroup
|
|
156
|
+
? network.whiteIpGroup.map((group) => ({
|
|
157
|
+
groupName: group.groupName ?? null,
|
|
158
|
+
ips: group.ips ?? [],
|
|
159
|
+
}))
|
|
160
|
+
: null,
|
|
161
|
+
})),
|
|
162
|
+
}),
|
|
163
|
+
...(info.privateNetwork === undefined
|
|
164
|
+
? {}
|
|
165
|
+
: {
|
|
166
|
+
privateNetwork: info.privateNetwork.map((network) => ({
|
|
167
|
+
type: network.type ?? null,
|
|
168
|
+
enabled: network.enabled ?? null,
|
|
169
|
+
domain: network.domain ?? null,
|
|
170
|
+
port: network.port ?? null,
|
|
171
|
+
vpcId: network.vpcId ?? null,
|
|
172
|
+
pvlEndpointId: network.pvlEndpointId ?? null,
|
|
173
|
+
whiteIpGroup: network.whiteIpGroup
|
|
174
|
+
? network.whiteIpGroup.map((group) => ({
|
|
175
|
+
groupName: group.groupName ?? null,
|
|
176
|
+
ips: group.ips ?? [],
|
|
177
|
+
}))
|
|
178
|
+
: null,
|
|
179
|
+
})),
|
|
180
|
+
}),
|
|
181
|
+
...(info.tags === undefined
|
|
182
|
+
? {}
|
|
183
|
+
: {
|
|
184
|
+
tags: info.tags.map((tag) => ({
|
|
185
|
+
key: tag.key ?? null,
|
|
186
|
+
value: tag.value ?? null,
|
|
187
|
+
})),
|
|
188
|
+
}),
|
|
189
|
+
});
|
|
190
|
+
exports.cloudEsToDefinition = cloudEsToDefinition;
|
|
@@ -13,9 +13,11 @@ const executeCreateAction = async (context, fn, currentState) => {
|
|
|
13
13
|
common_1.logger.info(lang_1.lang.__('RESOURCE_CREATED', { resourceType: 'function', name: fn.name }));
|
|
14
14
|
return newState;
|
|
15
15
|
};
|
|
16
|
-
const executeUpdateAction = async (context, fn, currentState) => {
|
|
16
|
+
const executeUpdateAction = async (context, fn, currentState, drifted) => {
|
|
17
17
|
common_1.logger.info(lang_1.lang.__('UPDATING_RESOURCE', { resourceType: 'function', name: fn.name }));
|
|
18
|
-
|
|
18
|
+
// A drifted plan item means the cloud left the config: force the config
|
|
19
|
+
// re-push even when state-vs-desired sees no change.
|
|
20
|
+
const newState = await (0, fc3Resource_1.updateResource)(context, fn, currentState, { force: drifted === true });
|
|
19
21
|
common_1.logger.info(lang_1.lang.__('RESOURCE_UPDATED', { resourceType: 'function', name: fn.name }));
|
|
20
22
|
return newState;
|
|
21
23
|
};
|
|
@@ -42,7 +44,7 @@ const executeSingleItem = async (context, item, functionsMap, currentState) => {
|
|
|
42
44
|
if (!fn) {
|
|
43
45
|
throw new Error(`Function not found for logical ID: ${item.logicalId}`);
|
|
44
46
|
}
|
|
45
|
-
return executeUpdateAction(context, fn, currentState);
|
|
47
|
+
return executeUpdateAction(context, fn, currentState, item.drifted);
|
|
46
48
|
}
|
|
47
49
|
case 'delete': {
|
|
48
50
|
const state = (0, stateManager_1.getResource)(currentState, item.logicalId);
|