fluent-plugin-typetalk 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- NTMzMzhkY2NkYzFlMjQ4MTI3YzhjNTE2ODY0Y2UzY2MzMjlkMTlhNA==
4
+ ZTQ2N2Y1ZWM2MDU1YTAyY2E0MWM0NGI4MjVjOTdkZTUyYmVlOGZjMw==
5
5
  data.tar.gz: !binary |-
6
- OTNmYjJiNzEwODFlYjM0N2U5YmZkMDVmZmVmYTI5MDA4MzJkY2I2MQ==
6
+ NDQ5NTY5ZTRkNTQyZjIxZmNmMzdlMTdjNWQ1MzYzOGZhZWIxMjg2Yw==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- MzIxNjFiZThhZDRkYTI5ODIxMzQ1Nzc2NDlhZGZhNjFmOWNmMjM5MGVlNzM5
10
- NTRjY2FlMDI3MTg4NmMyNjRiYzcwYWViZjExYmZkYmExMDhkYmE5YjgzZTc3
11
- OWYzY2UzMzAzZWM3MTYxMTJkOWQ0YmIwYTlkMWZhZjE4MmVhZmI=
9
+ YzNiNGMyYjkyNTg4MTY5NDlkNTI3ZmNjNGY2OGI2OTdiNzkxNDZhN2I0NTRm
10
+ NjEyYWJlNGY3OTZjZDk4NWVlNmVmM2M3NzkyZWU3OGFhMTRlMjQ0MmY3YmNi
11
+ MjM1YjcxNmE1ZjIyY2RjNmZiZTRjMTQ5NmUxZWI4NzM2MmMxMmI=
12
12
  data.tar.gz: !binary |-
13
- ZDEwNDdjOTkwOGJjYjNkM2M1YzgzZDg5YjcxZjkzNGJjYTY1N2VjNzkxN2Fl
14
- ZWUxMDJlYWZmZWMxNzNjMjk4M2QwZTExZjE3ODRjMDhiZTlhYzI3MzQ3YzY3
15
- NmFkZDA1MjYwYWNkNjIyM2EzMmQwNGE3ZWI2MjY4NzI4NTEzMzk=
13
+ NDQyNGVhNDZhNWQ2ZmIzODIzMGQyY2EyZDc1Mzg3ZDU2NjhhOGNiODkxMDdi
14
+ NDljZTFhMWNkYmVhYjIzZTZkYjRkMmVjNzgxYmI0NTc5MzFlM2Y1ZjQ0NWI5
15
+ YTcyZTQyMzc1NWMyN2JjMDNjMWQxMGI1NDA3ZjAyNWNlMWQ1Zjk=
data/.travis.yml CHANGED
@@ -1,3 +1,8 @@
1
1
  language: ruby
2
2
  rvm:
3
- - 1.9.3
3
+ - 1.9.3
4
+ notifications:
5
+ webhooks:
6
+ urls:
7
+ - https://nulab-inc.com/hubot/travis?room=3741
8
+ on_success: change
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # fluent-plugin-typetalk [![Build Status](https://travis-ci.org/tksmd/fluent-plugin-typetalk.png?branch=master)](https://travis-ci.org/tksmd/fluent-plugin-typetalk)
1
+ # fluent-plugin-typetalk [![Build Status](https://travis-ci.org/nulab/fluent-plugin-typetalk.svg?branch=master)](https://travis-ci.org/nulab/fluent-plugin-typetalk)
2
2
 
3
3
  ## Overview
4
4
 
@@ -61,9 +61,18 @@ By default, the number of notification you can send within a minute is limited t
61
61
  limit 10
62
62
  </match>
63
63
  ```
64
-
65
64
  In the example above, you can allow 10 notifications to be sent within 300 seconds. To remove the notification throttle, set both parameters to 0.
66
65
 
66
+ Typetalk doesn't allow message which length is equal to or greater than 4096. Since 0.0.5, the message over 4096 characters will be truncated automatically. To turn off this behaviour, set truncate_message to false
67
+ ```
68
+ <match ...>
69
+ type typetalk
70
+ :
71
+ truncate_message false
72
+ </match>
73
+ ```
74
+ If you set this value to false, the message over 4096 characters will not be sent to Typetalk.
75
+
67
76
  ## TODO
68
77
 
69
78
  Pull requests are very welcome!!
@@ -80,6 +89,16 @@ To run tests, do the following.
80
89
  $ VERBOSE=1 bundle exec rake test
81
90
  ```
