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
12 changes: 11 additions & 1 deletion __tests__/e2e/ci-mac-linux.sh
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,19 @@ s remove -y -t ./go/s.yaml
rm -rf ./go/code/target
cd ..

echo "test nodejs runtime with provision config ..."
cd nodejs
cd provision
export fc_component_function_name=nodejs18-provision-$(uname)-$(uname -m)-$RANDSTR
s deploy -y
s info -y
sleep 2
s deploy -y -t ./s2.yaml
s info -y -t ./s2.yaml
s remove -y -t ./s2.yaml
cd ..

echo "test nodejs runtime with provision config mode=drain ..."
cd nodejs
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
Expand Down
14 changes: 14 additions & 0 deletions __tests__/e2e/nodejs/provision/code/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
'use strict';
/*
To enable the initializer feature (https://help.aliyun.com/document_detail/2512970.html)
please implement the initializer function as below:
exports.initializer = (context, callback) => {
console.log('initializing');
callback(null, '');
};
*/
exports.handler = (event, context, callback) => {
// const eventObj = JSON.parse(event.toString());
console.log('hello world');
callback(null, 'hello world');
};
34 changes: 34 additions & 0 deletions __tests__/e2e/nodejs/provision/s.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
edition: 3.0.0
name: fc3-example
access: quanxi

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

resources:
fcDemo:
component: ${env('fc_component_version', path('../../../../'))}
props:
region: ${vars.region}
handler: index.handler
role: ''
description: ''
timeout: 60
diskSize: 512
internetAccess: true
logConfig: auto
functionName: fc3-provision-${env('fc_component_function_name', 'provision')}
runtime: nodejs16
cpu: 0.35
memorySize: 512
code: ./code
provisionConfig:
target: 1
targetTrackingPolicies:
- name: test
metricType: ProvisionedConcurrencyUtilization
metricTarget: 0.6
startTime: '2026-01-20T04:00:00.000Z'
endTime: '2026-01-20T07:00:00.000Z'
minCapacity: 1
maxCapacity: 5
26 changes: 26 additions & 0 deletions __tests__/e2e/nodejs/provision/s2.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
edition: 3.0.0
name: fc3-example
access: quanxi

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

resources:
fcDemo:
component: ${env('fc_component_version', path('../../../../'))}
props:
region: ${vars.region}
handler: index.handler
role: ''
description: ''
timeout: 60
diskSize: 512
internetAccess: true
logConfig: auto
functionName: fc3-provision-${env('fc_component_function_name', 'provision')}
runtime: nodejs16
cpu: 0.35
memorySize: 512
code: ./code
provisionConfig:
target: 0
20 changes: 17 additions & 3 deletions __tests__/ut/commands/deploy/impl/scaling_config_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,11 @@ describe('ScalingConfig', () => {
'ScalingConfig',
'test-function',
'LATEST',
{ minInstances: 1 },
{
horizontalScalingPolicies: [],
scheduledPolicies: [],
minInstances: 1,
},
);
expect(logger.info).toHaveBeenCalledWith(
'ScalingConfig of test-function/LATEST is ready. CurrentInstances: 1, TargetInstances: 1',
Expand Down Expand Up @@ -446,10 +450,16 @@ describe('ScalingConfig', () => {
'ScalingConfig',
'test-function',
'LATEST',
{ minInstances: 1 },
{
horizontalScalingPolicies: [],
scheduledPolicies: [],
minInstances: 1,
},
);
expect(waitForScalingReadySpy).toHaveBeenCalledWith('LATEST', {
horizontalScalingPolicies: [],
minInstances: 1,
scheduledPolicies: [],
});
});

Expand Down Expand Up @@ -489,7 +499,11 @@ describe('ScalingConfig', () => {
'ScalingConfig',
'test-function',
'LATEST',
{ minInstances: 1 },
{
horizontalScalingPolicies: [],
scheduledPolicies: [],
minInstances: 1,
},
);
expect(waitForScalingReadySpy).not.toHaveBeenCalled();
expect(logger.info).toHaveBeenCalledWith(
Expand Down
16 changes: 11 additions & 5 deletions src/subCommands/deploy/impl/provision_config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@ export default class ProvisionConfig extends Base {

if (!_.isEmpty(localConfig)) {
if (this.needDeploy) {
const defaultArrayProps = ['targetTrackingPolicies', 'scheduledActions'];
for (const prop of defaultArrayProps) {
if (!Array.isArray(localConfig[prop])) {
localConfig[prop] = [];
}
}
await provisionConfigErrorRetry(
this.fcSdk,
'ProvisionConfig',
Expand Down Expand Up @@ -88,8 +94,8 @@ export default class ProvisionConfig extends Base {
`Waiting for provisionConfig of ${this.functionName}/${qualifier} to instance up ...`,
);

const { defaultTarget, target } = config;
const realTarget = defaultTarget || target;
const { defaultTarget, target: configTarget } = config;
const realTarget = defaultTarget || configTarget;

// 如果没有目标值或目标值为0,则无需等待
if (!realTarget || realTarget <= 0) {
Expand All @@ -108,12 +114,12 @@ export default class ProvisionConfig extends Base {
for (let index = 0; index < maxRetries; index++) {
// eslint-disable-next-line no-await-in-loop
const result = await this.fcSdk.getFunctionProvisionConfig(this.functionName, qualifier);
const { current, currentError } = result || {};
const { current, currentError, target: remoteTarget } = result || {};

// 检查是否已达到目标值
if (current === undefined || (current && current === realTarget)) {
if (current === undefined || current === remoteTarget) {
logger.info(
`ProvisionConfig of ${this.functionName}/${qualifier} is ready. Current: ${current}, Target: ${realTarget}`,
`ProvisionConfig of ${this.functionName}/${qualifier} is ready. Current: ${current}, Target: ${remoteTarget}`,
);
return;
}
Expand Down
6 changes: 6 additions & 0 deletions src/subCommands/deploy/impl/scaling_config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@ export default class ScalingConfig extends Base {

if (!_.isEmpty(localConfig)) {
if (this.needDeploy) {
const defaultArrayProps = ['horizontalScalingPolicies', 'scheduledPolicies'];
for (const prop of defaultArrayProps) {
if (!Array.isArray(localConfig[prop])) {
localConfig[prop] = [];
}
}
await provisionConfigErrorRetry(
this.fcSdk,
'ScalingConfig',
Expand Down
8 changes: 4 additions & 4 deletions src/subCommands/deploy/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ import { isProvisionConfigError, sleep } from '../../../utils';

export async function provisionConfigErrorRetry(
fcSdk: any,
command,
functionName,
qualifier,
localConfig,
command: string,
functionName: string,
qualifier: string,
localConfig: any,
) {
logger.info(`provisionConfigErrorRetry Execute: ${command}`);
try {
Expand Down
2 changes: 1 addition & 1 deletion src/subCommands/model/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export const initClient = async (inputs: IInputs, region: string, solution: stri
}`,
});

logger.info(`new models service init, DEVS_ENDPOINT endpoint: ${config.endpoint}`);
logger.info(`DEVS_ENDPOINT endpoint: ${config.endpoint}`);

return new DevClient(config);
};
Expand Down
Loading