@geek-fun/serverlessinsight 0.8.3 → 0.8.5
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 +3 -2
- package/.serverlessinsight/state-iam-test-app-iam-test-service.json.backup +21 -2
- package/.serverlessinsight/state-insight-poc-deploy-app-insight-poc-deploy.json.backup +46 -35
- package/.serverlessinsight/state-insight-poc-destroy-app-insight-poc-destroy.json.backup +3 -2
- package/.serverlessinsight/state-insight-volc-app-insight-volc.json.backup +63 -23
- package/CHANGELOG.md +55 -0
- package/README.md +1 -1
- package/dist/package.json +26 -25
- package/dist/src/common/aliyunClient/apigwOperations.js +36 -0
- package/dist/src/common/aliyunClient/fc3Operations.js +7 -0
- package/dist/src/common/aliyunClient/slsOperations.js +35 -3
- package/dist/src/common/constants.js +5 -1
- package/dist/src/common/index.js +2 -0
- package/dist/src/common/nameBuilder.js +80 -0
- package/dist/src/common/providerNames.js +54 -0
- package/dist/src/common/runtimeMapper.js +25 -4
- package/dist/src/common/stateBackend/remoteStateBackend.js +4 -1
- package/dist/src/common/stateManager.js +52 -2
- package/dist/src/common/tencentClient/clsOperations.js +137 -0
- package/dist/src/common/tencentClient/index.js +21 -1
- package/dist/src/common/tencentClient/scfOperations.js +11 -0
- package/dist/src/common/volcengineClient/iamOperations.js +33 -0
- package/dist/src/common/volcengineClient/tlsOperations.js +84 -1
- package/dist/src/lang/en.js +29 -1
- package/dist/src/lang/zh-CN.js +29 -1
- package/dist/src/parser/index.js +2 -1
- package/dist/src/stack/aliyunStack/apigwPlanner.js +2 -0
- package/dist/src/stack/aliyunStack/apigwResource.js +118 -1
- package/dist/src/stack/aliyunStack/apigwTypes.js +32 -20
- package/dist/src/stack/aliyunStack/destroyer.js +25 -0
- package/dist/src/stack/aliyunStack/fc3Resource.js +91 -32
- package/dist/src/stack/aliyunStack/sharedLogProject.js +137 -0
- package/dist/src/stack/ownershipTag.js +19 -1
- package/dist/src/stack/scfStack/destroyer.js +13 -0
- package/dist/src/stack/scfStack/scfPlanner.js +9 -1
- package/dist/src/stack/scfStack/scfResource.js +205 -13
- package/dist/src/stack/scfStack/scfTypes.js +6 -0
- package/dist/src/stack/scfStack/sharedLogset.js +126 -0
- package/dist/src/stack/volcengineStack/apigwResource.js +64 -48
- package/dist/src/stack/volcengineStack/apigwTypes.js +10 -7
- package/dist/src/stack/volcengineStack/destroyer.js +12 -0
- package/dist/src/stack/volcengineStack/sharedLogProject.js +190 -0
- package/dist/src/stack/volcengineStack/vefaasPlanner.js +20 -13
- package/dist/src/stack/volcengineStack/vefaasResource.js +76 -76
- package/dist/src/types/domains/state.js +3 -0
- package/dist/src/validator/bucketSchema.js +3 -5
- package/dist/src/validator/eventSchema.js +7 -4
- package/dist/src/validator/functionSchema.js +3 -2
- package/dist/src/validator/iacSchema.js +11 -4
- package/dist/src/validator/rootSchema.js +27 -0
- package/dist/src/validator/semanticValidation.js +122 -0
- package/dist/src/validator/tableschema.js +2 -0
- package/dist/src/validator/templateRefSchema.js +23 -3
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +26 -25
- package/samples/aliyun-poc-fc-gpu.yml +2 -2
- package/samples/aliyun-poc-table.yml +1 -1
- package/samples/volcengine-poc-advanced.yml +4 -8
- package/samples/volcengine-poc-api.yml +1 -1
- package/samples/volcengine-poc-function.yml +1 -1
- package/samples/volcengine-poc-vpc.yml +3 -7
|
@@ -15,6 +15,7 @@ const logger_1 = require("../../common/logger");
|
|
|
15
15
|
const lang_1 = require("../../lang");
|
|
16
16
|
const ownershipTag_1 = require("../ownershipTag");
|
|
17
17
|
const alreadyExists_1 = require("../alreadyExists");
|
|
18
|
+
const sharedLogProject_1 = require("./sharedLogProject");
|
|
18
19
|
const RECOVERY_GET_FUNCTION_DELAY_MS = 1500;
|
|
19
20
|
const delay = async (ms) => {
|
|
20
21
|
await new Promise((resolve) => {
|
|
@@ -144,10 +145,11 @@ const buildHttpTriggerConfig = (trigger) => {
|
|
|
144
145
|
...(disableURLInternet !== undefined ? { disableURLInternet } : {}),
|
|
145
146
|
};
|
|
146
147
|
};
|
|
147
|
-
const createDependentResources = async (context, fn, serviceName, existingInstances = []) => {
|
|
148
|
+
const createDependentResources = async (context, fn, serviceName, existingInstances = [], state) => {
|
|
148
149
|
const client = (0, aliyunClient_1.createAliyunClient)(context);
|
|
149
150
|
const instances = [];
|
|
150
151
|
let logConfig;
|
|
152
|
+
let sharedProject;
|
|
151
153
|
let securityGroup;
|
|
152
154
|
let nasConfig;
|
|
153
155
|
const hasSlsProject = existingInstances.some((i) => i.type === 'ALIYUN_SLS_PROJECT');
|
|
@@ -165,29 +167,20 @@ const createDependentResources = async (context, fn, serviceName, existingInstan
|
|
|
165
167
|
}
|
|
166
168
|
}
|
|
167
169
|
else {
|
|
168
|
-
const
|
|
169
|
-
const
|
|
170
|
-
logger_1.logger.info(lang_1.lang.__('CREATING_SLS_PROJECT', { projectName }));
|
|
171
|
-
const project = await client.sls.createProject(projectName);
|
|
172
|
-
instances.push({ type: 'ALIYUN_SLS_PROJECT', id: projectName, attributes: { ...project } });
|
|
173
|
-
logger_1.logger.info(lang_1.lang.__('CREATING_SLS_LOGSTORE', { logstoreName }));
|
|
174
|
-
const logstore = await client.sls.createLogstore(projectName, logstoreName);
|
|
170
|
+
const shared = await (0, sharedLogProject_1.ensureSharedSlsProject)(context, client, state);
|
|
171
|
+
const logstore = await (0, sharedLogProject_1.ensureFunctionLogstore)(context, client, shared.projectName);
|
|
175
172
|
instances.push({
|
|
176
173
|
type: 'ALIYUN_SLS_LOGSTORE',
|
|
177
|
-
id: `${projectName}/${logstoreName}`,
|
|
178
|
-
attributes: {
|
|
174
|
+
id: `${shared.projectName}/${logstore.logstoreName}`,
|
|
175
|
+
attributes: { logstoreName: logstore.logstoreName },
|
|
179
176
|
});
|
|
180
|
-
logger_1.logger.info(lang_1.lang.__('CREATING_SLS_INDEX', { logstoreName }));
|
|
181
|
-
const index = await client.sls.createIndex(projectName, logstoreName);
|
|
182
177
|
instances.push({
|
|
183
178
|
type: 'ALIYUN_SLS_INDEX',
|
|
184
|
-
id: `${projectName}/${logstoreName}/index`,
|
|
185
|
-
attributes: {
|
|
179
|
+
id: `${shared.projectName}/${logstore.logstoreName}/index`,
|
|
180
|
+
attributes: { projectName: shared.projectName, logstoreName: logstore.logstoreName },
|
|
186
181
|
});
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
await client.sls.waitForLogstore(projectName, logstoreName);
|
|
190
|
-
logConfig = { project: projectName, logstore: logstoreName };
|
|
182
|
+
logConfig = { project: shared.projectName, logstore: logstore.logstoreName };
|
|
183
|
+
sharedProject = (0, sharedLogProject_1.buildSharedProjectResourceState)(context, shared);
|
|
191
184
|
}
|
|
192
185
|
}
|
|
193
186
|
const iamConfig = fn.iam?.role;
|
|
@@ -319,6 +312,7 @@ const createDependentResources = async (context, fn, serviceName, existingInstan
|
|
|
319
312
|
role,
|
|
320
313
|
securityGroup,
|
|
321
314
|
nasConfig,
|
|
315
|
+
sharedProject,
|
|
322
316
|
instances,
|
|
323
317
|
};
|
|
324
318
|
};
|
|
@@ -366,8 +360,9 @@ const deleteDependentResources = async (context, instances) => {
|
|
|
366
360
|
break;
|
|
367
361
|
}
|
|
368
362
|
case 'ALIYUN_SLS_PROJECT':
|
|
369
|
-
|
|
370
|
-
|
|
363
|
+
// Shared/legacy SLS projects are never deleted at resource level — the
|
|
364
|
+
// destroyer releases the shared project once unused (legacy orphans are
|
|
365
|
+
// manual cleanup, see issue #214).
|
|
371
366
|
break;
|
|
372
367
|
case 'ALIYUN_FC3_HTTP_TRIGGER':
|
|
373
368
|
// HTTP trigger deletion requires functionName which is not available here.
|
|
@@ -389,7 +384,10 @@ const createResource = async (context, fn, state) => {
|
|
|
389
384
|
const logicalId = `functions.${fn.key}`;
|
|
390
385
|
const existingResourceState = (0, common_1.getResource)(state, logicalId);
|
|
391
386
|
const existingDependentInstances = (existingResourceState?.instances ?? []).filter((i) => i.type !== 'ALIYUN_FC3_FUNCTION');
|
|
392
|
-
const dependentResources = await createDependentResources(context, fn, serviceName, existingDependentInstances);
|
|
387
|
+
const dependentResources = await createDependentResources(context, fn, serviceName, existingDependentInstances, state);
|
|
388
|
+
const stateWithSharedProject = dependentResources.sharedProject
|
|
389
|
+
? (0, common_1.setSharedResource)(state, context.stage, sharedLogProject_1.SHARED_LOG_PROJECT_KEY, dependentResources.sharedProject)
|
|
390
|
+
: state;
|
|
393
391
|
let config = (0, fc3Types_1.functionToFc3Config)(fn);
|
|
394
392
|
config = {
|
|
395
393
|
...config,
|
|
@@ -456,7 +454,7 @@ const createResource = async (context, fn, state) => {
|
|
|
456
454
|
lastUpdated: new Date().toISOString(),
|
|
457
455
|
status: 'tainted',
|
|
458
456
|
};
|
|
459
|
-
const stateAfterDependents = (0, common_1.setResource)(
|
|
457
|
+
const stateAfterDependents = (0, common_1.setResource)(stateWithSharedProject, logicalId, taintedResourceState);
|
|
460
458
|
const client = (0, aliyunClient_1.createAliyunClient)(context);
|
|
461
459
|
const isTainted = existingResourceState?.status === 'tainted';
|
|
462
460
|
const existingFunctionOnRetry = isTainted ? await client.fc3.getFunction(fn.name) : null;
|
|
@@ -591,27 +589,47 @@ const updateResource = async (context, fn, state) => {
|
|
|
591
589
|
const logicalId = `functions.${fn.key}`;
|
|
592
590
|
const existingState = (0, common_1.getResource)(state, logicalId);
|
|
593
591
|
const existingInstances = (existingState?.instances ?? []);
|
|
594
|
-
const hasSlsResources = existingInstances.some((i) => i.type === 'ALIYUN_SLS_PROJECT'
|
|
592
|
+
const hasSlsResources = existingInstances.some((i) => i.type === 'ALIYUN_SLS_PROJECT' ||
|
|
593
|
+
i.type === 'ALIYUN_SLS_LOGSTORE' ||
|
|
594
|
+
i.type === 'ALIYUN_SLS_INDEX');
|
|
595
595
|
const hasRamRole = existingInstances.some((i) => i.type === 'ALIYUN_RAM_ROLE');
|
|
596
596
|
const hasSecurityGroup = existingInstances.some((i) => i.type === 'ALIYUN_ECS_SECURITY_GROUP');
|
|
597
597
|
const hasNasResources = existingInstances.some((i) => i.type === 'ALIYUN_NAS_FILE_SYSTEM');
|
|
598
598
|
const client = (0, aliyunClient_1.createAliyunClient)(context);
|
|
599
599
|
const newDependentInstances = [];
|
|
600
600
|
let logConfig;
|
|
601
|
+
let sharedProjectState;
|
|
601
602
|
let role;
|
|
602
603
|
let securityGroup;
|
|
603
604
|
let nasConfig;
|
|
605
|
+
// SLS dependent-instance types to drop from the resulting state when
|
|
606
|
+
// function logging is disabled (true -> false).
|
|
607
|
+
const droppedSlsDependentTypes = [];
|
|
608
|
+
// Set when the shared project is released (deleted or gone) so its stale
|
|
609
|
+
// shared-state entry is removed from the returned state.
|
|
610
|
+
let releasedSharedProject = false;
|
|
604
611
|
if (fn.log && !hasSlsResources) {
|
|
605
|
-
const deps = await createDependentResources(context, { ...fn, network: undefined, storage: { ...fn.storage, nas: undefined } }, serviceName);
|
|
612
|
+
const deps = await createDependentResources(context, { ...fn, network: undefined, storage: { ...fn.storage, nas: undefined } }, serviceName, undefined, state);
|
|
606
613
|
logConfig = deps.logConfig;
|
|
607
614
|
newDependentInstances.push(...deps.instances.filter((i) => i.type.startsWith('ALIYUN_SLS_')));
|
|
615
|
+
if (deps.sharedProject) {
|
|
616
|
+
sharedProjectState = deps.sharedProject;
|
|
617
|
+
}
|
|
608
618
|
}
|
|
609
619
|
else if (hasSlsResources) {
|
|
610
|
-
const slsProjectInstance = existingInstances.find((i) => i.type === 'ALIYUN_SLS_PROJECT');
|
|
611
620
|
const slsLogstoreInstance = existingInstances.find((i) => i.type === 'ALIYUN_SLS_LOGSTORE');
|
|
612
|
-
if (
|
|
613
|
-
|
|
614
|
-
|
|
621
|
+
if (fn.log) {
|
|
622
|
+
if (slsLogstoreInstance) {
|
|
623
|
+
const [projectName, logstoreName] = slsLogstoreInstance.id.split('/');
|
|
624
|
+
logConfig = { project: projectName, logstore: logstoreName };
|
|
625
|
+
}
|
|
626
|
+
}
|
|
627
|
+
else {
|
|
628
|
+
// Logging disabled: the owned index + logstore are deleted from the
|
|
629
|
+
// provider after the function log config is cleared, and the SLS
|
|
630
|
+
// instances are dropped from state. The shared project is released by
|
|
631
|
+
// the destroyer once no logstores remain (issue #214).
|
|
632
|
+
droppedSlsDependentTypes.push('ALIYUN_SLS_INDEX', 'ALIYUN_SLS_LOGSTORE', 'ALIYUN_SLS_PROJECT');
|
|
615
633
|
}
|
|
616
634
|
}
|
|
617
635
|
const newIamRole = fn.iam?.role;
|
|
@@ -620,7 +638,7 @@ const updateResource = async (context, fn, state) => {
|
|
|
620
638
|
role = { roleName: '', arn: newIamRole };
|
|
621
639
|
}
|
|
622
640
|
else if (!hasRamRole) {
|
|
623
|
-
const deps = await createDependentResources(context, { ...fn, log: false, network: undefined, storage: { ...fn.storage, nas: undefined } }, serviceName);
|
|
641
|
+
const deps = await createDependentResources(context, { ...fn, log: false, network: undefined, storage: { ...fn.storage, nas: undefined } }, serviceName, undefined, state);
|
|
624
642
|
role = deps.role;
|
|
625
643
|
newDependentInstances.push(...deps.instances.filter((i) => i.type === 'ALIYUN_RAM_ROLE'));
|
|
626
644
|
}
|
|
@@ -660,7 +678,7 @@ const updateResource = async (context, fn, state) => {
|
|
|
660
678
|
}
|
|
661
679
|
}
|
|
662
680
|
if (fn.network && !hasSecurityGroup) {
|
|
663
|
-
const deps = await createDependentResources(context, { ...fn, log: false, storage: { ...fn.storage, nas: undefined } }, serviceName);
|
|
681
|
+
const deps = await createDependentResources(context, { ...fn, log: false, storage: { ...fn.storage, nas: undefined } }, serviceName, undefined, state);
|
|
664
682
|
securityGroup = deps.securityGroup;
|
|
665
683
|
newDependentInstances.push(...deps.instances.filter((i) => i.type === 'ALIYUN_ECS_SECURITY_GROUP'));
|
|
666
684
|
}
|
|
@@ -671,7 +689,7 @@ const updateResource = async (context, fn, state) => {
|
|
|
671
689
|
}
|
|
672
690
|
}
|
|
673
691
|
if (fn.storage?.nas && fn.storage.nas.length > 0 && fn.network && !hasNasResources) {
|
|
674
|
-
const deps = await createDependentResources(context, { ...fn, log: false }, serviceName);
|
|
692
|
+
const deps = await createDependentResources(context, { ...fn, log: false }, serviceName, undefined, state);
|
|
675
693
|
nasConfig = deps.nasConfig;
|
|
676
694
|
newDependentInstances.push(...deps.instances.filter((i) => i.type.startsWith('ALIYUN_NAS_')));
|
|
677
695
|
}
|
|
@@ -741,6 +759,36 @@ const updateResource = async (context, fn, state) => {
|
|
|
741
759
|
const ossCode = await ensureOssCodeUpload(client, codePath, context.region, fn.name);
|
|
742
760
|
await client.fc3.updateFunctionCode(fn.name, codePath, ossCode);
|
|
743
761
|
}
|
|
762
|
+
if (droppedSlsDependentTypes.length > 0) {
|
|
763
|
+
const slsLogstoreInstance = existingInstances.find((i) => i.type === 'ALIYUN_SLS_LOGSTORE');
|
|
764
|
+
if (slsLogstoreInstance) {
|
|
765
|
+
const [projectName, logstoreName] = slsLogstoreInstance.id.split('/');
|
|
766
|
+
logger_1.logger.info(lang_1.lang.__('DELETING_SLS_INDEX', { id: `${projectName}/${logstoreName}` }));
|
|
767
|
+
try {
|
|
768
|
+
await client.sls.deleteIndex(projectName, logstoreName);
|
|
769
|
+
}
|
|
770
|
+
catch {
|
|
771
|
+
// index already gone — best-effort
|
|
772
|
+
}
|
|
773
|
+
logger_1.logger.info(lang_1.lang.__('DELETING_SLS_LOGSTORE', { id: `${projectName}/${logstoreName}` }));
|
|
774
|
+
try {
|
|
775
|
+
await client.sls.deleteLogstore(projectName, logstoreName);
|
|
776
|
+
}
|
|
777
|
+
catch {
|
|
778
|
+
// logstore already gone — best-effort
|
|
779
|
+
}
|
|
780
|
+
}
|
|
781
|
+
// Release the shared project once no logstores remain in the provider; it
|
|
782
|
+
// is retained (with its state entry) while another service or the gateway
|
|
783
|
+
// still references it.
|
|
784
|
+
const shared = (0, common_1.getSharedResource)(state, context.stage, sharedLogProject_1.SHARED_LOG_PROJECT_KEY);
|
|
785
|
+
if (shared) {
|
|
786
|
+
const releaseResult = await (0, sharedLogProject_1.releaseSharedSlsProjectIfUnused)(context, client, shared);
|
|
787
|
+
if (releaseResult !== 'retained') {
|
|
788
|
+
releasedSharedProject = true;
|
|
789
|
+
}
|
|
790
|
+
}
|
|
791
|
+
}
|
|
744
792
|
if (!configChanged && !codeChanged) {
|
|
745
793
|
logger_1.logger.warn(lang_1.lang.__('UPDATING_RESOURCE_WITH_NO_CHANGES', { resourceType: 'function', name: fn.name }));
|
|
746
794
|
}
|
|
@@ -881,6 +929,7 @@ const updateResource = async (context, fn, state) => {
|
|
|
881
929
|
.filter((i) => i.type !== 'ALIYUN_FC3_HTTP_TRIGGER')
|
|
882
930
|
.filter((i) => i.type !== 'ALIYUN_FC3_CUSTOM_DOMAIN')
|
|
883
931
|
.filter((i) => !(typeof fn.iam?.role === 'string' && i.type === 'ALIYUN_RAM_ROLE'))
|
|
932
|
+
.filter((i) => !droppedSlsDependentTypes.includes(i.type))
|
|
884
933
|
.map((i) => {
|
|
885
934
|
const { sid: existingSid, id: existingId, ...rest } = i;
|
|
886
935
|
return {
|
|
@@ -911,7 +960,17 @@ const updateResource = async (context, fn, state) => {
|
|
|
911
960
|
],
|
|
912
961
|
lastUpdated: new Date().toISOString(),
|
|
913
962
|
};
|
|
914
|
-
|
|
963
|
+
let finalState;
|
|
964
|
+
if (sharedProjectState) {
|
|
965
|
+
finalState = (0, common_1.setSharedResource)(state, context.stage, sharedLogProject_1.SHARED_LOG_PROJECT_KEY, sharedProjectState);
|
|
966
|
+
}
|
|
967
|
+
else if (releasedSharedProject) {
|
|
968
|
+
finalState = (0, common_1.removeSharedResource)(state, context.stage, sharedLogProject_1.SHARED_LOG_PROJECT_KEY);
|
|
969
|
+
}
|
|
970
|
+
else {
|
|
971
|
+
finalState = state;
|
|
972
|
+
}
|
|
973
|
+
return (0, common_1.setResource)(finalState, logicalId, resourceState);
|
|
915
974
|
};
|
|
916
975
|
exports.updateResource = updateResource;
|
|
917
976
|
const deleteResource = async (context, functionName, logicalId, state) => {
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ensureGatewayLogstore = exports.ensureFunctionLogstore = exports.releaseSharedSlsProjectIfUnused = exports.isSharedProjectOwnedByApp = exports.adoptSharedSlsProjectState = exports.buildSharedProjectResourceState = exports.ensureSharedSlsProject = exports.resolveSharedProjectName = exports.buildSharedProjectName = exports.SHARED_LOG_PROJECT_KEY = void 0;
|
|
4
|
+
const common_1 = require("../../common");
|
|
5
|
+
const logger_1 = require("../../common/logger");
|
|
6
|
+
const lang_1 = require("../../lang");
|
|
7
|
+
const ownershipTag_1 = require("../ownershipTag");
|
|
8
|
+
/**
|
|
9
|
+
* Issue #214: one shared SLS project per app×stage, tracked in the stage-level
|
|
10
|
+
* `shared` slot under the provider-neutral key 'logs.project'. Function and
|
|
11
|
+
* gateway logstores stay nested under their owning resource inside the shared
|
|
12
|
+
* project; the shared project is released by the destroyer once the provider
|
|
13
|
+
* reports zero remaining logstores.
|
|
14
|
+
*/
|
|
15
|
+
exports.SHARED_LOG_PROJECT_KEY = 'logs.project';
|
|
16
|
+
const buildSharedProjectName = (app, stage) => `${app}-${stage}-sls`;
|
|
17
|
+
exports.buildSharedProjectName = buildSharedProjectName;
|
|
18
|
+
const resolveSharedProjectName = (shared) => {
|
|
19
|
+
const instanceId = shared.instances?.[0]?.id;
|
|
20
|
+
return instanceId ?? shared.definition?.projectName;
|
|
21
|
+
};
|
|
22
|
+
exports.resolveSharedProjectName = resolveSharedProjectName;
|
|
23
|
+
const ensureSharedSlsProject = async (context, client, state) => {
|
|
24
|
+
const shared = state
|
|
25
|
+
? (0, common_1.getSharedResource)(state, context.stage, exports.SHARED_LOG_PROJECT_KEY)
|
|
26
|
+
: undefined;
|
|
27
|
+
const existingName = shared ? (0, exports.resolveSharedProjectName)(shared) : undefined;
|
|
28
|
+
const projectName = existingName ?? (0, exports.buildSharedProjectName)(context.app, context.stage);
|
|
29
|
+
// A local shared-state entry is never trusted blindly: the provider must
|
|
30
|
+
// confirm the project exists and carries this app's shared ownership tag
|
|
31
|
+
// before it is reused. A foreign or untagged project is refused; a stale
|
|
32
|
+
// entry (project gone from provider) falls through to creation.
|
|
33
|
+
const existingProject = await client.sls.getProject(projectName);
|
|
34
|
+
if (existingProject) {
|
|
35
|
+
if (await (0, exports.isSharedProjectOwnedByApp)(context, client, projectName)) {
|
|
36
|
+
if (!existingName) {
|
|
37
|
+
logger_1.logger.info(lang_1.lang.__('SHARED_SLS_PROJECT_ADOPTED', { projectName }));
|
|
38
|
+
}
|
|
39
|
+
return { projectName };
|
|
40
|
+
}
|
|
41
|
+
throw new Error(lang_1.lang.__('SLS_PROJECT_FOREIGN_OWNED', { projectName }));
|
|
42
|
+
}
|
|
43
|
+
logger_1.logger.info(lang_1.lang.__('CREATING_SLS_PROJECT', { projectName }));
|
|
44
|
+
await client.sls.createProject(projectName);
|
|
45
|
+
await client.sls.addTags({
|
|
46
|
+
resourceType: 'project',
|
|
47
|
+
resourceId: projectName,
|
|
48
|
+
tags: [
|
|
49
|
+
{
|
|
50
|
+
key: ownershipTag_1.OWNERSHIP_TAG_KEY,
|
|
51
|
+
value: (0, ownershipTag_1.buildSharedOwnershipTagValue)(context.app, exports.SHARED_LOG_PROJECT_KEY),
|
|
52
|
+
},
|
|
53
|
+
],
|
|
54
|
+
});
|
|
55
|
+
return { projectName };
|
|
56
|
+
};
|
|
57
|
+
exports.ensureSharedSlsProject = ensureSharedSlsProject;
|
|
58
|
+
const buildSharedProjectResourceState = (context, result) => ({
|
|
59
|
+
mode: 'managed',
|
|
60
|
+
region: context.region,
|
|
61
|
+
definition: {
|
|
62
|
+
projectName: result.projectName,
|
|
63
|
+
region: context.region,
|
|
64
|
+
stage: context.stage,
|
|
65
|
+
},
|
|
66
|
+
instances: [
|
|
67
|
+
{
|
|
68
|
+
sid: (0, common_1.buildSid)('aliyun', 'sls_project', context.stage, result.projectName),
|
|
69
|
+
type: 'ALIYUN_SLS_PROJECT',
|
|
70
|
+
id: result.projectName,
|
|
71
|
+
},
|
|
72
|
+
],
|
|
73
|
+
lastUpdated: new Date().toISOString(),
|
|
74
|
+
});
|
|
75
|
+
exports.buildSharedProjectResourceState = buildSharedProjectResourceState;
|
|
76
|
+
const adoptSharedSlsProjectState = (context, projectName) => (0, exports.buildSharedProjectResourceState)(context, { projectName });
|
|
77
|
+
exports.adoptSharedSlsProjectState = adoptSharedSlsProjectState;
|
|
78
|
+
/**
|
|
79
|
+
* Exact app-scope ownership check for an SLS project. The caller must verify
|
|
80
|
+
* the project exists (getProject) before reading its tags; a foreign or
|
|
81
|
+
* untagged project is never adopted (issue #214).
|
|
82
|
+
*/
|
|
83
|
+
const isSharedProjectOwnedByApp = async (context, client, projectName) => {
|
|
84
|
+
const tags = await client.sls.getProjectTags(projectName);
|
|
85
|
+
return (0, ownershipTag_1.isOwnedByApp)(context.app, exports.SHARED_LOG_PROJECT_KEY, tags.map((t) => ({ Key: t.key, Value: t.value })));
|
|
86
|
+
};
|
|
87
|
+
exports.isSharedProjectOwnedByApp = isSharedProjectOwnedByApp;
|
|
88
|
+
const releaseSharedSlsProjectIfUnused = async (context, client, shared) => {
|
|
89
|
+
if (!shared) {
|
|
90
|
+
return 'absent';
|
|
91
|
+
}
|
|
92
|
+
const projectName = (0, exports.resolveSharedProjectName)(shared);
|
|
93
|
+
if (!projectName) {
|
|
94
|
+
return 'absent';
|
|
95
|
+
}
|
|
96
|
+
const project = await client.sls.getProject(projectName);
|
|
97
|
+
if (!project) {
|
|
98
|
+
return 'absent';
|
|
99
|
+
}
|
|
100
|
+
// Only ever delete a project we own. A foreign or untagged project is
|
|
101
|
+
// retained — the tracked entry may be stale and must not be torn down.
|
|
102
|
+
if (!(await (0, exports.isSharedProjectOwnedByApp)(context, client, projectName))) {
|
|
103
|
+
return 'retained';
|
|
104
|
+
}
|
|
105
|
+
const logstores = await client.sls.listLogStores(projectName);
|
|
106
|
+
if (logstores.length > 0) {
|
|
107
|
+
logger_1.logger.info(lang_1.lang.__('SHARED_SLS_PROJECT_IN_USE', {
|
|
108
|
+
projectName,
|
|
109
|
+
count: String(logstores.length),
|
|
110
|
+
}));
|
|
111
|
+
return 'retained';
|
|
112
|
+
}
|
|
113
|
+
await client.sls.deleteProject(projectName);
|
|
114
|
+
return 'deleted';
|
|
115
|
+
};
|
|
116
|
+
exports.releaseSharedSlsProjectIfUnused = releaseSharedSlsProjectIfUnused;
|
|
117
|
+
const ensureLogstoreInSharedProject = async (context, client, projectName, logstoreName) => {
|
|
118
|
+
const existing = await client.sls.getLogstore(projectName, logstoreName);
|
|
119
|
+
if (existing) {
|
|
120
|
+
return { logstoreName };
|
|
121
|
+
}
|
|
122
|
+
logger_1.logger.info(lang_1.lang.__('CREATING_SLS_LOGSTORE', { logstoreName }));
|
|
123
|
+
await client.sls.createLogstore(projectName, logstoreName);
|
|
124
|
+
logger_1.logger.info(lang_1.lang.__('CREATING_SLS_INDEX', { logstoreName }));
|
|
125
|
+
await client.sls.createIndex(projectName, logstoreName);
|
|
126
|
+
logger_1.logger.info(lang_1.lang.__('SLS_LOGSTORE_WAITING', { project: projectName, logstore: logstoreName }));
|
|
127
|
+
await client.sls.waitForLogstore(projectName, logstoreName);
|
|
128
|
+
return { logstoreName };
|
|
129
|
+
};
|
|
130
|
+
const ensureFunctionLogstore = async (context, client, projectName) => {
|
|
131
|
+
return ensureLogstoreInSharedProject(context, client, projectName, `${context.service}-${context.stage}-fn-logs`);
|
|
132
|
+
};
|
|
133
|
+
exports.ensureFunctionLogstore = ensureFunctionLogstore;
|
|
134
|
+
const ensureGatewayLogstore = async (context, client, projectName) => {
|
|
135
|
+
return ensureLogstoreInSharedProject(context, client, projectName, `${context.service}-${context.stage}-apigw-logs`);
|
|
136
|
+
};
|
|
137
|
+
exports.ensureGatewayLogstore = ensureGatewayLogstore;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isOwnedByStack = exports.parseOwnershipTagValue = exports.buildOwnershipTagValue = exports.OWNERSHIP_TAG_KEY = void 0;
|
|
3
|
+
exports.isOwnedByApp = exports.buildSharedOwnershipTagValue = exports.SHARED_SCOPE = exports.isOwnedByStack = exports.parseOwnershipTagValue = exports.buildOwnershipTagValue = exports.OWNERSHIP_TAG_KEY = void 0;
|
|
4
4
|
/**
|
|
5
5
|
* Ownership tag stamped on provider resources at create time so a deploy can
|
|
6
6
|
* idempotently adopt a resource that exists in the cloud but is missing from
|
|
@@ -38,3 +38,21 @@ const isOwnedByStack = (context, logicalId, tags) => {
|
|
|
38
38
|
return parsed.stack === `${context.app}-${context.service}` && parsed.logicalId === logicalId;
|
|
39
39
|
};
|
|
40
40
|
exports.isOwnedByStack = isOwnedByStack;
|
|
41
|
+
/**
|
|
42
|
+
* App-scoped ownership for resources shared across services of one app
|
|
43
|
+
* (issue #214 unified log container). Exact full-value match by design:
|
|
44
|
+
* per-service stacks have no claim on shared resources, so only the
|
|
45
|
+
* owning app may adopt them.
|
|
46
|
+
*/
|
|
47
|
+
exports.SHARED_SCOPE = 'shared';
|
|
48
|
+
const buildSharedOwnershipTagValue = (app, logicalId) => `${app}:${exports.SHARED_SCOPE}:${logicalId}`;
|
|
49
|
+
exports.buildSharedOwnershipTagValue = buildSharedOwnershipTagValue;
|
|
50
|
+
const isOwnedByApp = (app, logicalId, tags) => {
|
|
51
|
+
if (!tags)
|
|
52
|
+
return false;
|
|
53
|
+
const tag = tags.find((t) => t.Key === exports.OWNERSHIP_TAG_KEY);
|
|
54
|
+
if (!tag?.Value)
|
|
55
|
+
return false;
|
|
56
|
+
return tag.Value === (0, exports.buildSharedOwnershipTagValue)(app, logicalId);
|
|
57
|
+
};
|
|
58
|
+
exports.isOwnedByApp = isOwnedByApp;
|
|
@@ -11,6 +11,9 @@ const tdsqlcPlanner_1 = require("./tdsqlcPlanner");
|
|
|
11
11
|
const tdsqlcExecutor_1 = require("./tdsqlcExecutor");
|
|
12
12
|
const esServerlessPlanner_1 = require("./esServerlessPlanner");
|
|
13
13
|
const esServerlessExecutor_1 = require("./esServerlessExecutor");
|
|
14
|
+
const tencentClient_1 = require("../../common/tencentClient");
|
|
15
|
+
const stateManager_1 = require("../../common/stateManager");
|
|
16
|
+
const sharedLogset_1 = require("./sharedLogset");
|
|
14
17
|
const createSaveStateFn = (backend, app, service, stage) => async (state) => {
|
|
15
18
|
await backend.saveState(state, app, service, stage);
|
|
16
19
|
};
|
|
@@ -86,6 +89,16 @@ const destroyTencentStack = async (backend) => {
|
|
|
86
89
|
],
|
|
87
90
|
});
|
|
88
91
|
}
|
|
92
|
+
// Release the shared CLS logset once no topics reference it anymore. The
|
|
93
|
+
// per-function teardowns above deleted their own topics, so a logset with
|
|
94
|
+
// zero remaining topics is safe to delete.
|
|
95
|
+
const sharedLogset = (0, stateManager_1.getSharedResource)(state, context.stage, sharedLogset_1.SHARED_LOGSET_KEY);
|
|
96
|
+
if (sharedLogset) {
|
|
97
|
+
const releaseResult = await (0, sharedLogset_1.releaseSharedLogsetIfUnused)(context, (0, tencentClient_1.createTencentClient)(context), sharedLogset);
|
|
98
|
+
if (releaseResult === 'deleted') {
|
|
99
|
+
state = (0, stateManager_1.removeSharedResource)(state, context.stage, sharedLogset_1.SHARED_LOGSET_KEY);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
89
102
|
await backend.saveState(state, context.app, context.service, context.stage);
|
|
90
103
|
};
|
|
91
104
|
exports.destroyTencentStack = destroyTencentStack;
|
|
@@ -6,6 +6,7 @@ const scfTypes_1 = require("./scfTypes");
|
|
|
6
6
|
const stateManager_1 = require("../../common/stateManager");
|
|
7
7
|
const hashUtils_1 = require("../../common/hashUtils");
|
|
8
8
|
const ownershipTag_1 = require("../ownershipTag");
|
|
9
|
+
const sharedLogset_1 = require("./sharedLogset");
|
|
9
10
|
const planFunctionDeletion = (logicalId, definition) => ({
|
|
10
11
|
logicalId,
|
|
11
12
|
action: 'delete',
|
|
@@ -24,7 +25,14 @@ const generateFunctionPlan = async (context, state, functions) => {
|
|
|
24
25
|
const functionItems = await Promise.all(functions.map(async (fn) => {
|
|
25
26
|
const logicalId = `functions.${fn.key}`;
|
|
26
27
|
const currentState = (0, stateManager_1.getResource)(state, logicalId);
|
|
27
|
-
|
|
28
|
+
let config = (0, scfTypes_1.functionToScfConfig)(fn);
|
|
29
|
+
if (fn.log) {
|
|
30
|
+
config = {
|
|
31
|
+
...config,
|
|
32
|
+
ClsLogsetName: (0, sharedLogset_1.buildSharedLogsetName)(context.app, context.stage),
|
|
33
|
+
ClsTopicName: (0, sharedLogset_1.buildFunctionTopicName)(context),
|
|
34
|
+
};
|
|
35
|
+
}
|
|
28
36
|
const codePath = fn.code.path;
|
|
29
37
|
const desiredCodeHash = await (0, hashUtils_1.computeZipContentHash)(codePath);
|
|
30
38
|
const desiredDefinition = (0, scfTypes_1.extractScfDefinition)(config, desiredCodeHash, fn.iam);
|