fluent-plugin-typetalk 0.0.3 → 0.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +8 -8
- data/README.md +12 -0
- data/fluent-plugin-typetalk.gemspec +2 -2
- data/lib/fluent/plugin/out_typetalk.rb +29 -7
- data/test/plugin/test_out_typetalk.rb +46 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
NTMzMzhkY2NkYzFlMjQ4MTI3YzhjNTE2ODY0Y2UzY2MzMjlkMTlhNA==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
OTNmYjJiNzEwODFlYjM0N2U5YmZkMDVmZmVmYTI5MDA4MzJkY2I2MQ==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
MzIxNjFiZThhZDRkYTI5ODIxMzQ1Nzc2NDlhZGZhNjFmOWNmMjM5MGVlNzM5
|
10
|
+
NTRjY2FlMDI3MTg4NmMyNjRiYzcwYWViZjExYmZkYmExMDhkYmE5YjgzZTc3
|
11
|
+
OWYzY2UzMzAzZWM3MTYxMTJkOWQ0YmIwYTlkMWZhZjE4MmVhZmI=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
ZDEwNDdjOTkwOGJjYjNkM2M1YzgzZDg5YjcxZjkzNGJjYTY1N2VjNzkxN2Fl
|
14
|
+
ZWUxMDJlYWZmZWMxNzNjMjk4M2QwZTExZjE3ODRjMDhiZTlhYzI3MzQ3YzY3
|
15
|
+
NmFkZDA1MjYwYWNkNjIyM2EzMmQwNGE3ZWI2MjY4NzI4NTEzMzk=
|
data/README.md
CHANGED
@@ -52,6 +52,18 @@ This plugin allows you to use special value namely $hostname in out_keys. By usi
|
|
52
52
|
</match>
|
53
53
|
```
|
54
54
|
|
55
|
+
By default, the number of notification you can send within a minute is limited to 10. Log lines that exceed this limit will be discarded. You can change it with `interval` and `limit` parameters.
|
56
|
+
```
|
57
|
+
<match ...>
|
58
|
+
type typetalk
|
59
|
+
:
|
60
|
+
interval 300
|
61
|
+
limit 10
|
62
|
+
</match>
|
63
|
+
```
|
64
|
+
|
65
|
+
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
|
+
|
55
67
|
## TODO
|
56
68
|
|
57
69
|
Pull requests are very welcome!!
|
@@ -4,8 +4,8 @@ $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.
|
8
|
-
spec.authors = ["tksmd"]
|
7
|
+
spec.version = "0.0.4"
|
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
|
@@ -1,11 +1,10 @@
|
|
1
1
|
module Fluent
|
2
|
-
class TypetalkOutput < Fluent::
|
2
|
+
class TypetalkOutput < Fluent::Output
|
3
3
|
Fluent::Plugin.register_output('typetalk', self)
|
4
4
|
|
5
5
|
config_param :client_id, :string
|
6
6
|
config_param :client_secret, :string
|
7
7
|
config_param :topic_id, :integer
|
8
|
-
config_param :flush_interval, :time, :default => 1
|
9
8
|
|
10
9
|
config_param :message, :string
|
11
10
|
config_param :out_keys, :string, :default => ""
|
@@ -13,6 +12,9 @@ module Fluent
|
|
13
12
|
config_param :time_format, :string, :default => nil
|
14
13
|
config_param :tag_key, :string, :default => 'tag'
|
15
14
|
|
15
|
+
config_param :interval, :time, :default => 60
|
16
|
+
config_param :limit, :integer, :default => 10
|
17
|
+
|
16
18
|
attr_reader :typetalk
|
17
19
|
|
18
20
|
# Define `log` method for v0.10.42 or earlier
|
@@ -56,6 +58,9 @@ module Fluent
|
|
56
58
|
@time_parse_proc = Proc.new {|str| str.to_i }
|
57
59
|
end
|
58
60
|
|
61
|
+
@need_throttle = @limit > 0 && @interval > 0
|
62
|
+
@slot = []
|
63
|
+
|
59
64
|
end
|
60
65
|
|
61
66
|
def start
|
@@ -66,18 +71,35 @@ module Fluent
|
|
66
71
|
super
|
67
72
|
end
|
68
73
|
|
69
|
-
def
|
70
|
-
|
71
|
-
|
74
|
+
def emit(tag, es, chain)
|
75
|
+
es.each do |time, record|
|
76
|
+
if @need_throttle && throttle(time)
|
77
|
+
log.error("out_typetalk:", :error => "number of posting message within #{@interval}(sec) reaches to the limit #{@limit}")
|
78
|
+
next
|
79
|
+
end
|
72
80
|
|
73
|
-
def write(chunk)
|
74
|
-
chunk.msgpack_each do |(tag,time,record)|
|
75
81
|
begin
|
76
82
|
send_message(tag, time, record)
|
77
83
|
rescue => e
|
78
84
|
log.error("out_typetalk:", :error_class => e.class, :error => e.message)
|
79
85
|
end
|
80
86
|
end
|
87
|
+
|
88
|
+
chain.next
|
89
|
+
end
|
90
|
+
|
91
|
+
def throttle(time)
|
92
|
+
expired = time.to_f - @interval
|
93
|
+
while @slot.first && (@slot.first <= expired)
|
94
|
+
@slot.shift
|
95
|
+
end
|
96
|
+
|
97
|
+
exceed = @slot.length >= @limit
|
98
|
+
unless exceed
|
99
|
+
@slot.push(time.to_f)
|
100
|
+
end
|
101
|
+
|
102
|
+
exceed
|
81
103
|
end
|
82
104
|
|
83
105
|
def send_message(tag, time, record)
|
@@ -17,14 +17,44 @@ class TypetalkOutputTest < Test::Unit::TestCase
|
|
17
17
|
out_keys message
|
18
18
|
]
|
19
19
|
|
20
|
+
CONFIG_THROTTLE = %[
|
21
|
+
type typetalk
|
22
|
+
client_id 123456
|
23
|
+
client_secret secret
|
24
|
+
topic_id 1
|
25
|
+
message notice : %s
|
26
|
+
out_keys message
|
27
|
+
interval 5
|
28
|
+
limit 1
|
29
|
+
]
|
30
|
+
|
31
|
+
CONFIG_NO_THROTTLE = %[
|
32
|
+
type typetalk
|
33
|
+
client_id 123456
|
34
|
+
client_secret secret
|
35
|
+
topic_id 1
|
36
|
+
message notice : %s
|
37
|
+
out_keys message
|
38
|
+
interval 0
|
39
|
+
limit 0
|
40
|
+
]
|
41
|
+
|
20
42
|
def create_driver(conf = CONFIG, tag = 'test')
|
21
|
-
Fluent::Test::
|
43
|
+
Fluent::Test::OutputTestDriver.new(Fluent::TypetalkOutput, tag).configure(conf)
|
22
44
|
end
|
23
45
|
|
24
46
|
def test_configure
|
25
47
|
d = create_driver()
|
26
48
|
assert_equal '123456', Typetalk.config.client_id
|
27
49
|
assert_equal 'secret', Typetalk.config.client_secret
|
50
|
+
assert_equal 60, d.instance.instance_variable_get(:@interval)
|
51
|
+
assert_equal 10, d.instance.instance_variable_get(:@limit)
|
52
|
+
assert_equal true, d.instance.instance_variable_get(:@need_throttle)
|
53
|
+
end
|
54
|
+
|
55
|
+
def test_configure_no_throttle
|
56
|
+
d = create_driver(CONFIG_NO_THROTTLE)
|
57
|
+
assert_equal false, d.instance.instance_variable_get(:@need_throttle)
|
28
58
|
end
|
29
59
|
|
30
60
|
def test_write
|
@@ -88,4 +118,19 @@ class TypetalkOutputTest < Test::Unit::TestCase
|
|
88
118
|
d.run()
|
89
119
|
end
|
90
120
|
|
121
|
+
def test_throttle
|
122
|
+
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')
|
125
|
+
stub(d.instance.log).error {|name, params|
|
126
|
+
assert_equal "out_typetalk:", name
|
127
|
+
assert_equal "number of posting message within 5.0(sec) reaches to the limit 1", params[:error]
|
128
|
+
}
|
129
|
+
d.emit({'message' => 'test1'})
|
130
|
+
d.emit({'message' => 'test2'})
|
131
|
+
sleep 5
|
132
|
+
d.emit({'message' => 'test3'})
|
133
|
+
d.run()
|
134
|
+
end
|
135
|
+
|
91
136
|
end
|
metadata
CHANGED
@@ -1,14 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fluent-plugin-typetalk
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- tksmd
|
8
|
+
- umakoz
|
8
9
|
autorequire:
|
9
10
|
bindir: bin
|
10
11
|
cert_chain: []
|
11
|
-
date: 2014-06-
|
12
|
+
date: 2014-06-17 00:00:00.000000000 Z
|
12
13
|
dependencies:
|
13
14
|
- !ruby/object:Gem::Dependency
|
14
15
|
name: bundler
|