fluent-plugin-cloudfront-log 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e41573e85cd6b33115e5f1525475c09c8668c099
4
- data.tar.gz: ade5e4dd5a8ba5bdcc52de52396840ea4fd8ef0e
3
+ metadata.gz: 5d748be8ee5e67aa860a241c5f1397a91637bd62
4
+ data.tar.gz: 368fc0b0eed3682eab165301d2a6fae2be653716
5
5
  SHA512:
6
- metadata.gz: 65fcc533f4fb58e998a60a2b6bbc9e9e48088b1b7c8d5268b25fd0aec426ed3a0e512100a7abe9255816c3e4b49544a0db015ef85e6ce36c9c36fcc7a7b8d43a
7
- data.tar.gz: 353fb1744667a60477e2cb03b91d7007442766823922afeac18eca682b7bad2ac6fce969205adf7b0edaddaa5c52e554f4fea7e145e21fa2e12881e8dec50f91
6
+ metadata.gz: e6c81c25e0bbe1aaee20058e26caff7d5d697967143302323633b7da87f73599752574023411855050b60c3bdb3f4ee087b3594f23f04b3e6b23566076812ecf
7
+ data.tar.gz: 62f9f3e73c36c0e1b1f997274eaa0d4215ff7691a42cffce0d0c541754e282a3938ef383eb04ad1e7e3a3f43be427aa574d36ed5319a48b7d1b888f30b0753eb
data/README.md CHANGED
@@ -1,8 +1,56 @@
1
1
  # Fluent::Plugin::Cloudfront::Log
