fluent-plugin-http-pull 0.1.0 → 0.2.0.pre

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3dba2cd5721def7eb2a06c6c555ac86ed7e71af7
4
- data.tar.gz: 7c236824e3f147f3834cb48808b29d0a21a8a197
3
+ metadata.gz: 198fe9ad32356188705d13ad28b5587e956a9dae
4
+ data.tar.gz: 1bd9d9eb636748fbd24e5ea58b687138990d3021
5
5
  SHA512:
6
- metadata.gz: 44b6b63cc58a1fd1fc7811cbba3aa92597db70827b2acbbe327b778217f8760696c2e6d7a79837eaada4da0e2a3e41267c5a393600aae85bc5052799efa1c4b3
7
- data.tar.gz: 606d3ba7b39fd1c8966215599dca7fa0e63b30267c7f782b902b8a2fa81a9a9cd22ed38adea50657061b63e528402fb9c70571a99ee6b7ce476874c901574740
6
+ metadata.gz: d28286e0838a18b75954d315beea25d9da6831fff29b28d2ad7d5471505e7e758ceff63e5dc85dbd7cf2069325bb0692582c7a7d0ec7e07561a49d43d22faf37
7
+ data.tar.gz: 55fe7c398310a9fbc4596a57753a43e3970a8c5091507396bcda160e3765a4e7c223a5f333e2b5d4e94e7b09df08505e18f0fd628bc7717892c207b01a47151d
data/README.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # fluent-plugin-http-pull
2
2
 
