Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 13 additions & 5 deletions __tests__/e2e/ci-mac-linux.sh
Original file line number Diff line number Diff line change
Expand Up @@ -77,30 +77,38 @@ s remove -y -t ./go/s.yaml
rm -rf ./go/code/target
cd ..

echo "test nodejs runtime with auto ..."

echo "test nodejs runtime with provision config mode=drain ..."
cd nodejs
export fc_component_function_name=nodejs18-$(uname)-$(uname -m)-$RANDSTR
export fc_component_function_name=nodejs18-provision-drain-$(uname)-$(uname -m)-$RANDSTR
s deploy -y -t s_provision_drain.yaml
s invoke -e '{"hello":"fc nodejs provision config mode=drain"}' -t s_provision_drain.yaml
s info -y -t s_provision_drain.yaml
s remove -y -t s_provision_drain.yaml

echo "test nodejs runtime with auto ..."
export fc_component_function_name=nodejs18-nas-auto-$(uname)-$(uname -m)-$RANDSTR
s deploy -y -t s_auto.yaml
s invoke -e '{"hello":"fc nodejs with auto"}' -t s_auto.yaml
s info -y -t s_auto.yaml
s remove -y -t s_auto.yaml

echo "test nodejs runtime with oss config auto ..."
export fc_component_function_name=nodejs18-$(uname)-$(uname -m)-$RANDSTR
export fc_component_function_name=nodejs18-oss-auto-$(uname)-$(uname -m)-$RANDSTR
s deploy -y -t ./s_oss_config_auto.yaml
s invoke -e '{"hello":"fc nodejs with oss config auto"}' -t ./s_oss_config_auto.yaml
s info -y -t ./s_oss_config_auto.yaml
s remove -y -t ./s_oss_config_auto.yaml

echo "test nodejs runtime with more vpc and nas auto ..."
export fc_component_function_name=nodejs16-$(uname)-$(uname -m)-$RANDSTR
export fc_component_function_name=nodejs16-multi-nas-auto-$(uname)-$(uname -m)-$RANDSTR
s deploy -y -t ./s_lock_auto.yaml
s invoke -e '{"hello":"fc nodejs with more vpc and nas auto"}' -t ./s_lock_auto.yaml
s info -y -t ./s_lock_auto.yaml
s remove -y -t ./s_lock_auto.yaml

echo "test nodejs runtime with tags ..."
export fc_component_function_name=nodejs16-$(uname)-$(uname -m)-$RANDSTR
export fc_component_function_name=nodejs16-tags-$(uname)-$(uname -m)-$RANDSTR
s deploy -y -t ./s_tags.yaml
s deploy -y -t ./s_tags2.yaml
s deploy -y -t ./s_tags3.yaml
Expand Down
4 changes: 4 additions & 0 deletions __tests__/e2e/nodejs/hello-code/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
exports.handler = async function (event, context) {
console.log('event: \n' + event);
return 'Hello World!';
};
22 changes: 22 additions & 0 deletions __tests__/e2e/nodejs/s_provision_drain.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
edition: 3.0.0
name: test-node-app
access: quanxi

vars:
region: ${env('REGION', 'cn-hongkong')}

resources:
fcDemo: # 业务名称/模块名称
component: ${env('fc_component_version', path('../../../'))}
props: # 组件的属性值
region: ${vars.region}
functionName: fc3-event-test-drain-${env('fc_component_function_name', 'nodejs18')}
runtime: ${env('fc_component_runtime', 'nodejs18')}
code: ./hello-code
handler: index.handler
memorySize: 128
timeout: 60

provisionConfig:
defaultTarget: 0
mode: drain
61 changes: 29 additions & 32 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"dependencies": {
"@alicloud/devs20230714": "^2.4.6-alpha.2",
"@alicloud/fc2": "^2.6.6",
"@alicloud/fc20230330": "4.6.0",
"@alicloud/fc20230330": "4.6.2",
"@alicloud/pop-core": "^1.8.0",
"@serverless-cd/srm-aliyun-pop-core": "^0.0.8-beta.1",
"@serverless-cd/srm-aliyun-ram20150501": "^0.0.2-beta.9",
Expand Down Expand Up @@ -68,7 +68,7 @@
"patch-package": "^8.0.0",
"postinstall-prepare": "^2.0.0",
"prettier": "^3.6.2",
"ts-jest": "^29.4.4",
"ts-jest": "^29.4.5",
"ts-node": "^10.9.2",
"typescript": "^4.4.2",
"typescript-json-schema": "^0.65.1"
Expand Down
22 changes: 22 additions & 0 deletions src/resources/fc/impl/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ import FCClient, {
PutScalingConfigInput,
GetScalingConfigRequest,
DeleteScalingConfigRequest,
DisableFunctionInvocationRequest,
} from '@alicloud/fc20230330';
import { ICredentials } from '@serverless-devs/component-interface';
import { RuntimeOptions } from '@alicloud/tea-util';
Expand Down Expand Up @@ -639,4 +640,25 @@ export default class FC_Client {
);
return body;
}

async disableFunctionInvocation(
functionName: string,
abortOngoingRequest: boolean,
reason: string,
) {
const request = new DisableFunctionInvocationRequest({
reason,
abortOngoingRequest,
});
const result = await this.fc20230330Client.disableFunctionInvocation(functionName, request);
const { body } = result.toMap();
logger.debug(`DisableFunction ${functionName} result body: ${JSON.stringify(body)}`);
return body;
}
async enableFunctionInvocation(functionName: string) {
const result = await this.fc20230330Client.enableFunctionInvocation(functionName);
const { body } = result.toMap();
logger.debug(`EnableFunction ${functionName} result body: ${JSON.stringify(body)}`);
return body;
}
}
4 changes: 4 additions & 0 deletions src/resources/fc/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -493,6 +493,10 @@ export default class FC extends FC_Client {
_.unset(body, 'ossMountConfig');
}

if (_.isEmpty(body.polarFsConfig?.mountPoints)) {
_.unset(body, 'polarFsConfig');
}

if (_.isEmpty(body.tracingConfig)) {
_.unset(body, 'tracingConfig');
}
Expand Down
14 changes: 11 additions & 3 deletions src/subCommands/deploy/impl/provision_config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export default class ProvisionConfig extends Base {
if (this.needDeploy) {
await this.fcSdk.putFunctionProvisionConfig(this.functionName, qualifier, localConfig);

if (this.ProvisionMode === 'sync') {
if (this.ProvisionMode === 'sync' || this.ProvisionMode === 'drain') {
await this.waitForProvisionReady(qualifier, localConfig);
} else {
logger.info(
Expand Down Expand Up @@ -86,7 +86,16 @@ export default class ProvisionConfig extends Base {

// 如果没有目标值或目标值为0,则无需等待
if (!realTarget || realTarget <= 0) {
return;
if (this.ProvisionMode !== 'drain') {
return;
} else {
logger.info(`disableFunctionInvocation ${this.functionName} ...`);
await this.fcSdk.disableFunctionInvocation(this.functionName, true, 'Fast scale-to-zero');
await sleep(5);
logger.info(`enableFunctionInvocation ${this.functionName} ...`);
await this.fcSdk.enableFunctionInvocation(this.functionName);
return;
}
}

let getCurrentErrorCount = 0;
Expand Down Expand Up @@ -143,7 +152,6 @@ export default class ProvisionConfig extends Base {
// eslint-disable-next-line no-await-in-loop
await sleep(5);
}

logger.warn(
`Timeout waiting for provisionConfig of ${this.functionName}/${qualifier} to be ready`,
);
Expand Down