2
+ This plugin will connect to the S3 bucket that you store your cloudfront logs in. Once the plugin processes them and ships them to FluentD, it moves them to another location(either another bucket or sub directory).
2
3
 
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/fluent/plugin/cloudfront/log`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+ ## Example config
5
+ ```
6
+ <source>
7
+ @type cloudfront_log
8
+ log_bucket cloudfront-logs
9
+ log_prefix production
10
+ region us-east-1
11
+ interval 300
12
+ aws_key_id xxxxxx
13
+ aws_sec_key xxxxxx
14
+ tag reverb.cloudfront
15
+ verbose true
16
+ </source>
17
+ ```
18
+
19
+ ## Configuration options
20
+
21
+ #### log_bucket
22
+ This option tells the plugin where to look for the cloudfront logs
23
+
24
+ #### log_prefix
25
+ For example if your logs are stored in a folder called "production" under the "cloudfront-logs" bucket, your logs would be stored in cloudfront like "cloudfront-logs/production/log.gz".
26
+ In this case, you'd want to use the prefix "production".
27
+
28
+ #### moved_log_bucket
29
+ Here you can specify where you'd like the log files to be moved after processing. If left blank this defaults to a folder called `_moved` under the bucket configured for `@log_bucket`.
30
+
31
+ #### moved_log_prefix
32
+ This specifices what the log files will be named once they're processed. This defaults to `_moved`.
33
+
34
+ #### region
35
+ The region where your cloudfront logs are stored.
4
36
 
5
- TODO: Delete this and the text above, and describe your gem
37
+ #### interval
38
+ This is the rate in seconds at which we check the bucket for updated logs. It's recommended not to put this lower than 300(The default), cloudfront delivers logs every 20~ minutes to s3, so shortening this interval won't deliver your logs faster.
39
+
40
+ #### aws_sec_id
41
+ The ID of your AWS keypair. Note: Since this plugin uses aws-sdk under the hood you can leave these two aws fields blank if you have an IAM role applied to your FluentD instance.
42
+
43
+ #### aws_sec_key
44
+ The secret key portion of your AWS keypair
45
+
46
+ #### tag
47
+ This is a FluentD builtin.
48
+
49
+ #### delimiter
50
+ You shouldn't have to specify delimiter at all but this option is provided and passed to the S3 client in the event that you have a weird delimiter in your log file names. Defaults to `nil`.
51
+
52
+ #### verbose
53
+ Turn this on if you'd like to see verbose information about the plugin and how it's processing your files.
6
54
 
7
55
  ## Installation
8
56
 
@@ -14,15 +62,11 @@ gem 'fluent-plugin-cloudfront-log'
14
62
 
15
63
  And then execute:
16
64
 
17
- $ bundle
65
+ $ bundle
18
66
 
19
67
  Or install it yourself as:
20
68
 
21
- $ gem install fluent-plugin-cloudfront-log
22
-
23
- ## Usage
24
-
25
- TODO: Write usage instructions here
69
+ $ gem install fluent-plugin-cloudfront-log
26
70
 
27
71
  ## Development
28
72
 
@@ -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-cloudfront-log"
7
- spec.version = "0.0.1"
7
+ spec.version = "0.0.2"
8
8
  spec.authors = ["kubihie"]
9
9
  spec.email = ["kubihie@gmail.com"]
10
10
 
@@ -4,12 +4,14 @@ class Fluent::Cloudfront_LogInput < Fluent::Input
4
4
  config_param :aws_key_id, :string, :default => nil, :secret => true
5
5
  config_param :aws_sec_key, :string, :default => nil, :secret => true
6
6
  config_param :log_bucket, :string
7
- config_param :log_prefix, :string, :default => nil
7
+ config_param :log_prefix, :string
8
8
  config_param :moved_log_bucket, :string, :default => @log_bucket
9
9
  config_param :moved_log_prefix, :string, :default => '_moved'
10
10
  config_param :region, :string
11
11
  config_param :tag, :string, :default => 'cloudfront.access'
12
- config_param :interval, :integer, :default => 300
12
+ config_param :interval, :integer, :default => 300
13
+ config_param :delimiter, :string, :default => nil
14
+ config_param :verbose, :string, :default => false
13
15
 
14
16
  def initialize
15
17
  super
@@ -25,24 +27,25 @@ class Fluent::Cloudfront_LogInput < Fluent::Input
25
27
 
26
28
  raise Fluent::ConfigError.new unless @log_bucket
27
29
  raise Fluent::ConfigError.new unless @region
30
+ raise Fluent::ConfigError.new unless @log_prefix
28
31
 
29
32
  @moved_log_bucket = @log_bucket unless @moved_log_bucket
30
33
  @moved_log_prefix = @log_prefix + '_moved' unless @moved_log_prefix
31
-
32
- log.info('@log_bucket:' + @log_bucket)
33
- log.info('@moved_log_bucket:' + @moved_log_bucket)
34
- log.info('@log_prefix:' + @log_prefix)
35
- log.info('@moved_log_prefix:' + @moved_log_prefix)
34
+
35
+ if @verbose
36
+ log.info("@log_bucket: #{@log_bucket}")
37
+ log.info("@moved_log_bucket: #{@moved_log_bucket}")
38
+ log.info("@log_prefix: #{@log_prefix}")
39
+ log.info("@moved_log_prefix: #{@moved_log_prefix}")
40
+ end
36
41
  end
37
42
 
38
43
  def start
39
44
  super
45
+ log.info("Cloudfront verbose logging enabled") if @verbose
40
46
  client
41
47
 
42
48
  @loop = Coolio::Loop.new
43
- #timer = TimerWatcher.new(@interval, true, log) do
44
- # input
45
- #end
46
49
  timer = TimerWatcher.new(@interval, true, log, &method(:input))
47
50
 
48
51
  @loop.attach(timer)
@@ -81,17 +84,27 @@ class Fluent::Cloudfront_LogInput < Fluent::Input
81
84
  end
82
85
 
83
86
  def purge(filename)
84
- log.info('copy_src:' + @log_bucket + '/' + @log_prefix + filename)
85
- log.info('copy_dst:' + @moved_log_bucket + '/' + @moved_log_prefix + '/' + filename)
86
- client.copy_object(:bucket => @moved_log_bucket, :copy_source => @log_bucket + '/' + @log_prefix + filename, :key => @moved_log_prefix + '/' + filename)
87
- client.delete_object(:bucket => @log_bucket, :key => @log_prefix + filename)
87
+ # Key is the name of the object without the bucket prefix, e.g: asdf/asdf.jpg
88
+ source_object_key = [@log_prefix, filename].join('/')
89
+
90
+ # Full path includes bucket name in addition to object key, e.g: bucket/asdf/asdf.jpg
91
+ source_object_full_path = [@log_bucket, source_object_key].join('/')
92
+
93
+ dest_object_key = [@moved_log_prefix, filename].join('/')
94
+ dest_object_full_path = [@moved_log_bucket, dest_object_key].join('/')
95
+
96
+ log.info("Copying object: #{source_object_full_path} to #{dest_object_full_path}") if @verbose
97
+ client.copy_object(:bucket => @moved_log_bucket, :copy_source => source_object_full_path, :key => dest_object_key)
98
+
99
+ log.info("Deleting object: #{source_object_key} from #{@log_bucket}") if @verbose
100
+ client.delete_object(:bucket => @log_bucket, :key => source_object_key)
88
101
  end
89
102
 
90
103
  def input
91
- client.list_objects(:bucket => @log_bucket, :prefix => @log_prefix , :delimiter => '/').each do |list|
104
+ client.list_objects(:bucket => @log_bucket, :prefix => @log_prefix , :delimiter => @delimiter).each do |list|
92
105
  list.contents.each do |content|
93
- filename = content.key.sub(/#{@log_prefix}/, '')
94
- #log.info('filename:' + filename)
106
+ filename = content.key.sub(/^#{@log_prefix}\//, "")
107
+ log.info("Currently processing: #{filename}") if @verbose
95
108
  next if filename[-1] == '/' #skip directory/
96
109
  next unless filename[-2, 2] == 'gz' #skip without gz file
97
110
 
@@ -107,7 +120,7 @@ class Fluent::Cloudfront_LogInput < Fluent::Input
107
120
  line = URI.unescape(line) #hoge%20fuga -> hoge fuga
108
121
  line = line.split("\t")
109
122
  record = Hash[@fields.collect.zip(line)]
110
- timestamp = Time.parse("#{record['date']} #{record['time']} +0900").to_i
123
+ timestamp = Time.parse("#{record['date']}T#{record['time']}+00:00").to_i
111
124
  router.emit(@tag, timestamp, record)
112
125
  end
113
126
  purge(filename)
@@ -15,7 +15,9 @@ class Cloudfront_LogInputTest < Test::Unit::TestCase
15
15
  :moved_log_prefix => 'a/b/c_moved',
16
16
  :region => 'ap-northeast-1',
17
17
  :tag => 'cloudfront',
18
- :interval => '500'
18
+ :interval => '500',
19
+ :delimiter => nil,
20
+ :verbose => true,
19
21
  }
20
22
 
21
23
  def parse_config(conf = {})
@@ -43,6 +45,13 @@ class Cloudfront_LogInputTest < Test::Unit::TestCase
43
45
  }
44
46
  assert_equal("'region' parameter is required", exception.message)
45
47
 
48
+ exception = assert_raise(Fluent::ConfigError) {
49
+ conf = DEFAULT_CONFIG.clone
50
+ conf.delete(:log_prefix)
51
+ driver = create_driver(conf)
52
+ }
53
+ assert_equal("'log_prefix' parameter is required", exception.message)
54
+
46
55
  conf = DEFAULT_CONFIG.clone
47
56
  conf.delete(:moved_log_bucket)
48
57
  driver = create_driver(conf)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fluent-plugin-cloudfront-log
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - kubihie
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-03-01 00:00:00.000000000 Z
11
+ date: 2016-05-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: fluentd
@@ -114,7 +114,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
114
114
  version: '0'
115
115
  requirements: []
116
116
  rubyforge_project:
117
- rubygems_version: 2.2.0
117
+ rubygems_version: 2.4.7
118
118
  signing_key:
119
119
  specification_version: 4
120
120
  summary: AWS CloudFront log input plugin.