fluent-plugin-http_file_upload 0.1.2 → 0.1.3
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 +4 -4
- data/fluent-plugin-http_file_upload.gemspec +1 -1
- data/lib/fluent/plugin/out_http_file_upload.rb +67 -7
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 2620b143deb8788ff60dc04a35121e3d46784bca
|
|
4
|
+
data.tar.gz: f7fc807e21aaae3a55389957d0dab94ff948f0e5
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 2bb710641f615280bbf7169ac3d9d43a207814b6403918c2c0a9853f35ee60854102287a292b3f43cadb7750924e7d0b957e0a6bda37f88e7b029cf4ce7ac2f0
|
|
7
|
+
data.tar.gz: c7b88c29596196b1cb6fd3ad2112db370a27d743d7efff2a86130330bdcee2435e365b893b00699ca3d3c74b94aa0dd0cdda6eb774b593d836529fcf794ed32b
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
require 'fluent/output'
|
|
2
2
|
require 'fluent/mixin'
|
|
3
3
|
|
|
4
|
+
require 'tempfile'
|
|
4
5
|
require 'openssl'
|
|
5
6
|
require 'uri'
|
|
6
7
|
require 'httpclient'
|
|
@@ -21,6 +22,7 @@ module Fluent
|
|
|
21
22
|
config_set_default :buffer_type, "file"
|
|
22
23
|
|
|
23
24
|
config_param :uri, :string, desc: "Full URI for http upload endpoint for POST requests"
|
|
25
|
+
|
|
24
26
|
config_param :param_name, :string, default: "file", desc: "Parameter name which contains uploaded file content"
|
|
25
27
|
config_param :user_agent, :string, default: "fluent-plugin-http_file_upload", desc: "User-Agent header content"
|
|
26
28
|
config_param :headers, :hash, default: {}, desc: "Additional header fields for requests"
|
|
@@ -40,8 +42,13 @@ module Fluent
|
|
|
40
42
|
|
|
41
43
|
config_param :format, :string, default: "json", desc: "How to format records in uploaded files"
|
|
42
44
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
+
SUPPORTED_COMPRESSION_TYPES = ['gzip']
|
|
46
|
+
config_param :compress, default: nil do |val|
|
|
47
|
+
unless SUPPORTED_COMPRESSION_TYPES.include?(val)
|
|
48
|
+
raise Fluent::ConfigError, "unsupported compression type: #{val}"
|
|
49
|
+
end
|
|
50
|
+
val
|
|
51
|
+
end
|
|
45
52
|
|
|
46
53
|
def configure(conf)
|
|
47
54
|
super
|
|
@@ -53,6 +60,11 @@ module Fluent
|
|
|
53
60
|
if @uri.start_with?("https://")
|
|
54
61
|
@client.ssl_config.verify_mode = @ssl_verify_mode
|
|
55
62
|
end
|
|
63
|
+
|
|
64
|
+
case @compress
|
|
65
|
+
when 'gzip'
|
|
66
|
+
raise Fluent::ConfigError, "gzip command unavailable" unless system('gzip -h > /dev/null 2>&1')
|
|
67
|
+
end
|
|
56
68
|
end
|
|
57
69
|
|
|
58
70
|
def format(tag, time, record)
|
|
@@ -60,14 +72,62 @@ module Fluent
|
|
|
60
72
|
end
|
|
61
73
|
|
|
62
74
|
def write(chunk)
|
|
75
|
+
case @compress
|
|
76
|
+
when 'gzip'
|
|
77
|
+
write_gzip(chunk)
|
|
78
|
+
else
|
|
79
|
+
write_plain(chunk)
|
|
80
|
+
end
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
def write_plain(chunk)
|
|
63
84
|
filename = Time.now.strftime(@filename)
|
|
64
85
|
chunk.open do |io|
|
|
65
|
-
io
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
86
|
+
upload(io, filename)
|
|
87
|
+
end
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
def write_gzip(chunk)
|
|
91
|
+
filename = Time.now.strftime(@filename) + '.gz'
|
|
92
|
+
path = if chunk.respond_to?(:path)
|
|
93
|
+
chunk.path
|
|
94
|
+
else
|
|
95
|
+
w = Tempfile.new('chunk-gzip-temp-http_file_upload')
|
|
96
|
+
chunk.write_to(w)
|
|
97
|
+
w.close
|
|
98
|
+
w.path
|
|
99
|
+
end
|
|
100
|
+
tmp = Tempfile.new('gzip-temp-http_file_upload')
|
|
101
|
+
tmp.close # file will be removed after GC
|
|
102
|
+
res = system "gzip -c #{path} > #{tmp.path}"
|
|
103
|
+
unless res
|
|
104
|
+
log.warn "failed to execute gzip command: exit code '#{$?}'"
|
|
105
|
+
end
|
|
106
|
+
tmp.open
|
|
107
|
+
upload(tmp, filename)
|
|
108
|
+
tmp.close
|
|
109
|
+
end
|
|
110
|
+
|
|
111
|
+
StatDummy = Struct.new(:size)
|
|
112
|
+
|
|
113
|
+
def upload(io, filename)
|
|
114
|
+
stat_dummy = StatDummy.new(io.size)
|
|
115
|
+
io.singleton_class.class_eval{
|
|
116
|
+
define_method(:path){ filename } # override path to feed specified filename to httpclient
|
|
117
|
+
define_method(:lstat){ stat_dummy } # override lstat to return chunk size only (lstat doesn't work for chunk buffer file)
|
|
118
|
+
}
|
|
119
|
+
postdata = { @param_name => io }
|
|
120
|
+
unless @parameters.empty?
|
|
121
|
+
postdata = @parameters.merge(postdata)
|
|
122
|
+
end
|
|
123
|
+
res = @client.post(@uri, postdata)
|
|
124
|
+
if res.status == 200
|
|
125
|
+
log.info "upload success with code 200" # TODO: make this `debug`
|
|
126
|
+
else
|
|
127
|
+
log.error "failed to upload", uri: @uri, code: res.status, content: res.content
|
|
128
|
+
if res.status >= 500 && res.status < 600
|
|
129
|
+
raise "failed to upload with ServerError. retrying."
|
|
69
130
|
end
|
|
70
|
-
@client.post(@uri, postdata)
|
|
71
131
|
end
|
|
72
132
|
end
|
|
73
133
|
end
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: fluent-plugin-http_file_upload
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.1.
|
|
4
|
+
version: 0.1.3
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- TAGOMORI Satoshi
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2016-
|
|
11
|
+
date: 2016-03-04 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: fluentd
|