Skip to content

Commit 346356b

Browse files
高魏洪qwencoder
andcommitted
fix: provisionConfig and scalingConfig array property handling
- Add default empty array initialization for targetTrackingPolicies and scheduledActions in provisionConfig - Add default empty array initialization for horizontalScalingPolicies and scheduledPolicies in scalingConfig - Fix variable naming conflict with 'target' in provisionConfig - Update test cases to include new required properties - Add e2e test for nodejs provision config - Remove redundant log message in model utils Co-authored-by: Qwen-Coder <qwen-coder@alibabacloud.com>
1 parent 2f32348 commit 346356b

9 files changed

Lines changed: 124 additions & 14 deletions

File tree

__tests__/e2e/ci-mac-linux.sh

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,19 @@ s remove -y -t ./go/s.yaml
8888
rm -rf ./go/code/target
8989
cd ..
9090

91+
echo "test nodejs runtime with provision config ..."
92+
cd nodejs
93+
cd provision
94+
export fc_component_function_name=nodejs18-provision-$(uname)-$(uname -m)-$RANDSTR
95+
s deploy -y
96+
s info -y
97+
sleep 2
98+
s deploy -y -t ./s2.yaml
99+
s info -y -t ./s2.yaml
100+
s remove -y -t ./s2.yaml
101+
cd ..
91102