82
91
 
92
+ If you want to run a certain file, run rake like this
93
+ ```
94
+ $ VERBOSE=1 bundle exec rake test TEST=test/plugin/test_out_typetalk.rb
95
+ ```
96
+
97
+ In addition, you can run specific method like this.
98
+ ```
99
+ $ VERBOSE=1 bundle exec rake test TEST=test/plugin/test_out_typetalk.rb TESTOPTS="--name=test_post_message_invalid_request_error"
100
+ ```
101
+
83
102
  When releasing, call rake release as follows.
84
103
  ```
85
104
  $ bundle exec rake release
@@ -4,12 +4,12 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
 
5
5
  Gem::Specification.new do |spec|
6
6
  spec.name = "fluent-plugin-typetalk"
7
- spec.version = "0.0.4"
7
+ spec.version = "0.0.5"
8
8
  spec.authors = ["tksmd","umakoz"]
9
9
  spec.email = ["someda@isenshi.com"]
10
10
  spec.description = %q{fluent plugin to send message to typetalk}
11
11
  spec.summary = spec.description
12
- spec.homepage = "https://github.com/tksmd/fluent-plugin-typetalk"
12
+ spec.homepage = "https://github.com/nulab/fluent-plugin-typetalk"
13
13
  spec.license = "Apache-2.0"
14
14
 
15
15
  spec.files = `git ls-files`.split($/)
@@ -15,6 +15,8 @@ module Fluent
15
15
  config_param :interval, :time, :default => 60
16
16
  config_param :limit, :integer, :default => 10
17
17
 
18
+ config_param :truncate_message, :bool, :default => true
19
+
18
20
  attr_reader :typetalk
19
21
 
20
22
  # Define `log` method for v0.10.42 or earlier
@@ -113,7 +115,9 @@ module Fluent
113
115
  res = JSON.parse(e.message) rescue {}
114
116
  unless res['body'].nil?
115
117
  body = JSON.parse(res['body']) rescue {}
116
- msg = body['error']
118
+ msg = body['errors'].map{|f|
119
+ f['field'] + ' : ' + f['message']
120
+ }.join(',')
117
121
  end
118
122
  raise TypetalkError, "failed to post, msg: #{msg}, code: #{res['status']}"
119
123
  end
@@ -134,7 +138,11 @@ module Fluent
134
138
  end
135
139
  end
136
140
 
137
- (message % values).gsub(/\\n/, "\n")
141
+ truncate (@message % values).gsub(/\\n/, "\n")
142
+ end
143
+
144
+ def truncate(str, limit=4096)
145
+ @truncate_message && str.size >= limit ? str[0,limit-5] + ' ...' : str
138
146
  end
139
147
 
140
148
  end
@@ -39,6 +39,17 @@ class TypetalkOutputTest < Test::Unit::TestCase
39
39
  limit 0
40
40
  ]
41
41
 
42
+ CONFIG_TRUNCATE = %[
43
+ type typetalk
44
+ client_id 123456
45
+ client_secret secret
46
+ topic_id 1
47
+ message %s
48
+ out_keys message
49
+ truncate_message true
50
+ ]
51
+
52
+
42
53
  def create_driver(conf = CONFIG, tag = 'test')
43
54
  Fluent::Test::OutputTestDriver.new(Fluent::TypetalkOutput, tag).configure(conf)
44
55
  end
@@ -59,7 +70,7 @@ class TypetalkOutputTest < Test::Unit::TestCase
59
70
 
60
71
  def test_write
61
72
  d = create_driver()
62
- stub(d.instance.typetalk).post_message(1, 'notice : test1')
73
+ mock(d.instance.typetalk).post_message(1, 'notice : test1')
63
74
  d.emit({'message' => 'test1'})
64
75
  d.run()
65
76
  end
@@ -68,7 +79,7 @@ class TypetalkOutputTest < Test::Unit::TestCase
68
79
  d = create_driver(CONFIG, 'warn')
69
80
  d.instance.message = "notice : %s [%s]"
70
81
  d.instance.out_keys = ["message", "time"]
71
- stub(d.instance.typetalk).post_message(1, "notice : test1 [1399910738]")
82
+ mock(d.instance.typetalk).post_message(1, "notice : test1 [1399910738]")
72
83
 
73
84
  ENV["TZ"]="Asia/Tokyo"
74
85
  t = Time.strptime('2014-05-13 01:05:38', '%Y-%m-%d %T')
@@ -93,12 +104,12 @@ class TypetalkOutputTest < Test::Unit::TestCase
93
104
  def test_post_message_invalid_request_error
94
105
  d = create_driver()
95
106
  stub(d.instance.typetalk).post_message(1, 'notice : test1') {
96
- raise Typetalk::InvalidRequest, {status:400, headers:{}, body:'{"error":"invalid_client","error_description":""}'}.to_json
107
+ raise Typetalk::InvalidRequest, {status:400, headers:{}, body:'{"errors":[{"field":"message", "name":"error.maxLength", "message":"Maximum length is 4,096 characters."}]}'}.to_json
97
108
  }
98
109
  stub(d.instance.log).error {|name, params|
99
110
  assert_equal "out_typetalk:", name
100
111
  assert_equal Fluent::TypetalkError, params[:error_class]
101
- assert_equal "failed to post, msg: invalid_client, code: 400", params[:error]
112
+ assert_equal "failed to post, msg: message : Maximum length is 4,096 characters., code: 400", params[:error]
102
113
  }
103
114
  d.emit({'message' => 'test1'})
104
115
  d.run()
@@ -107,7 +118,7 @@ class TypetalkOutputTest < Test::Unit::TestCase
107
118
  def test_post_message_notfound_error
108
119
  d = create_driver()
109
120
  stub(d.instance.typetalk).post_message(1, 'notice : test1') {
110
- raise Typetalk::NotFound, {status:404, headers:{}, body:''}.to_json
121
+ raise Typetalk::NotFound, {status:404, headers:{}, body:'{"errors":[]}'}.to_json
111
122
  }
112
123
  stub(d.instance.log).error {|name, params|
113
124
  assert_equal "out_typetalk:", name
@@ -120,8 +131,8 @@ class TypetalkOutputTest < Test::Unit::TestCase
120
131
 
121
132
  def test_throttle
122
133
  d = create_driver(CONFIG_THROTTLE)
123
- stub(d.instance.typetalk).post_message(1, 'notice : test1')
124
- stub(d.instance.typetalk).post_message(1, 'notice : test3')
134
+ mock(d.instance.typetalk).post_message(1, 'notice : test1')
135
+ mock(d.instance.typetalk).post_message(1, 'notice : test3')
125
136
  stub(d.instance.log).error {|name, params|
126
137
  assert_equal "out_typetalk:", name
127
138
  assert_equal "number of posting message within 5.0(sec) reaches to the limit 1", params[:error]
@@ -133,4 +144,15 @@ class TypetalkOutputTest < Test::Unit::TestCase
133
144
  d.run()
134
145
  end
135
146
 
147
+ def test_truncate
148
+ d = create_driver(CONFIG_TRUNCATE)
149
+ mock(d.instance.typetalk).post_message(1, '1')
150
+ mock(d.instance.typetalk).post_message(1, '1'*4095)
151
+ mock(d.instance.typetalk).post_message(1, '1'*4091 + ' ...')
152
+ d.emit({'message' => '1'})
153
+ d.emit({'message' => '1'*4095}) # not truncated
154
+ d.emit({'message' => '1'*4096}) # should be truncated
155
+ d.run()
156
+ end
157
+
136
158
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fluent-plugin-typetalk
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - tksmd
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-06-17 00:00:00.000000000 Z
12
+ date: 2015-05-01 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -98,7 +98,7 @@ files:
98
98
  - lib/fluent/plugin/out_typetalk.rb
99
99
  - test/helper.rb
100
100
  - test/plugin/test_out_typetalk.rb
101
- homepage: https://github.com/tksmd/fluent-plugin-typetalk
101
+ homepage: https://github.com/nulab/fluent-plugin-typetalk
102
102
  licenses:
103
103
  - Apache-2.0
104
104
  metadata: {}