Skip to content

Commit f4fdbb3

Browse files
authored
Merge pull request #76 from devsapp/feat-SessionAffinityConfig
feat: support sessionAffinityConfig
2 parents a50c062 + 6b24adc commit f4fdbb3

12 files changed

Lines changed: 99 additions & 14 deletions

File tree

__tests__/e2e/ci-mac-linux.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,13 @@ s remove -y
4747
rm -rf ./target
4848
cd ..
4949

50+
echo "test php runtime with session config"
51+
cd php
52+
export fc_component_function_name=php-$(uname)-$(uname -m)-$RANDSTR
53+
s deploy -y
54+
s info
55+
s remove -y
56+
cd ..
5057

5158
echo "test custom go runtime ..."
5259
cd custom

__tests__/e2e/php/s.yaml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,10 @@ resources:
1616
code: ./code
1717
timeout: 30
1818
handler: index.handler
19-
memorySize: 128
19+
memorySize: 2048
20+
instanceIsolationMode: SESSION_EXCLUSIVE
21+
sessionAffinity: GENERATED_COOKIE
22+
sessionAffinityConfig:
23+
sessionConcurrencyPerInstance: 1
24+
sessionIdleTimeoutInSeconds: 1800
25+
sessionTTLInSeconds: 21600

__tests__/it/integration_test.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,8 @@ describe('Integration Tests', () => {
8787
role: '',
8888
runtime: 'python3.9',
8989
timeout: 60,
90+
instanceIsolationMode: "SHARE",
91+
sessionAffinity: "NONE",
9092
asyncInvokeConfig: undefined,
9193
concurrencyConfig: undefined,
9294
customDomain: undefined,
@@ -129,6 +131,8 @@ describe('Integration Tests', () => {
129131
runtime: 'python3.9',
130132
timeout: 60,
131133
disableOndemand: false,
134+
instanceIsolationMode: "SHARE",
135+
sessionAffinity: "NONE",
132136
triggers: [
133137
{
134138
description: 'xxxx',

package-lock.json

Lines changed: 7 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
"dependencies": {
2525
"@alicloud/devs20230714": "^2.4.5",
2626
"@alicloud/fc2": "^2.6.6",
27-
"@alicloud/fc20230330": "4.3.4",
27+
"@alicloud/fc20230330": "4.4.0",
2828
"@alicloud/pop-core": "^1.8.0",
2929
"@serverless-cd/srm-aliyun-pop-core": "^0.0.8-beta.1",
3030
"@serverless-cd/srm-aliyun-ram20150501": "^0.0.2-beta.9",

src/default/config.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ export const FC_RESOURCES_EMPTY_CONFIG = {
4040
},
4141
environmentVariables: {},
4242
layers: [],
43+
instanceIsolationMode: 'SHARE',
44+
sessionAffinity: 'NONE',
4345
};
4446

4547
export const FC_TRIGGER_DEFAULT_CONFIG = {

src/interface/function.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,14 @@ export interface ITracingConfig {
102102
type?: string;
103103
}
104104

105+
export interface ISessionAffinityConfig {
106+
sessionConcurrencyPerInstance?: number;
107+
sessionIdleTimeoutInSeconds?: number;
108+
sessionTTLInSeconds?: number;
109+
affinityHeaderFieldName?: string;
110+
sseEndpointPath?: string;
111+
}
112+
105113
export interface IVpcConfig {
106114
securityGroupId: string;
107115
vSwitchIds: string[] | 'auto';
@@ -126,6 +134,8 @@ export interface IFunction {
126134
memorySize?: number;
127135
timeout?: number;
128136
sessionAffinity?: string;
137+
sessionAffinityConfig?: ISessionAffinityConfig | string;
138+
instanceIsolationMode?: string;
129139
enableLongLiving?: boolean;
130140

131141
logConfig?: 'auto' | ILogConfig;

src/resources/fc/index.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -517,6 +517,10 @@ export default class FC extends FC_Client {
517517
_.unset(body.customContainerConfig, 'entrypoint');
518518
}
519519

520+
if (body.sessionAffinityConfig) {
521+
body.sessionAffinityConfig = JSON.parse(body.sessionAffinityConfig);
522+
}
523+
520524
if (body.layers) {
521525
logger.debug(body.layers);
522526
const newLayers = [];

src/schema.json

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -884,6 +884,26 @@
884884
],
885885
"type": "string"
886886
},
887+
"ISessionAffinityConfig": {
888+
"properties": {
889+
"affinityHeaderFieldName": {
890+
"type": "string"
891+
},
892+
"sessionConcurrencyPerInstance": {
893+
"type": "number"
894+
},
895+
"sessionIdleTimeoutInSeconds": {
896+
"type": "number"
897+
},
898+
"sessionTTLInSeconds": {
899+
"type": "number"
900+
},
901+
"sseEndpointPath": {
902+
"type": "string"
903+
}
904+
},
905+
"type": "object"
906+
},
887907
"ITags": {
888908
"properties": {
889909
"key": {
@@ -1173,6 +1193,9 @@
11731193
"handler": {
11741194
"type": "string"
11751195
},
1196+
"instanceIsolationMode": {
1197+
"type": "string"
1198+
},
11761199
"instanceLifecycleConfig": {
11771200
"properties": {
11781201
"initializer": {
@@ -1240,6 +1263,16 @@
12401263
"sessionAffinity": {
12411264
"type": "string"
12421265
},
1266+
"sessionAffinityConfig": {
1267+
"anyOf": [
1268+
{
1269+
"$ref": "#/definitions/ISessionAffinityConfig"
1270+
},
1271+
{
1272+
"type": "string"
1273+
}
1274+
]
1275+
},
12431276
"tags": {
12441277
"items": {
12451278
"$ref": "#/definitions/ITags"

src/subCommands/deploy/impl/function.ts

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,9 +110,15 @@ export default class Service extends Base {
110110
await this._pushImage();
111111
}
112112
}
113-
114113
// 部署函数
115114
const config = _.defaults(this.local, FC_RESOURCES_EMPTY_CONFIG);
115+
if (
116+
!_.isEmpty(config.sessionAffinityConfig) &&
117+
typeof config.sessionAffinityConfig !== 'string'
118+
) {
119+
logger.debug('sessionAffinityConfig', config.sessionAffinityConfig);
120+
config.sessionAffinityConfig = JSON.stringify(config.sessionAffinityConfig);
121+
}
116122
await this.fcSdk.deployFunction(config, {
117123
slsAuto: !_.isEmpty(this.createResource.sls),
118124
type: this.type,
@@ -146,6 +152,14 @@ export default class Service extends Base {
146152
_.unset(this.remote, 'resourceGroupId');
147153
}
148154

155+
if (_.get(this.remote, 'instanceIsolationMode') === 'SHARE') {
156+
_.unset(this.remote, 'instanceIsolationMode');
157+
}
158+
159+
if (_.get(this.remote, 'sessionAffinity') === 'NONE') {
160+
_.unset(this.remote, 'sessionAffinity');
161+
}
162+
149163
_.unset(this.local, 'endpoint');
150164
const { code } = this.local;
151165
_.unset(this.local, 'code');
@@ -390,7 +404,7 @@ vpcConfig:
390404
_.set(this.local, 'vpcConfig', vpcConfig);
391405
}
392406
if (nasAuto) {
393-
let modelConfig = supplement?.modelConfig || annotations?.modelConfig;
407+
const modelConfig = supplement?.modelConfig || annotations?.modelConfig;
394408

395409
logger.write(
396410
yellow(`Created nas resource succeeded, please replace nasConfig: auto in yaml with:

0 commit comments

Comments
 (0)