fluent-plugin-gcloud-storage 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 1d305c8f71fafe1ec78eab6aca3abd92f210b9bc
4
+ data.tar.gz: 8be97348873b53a49ca2248418ff5141d9d4cd35
5
+ SHA512:
6
+ metadata.gz: 7d6a4049c2aa0f9a1b78f65003459c16243de55320f09ccc0c4a691516cf30569a8ab12f508a3a5b3f4b4f519afb37b674d63f6b6c92c9d4936591ef689ad307
7
+ data.tar.gz: 7a6a8f29f5e010ea4a758e03f36346e35971ca8edfa8a57695d17d756ce76202a238ec87ad12edcc69ffba695ab502c781d616a56319dff28706763a3bfc1276
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.3
4
+ before_install: gem install bundler -v 1.10.6
@@ -0,0 +1,13 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
4
+
5
+ We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, or religion.
6
+
7
+ Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
8
+
9
+ Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
10
+
11
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
12
+
13
+ This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in fluent-plugin-gcloud-storage.gemspec
4
+ gemspec
data/README.md ADDED
@@ -0,0 +1,57 @@
1
+ # fluent-plugin-gcloud-storage
2
+ [![Build Status](https://travis-ci.org/trekdemo/fluent-plugin-gcloud-storage.svg?branch=master)](https://travis-ci.org/trekdemo/fluent-plugin-gcloud-storage)
3
+
4
+ [Cloud Storage](https://cloud.google.com/storage/) Output plugin for [Fluentd](http://www.fluentd.org/) with [gcloud](https://googlecloudplatform.github.io/gcloud-ruby/) gem.
5
+
6
+ Sponsored by [BIDMATH](http://bidmath.com)
7
+
8
+ ## Installation
9
+
10
+ Please follow the [Plugin Management](http://docs.fluentd.org/articles/plugin-management) guide of fluentd.
11
+
12
+ ```ruby
13
+ # If you're using fluentd
14
+ fluent-gem install 'fluent-plugin-gcloud-storage'
15
+
16
+ # If you're using td-agent
17
+ td-agent-gem install 'fluent-plugin-gcloud-storage'
18
+ ```
19
+
20
+ ## Preparation
21
+
22
+ - Create a project on Google Developer Console
23
+ - Create a bucket within your project
24
+ - Download your credential (json)
25
+
26
+ ## Configuration
27
+ publish dummy json data like `{"message": "dummy", "value": 0}\n{"message": "dummy", "value": 1}\n ...`.
28
+
29
+ ```
30
+ <source>
31
+ type dummy
32
+ tag example.publish
33
+ auto_increment_key value
34
+ </source>
35
+
36
+ <match example.publish>
37
+ type gcloud_storage
38
+
39
+ key <PATH YOUR KEY JSON FILE>
40
+ project <YOUR PROJECT ID>
41
+ bucket <YOUR BUCKET ID>
42
+ path /path/to/the/output/file
43
+
44
+ buffer_path <PATH OF THE BUFFER>
45
+ </match>
46
+ ```
47
+
48
+ ## Development
49
+
50
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
51
+
52
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
53
+
54
+ ## Contributing
55
+
56
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/fluent-plugin-gcloud-storage. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](contributor-covenant.org) code of conduct.
57
+
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task default: :spec
data/bin/setup ADDED
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+
3
+ Gem::Specification.new do |spec|
4
+ spec.name = 'fluent-plugin-gcloud-storage'
5
+ spec.version = '0.1.0'
6
+ spec.authors = ['Gergő Sulymosi']
7
+ spec.email = ['gergo.sulymosi@gmail.com']
8
+
9
+ spec.summary = 'Google Cloud Storage output plugin for fluentd event collector'
10
+ spec.description = spec.summary
11
+ spec.homepage = 'https://github.com/trekdemo/fluent-plugin-gcloud-storage'
12
+
13
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
14
+ spec.bindir = 'exe'
15
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
16
+ spec.require_paths = ['lib']
17
+
18
+ spec.add_development_dependency 'bundler', '~> 1.10'
19
+ spec.add_development_dependency 'rake', '~> 10.0'
20
+ spec.add_development_dependency 'rspec'
21
+ spec.add_development_dependency 'test-unit'
22
+
23
+ spec.add_runtime_dependency 'fluentd', '> 0.10.42'
24
+ spec.add_runtime_dependency 'gcloud', '~> 0.4.0'
25
+ end
@@ -0,0 +1,114 @@
1
+ module Fluent
2
+ class GcloudStorageOutput < TimeSlicedOutput
3
+ CHUNK_ID_PLACE_HOLDER = '${chunk_id}'
4
+ DEFAULT_TIME_SLICE_FORMAT = '%Y%m%d'
5
+
6
+ Fluent::Plugin.register_output('gcloud_storage', self)
7
+
8
+ config_set_default :time_slice_format, DEFAULT_TIME_SLICE_FORMAT
9
+ config_param :project, :string, :default => nil
10
+ config_param :bucket, :string, :default => nil
11
+ config_param :key, :string, :default => nil
12
+ config_param :path, :string, :default => nil
13
+ config_param :format, :string, :default => 'out_file'
14
+
15
+ def initialize
16
+ super
17
+
18
+ require 'gcloud'
19
+ end
20
+
21
+ def configure(conf)
22
+ predict_time_slice_format!(conf)
23
+
24
+ super
25
+
26
+ ensure_gcloud_arguments!
27
+ ensure_proper_path!
28
+ ensure_buffer_type!
29
+ setup_formatter(conf)
30
+ end
31
+
32
+ def start
33
+ super
34
+
35
+ @gs_bucket = Gcloud
36
+ .new(@project, @key)
37
+ .storage
38
+ .bucket(@bucket)
39
+ end
40
+
41
+ # def shutdown; super; end
42
+
43
+ def format(tag, time, record)
44
+ @formatter.format(tag, time, record)
45
+ end
46
+
47
+ def write(chunk)
48
+ local_path = chunk.path
49
+ remote_path = generate_path(chunk)
50
+
51
+ log.debug('Writting chunk(%s) from: %s to: %s' % [chunk.key, local_path, remote_path])
52
+ before = Time.now.to_f
53
+
54
+ @gs_bucket.create_file(local_path, remote_path)
55
+
56
+ log.debug('Chunk(%s) upload was done in: %.2fs' % [chunk.key, (Time.now.to_f - before)])
57
+ end
58
+
59
+ private
60
+
61
+ def generate_path(chunk)
62
+ path_chunk_id = chunk_unique_id_to_str(chunk.unique_id)
63
+
64
+ Time
65
+ .strptime(chunk.key, @time_slice_format) # parse chunk time
66
+ .strftime(@path) # replace path placeholders
67
+ .gsub(CHUNK_ID_PLACE_HOLDER, path_chunk_id)
68
+ end
69
+
70
+ def chunk_unique_id_to_str(unique_id)
71
+ unique_id.unpack('C*').map{|x| x.to_s(16).rjust(2,'0')}.join('')
72
+ end
73
+
74
+ def predict_time_slice_format!(conf)
75
+ return unless (path = conf['path'])
76
+
77
+ conf['time_slice_format'] =
78
+ case
79
+ when path.index('%S') then '%Y%m%d%H%M%S'
80
+ when path.index('%M') then '%Y%m%d%H%M'
81
+ when path.index('%H') then '%Y%m%d%H'
82
+ else DEFAULT_TIME_SLICE_FORMAT
83
+ end
84
+ end
85
+
86
+ def ensure_gcloud_arguments!
87
+ fail ConfigError, "'project' must be specified." unless @project
88
+ fail ConfigError, "'bucket' must be specified." unless @bucket
89
+ fail ConfigError, "'key' must be specified." unless @key
90
+ end
91
+
92
+ def ensure_proper_path!
93
+ fail ConfigError, "'path' parameter is required" unless @path
94
+
95
+ if @path.index(CHUNK_ID_PLACE_HOLDER).nil?
96
+ fail Fluent::ConfigError,
97
+ 'path must contain ${chunk_id}, which is the placeholder for buffer'\
98
+ 'chunk.key. Google Cloud Storage does not support append operation'\
99
+ 'on objects. Tip: Use gsutil compose command to merge objects.'
100
+ end
101
+ end
102
+
103
+ def ensure_buffer_type!
104
+ fail ConfigError, "'buffer_type file' is mandatory" unless @buffer_type == 'file'
105
+ end
106
+
107
+ def setup_formatter(conf)
108
+ # http://docs.fluentd.org/articles/out_file#format
109
+ @formatter = Plugin.new_formatter(@format)
110
+ @formatter.configure(conf)
111
+ end
112
+ end
113
+ end
114
+
metadata ADDED
@@ -0,0 +1,137 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fluent-plugin-gcloud-storage
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Gergő Sulymosi
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-10-19 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.10'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.10'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: test-unit
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: fluentd
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">"
74
+ - !ruby/object:Gem::Version
75
+ version: 0.10.42
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">"
81
+ - !ruby/object:Gem::Version
82
+ version: 0.10.42
83
+ - !ruby/object:Gem::Dependency
84
+ name: gcloud
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: 0.4.0
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: 0.4.0
97
+ description: Google Cloud Storage output plugin for fluentd event collector
98
+ email:
99
+ - gergo.sulymosi@gmail.com
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - ".gitignore"
105
+ - ".rspec"
106
+ - ".travis.yml"
107
+ - CODE_OF_CONDUCT.md
108
+ - Gemfile
109
+ - README.md
110
+ - Rakefile
111
+ - bin/setup
112
+ - fluent-plugin-gcloud-storage.gemspec
113
+ - lib/fluent/plugin/out_gcloud_storage.rb
114
+ homepage: https://github.com/trekdemo/fluent-plugin-gcloud-storage
115
+ licenses: []
116
+ metadata: {}
117
+ post_install_message:
118
+ rdoc_options: []
119
+ require_paths:
120
+ - lib
121
+ required_ruby_version: !ruby/object:Gem::Requirement
122
+ requirements:
123
+ - - ">="
124
+ - !ruby/object:Gem::Version
125
+ version: '0'
126
+ required_rubygems_version: !ruby/object:Gem::Requirement
127
+ requirements:
128
+ - - ">="
129
+ - !ruby/object:Gem::Version
130
+ version: '0'
131
+ requirements: []
132
+ rubyforge_project:
133
+ rubygems_version: 2.4.5.1
134
+ signing_key:
135
+ specification_version: 4
136
+ summary: Google Cloud Storage output plugin for fluentd event collector
137
+ test_files: []