fluent-plugin-grassland 0.0.1

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 3355444d5dbd8e2b8959c60beb289eb0d94e960d
4
+ data.tar.gz: f136db3ac51462deeb2417b1a01ed9128562aa38
5
+ SHA512:
6
+ metadata.gz: 7abb4001d45fd3a37ff0fa2fcd825c78b0cd1c04d5534632874715884f18e029deadd29a6045fec3fb0acb6d6f0cc0b8f886dab2c6956c253316d714580d0f74
7
+ data.tar.gz: 96d60b8872a1f44f35544b93cc0deb9f3b923a7e367239179d95e0fbf3b12fb6103aaa5a08432bcd341fa99e69c33875f5f868f6f7f516e145cd293f6207a0fa
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in fluent-plugin-kinesis-alt.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Genki Sugawara
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,36 @@
1
+ # fluent-plugin-grassland
2
+
3
+ Output filter plugin for Grassland
4
+
5
+ [![Gem Version](https://badge.fury.io/rb/fluent-plugin-kinesis-alt.png)](http://badge.fury.io/rb/fluent-plugin-kinesis-alt)
6
+
7
+ ## Notice
8
+
9
+ maybe write after.
10
+
11
+ ## Installation
12
+ * It still not working
13
+
14
+ Add this line to your application's Gemfile:
15
+
16
+ gem 'fluent-plugin-grassland'
17
+
18
+ And then execute:
19
+
20
+ $ bundle
21
+
22
+ Or install it yourself as:
23
+
24
+ $ gem install fluent-plugin-grassland
25
+
26
+ ## Usage
27
+
28
+ ### Configuration
29
+
30
+ ```
31
+ <match kinesis.**>
32
+ type grassland
33
+ key xxxxxxxxxxxxxxxx
34
+ flush_interval 3
35
+ </match>
36
+ ```
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rake/testtask'
3
+
4
+ Rake::TestTask.new(:test) do |test|
5
+ test.libs << 'lib' << 'test'
6
+ test.pattern = 'test/**/test_*.rb'
7
+ test.verbose = true
8
+ end
9
+
10
+ task :default => :test
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = 'fluent-plugin-grassland'
7
+ spec.version = '0.0.1'
8
+ spec.authors = ['Ripplation Inc.']
9
+ # spec.email = ['xxxxxx@ripplation.co.jp']
10
+ spec.description = 'Output filter plugin for Grassland'
11
+ spec.summary = 'Output filter plugin for Grassland'
12
+ spec.homepage = 'https://bitbucket.org/winebarrel/fluent-plugin-kinesis-alt'
13
+ spec.license = 'MIT'
14
+
15
+ spec.files = `git ls-files`.split($/)
16
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
17
+ spec.require_paths = ['lib']
18
+
19
+ spec.add_dependency 'fluentd'
20
+ spec.add_dependency 'aws-sdk', '~> 1.38'
21
+ spec.add_dependency 'json'
22
+ # spec.add_development_dependency 'bundler', '~> 1.3'
23
+ # spec.add_development_dependency 'rake'
24
+ end
@@ -0,0 +1,147 @@
1
+ module Fluent
2
+ class GrasslandOutput < Fluent::BufferedOutput
3
+ Fluent::Plugin.register_output('grassland', self)
4
+
5
+ attr_accessor :apiuri, :stream_name, :access_key_id, :secret_access_key, :region
6
+
7
+ def initialize
8
+ super
9
+ require 'aws-sdk'
10
+ require 'base64'
11
+ require 'json'
12
+ require 'logger'
13
+ require 'net/http'
14
+ require 'uri'
15
+ @apiuri = 'https://s3.amazonaws.com/apicre/credential.json'
16
+ end
17
+
18
+ config_param :key, :string, :default => nil
19
+ config_param :debug, :bool, :default => false
20
+
21
+ def configure(conf)
22
+ super
23
+
24
+ [:key].each do |name|
25
+ unless self.instance_variable_get("@#{name}")
26
+ raise ConfigError, "'#{name}' is required"
27
+ end
28
+ end
29
+ end
30
+
31
+ def start
32
+ super
33
+ setCredential
34
+ configure_aws
35
+ AWS.kinesis.client.put_record({
36
+ :stream_name => @stream_name,
37
+ :data => "test",
38
+ :partition_key => "#{rand(999)}"
39
+ })
40
+ end
41
+
42
+ def shutdown
43
+ super
44
+ end
45
+
46
+ def setCredential()
47
+ credential = get_json(@apiuri)
48
+ @stream_name = credential['streamName']
49
+ @access_key_id = credential['accessKeyId']
50
+ @secret_access_key = credential['secretAccessKey']
51
+ @region = credential['region']
52
+ end
53
+
54
+ def get_json(location, limit = 3)
55
+ raise ArgumentError, 'too many HTTP redirects' if limit == 0
56
+ uri = URI.parse(location)
57
+ begin
58
+ response = Net::HTTP.start(uri.host, uri.port, use_ssl: uri.scheme == 'https') do |http|
59
+ http.open_timeout = 5
60
+ http.read_timeout = 10
61
+ http.get(uri.request_uri)
62
+ end
63
+ case response
64
+ when Net::HTTPSuccess
65
+ json = response.body
66
+ JSON.parse(json)
67
+ when Net::HTTPRedirection
68
+ location = response['location']
69
+ warn "redirected to #{location}"
70
+ get_json(location, limit - 1)
71
+ else
72
+ puts [uri.to_s, response.value].join(" : ")
73
+ # handle error
74
+ end
75
+ rescue => e
76
+ puts [uri.to_s, e.class, e].join(" : ")
77
+ # handle error
78
+ end
79
+ end
80
+
81
+ def format(tag, time, record)
82
+ # print(record)
83
+ ['cid', 'dt', 'uid', 'pt', 'd'].each do |key|
84
+ unless record.has_key?(key)
85
+ puts "input data error: '#{key}' is required"
86
+ return ""
87
+ end
88
+ end
89
+
90
+ record['pk'] = record['cid'] + record['dt']
91
+ return "#{record.to_json},"
92
+ end
93
+
94
+ def write(chunk)
95
+ buf = chunk.read
96
+ dataList = JSON.parse("[#{buf.chop}]")
97
+ putBuf = ""
98
+ bufList = {}
99
+
100
+ dataList.each do |data|
101
+ if bufList[":#{data['pk']}"] == nil then
102
+ bufList[":#{data['pk']}"] = "#{data.to_json},"
103
+ else
104
+ bufList[":#{data['pk']}"] += "#{data.to_json},"
105
+ end
106
+ if bufList[":#{data['pk']}"].bytesize >= 30720 then
107
+ AWS.kinesis.client.put_record({
108
+ :stream_name => @stream_name,
109
+ :data => "["+bufList[":#{data['pk']}"].chop+"]",
110
+ :partition_key => data['pk']
111
+ })
112
+ bufList.delete(":#{data['pk']}")
113
+ end
114
+ end
115
+ dataList.each do |data|
116
+ if bufList[":#{data['pk']}"] != nil then
117
+ AWS.kinesis.client.put_record({
118
+ :stream_name => @stream_name,
119
+ :data => "["+bufList[":#{data['pk']}"].chop+"]",
120
+ :partition_key => data['pk']
121
+ })
122
+ bufList.delete(":#{data['pk']}")
123
+ end
124
+ end
125
+ end
126
+
127
+ private
128
+
129
+ def configure_aws
130
+ options = {
131
+ :access_key_id => @access_key_id,
132
+ :secret_access_key => @secret_access_key,
133
+ :region => @region
134
+ }
135
+
136
+ if @debug
137
+ options.update(
138
+ :logger => Logger.new($log.out),
139
+ :log_level => :debug,
140
+ #http_wire_trace => true
141
+ )
142
+ end
143
+
144
+ AWS.config(options)
145
+ end
146
+ end
147
+ end
data/test/helper.rb ADDED
@@ -0,0 +1,32 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+
4
+ begin
5
+ Bundler.setup(:default, :development)
6
+ rescue Bundler::BundlerError => e
7
+ $stderr.puts e.message
8
+ $stderr.puts "Run `bundle install` to install missing gems"
9
+ exit e.status_code
10
+ end
11
+
12
+ require 'test/unit'
13
+
14
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
15
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
16
+
17
+ require 'fluent/test'
18
+
19
+ unless ENV.has_key?('VERBOSE')
20
+ nulllogger = Object.new
21
+
22
+ nulllogger.instance_eval do |obj|
23
+ def method_missing(method, *args); end
24
+ end
25
+
26
+ $log = nulllogger
27
+ end
28
+
29
+ require 'fluent/plugin/out_kinesis_alt'
30
+
31
+ class Test::Unit::TestCase
32
+ end
@@ -0,0 +1,56 @@
1
+ require 'helper'
2
+
3
+ class KinesisAltOutputTest < Test::Unit::TestCase
4
+ def setup
5
+ Fluent::Test.setup
6
+ end
7
+
8
+ CONFIG = %[
9
+ ]
10
+ # CONFIG = %[
11
+ # path #{TMP_DIR}/out_file_test
12
+ # compress gz
13
+ # utc
14
+ # ]
15
+
16
+ def create_driver(conf = CONFIG, tag='test')
17
+ Fluent::Test::BufferedOutputTestDriver.new(Fluent::KinesisAltOutput, tag).configure(conf)
18
+ end
19
+
20
+ def test_configure
21
+ #### set configurations
22
+ # d = create_driver %[
23
+ # path test_path
24
+ # compress gz
25
+ # ]
26
+ #### check configurations
27
+ # assert_equal 'test_path', d.instance.path
28
+ # assert_equal :gz, d.instance.compress
29
+ end
30
+
31
+ def test_format
32
+ #d = create_driver
33
+
34
+ # time = Time.parse("2011-01-02 13:14:15 UTC").to_i
35
+ # d.emit({"a"=>1}, time)
36
+ # d.emit({"a"=>2}, time)
37
+
38
+ # d.expect_format %[2011-01-02T13:14:15Z\ttest\t{"a":1}\n]
39
+ # d.expect_format %[2011-01-02T13:14:15Z\ttest\t{"a":2}\n]
40
+
41
+ # d.run
42
+ end
43
+
44
+ def test_write
45
+ #d = create_driver
46
+
47
+ # time = Time.parse("2011-01-02 13:14:15 UTC").to_i
48
+ # d.emit({"a"=>1}, time)
49
+ # d.emit({"a"=>2}, time)
50
+
51
+ # ### FileOutput#write returns path
52
+ # path = d.run
53
+ # expect_path = "#{TMP_DIR}/out_file_test._0.log.gz"
54
+ # assert_equal expect_path, path
55
+ end
56
+ end
metadata ADDED
@@ -0,0 +1,96 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fluent-plugin-grassland
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Ripplation Inc.
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-04-12 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: fluentd
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: aws-sdk
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '1.38'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '1.38'
41
+ - !ruby/object:Gem::Dependency
42
+ name: json
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description: Output filter plugin for Grassland
56
+ email:
57
+ executables: []
58
+ extensions: []
59
+ extra_rdoc_files: []
60
+ files:
61
+ - .gitignore
62
+ - Gemfile
63
+ - LICENSE.txt
64
+ - README.md
65
+ - Rakefile
66
+ - fluent-plugin-grassland.gemspec
67
+ - lib/fluent/plugin/out_grassland.rb
68
+ - test/helper.rb
69
+ - test/plugin/test_out_grassland.rb
70
+ homepage: https://bitbucket.org/winebarrel/fluent-plugin-kinesis-alt
71
+ licenses:
72
+ - MIT
73
+ metadata: {}
74
+ post_install_message:
75
+ rdoc_options: []
76
+ require_paths:
77
+ - lib
78
+ required_ruby_version: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ required_rubygems_version: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - '>='
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
88
+ requirements: []
89
+ rubyforge_project:
90
+ rubygems_version: 2.0.14
91
+ signing_key:
92
+ specification_version: 4
93
+ summary: Output filter plugin for Grassland
94
+ test_files:
95
+ - test/helper.rb
96
+ - test/plugin/test_out_grassland.rb