92103
echo "test nodejs runtime with provision config mode=drain ..."
93-
cd nodejs
94104
export fc_component_function_name=nodejs18-provision-drain-$(uname)-$(uname -m)-$RANDSTR
95105
s deploy -y -t s_provision_drain.yaml
96106
s invoke -e '{"hello":"fc nodejs provision config mode=drain"}' -t s_provision_drain.yaml
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
'use strict';
2+
/*
3+
To enable the initializer feature (https://help.aliyun.com/document_detail/2512970.html)
4+
please implement the initializer function as below:
5+
exports.initializer = (context, callback) => {
6+
console.log('initializing');
7+
callback(null, '');
8+
};
9+
*/
10+
exports.handler = (event, context, callback) => {
11+
// const eventObj = JSON.parse(event.toString());
12+
console.log('hello world');
13+
callback(null, 'hello world');
14+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
edition: 3.0.0
2+
name: fc3-example
3+
access: quanxi
4+
5+
vars:
6+
region: ${env('REGION', 'cn-hongkong')}
7+
8+
resources:
9+
fcDemo:
10+
component: ${env('fc_component_version', path('../../../'))}
11+
props:
12+
region: ${vars.region}
13+
handler: index.handler
14+
role: ''
15+
description: ''
16+
timeout: 60
17+
diskSize: 512
18+
internetAccess: true
19+
logConfig: auto
20+
functionName: fc3-provision-${env('fc_component_function_name', 'provision')}
21+
runtime: nodejs16
22+
cpu: 0.35
23+
memorySize: 512
24+
code: ./code
25+
provisionConfig:
26+
target: 1
27+
targetTrackingPolicies:
28+
- name: test
29+
metricType: ProvisionedConcurrencyUtilization
30+
metricTarget: 0.6
31+
startTime: '2026-01-20T04:00:00.000Z'
32+
endTime: '2026-01-20T07:00:00.000Z'
33+
minCapacity: 1
34+
maxCapacity: 5
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
edition: 3.0.0
2+
name: fc3-example
3+
access: quanxi
4+
5+
vars:
6+
region: ${env('REGION', 'cn-hongkong')}
7+
8+
resources:
9+
fcDemo:
10+
component: ${env('fc_component_version', path('../../../'))}
11+
props:
12+
region: ${vars.region}
13+
handler: index.handler
14+
role: ''
15+
description: ''
16+
timeout: 60
17+
diskSize: 512
18+
internetAccess: true
19+
logConfig: auto
20+
functionName: fc3-provision-${env('fc_component_function_name', 'provision')}
21+
runtime: nodejs16
22+
cpu: 0.35
23+
memorySize: 512
24+
code: ./code
25+
provisionConfig:
26+
target: 0

__tests__/ut/commands/deploy/impl/scaling_config_test.ts

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,11 @@ describe('ScalingConfig', () => {
398398
'ScalingConfig',
399399
'test-function',
400400
'LATEST',
401-
{ minInstances: 1 },
401+
{
402+
horizontalScalingPolicies: [],
403+
scheduledPolicies: [],
404+
minInstances: 1,
405+
},
402406
);
403407
expect(logger.info).toHaveBeenCalledWith(
404408
'ScalingConfig of test-function/LATEST is ready. CurrentInstances: 1, TargetInstances: 1',
@@ -446,10 +450,16 @@ describe('ScalingConfig', () => {
446450
'ScalingConfig',
447451
'test-function',
448452
'LATEST',
449-
{ minInstances: 1 },
453+
{
454+
horizontalScalingPolicies: [],
455+
scheduledPolicies: [],
456+
minInstances: 1,
457+
},
450458
);
451459
expect(waitForScalingReadySpy).toHaveBeenCalledWith('LATEST', {
460+
"horizontalScalingPolicies": [],
452461
minInstances: 1,
462+
"scheduledPolicies": [],
453463
});
454464
});
455465

@@ -489,7 +499,11 @@ describe('ScalingConfig', () => {
489499
'ScalingConfig',
490500
'test-function',
491501
'LATEST',
492-
{ minInstances: 1 },
502+
{
503+
horizontalScalingPolicies: [],
504+
scheduledPolicies: [],
505+
minInstances: 1,
506+
},
493507
);
494508
expect(waitForScalingReadySpy).not.toHaveBeenCalled();
495509
expect(logger.info).toHaveBeenCalledWith(

src/subCommands/deploy/impl/provision_config.ts

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,12 @@ export default class ProvisionConfig extends Base {
4747

4848
if (!_.isEmpty(localConfig)) {
4949
if (this.needDeploy) {
50+
const defaultArrayProps = ['targetTrackingPolicies', 'scheduledActions'];
51+
for (const prop of defaultArrayProps) {
52+
if (!Array.isArray(localConfig[prop])) {
53+
localConfig[prop] = [];
54+
}
55+
}
5056
await provisionConfigErrorRetry(
5157
this.fcSdk,
5258
'ProvisionConfig',
@@ -88,8 +94,8 @@ export default class ProvisionConfig extends Base {
8894
`Waiting for provisionConfig of ${this.functionName}/${qualifier} to instance up ...`,
8995
);
9096

91-
const { defaultTarget, target } = config;
92-
const realTarget = defaultTarget || target;
97+
const { defaultTarget, target: configTarget } = config;
98+
const realTarget = defaultTarget || configTarget;
9399

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

113119
// 检查是否已达到目标值
114-
if (current === undefined || (current && current === realTarget)) {
120+
if (current === undefined || current === remoteTarget) {
115121
logger.info(
116-
`ProvisionConfig of ${this.functionName}/${qualifier} is ready. Current: ${current}, Target: ${realTarget}`,
122+
`ProvisionConfig of ${this.functionName}/${qualifier} is ready. Current: ${current}, Target: ${remoteTarget}`,
117123
);
118124
return;
119125
}

src/subCommands/deploy/impl/scaling_config.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,12 @@ export default class ScalingConfig extends Base {
4545

4646
if (!_.isEmpty(localConfig)) {
4747
if (this.needDeploy) {
48+
const defaultArrayProps = ['horizontalScalingPolicies', 'scheduledPolicies'];
49+
for (const prop of defaultArrayProps) {
50+
if (!Array.isArray(localConfig[prop])) {
51+
localConfig[prop] = [];
52+
}
53+
}
4854
await provisionConfigErrorRetry(
4955
this.fcSdk,
5056
'ScalingConfig',

src/subCommands/deploy/utils/index.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ import { isProvisionConfigError, sleep } from '../../../utils';
33

44
export async function provisionConfigErrorRetry(
55
fcSdk: any,
6-
command,
7-
functionName,
8-
qualifier,
9-
localConfig,
6+
command: string,
7+
functionName: string,
8+
qualifier: string,
9+
localConfig: any,
1010
) {
1111
logger.info(`provisionConfigErrorRetry Execute: ${command}`);
1212
try {

src/subCommands/model/utils/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ export const initClient = async (inputs: IInputs, region: string, solution: stri
5555
}`,
5656
});
5757

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

6060
return new DevClient(config);
6161
};

0 commit comments

Comments
 (0)