Skip to content

Commit

Permalink
Merge pull request #1120 from alibaba/layer
Browse files Browse the repository at this point in the history
支持 layer、EnableInstanceMetrics、有状态的异步调用配置
  • Loading branch information
rsonghuster authored Jun 21, 2021
2 parents 74c8239 + 76cdf23 commit 7d7c183
Show file tree
Hide file tree
Showing 8 changed files with 64 additions and 5 deletions.
1 change: 1 addition & 0 deletions src/lib/deploy/deploy-by-tpl.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 6 additions & 3 deletions src/lib/fc.js
Original file line number Diff line number Diff line change
Expand Up @@ -1182,6 +1182,7 @@ async function makeFunction(baseDir, {
instanceConcurrency,
nasConfig,
vpcConfig,
layers = [],
InstanceLifecycleConfig
}, onlyConfig, tplPath, useNas = false, assumeYes) {
const fc = await getFcClient();
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -1325,7 +1326,8 @@ async function generateDefaultLogConfig() {
return {
project: generateSlsProjectName(profile.accountId, profile.defaultRegion),
logstore: `function-log`,
enableRequestMetrics: true
enableRequestMetrics: true,
enableInstanceMetrics: true
};
}

Expand All @@ -1345,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
};
}

Expand Down
2 changes: 2 additions & 0 deletions src/lib/function-async-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ async function makeDestination(serviceName, functionName, asyncConfiguration, qu
const asyncConfig = {
maxAsyncRetryAttempts: asyncConfiguration.MaxAsyncRetryAttempts,
maxAsyncEventAgeInSeconds: asyncConfiguration.MaxAsyncEventAgeInSeconds,
statefulInvocation: asyncConfiguration.StatefulInvocation,
destinationConfig
};

Expand All @@ -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)) {
Expand Down
3 changes: 3 additions & 0 deletions src/lib/language-service/schema/ros/ALIYUN-FC-Function.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
"EnvironmentVariables": {
"type": "object"
},
"Layers": {
"type": "array"
},
"Description": {
"type": "string"
},
Expand Down
17 changes: 16 additions & 1 deletion src/lib/language-service/schema/rosSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -236,6 +237,9 @@ export const rosSchema = {
}
}
},
"StatefulInvocation": {
"type": "boolean"
},
"MaxAsyncEventAgeInSeconds": {
"type": "integer"
},
Expand All @@ -253,6 +257,10 @@ export const rosSchema = {
"EnvironmentVariables": {
"type": "object"
},
"Layers": {
"type": "array",
"items": { "type": "string" }
},
"MemorySize": {
"type": "integer",
"enum": [
Expand Down Expand Up @@ -344,6 +352,9 @@ export const rosSchema = {
}
}
},
"StatefulInvocation": {
"type": "boolean"
},
"MaxAsyncEventAgeInSeconds": {
"type": "integer"
},
Expand All @@ -361,6 +372,10 @@ export const rosSchema = {
"EnvironmentVariables": {
"type": "object"
},
"Layers": {
"type": "array",
"items": { "type": "string" }
},
"MemorySize": {
"type": "integer",
"enum": [
Expand Down
12 changes: 12 additions & 0 deletions src/lib/validate/schema/function.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,17 @@ const functionSchema = {
'MaxAsyncEventAgeInSeconds': {
'type': 'integer'
},
'StatefulInvocation': {
'type': 'boolean'
},
'MaxAsyncRetryAttempts': {
'type': 'integer'
}
}
},
'Layers': {
'type': 'array'
},
'MemorySize': {
'type': 'integer'
},
Expand Down Expand Up @@ -179,6 +185,9 @@ const functionSchema = {
'MaxAsyncEventAgeInSeconds': {
'type': 'integer'
},
'StatefulInvocation': {
'type': 'boolean'
},
'MaxAsyncRetryAttempts': {
'type': 'integer'
}
Expand All @@ -187,6 +196,9 @@ const functionSchema = {
'MemorySize': {
'type': 'integer'
},
'Layers': {
'type': 'array'
},
'CustomContainerConfig': {
'type': 'object',
'properties': {
Expand Down
3 changes: 2 additions & 1 deletion src/lib/validate/schema/service-resource.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
22 changes: 22 additions & 0 deletions test/deploy/deploy-by-tpl.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ describe('deploy', () => {
environmentVariables: undefined,
instanceConcurrency: undefined,
InstanceLifecycleConfig: undefined,
layers: undefined,
functionName: 'nodejs8',
handler: 'index.handler',
initializationTimeout: undefined,
Expand Down Expand Up @@ -228,6 +229,7 @@ describe('deploy', () => {
memorySize: undefined,
runtime: 'nodejs6',
InstanceLifecycleConfig: undefined,
layers: undefined,
instanceType: undefined,
asyncConfiguration: undefined,
initializationTimeout: undefined,
Expand Down Expand Up @@ -263,6 +265,7 @@ describe('deploy', () => {
handler: 'helloworld.index',
initializer: undefined,
InstanceLifecycleConfig: undefined,
layers: undefined,
memorySize: undefined,
instanceType: undefined,
asyncConfiguration: undefined,
Expand Down Expand Up @@ -302,6 +305,7 @@ describe('deploy', () => {
memorySize: undefined,
runtime: 'java8',
InstanceLifecycleConfig: undefined,
layers: undefined,
serviceName: 'java',
instanceType: undefined,
asyncConfiguration: undefined,
Expand Down Expand Up @@ -351,6 +355,7 @@ describe('deploy', () => {
memorySize: undefined,
runtime: 'nodejs8',
InstanceLifecycleConfig: undefined,
layers: undefined,
serviceName: 'nasDemo',
instanceType: undefined,
asyncConfiguration: undefined,
Expand Down Expand Up @@ -385,6 +390,7 @@ describe('deploy', () => {
asyncConfiguration: undefined,
initializer: undefined,
InstanceLifecycleConfig: undefined,
layers: undefined,
memorySize: undefined,
runtime: 'python2.7',
serviceName: 'nasDemo',
Expand Down Expand Up @@ -438,6 +444,7 @@ describe('deploy', () => {
serviceName: 'fc',
timeout: undefined,
InstanceLifecycleConfig: undefined,
layers: undefined,
cAPort: undefined,
customContainerConfig: undefined,
initializationTimeout: undefined,
Expand Down Expand Up @@ -509,6 +516,7 @@ describe('deploy', () => {
instanceType: undefined,
asyncConfiguration: undefined,
InstanceLifecycleConfig: undefined,
layers: undefined,
functionName: 'fun-ots-func',
memorySize: undefined,
runtime: 'nodejs8',
Expand Down Expand Up @@ -557,6 +565,7 @@ describe('deploy', () => {
instanceType: undefined,
asyncConfiguration: undefined,
InstanceLifecycleConfig: undefined,
layers: undefined,
memorySize: undefined,
runtime: 'python2.7',
serviceName: 'log-compute',
Expand Down Expand Up @@ -605,6 +614,7 @@ describe('deploy', () => {
instanceType: undefined,
asyncConfiguration: undefined,
InstanceLifecycleConfig: undefined,
layers: undefined,
functionName: 'rds-function',
memorySize: undefined,
runtime: 'python2.7',
Expand Down Expand Up @@ -657,6 +667,7 @@ describe('deploy', () => {
instanceType: undefined,
asyncConfiguration: undefined,
InstanceLifecycleConfig: undefined,
layers: undefined,
runtime: 'python2.7',
serviceName: 'oss-test-service',
timeout: undefined,
Expand Down Expand Up @@ -708,6 +719,7 @@ describe('deploy', () => {
instanceType: undefined,
asyncConfiguration: undefined,
InstanceLifecycleConfig: undefined,
layers: undefined,
memorySize: undefined,
runtime: 'nodejs8',
serviceName: 'cdn-test-service',
Expand Down Expand Up @@ -765,6 +777,7 @@ describe('deploy', () => {
instanceType: undefined,
asyncConfiguration: undefined,
InstanceLifecycleConfig: undefined,
layers: undefined,
functionName: 'mnsTopic-function',
memorySize: undefined,
runtime: 'python2.7',
Expand Down Expand Up @@ -815,6 +828,7 @@ describe('deploy', () => {
instanceType: undefined,
asyncConfiguration: undefined,
InstanceLifecycleConfig: undefined,
layers: undefined,
memorySize: undefined,
runtime: 'python2.7',
serviceName: 'pythondemo',
Expand Down Expand Up @@ -895,6 +909,7 @@ describe('deploy', () => {
instanceType: undefined,
asyncConfiguration: undefined,
InstanceLifecycleConfig: undefined,
layers: undefined,
memorySize: undefined,
runtime: 'nodejs8',
serviceName: 'maas',
Expand Down Expand Up @@ -959,6 +974,7 @@ describe('deploy', () => {
instanceType: undefined,
asyncConfiguration: undefined,
InstanceLifecycleConfig: undefined,
layers: undefined,
initializer: undefined,
memorySize: undefined,
runtime: 'nodejs8',
Expand Down Expand Up @@ -1005,6 +1021,7 @@ describe('deploy', () => {
handler: 'wechat.get',
initializer: undefined,
InstanceLifecycleConfig: undefined,
layers: undefined,
instanceType: undefined,
asyncConfiguration: undefined,
memorySize: undefined,
Expand Down Expand Up @@ -1064,6 +1081,7 @@ describe('deploy', () => {
initializer: undefined,
instanceType: undefined,
InstanceLifecycleConfig: undefined,
layers: undefined,
asyncConfiguration: undefined,
memorySize: undefined,
runtime: 'nodejs6',
Expand Down Expand Up @@ -1152,6 +1170,7 @@ describe('deploy', () => {
environmentVariables: undefined,
instanceConcurrency: undefined,
InstanceLifecycleConfig: undefined,
layers: undefined,
functionName: 'initializer',
handler: 'main.my_handler',
initializationTimeout: undefined,
Expand Down Expand Up @@ -1227,6 +1246,7 @@ describe('deploy', () => {
initializer: undefined,
instanceType: undefined,
InstanceLifecycleConfig: undefined,
layers: undefined,
asyncConfiguration: undefined,
memorySize: undefined,
runtime: 'nodejs6',
Expand Down Expand Up @@ -1283,6 +1303,7 @@ describe('deploy', () => {
instanceType: undefined,
asyncConfiguration: undefined,
InstanceLifecycleConfig: undefined,
layers: undefined,
initializer: undefined,
memorySize: undefined,
runtime: 'nodejs8',
Expand Down Expand Up @@ -1319,6 +1340,7 @@ describe('deploy', () => {
functionName: 'function-async-config',
handler: 'index.handler',
InstanceLifecycleConfig: undefined,
layers: undefined,
initializer: undefined,
memorySize: undefined,
instanceType: 'e1',
Expand Down

0 comments on commit 7d7c183

Please sign in to comment.