Skip to content

Commit 0bf8802

Browse files
authored
fix sls trigger not enabled bug (#69)
* fix log trigger not enable bug * add sls trigger demo * add sls trigger test * update related documents
1 parent d46eb20 commit 0bf8802

11 files changed

Lines changed: 156 additions & 22 deletions

File tree

docs/specs/2018-04-03-zh-cn.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,8 @@ http-trigger-test: # trigger name
232232
---|:---:|---
233233
SourceConfig | `object` | **必填。** 数据源的 Logstore 名称。触发器会定时从该 Logstore 订阅数据到函数计算。
234234
JobConfig | `object` | **必填。** 包含两个可配置属性,一个是 MaxRetryTime,表示日志服务触发函数执行时,如果遇到错误,所允许的最大尝试次数。另一个是 TriggerInterval,表示日志服务触发函数执行的间隔。
235-
LogConfig | `object` | **必填。** 包含四个可配置属性。第一个是 Project,表示日志服务 Project 名称。第二个是 Logstore,表示触发函数执行时,产生的日志会记录到该 Logstore。第三个是 Enable,表示是否启用该触发器。第四个是可选属性 FunctionParameter,它本身也是一个 object,当事件触发时,会连同它的内容一起发送给函数。
235+
LogConfig | `object` | **必填。** 包含三个可配置属性。第一个是 Project,表示日志服务 Project 名称。第二个是 Logstore,表示触发函数执行时,产生的日志会记录到该 Logstore。第三个是可选属性 FunctionParameter,它本身也是一个 object,当事件触发时,会连同它的内容一起发送给函数。
236+
Enable | `boolean` | 表示是否启用该触发器。
236237

237238
##### 示例:Log 事件源对象
238239

@@ -247,7 +248,7 @@ Properties:
247248
LogConfig:
248249
Project: testlog
249250
Logstore: logstore2
250-
Enable: true
251+
Enable: true
251252
```
252253

253254
### Property 类型

docs/specs/2018-04-03.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,8 @@ Property Name | Type | Description
230230
SourceConfig | `object` | **Required.** The datasource's Logstore name. Triggers periodically subscribe to data from the Logstore to Function compute.
231231

232232
JobConfig | `object` | **Required.** There are two configurable properties, one of which is MaxRetryTime, which represents the maximum number of attempts allowed if the logging service triggers a function execution. The other is TriggerInterval, which indicates the interval at which the logging service triggers the execution of the function.
233-
LogConfig | `object` | **Required.** There are four configurable properties. The first is Project, which represents the log service Project name. The second is the Logstore, which means that when the trigger function is executed, the resulting log will be logged to the Logstore. The third is Enable, which indicates whether the trigger is enabled. The fourth is an optional property, FunctionParameter, which is itself an object that, when the event fires, is sent to the function along with its contents.
233+
LogConfig | `object` | **Required.** There are three configurable properties. The first is Project, which represents the log service Project name. The second is the Logstore, which means that when the trigger function is executed, the resulting log will be logged to the Logstore. The third is an optional property, FunctionParameter, which is itself an object that, when the event fires, is sent to the function along with its contents.
234+
Enable | `boolean` | Indicates whether the trigger is enabled.
234235

235236
##### Example: Log event source object
236237

@@ -245,7 +246,7 @@ Properties:
245246
LogConfig:
246247
Project: testlog
247248
Logstore: logstore2
248-
Enable: true
249+
Enable: true
249250
```
250251

251252
### Property types

examples/sls_demo/template.yml

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
ROSTemplateFormatVersion: '2015-09-01'
22
Transform: 'Aliyun::Serverless-2018-04-03'
33
Resources:
4-
log-compute1:
4+
log-compute:
55
Type: 'Aliyun::Serverless::Service'
66
Properties:
77
Description: 'sls test'
@@ -17,15 +17,14 @@ Resources:
1717
Type: Log
1818
Properties:
1919
SourceConfig:
20-
Logstore: log-com-m
20+
Logstore: log-com-m
2121
JobConfig:
22-
MaxRetryTime: 1
23-
TriggerInterval: 30
22+
MaxRetryTime: 1
23+
TriggerInterval: 30
2424
LogConfig:
25-
Project: log-com-m
26-
Logstore: log-en-m
27-
Enable: true
28-
25+
Project: log-com-m
26+
Logstore: log-en-m
27+
Enable: true
2928
log-com-m:
3029
Type: 'Aliyun::Serverless::Log'
3130
Properties:

examples/sls_trigger_demo/index.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
'use strict';
2+
3+
exports.handler = function(event, context, callback) {
4+
var response = {
5+
isBase64Encoded:false,
6+
statusCode: 200,
7+
headers: {
8+
"x-custom-header" : "header value"
9+
},
10+
body: "hellowrold"
11+
};
12+
13+
console.log("response: " + JSON.stringify(response));
14+
callback(null, response);
15+
};
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
ROSTemplateFormatVersion: '2015-09-01'
2+
Transform: 'Aliyun::Serverless-2018-04-03'
3+
Resources:
4+
helloworld:
5+
Type: 'Aliyun::Serverless::Service'
6+
Properties:
7+
Description: 'sls test'
8+
LogConfig:
9+
Project: sls-log-test
10+
Logstore: log-trigger
11+
helloworld:
12+
Type: 'Aliyun::Serverless::Function'
13+
Properties:
14+
Handler: index.handler
15+
Runtime: nodejs8
16+
CodeUri: './index.js'
17+
18+
fc:
19+
Type: 'Aliyun::Serverless::Service'
20+
Properties:
21+
Description: 'sls test'
22+
LogConfig:
23+
Project: sls-log-test
24+
Logstore: log
25+
slstrigger:
26+
Type: 'Aliyun::Serverless::Function'
27+
Properties:
28+
Handler: trigger.handler
29+
Runtime: nodejs8
30+
CodeUri: './trigger.js'
31+
Events:
32+
log-stream:
33+
Type: Log
34+
Properties:
35+
SourceConfig:
36+
Logstore: log
37+
JobConfig:
38+
MaxRetryTime: 1
39+
TriggerInterval: 30
40+
LogConfig:
41+
Project: sls-log-test
42+
Logstore: sls-log
43+
Enable: true
44+
45+
sls-log-test:
46+
Type: 'Aliyun::Serverless::Log'
47+
Properties:
48+
Description: 'just python log'
49+
log-trigger:
50+
Type: 'Aliyun::Serverless::Log::Logstore'
51+
Properties:
52+
TTL: 10
53+
ShardCount: 1
54+
sls-log:
55+
Type: 'Aliyun::Serverless::Log::Logstore'
56+
Properties:
57+
TTL: 10
58+
ShardCount: 1
59+
log:
60+
Type: 'Aliyun::Serverless::Log::Logstore'
61+
Properties:
62+
TTL: 10
63+
ShardCount: 1
64+
65+
hello:
66+
Type: 'Aliyun::Serverless::Api'
67+
Properties:
68+
StageName: RELEASE
69+
DefinitionBody:
70+
'/hello':
71+
get:
72+
x-aliyun-apigateway-api-name: pythonhello
73+
x-aliyun-apigateway-fc:
74+
arn: acs:fc:::services/${helloworld.Arn}/functions/${helloworld.Arn}/
75+
76+
77+
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
'use strict';
2+
3+
exports.handler = function(event, context, callback) {
4+
5+
console.log("triggerd by sls trigger...");
6+
callback(null, "trigged...");
7+
};

lib/deploy/deploy-support.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -407,9 +407,9 @@ function getTriggerConfig(triggerType, triggerProperties) {
407407
logConfig: {
408408
project: logConfig.Project,
409409
logstore: logConfig.Logstore,
410-
functionParameter: logConfig.FunctionParameter || {},
411-
enable: logConfig.Enable
412-
}
410+
functionParameter: logConfig.FunctionParameter || {}
411+
},
412+
Enable: triggerProperties.Enable || true
413413
};
414414
}
415415
console.error(`trigger type is ${triggerType} not supported.`);

lib/validate/schema/log-event.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,13 @@ const logEventSchema = {
4141
'Logstore': {
4242
'type': 'string'
4343
},
44-
'Enable': {
45-
'type': 'boolean'
46-
},
4744
'FunctionParameter': {
4845
'type': 'object'
4946
}
5047
},
51-
'required': ['Project', 'Logstore', 'Enable']
52-
}
48+
'required': ['Project', 'Logstore']
49+
},
50+
'Enabled': { 'type': 'boolean' }
5351
},
5452
'required': ['SourceConfig', 'JobConfig', 'LogConfig']
5553
}

package-lock.json

Lines changed: 1 addition & 1 deletion
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
@@ -1,6 +1,6 @@
11
{
22
"name": "@alicloud/fun",
3-
"version": "2.2.0",
3+
"version": "2.2.1",
44
"description": "(have)Fun with Serverless",
55
"engines": {
66
"node": ">=8.0.0"

0 commit comments

Comments
 (0)