fluent-plugin-google-cloud-storage-out 0.1.10 → 0.1.11

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: 13338f63d5b2ddf5e91c56b380d00dec3d24f690
4
- data.tar.gz: 46932068452621ea096f14ffcfac24080e102238
3
+ metadata.gz: 0ae88e22d3d8cac4aa939ccc35fe2af17ca90fbe
4
+ data.tar.gz: 6e94e55d777c8c0bc07819d2119c68402deffd05
5
5
  SHA512:
6
- metadata.gz: bd46b63ba61e5447ec224a0753803df242555766330c2882a1d28b2625860cf42b6737918be2ec6cc089dd372bf954cfc5f60ddeca88371b39d74eb8d659092e
7
- data.tar.gz: dfcf8bfa3814af0f376ebf44d0d877185aa0aff8a1abed746be3231c14e2f7fe9dc9065059765bc807249d61678d3c3bb7310c68fb8999d17e90a4a7f2f61b15
6
+ metadata.gz: 2977e856bd530808ec34d62a30c37fcc85ac3c086c4be95a4a88a470611739fa8e1f937daa3ef584eb903a11a1ffda7d7c74b4cb2a00342454cb73e1304ac229
7
+ data.tar.gz: 4326eaad59d06a09c3416fd2e9095804a5d0fea152176517f8a3027383a31eff0515c5276f0282e78b0fd65f02cdf04cbd2c96b4de7b5b650feb2676d5ba1659
@@ -4,7 +4,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
 
5
5
  Gem::Specification.new do |spec|
6
6
  spec.name = "fluent-plugin-google-cloud-storage-out"
7
- spec.version = "0.1.10"
7
+ spec.version = "0.1.11"
8
8
  spec.authors = ["Hideki Matsuoka"]
9
9
  spec.email = ["matsuoka.hide@gmail.com"]
10
10
 
@@ -13,9 +13,17 @@ module Fluent
13
13
 
14
14
  SUPPORTED_COMPRESS = {
15
15
  'gz' => :gz,
16
- 'gzip' => :gzip,
16
+ 'gzip' => :gz,
17
17
  }
18
18
 
19
+ UNIQUE_STRATEGY= {
20
+ 'chunk_id' => :chunk_id,
21
+ 'increment' => :increment,
22
+ 'timestamp' => :timestamp,
23
+ }
24
+
25
+ UNIQUE_PLACE_HOLDER = '${unique}'
26
+
19
27
  #
20
28
  # Config Parameters
21
29
  #
@@ -40,6 +48,18 @@ module Fluent
40
48
  #desc "The tag for out"
41
49
  config_param :default_tag, :string, :default => 'tag_missing'
42
50
 
51
+ #desc "The unique strategy for avoid override for same path"
52
+ config_param :unique_strategy, :default => nil do |val|
53
+ c = UNIQUE_STRATEGY[val]
54
+ unless c
55
+ raise ConfigError, "Unsupported make uniuqe strategy '#{val}'"
56
+ end
57
+ c
58
+ end
59
+
60
+ #desc "The format for unique replacement, if you set timestamp to unique_strategy, you should set time format"
61
+ config_param :unique_format, :string, :default => "%Y%m%d%H%M%S%L"
62
+
43
63
  #desc "Compress flushed file."
44
64
  config_param :compress, :default => nil do |val|
45
65
  c = SUPPORTED_COMPRESS[val]
@@ -75,9 +95,18 @@ module Fluent
75
95
 
76
96
  super
77
97
 
98
+ if @path.index(UNIQUE_PLACE_HOLDER).nil? && @unique_strategy
99
+ raise Fluent::ConfigError, "Path must contain ${unique}, or you set the unique_strategy to nil."
100
+ end
101
+
78
102
  @formatter = Plugin.new_formatter(@format)
79
103
  @formatter.configure(conf)
104
+ @path_suffix = ".log"
80
105
  prepare_client()
106
+
107
+ if @unique_strategy == :increment
108
+ @samepath_counter = 0
109
+ end
81
110
  end
82
111
 
83
112
  def prepare_client
@@ -103,17 +132,56 @@ module Fluent
103
132
  @formatter.format(tag, time, record)
104
133
  end
105
134
 
106
- def path_format(chunk_key)
107
- path = Time.strptime(chunk_key, @time_slice_format).strftime(@path)
108
- log.debug "GCS Path: #{path}"
109
- path
135
+ def chunk_unique_id_to_str(unique_id)
136
+ unique_id.unpack('C*').map{|x| x.to_s(16).rjust(2,'0')}.join('')
137
+ end
138
+
139
+ def path_format_with_unique_strategy(path, strategy, chunk_key, chunk_unique)
140
+ case strategy
141
+ when nil
142
+ path
143
+ when :chunk_id
144
+ path.gsub(UNIQUE_PLACE_HOLDER, chunk_unique_id_to_str(chunk_unique))
145
+ when :increment
146
+ if @before_chunk_key
147
+ if @before_chunk_key == chunk_key
148
+ @samepath_counter += 1
149
+ else
150
+ @samepath_counter = 0
151
+ end
152
+ end
153
+ @before_chunk_key = chunk_key
154
+ path.gsub(UNIQUE_PLACE_HOLDER, "#{@samepath_counter}")
155
+ when :timestamp
156
+ path.gsub(UNIQUE_PLACE_HOLDER, Time.now.strftime(@unique_format))
157
+ end
158
+ end
159
+
160
+ def path_format(chunk)
161
+ # format from chunk key
162
+ path = Time.strptime(chunk.key, @time_slice_format).strftime(@path)
163
+
164
+ # format for make unique
165
+ path = path_format_with_unique_strategy(path, @unique_strategy, chunk.key, chunk.unique_id)
166
+
167
+ # append .log
168
+ unless path.include?(".log")
169
+ path.concat(@path_suffix)
170
+ end
171
+
172
+ # append .gz
173
+ case @compress
174
+ when nil
175
+ path
176
+ when :gz
177
+ "#{path}.gz"
178
+ end
110
179
  end
111
180
 
112
181
  def send(path, data)
113
182
  mimetype = MIME::Types.type_for(path).first
114
-
115
183
  io = nil
116
- if SUPPORTED_COMPRESS.include?(@compress)
184
+ if @compress
117
185
  io = StringIO.new("")
118
186
  writer = Zlib::GzipWriter.new(io)
119
187
  writer.write(data)
@@ -127,10 +195,9 @@ module Fluent
127
195
  end
128
196
 
129
197
  def write(chunk)
130
- gcs_path = path_format(chunk.key)
198
+ gcs_path = path_format(chunk)
131
199
  send(gcs_path, chunk.read)
132
200
  gcs_path
133
201
  end
134
202
  end
135
203
  end
136
-
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fluent-plugin-google-cloud-storage-out
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.10
4
+ version: 0.1.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - Hideki Matsuoka