3
+ [![Build Status](https://travis-ci.org/HatsuneMiku3939/fluent-plugin-http-pull.svg?branch=master)](https://travis-ci.org/HatsuneMiku3939/fluent-plugin-http-pull)
4
+ [![Gem Version](https://badge.fury.io/rb/fluent-plugin-http-pull.svg)](https://badge.fury.io/rb/fluent-plugin-http-pull)
5
+
6
+
3
7
  [Fluentd](http://fluentd.org/) input plugin to pull log from rest api.
4
8
 
5
9
  Many of modern server application offer status reporting API via http (even 'fluentd' too). This plugin will help to gathering status log from these status api.
@@ -61,21 +65,19 @@ $ bundle
61
65
  <source>
62
66
  @type http_pull
63
67
 
64
- tag test
68
+ tag fluentd.status
65
69
  url http://localhost:24220/api/plugins.json
66
70
  interval 1
67
-
68
- status_only false
69
71
  </source>
70
72
 
71
- <match test>
73
+ <match fluentd.status>
72
74
  @type stdout
73
75
  </match>
74
76
 
75
- # 2017-05-17 21:41:47.872951000 +0900 test: {"url":"http://localhost:24220/api/plugins.json","status":200,"message":{"plugins":[{"plugin_id":"object:1e7e3d...
76
- # 2017-05-17 21:41:48.955316000 +0900 test: {"url":"http://localhost:24220/api/plugins.json","status":200,"message":{"plugins":[{"plugin_id":"object:1e7e3d...
77
- # 2017-05-17 21:41:50.033628000 +0900 test: {"url":"http://localhost:24220/api/plugins.json","status":200,"message":{"plugins":[{"plugin_id":"object:1e7e3d...
78
- # 2017-05-17 21:41:51.107372000 +0900 test: {"url":"http://localhost:24220/api/plugins.json","status":200,"message":{"plugins":[{"plugin_id":"object:1e7e3d...
77
+ # 2017-05-17 21:41:47.872951000 +0900 fluentd.status: {"url":"http://localhost:24220/api/plugins.json","status":200,"message":{"plugins":[{"plugin_id":"object:1e7e3d...
78
+ # 2017-05-17 21:41:48.955316000 +0900 fluentd.status: {"url":"http://localhost:24220/api/plugins.json","status":200,"message":{"plugins":[{"plugin_id":"object:1e7e3d...
79
+ # 2017-05-17 21:41:50.033628000 +0900 fluentd.status: {"url":"http://localhost:24220/api/plugins.json","status":200,"message":{"plugins":[{"plugin_id":"object:1e7e3d...
80
+ # 2017-05-17 21:41:51.107372000 +0900 fluentd.status: {"url":"http://localhost:24220/api/plugins.json","status":200,"message":{"plugins":[{"plugin_id":"object:1e7e3d...
79
81
  ```
80
82
 
81
83
 
@@ -84,44 +86,60 @@ $ bundle
84
86
  <source>
85
87
  @type http_pull
86
88
 
87
- tag test
89
+ tag es.cluster.health
88
90
  url http://localhost:9200/_cluster/health
89
91
  interval 1
90
-
91
- status_only false
92
92
  </source>
93
93
 
94
- <match test>
94
+ <match es.cluster.health>
95
95
  @type stdout
96
96
  </match>
97
97
 
98
- # 2017-05-17 12:49:09.886298008 +0000 test: {"url":"http://localhost:9200/_cluster/health","status":200,"message":{"cluster_name":"elasticsearch","status":"green",...
99
- # 2017-05-17 12:49:10.669431296 +0000 test: {"url":"http://localhost:9200/_cluster/health","status":200,"message":{"cluster_name":"elasticsearch","status":"green",...
100
- # 2017-05-17 12:49:11.668789668 +0000 test: {"url":"http://localhost:9200/_cluster/health","status":200,"message":{"cluster_name":"elasticsearch","status":"green",...
101
- # 2017-05-17 12:49:12.668789849 +0000 test: {"url":"http://localhost:9200/_cluster/health","status":200,"message":{"cluster_name":"elasticsearch","status":"green",...
98
+ # 2017-05-17 12:49:09.886298008 +0000 es.cluster.health: {"url":"http://localhost:9200/_cluster/health","status":200,"message":{"cluster_name":"elasticsearch","status":"green",...
99
+ # 2017-05-17 12:49:10.669431296 +0000 es.cluster.health: {"url":"http://localhost:9200/_cluster/health","status":200,"message":{"cluster_name":"elasticsearch","status":"green",...
100
+ # 2017-05-17 12:49:11.668789668 +0000 es.cluster.health: {"url":"http://localhost:9200/_cluster/health","status":200,"message":{"cluster_name":"elasticsearch","status":"green",...
101
+ # 2017-05-17 12:49:12.668789849 +0000 es.cluster.health: {"url":"http://localhost:9200/_cluster/health","status":200,"message":{"cluster_name":"elasticsearch","status":"green",...
102
102
  ```
103
103
 
104
104
  ## Configuration
105
105
 
106
- * See also: Fluent::Plugin::Input
107
-
108
- ## Fluent::Plugin::HttpPullInput
109
-
110
106
  ### tag (string) (required)
111
107
 
112
108
  The tag of the event.
113
109
 
114
110
  ### url (string) (required)
115
111
 
116
- The uri of monitoring target
112
+ The url of remote server.
117
113
 
118
114
  ### interval (integer) (required)
119
115
 
120
- The second interval time between periodic request
116
+ The second interval time between periodic request.
121
117
 
122
- ### status_only (bool) (optional)
118
+ ### status_only (bool) (optional, default: false)
123
119
 
124
- status_only
120
+ If atatus_only is true, body is not parsed.
121
+
122
+ ## In case of remote error
123
+
124
+ ### Can receive response from remote
125
+
126
+ ```
127
+ {
128
+ "url": url of remote
129
+ "status": status code of response
130
+ "error": "RestClient::NotFound: 404 Not Found" or something similar
131
+ }
132
+ ```
133
+
134
+ ### All the other case
135
+
136
+ ```
137
+ {
138
+ "url": url of remote
139
+ "status": 0
140
+ "error": "Errno::ECONNREFUSED: Connection refused - connect(2) for "localhost" port 12345" or something similar
141
+ }
142
+ ```
125
143
 
126
144
  ## Copyright
127
145
 
@@ -3,7 +3,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
3
 
4
4
  Gem::Specification.new do |spec|
5
5
  spec.name = "fluent-plugin-http-pull"
6
- spec.version = "0.1.0"
6
+ spec.version = "0.2.0.pre"
7
7
  spec.authors = ["filepang"]
8
8
  spec.email = ["filepang@gmail.com"]
9
9
 
@@ -22,6 +22,7 @@ Gem::Specification.new do |spec|
22
22
 
23
23
  spec.add_development_dependency "rake", "~> 12.0"
24
24
  spec.add_development_dependency "test-unit", "~> 3.0"
25
+ spec.add_development_dependency "test-unit-rr", "~> 1.0", "~> 1.0.2"
25
26
 
26
27
  spec.add_runtime_dependency "fluentd", [">= 0.14.10", "< 2"]
27
28
  spec.add_runtime_dependency "rest-client", [">= 2.0.0", "< 3"]
@@ -47,20 +47,25 @@ module Fluent
47
47
  while !@shutdown
48
48
  ts = Time.now.to_f
49
49
 
50
- res = RestClient.get(@url)
51
- if @status_only
52
- router.emit(@tag, Engine.now, {
53
- "url" => @url,
54
- "status" => res.code
55
- })
56
- else
57
- router.emit(@tag, Engine.now, {
58
- "url" => @url,
59
- "status" => res.code,
60
- "message" => JSON.parse(res.body)
61
- })
50
+ log = { "url" => @url }
51
+
52
+ begin
53
+ res = RestClient.get(@url)
54
+ log["status"] = res.code
55
+ log["body"] = res.body
56
+ rescue RestClient::ExceptionWithResponse => err
57
+ log["status"] = err.code
58
+ log["error"] = err.message
59
+ rescue Exception => err
60
+ log["status"] = 0
61
+ log["error"] = err.message
62
62
  end
63
63
 
64
+ log["message"] = JSON.parse(log["body"]) if !@status_only && log["body"] != nil
65
+ log.delete("body")
66
+
67
+ router.emit(@tag, Engine.now, log)
68
+
64
69
  te = Time.now.to_f
65
70
  delay = @interval - (te - ts)
66
71
  delay = delay > 0 ? delay : 0
@@ -4,5 +4,7 @@ require "fluent/test"
4
4
  require "fluent/test/driver/input"
5
5
  require "fluent/test/helpers"
6
6
 
7
+ require "test/unit/rr"
8
+
7
9
  Test::Unit::TestCase.include(Fluent::Test::Helpers)
8
10
  Test::Unit::TestCase.extend(Fluent::Test::Helpers)
@@ -1,13 +1,12 @@
1
1
  require "helper"
2
2
  require "fluent/plugin/in_http_pull.rb"
3
3
 
4
- require 'webrick'
4
+ require 'ostruct'
5
5
 
6
6
  class HttpPullInputTest < Test::Unit::TestCase
7
- PORT = rand(1000) + 3000
8
7
  TEST_INTERVAL_3_CONFIG = %[
9
8
  tag test
10
- url http://127.0.0.1:#{PORT}
9
+ url http://127.0.0.1
11
10
 
12
11
  interval 3
13
12
  status_only true
@@ -15,61 +14,72 @@ class HttpPullInputTest < Test::Unit::TestCase
15
14
 
16
15
  TEST_INTERVAL_5_CONFIG = %[
17
16
  tag test
18
- url http://127.0.0.1:#{PORT}
17
+ url http://127.0.0.1
19
18
 
20
19
  interval 5
21
20
  ]
22
21
 
23
- @test_server = nil
24
-
25
22
  setup do
26
23
  Fluent::Test.setup
24
+ end
27
25
 
28
- Thread.new do
29
- @test_server = WEBrick::HTTPServer.new :Port => PORT
30
- @test_server.mount_proc '/' do |req, res|
31
- res.status = 200
32
- res['Content-Type'] = 'application/json'
33
- res.body = '{"status":"OK"}'
26
+ sub_test_case "success case with status only" do
27
+ setup do
28
+ mock(RestClient).get("http://127.0.0.1").times(2) do
29
+ OpenStruct.new({code: 200, body: '{"status": "OK"}'})
34
30
  end
35
- @test_server.start
36
31
  end
37
- end
38
32
 
39
- teardown do
40
- @test_server.shutdown
41
- sleep 1
42
- end
33
+ test 'interval 3 with status_only' do
34
+ d = create_driver TEST_INTERVAL_3_CONFIG
35
+ assert_equal "test", d.instance.tag
43
36
 
44
- test 'interval 3 with status_only' do
45
- d = create_driver TEST_INTERVAL_3_CONFIG
46
- assert_equal "test", d.instance.tag
37
+ d.run(timeout: 5) do
38
+ sleep 5
39
+ end
40
+ assert_equal 2, d.events.size
47
41
 
48
- d.run(timeout: 8) do
49
- sleep 8
42
+ d.events.each do |tag, time, record|
43
+ assert_equal("test", tag)
44
+ assert_equal({"url"=>"http://127.0.0.1","status"=>200}, record)
45
+ assert(time.is_a?(Fluent::EventTime))
46
+ end
50
47
  end
51
- assert_equal 3, d.events.size
52
48
 
53
- d.events.each do |tag, time, record|
54
- assert_equal("test", tag)
55
- assert_equal({"url"=>"http://127.0.0.1:#{PORT}","status"=>200}, record)
56
- assert(time.is_a?(Fluent::EventTime))
57
- end
58
- end
49
+ test 'interval 5' do
50
+ d = create_driver TEST_INTERVAL_5_CONFIG
51
+ assert_equal "test", d.instance.tag
59
52
 
60
- test 'interval 5' do
61
- d = create_driver TEST_INTERVAL_5_CONFIG
62
- assert_equal "test", d.instance.tag
53
+ d.run(timeout: 7) do
54
+ sleep 7
55
+ end
56
+ assert_equal 2, d.events.size
63
57
 
64
- d.run(timeout: 7) do
65
- sleep 7
58
+ d.events.each do |tag, time, record|
59
+ assert_equal("test", tag)
60
+ assert_equal({"url"=>"http://127.0.0.1","status"=>200, "message"=>{"status"=>"OK"}}, record)
61
+ assert(time.is_a?(Fluent::EventTime))
62
+ end
66
63
  end
67
- assert_equal 2, d.events.size
64
+ end
68
65
 
69
- d.events.each do |tag, time, record|
70
- assert_equal("test", tag)
71
- assert_equal({"url"=>"http://127.0.0.1:#{PORT}","status"=>200, "message"=>{"status"=>"OK"}}, record)
72
- assert(time.is_a?(Fluent::EventTime))
66
+ sub_test_case "fail when remote down" do
67
+ TEST_REFUSED_CONFIG = %[
68
+ tag test
69
+ url http://127.0.0.1:5927
70
+ interval 1
71
+ ]
72
+ test "connection refused by remote" do
73
+ d = create_driver TEST_REFUSED_CONFIG
74
+ d.run(timeout: 2) { sleep 3 }
75
+
76
+ assert_equal 3, d.events.size
77
+ d.events.each do |tag, time, record|
78
+ assert_equal("test", tag)
79
+ assert_equal("http://127.0.0.1:5927", record["url"])
80
+ assert_equal(0, record["status"])
81
+ assert(time.is_a?(Fluent::EventTime))
82
+ end
73
83
  end
74
84
  end
75
85
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fluent-plugin-http-pull
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0.pre
5
5
  platform: ruby
6
6
  authors:
7
7
  - filepang
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-05-17 00:00:00.000000000 Z
11
+ date: 2017-08-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -38,6 +38,26 @@ dependencies:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '3.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: test-unit-rr
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.0'
48
+ - - "~>"
49
+ - !ruby/object:Gem::Version
50
+ version: 1.0.2
51
+ type: :development
52
+ prerelease: false
53
+ version_requirements: !ruby/object:Gem::Requirement
54
+ requirements:
55
+ - - "~>"
56
+ - !ruby/object:Gem::Version
57
+ version: '1.0'
58
+ - - "~>"
59
+ - !ruby/object:Gem::Version
60
+ version: 1.0.2
41
61
  - !ruby/object:Gem::Dependency
42
62
  name: fluentd
43
63
  requirement: !ruby/object:Gem::Requirement
@@ -109,9 +129,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
109
129
  version: '0'
110
130
  required_rubygems_version: !ruby/object:Gem::Requirement
111
131
  requirements:
112
- - - ">="
132
+ - - ">"
113
133
  - !ruby/object:Gem::Version
114
- version: '0'
134
+ version: 1.3.1
115
135
  requirements: []
116
136
  rubyforge_project:
117
137
  rubygems_version: 2.5.2