From 8d93a0f012208ddaeb945449f059de2c97506112 Mon Sep 17 00:00:00 2001 From: wss-git Date: Tue, 1 Jun 2021 13:40:32 +0800 Subject: [PATCH 1/4] feat: function layer --- src/lib/deploy/deploy-by-tpl.js | 1 + src/lib/fc.js | 3 ++- .../language-service/schema/ros/ALIYUN-FC-Function.json | 3 +++ src/lib/language-service/schema/rosSchema.ts | 8 ++++++++ src/lib/validate/schema/function.js | 6 ++++++ 5 files changed, 20 insertions(+), 1 deletion(-) diff --git a/src/lib/deploy/deploy-by-tpl.js b/src/lib/deploy/deploy-by-tpl.js index 0c6d91e0c..c6df8af03 100644 --- a/src/lib/deploy/deploy-by-tpl.js +++ b/src/lib/deploy/deploy-by-tpl.js @@ -126,6 +126,7 @@ async function deployFunction({ baseDir, nasConfig, vpcConfig, useNas, assumeYes asyncConfiguration: properties.AsyncConfiguration, environmentVariables: properties.EnvironmentVariables, instanceConcurrency: properties.InstanceConcurrency, + layers: properties.Layers, nasConfig, vpcConfig, InstanceLifecycleConfig: properties.InstanceLifecycleConfig diff --git a/src/lib/fc.js b/src/lib/fc.js index d8e7c269a..27e56bb68 100644 --- a/src/lib/fc.js +++ b/src/lib/fc.js @@ -1182,6 +1182,7 @@ async function makeFunction(baseDir, { instanceConcurrency, nasConfig, vpcConfig, + layers = [], InstanceLifecycleConfig }, onlyConfig, tplPath, useNas = false, assumeYes) { const fc = await getFcClient(); @@ -1251,7 +1252,7 @@ async function makeFunction(baseDir, { const transformedInstanceLifecycleConfig = transformInstanceLifecycleConfig(InstanceLifecycleConfig); const params = { - description, handler, initializer, + description, handler, initializer, layers, timeout, initializationTimeout, memorySize, runtime, instanceConcurrency, instanceType, InstanceLifecycleConfig: transformedInstanceLifecycleConfig diff --git a/src/lib/language-service/schema/ros/ALIYUN-FC-Function.json b/src/lib/language-service/schema/ros/ALIYUN-FC-Function.json index 916110a61..bd6f12323 100644 --- a/src/lib/language-service/schema/ros/ALIYUN-FC-Function.json +++ b/src/lib/language-service/schema/ros/ALIYUN-FC-Function.json @@ -23,6 +23,9 @@ "EnvironmentVariables": { "type": "object" }, + "Layers": { + "type": "array" + }, "Description": { "type": "string" }, diff --git a/src/lib/language-service/schema/rosSchema.ts b/src/lib/language-service/schema/rosSchema.ts index 43e327d43..cfb7d5231 100644 --- a/src/lib/language-service/schema/rosSchema.ts +++ b/src/lib/language-service/schema/rosSchema.ts @@ -253,6 +253,10 @@ export const rosSchema = { "EnvironmentVariables": { "type": "object" }, + "Layers": { + "type": "array", + "items": { "type": "string" } + }, "MemorySize": { "type": "integer", "enum": [ @@ -361,6 +365,10 @@ export const rosSchema = { "EnvironmentVariables": { "type": "object" }, + "Layers": { + "type": "array", + "items": { "type": "string" } + }, "MemorySize": { "type": "integer", "enum": [ diff --git a/src/lib/validate/schema/function.js b/src/lib/validate/schema/function.js index ee36663d3..2063927a1 100644 --- a/src/lib/validate/schema/function.js +++ b/src/lib/validate/schema/function.js @@ -92,6 +92,9 @@ const functionSchema = { } } }, + 'Layers': { + 'type': 'array' + }, 'MemorySize': { 'type': 'integer' }, @@ -187,6 +190,9 @@ const functionSchema = { 'MemorySize': { 'type': 'integer' }, + 'Layers': { + 'type': 'array' + }, 'CustomContainerConfig': { 'type': 'object', 'properties': { From 47379eace1a5b86cb291c6cdde062315c98c8124 Mon Sep 17 00:00:00 2001 From: wss-git Date: Tue, 1 Jun 2021 13:40:56 +0800 Subject: [PATCH 2/4] feat: service logconfig enableInstanceMetrics --- src/lib/fc.js | 6 ++++-- src/lib/language-service/schema/rosSchema.ts | 3 ++- src/lib/validate/schema/service-resource.js | 3 ++- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/lib/fc.js b/src/lib/fc.js index 27e56bb68..ce0cc9de6 100644 --- a/src/lib/fc.js +++ b/src/lib/fc.js @@ -1326,7 +1326,8 @@ async function generateDefaultLogConfig() { return { project: generateSlsProjectName(profile.accountId, profile.defaultRegion), logstore: `function-log`, - enableRequestMetrics: true + enableRequestMetrics: true, + enableInstanceMetrics: true }; } @@ -1346,7 +1347,8 @@ async function transformLogConfig(logConfig) { return { project: logConfig.Project || '', logstore: logConfig.Logstore || '', - enableRequestMetrics: logConfig.EnableRequestMetrics || false + enableRequestMetrics: logConfig.EnableRequestMetrics || false, + enableInstanceMetrics: logConfig.EnableInstanceMetrics || false }; } diff --git a/src/lib/language-service/schema/rosSchema.ts b/src/lib/language-service/schema/rosSchema.ts index cfb7d5231..20773786d 100644 --- a/src/lib/language-service/schema/rosSchema.ts +++ b/src/lib/language-service/schema/rosSchema.ts @@ -69,7 +69,8 @@ export const rosSchema = { "properties": { "Project": { "type": "string" }, "Logstore": { "type": "string" }, - "EnableRequestMetrics": { "type": "boolean" } + "EnableRequestMetrics": { "type": "boolean" }, + "EnableInstanceMetrics": { "type": "boolean" } }, "required": ["Project", "Logstore"], "additionalProperties": false diff --git a/src/lib/validate/schema/service-resource.js b/src/lib/validate/schema/service-resource.js index fbddeb3b1..2caf38d83 100644 --- a/src/lib/validate/schema/service-resource.js +++ b/src/lib/validate/schema/service-resource.js @@ -62,7 +62,8 @@ const serviceResourceSchema = { 'properties': { 'Project': { 'type': 'string' }, 'Logstore': { 'type': 'string' }, - 'EnableRequestMetrics': { 'type': 'boolean' } + 'EnableRequestMetrics': { 'type': 'boolean' }, + 'EnableInstanceMetrics': { 'type': 'boolean' } }, 'required': ['Project', 'Logstore'], 'additionalProperties': false From b63d93c77a34c5881d4c9bcc66e48891290327b8 Mon Sep 17 00:00:00 2001 From: wss-git Date: Tue, 1 Jun 2021 13:48:22 +0800 Subject: [PATCH 3/4] test: layer test --- test/deploy/deploy-by-tpl.test.js | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/test/deploy/deploy-by-tpl.test.js b/test/deploy/deploy-by-tpl.test.js index fa5bb1db8..5720762d7 100644 --- a/test/deploy/deploy-by-tpl.test.js +++ b/test/deploy/deploy-by-tpl.test.js @@ -184,6 +184,7 @@ describe('deploy', () => { environmentVariables: undefined, instanceConcurrency: undefined, InstanceLifecycleConfig: undefined, + layers: undefined, functionName: 'nodejs8', handler: 'index.handler', initializationTimeout: undefined, @@ -228,6 +229,7 @@ describe('deploy', () => { memorySize: undefined, runtime: 'nodejs6', InstanceLifecycleConfig: undefined, + layers: undefined, instanceType: undefined, asyncConfiguration: undefined, initializationTimeout: undefined, @@ -263,6 +265,7 @@ describe('deploy', () => { handler: 'helloworld.index', initializer: undefined, InstanceLifecycleConfig: undefined, + layers: undefined, memorySize: undefined, instanceType: undefined, asyncConfiguration: undefined, @@ -302,6 +305,7 @@ describe('deploy', () => { memorySize: undefined, runtime: 'java8', InstanceLifecycleConfig: undefined, + layers: undefined, serviceName: 'java', instanceType: undefined, asyncConfiguration: undefined, @@ -351,6 +355,7 @@ describe('deploy', () => { memorySize: undefined, runtime: 'nodejs8', InstanceLifecycleConfig: undefined, + layers: undefined, serviceName: 'nasDemo', instanceType: undefined, asyncConfiguration: undefined, @@ -385,6 +390,7 @@ describe('deploy', () => { asyncConfiguration: undefined, initializer: undefined, InstanceLifecycleConfig: undefined, + layers: undefined, memorySize: undefined, runtime: 'python2.7', serviceName: 'nasDemo', @@ -438,6 +444,7 @@ describe('deploy', () => { serviceName: 'fc', timeout: undefined, InstanceLifecycleConfig: undefined, + layers: undefined, cAPort: undefined, customContainerConfig: undefined, initializationTimeout: undefined, @@ -509,6 +516,7 @@ describe('deploy', () => { instanceType: undefined, asyncConfiguration: undefined, InstanceLifecycleConfig: undefined, + layers: undefined, functionName: 'fun-ots-func', memorySize: undefined, runtime: 'nodejs8', @@ -557,6 +565,7 @@ describe('deploy', () => { instanceType: undefined, asyncConfiguration: undefined, InstanceLifecycleConfig: undefined, + layers: undefined, memorySize: undefined, runtime: 'python2.7', serviceName: 'log-compute', @@ -605,6 +614,7 @@ describe('deploy', () => { instanceType: undefined, asyncConfiguration: undefined, InstanceLifecycleConfig: undefined, + layers: undefined, functionName: 'rds-function', memorySize: undefined, runtime: 'python2.7', @@ -657,6 +667,7 @@ describe('deploy', () => { instanceType: undefined, asyncConfiguration: undefined, InstanceLifecycleConfig: undefined, + layers: undefined, runtime: 'python2.7', serviceName: 'oss-test-service', timeout: undefined, @@ -708,6 +719,7 @@ describe('deploy', () => { instanceType: undefined, asyncConfiguration: undefined, InstanceLifecycleConfig: undefined, + layers: undefined, memorySize: undefined, runtime: 'nodejs8', serviceName: 'cdn-test-service', @@ -765,6 +777,7 @@ describe('deploy', () => { instanceType: undefined, asyncConfiguration: undefined, InstanceLifecycleConfig: undefined, + layers: undefined, functionName: 'mnsTopic-function', memorySize: undefined, runtime: 'python2.7', @@ -815,6 +828,7 @@ describe('deploy', () => { instanceType: undefined, asyncConfiguration: undefined, InstanceLifecycleConfig: undefined, + layers: undefined, memorySize: undefined, runtime: 'python2.7', serviceName: 'pythondemo', @@ -895,6 +909,7 @@ describe('deploy', () => { instanceType: undefined, asyncConfiguration: undefined, InstanceLifecycleConfig: undefined, + layers: undefined, memorySize: undefined, runtime: 'nodejs8', serviceName: 'maas', @@ -959,6 +974,7 @@ describe('deploy', () => { instanceType: undefined, asyncConfiguration: undefined, InstanceLifecycleConfig: undefined, + layers: undefined, initializer: undefined, memorySize: undefined, runtime: 'nodejs8', @@ -1005,6 +1021,7 @@ describe('deploy', () => { handler: 'wechat.get', initializer: undefined, InstanceLifecycleConfig: undefined, + layers: undefined, instanceType: undefined, asyncConfiguration: undefined, memorySize: undefined, @@ -1064,6 +1081,7 @@ describe('deploy', () => { initializer: undefined, instanceType: undefined, InstanceLifecycleConfig: undefined, + layers: undefined, asyncConfiguration: undefined, memorySize: undefined, runtime: 'nodejs6', @@ -1152,6 +1170,7 @@ describe('deploy', () => { environmentVariables: undefined, instanceConcurrency: undefined, InstanceLifecycleConfig: undefined, + layers: undefined, functionName: 'initializer', handler: 'main.my_handler', initializationTimeout: undefined, @@ -1227,6 +1246,7 @@ describe('deploy', () => { initializer: undefined, instanceType: undefined, InstanceLifecycleConfig: undefined, + layers: undefined, asyncConfiguration: undefined, memorySize: undefined, runtime: 'nodejs6', @@ -1283,6 +1303,7 @@ describe('deploy', () => { instanceType: undefined, asyncConfiguration: undefined, InstanceLifecycleConfig: undefined, + layers: undefined, initializer: undefined, memorySize: undefined, runtime: 'nodejs8', @@ -1319,6 +1340,7 @@ describe('deploy', () => { functionName: 'function-async-config', handler: 'index.handler', InstanceLifecycleConfig: undefined, + layers: undefined, initializer: undefined, memorySize: undefined, instanceType: 'e1', From 76cdf233c441d85ce3b7bc3790d32bf7145770d7 Mon Sep 17 00:00:00 2001 From: wss-git Date: Tue, 1 Jun 2021 14:40:03 +0800 Subject: [PATCH 4/4] feat: putFunctionAsyncConfig statefulInvocation --- src/lib/function-async-config.js | 2 ++ src/lib/language-service/schema/rosSchema.ts | 6 ++++++ src/lib/validate/schema/function.js | 6 ++++++ 3 files changed, 14 insertions(+) diff --git a/src/lib/function-async-config.js b/src/lib/function-async-config.js index 3d39d0f33..9789d87b0 100644 --- a/src/lib/function-async-config.js +++ b/src/lib/function-async-config.js @@ -23,6 +23,7 @@ async function makeDestination(serviceName, functionName, asyncConfiguration, qu const asyncConfig = { maxAsyncRetryAttempts: asyncConfiguration.MaxAsyncRetryAttempts, maxAsyncEventAgeInSeconds: asyncConfiguration.MaxAsyncEventAgeInSeconds, + statefulInvocation: asyncConfiguration.StatefulInvocation, destinationConfig }; @@ -33,6 +34,7 @@ async function makeDestination(serviceName, functionName, asyncConfiguration, qu const asyncConfigCache = { destinationConfig: data.destinationConfig, maxAsyncEventAgeInSeconds: data.maxAsyncEventAgeInSeconds, + statefulInvocation: data.statefulInvocation, maxAsyncRetryAttempts: data.maxAsyncRetryAttempts }; if (_.isEqual(asyncConfig, asyncConfigCache)) { diff --git a/src/lib/language-service/schema/rosSchema.ts b/src/lib/language-service/schema/rosSchema.ts index 20773786d..94487c096 100644 --- a/src/lib/language-service/schema/rosSchema.ts +++ b/src/lib/language-service/schema/rosSchema.ts @@ -237,6 +237,9 @@ export const rosSchema = { } } }, + "StatefulInvocation": { + "type": "boolean" + }, "MaxAsyncEventAgeInSeconds": { "type": "integer" }, @@ -349,6 +352,9 @@ export const rosSchema = { } } }, + "StatefulInvocation": { + "type": "boolean" + }, "MaxAsyncEventAgeInSeconds": { "type": "integer" }, diff --git a/src/lib/validate/schema/function.js b/src/lib/validate/schema/function.js index 2063927a1..3623fe9ac 100644 --- a/src/lib/validate/schema/function.js +++ b/src/lib/validate/schema/function.js @@ -87,6 +87,9 @@ const functionSchema = { 'MaxAsyncEventAgeInSeconds': { 'type': 'integer' }, + 'StatefulInvocation': { + 'type': 'boolean' + }, 'MaxAsyncRetryAttempts': { 'type': 'integer' } @@ -182,6 +185,9 @@ const functionSchema = { 'MaxAsyncEventAgeInSeconds': { 'type': 'integer' }, + 'StatefulInvocation': { + 'type': 'boolean' + }, 'MaxAsyncRetryAttempts': { 'type': 'integer' }