fluent-plugin-storage-leveldb 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +11 -0
- data/.travis.yml +10 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +50 -0
- data/Rakefile +10 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/fluent-plugin-storage-leveldb.gemspec +37 -0
- data/lib/fluent/plugin/storage_leveldb.rb +121 -0
- metadata +131 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: d1fc5fc9381f01c898a4b9038f69192e2004f662
|
4
|
+
data.tar.gz: aa968d999c2d9958f7f13c8a662ed3ff8b056d6d
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 7e71ae2106c020541c3657ce11164db6d97a08f6bd0c41c4ca45a946a6c47f6e988dfafcad23cf5e2815c60a868698454a46699cd3f38a341645cab94f7fb772
|
7
|
+
data.tar.gz: fda8171b97dc299aac6f4823324f5dcac7944654e38cebfcb4c67d0eb9e174726621b0f20b3721e5fc15ffb68e9cea6d850419d1adf6ff11173ef1c9809eec2b
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2017 Hiroshi Hatake
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
# LevelDB storage plugin for Fluent
|
2
|
+
|
3
|
+
[![Build Status](https://travis-ci.org/cosmo0920/fluent-plugin-storage-leveldb.svg?branch=master)](https://travis-ci.org/cosmo0920/fluent-plugin-storage-leveldb)
|
4
|
+
|
5
|
+
fluent-plugin-storage-leveldb is a fluent plugin to store plugin state into LevelDB.
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'fluent-plugin-storage-leveldb'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install fluent-plugin-storage-leveldb
|
22
|
+
|
23
|
+
Then Fluentd automatically loads the plugin installed.
|
24
|
+
|
25
|
+
## Configuration
|
26
|
+
|
27
|
+
```aconf
|
28
|
+
<storage>
|
29
|
+
@type leveldb
|
30
|
+
|
31
|
+
path /path/to/leveldb/dbpath # or conf.arg will be used as leveldb's db files directory path
|
32
|
+
dir_mode 755 # 0755 is default.
|
33
|
+
root_key leveldb # leveldb is default.
|
34
|
+
</storage>
|
35
|
+
```
|
36
|
+
|
37
|
+
## Development
|
38
|
+
|
39
|
+
After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
40
|
+
|
41
|
+
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).
|
42
|
+
|
43
|
+
## Contributing
|
44
|
+
|
45
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/cosmo0920/fluent-plugin-storage-leveldb.
|
46
|
+
|
47
|
+
|
48
|
+
## License
|
49
|
+
|
50
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "fluent/plugin/storage/leveldb"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
@@ -0,0 +1,37 @@
|
|
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-storage-leveldb"
|
7
|
+
spec.version = "0.0.1"
|
8
|
+
spec.authors = ["Hiroshi Hatake"]
|
9
|
+
spec.email = ["cosmo0920.oucc@gmail.com"]
|
10
|
+
|
11
|
+
spec.summary = %q{Fluentd storage plugin for LevelDB.}
|
12
|
+
spec.description = %q{Fluentd storage plugin for LevelDB.}
|
13
|
+
spec.homepage = "https://github.com/cosmo0920/fluent-plugin-storage-leveldb"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
17
|
+
# to allow pushing to a single host or delete this section to allow pushing to any host.
|
18
|
+
if spec.respond_to?(:metadata)
|
19
|
+
spec.metadata['allowed_push_host'] = "https://rubygems.org"
|
20
|
+
else
|
21
|
+
raise "RubyGems 2.0 or newer is required to protect against " \
|
22
|
+
"public gem pushes."
|
23
|
+
end
|
24
|
+
|
25
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
26
|
+
f.match(%r{^(test|spec|features)/})
|
27
|
+
end
|
28
|
+
spec.bindir = "exe"
|
29
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
30
|
+
spec.require_paths = ["lib"]
|
31
|
+
|
32
|
+
spec.add_development_dependency "bundler", "~> 1.14"
|
33
|
+
spec.add_development_dependency "rake", "~> 12.0"
|
34
|
+
spec.add_development_dependency "test-unit", "~> 3.2.0"
|
35
|
+
spec.add_dependency "fluentd", [">= 0.14.12", "< 2"]
|
36
|
+
spec.add_dependency "leveldb", "~> 0.1.9"
|
37
|
+
end
|
@@ -0,0 +1,121 @@
|
|
1
|
+
require 'leveldb'
|
2
|
+
require 'fluent/plugin/storage'
|
3
|
+
|
4
|
+
module Fluent
|
5
|
+
module Plugin
|
6
|
+
class LevelDBStorage < Storage
|
7
|
+
Fluent::Plugin.register_storage('leveldb', self)
|
8
|
+
|
9
|
+
DEFAULT_DIR_MODE = 0755
|
10
|
+
|
11
|
+
config_param :path, :string, default: nil
|
12
|
+
config_param :dir_mode, default: DEFAULT_DIR_MODE do |v|
|
13
|
+
v.to_i(8)
|
14
|
+
end
|
15
|
+
config_param :root_key, :string, default: "leveldb"
|
16
|
+
# Set persistent true by default
|
17
|
+
config_set_default :persistent, true
|
18
|
+
|
19
|
+
attr_reader :store, :leveldb # for test
|
20
|
+
|
21
|
+
def initialize
|
22
|
+
super
|
23
|
+
|
24
|
+
@store = {}
|
25
|
+
end
|
26
|
+
|
27
|
+
def configure(conf)
|
28
|
+
super
|
29
|
+
|
30
|
+
if @path
|
31
|
+
if File.exist?(@path) && File.file?(@path)
|
32
|
+
raise Fluent::ConfigError, "path for <storage> should be a directory."
|
33
|
+
elsif File.exist?(@path) && File.directory?(@path)
|
34
|
+
@path = File.join(@path, "worker#{fluentd_worker_id}", "storage.db")
|
35
|
+
@multi_workers_available = true
|
36
|
+
end
|
37
|
+
elsif root_dir = owner.plugin_root_dir
|
38
|
+
basename = (conf.arg && !conf.arg.empty?) ? "storage.#{conf.arg}.db" : "storage.db"
|
39
|
+
@path = File.join(root_dir, basename)
|
40
|
+
@multi_workers_available = true
|
41
|
+
else
|
42
|
+
raise Fluent::ConfigError, "path for <storage> is required."
|
43
|
+
end
|
44
|
+
|
45
|
+
dir = File.dirname(@path)
|
46
|
+
FileUtils.mkdir_p(dir, mode: @dir_mode) unless Dir.exist?(dir)
|
47
|
+
if File.exist?(@path)
|
48
|
+
raise Fluent::ConfigError, "Plugin storage path '#{@path}' is not readable/writable" unless File.readable?(@path) && File.writable?(@path)
|
49
|
+
else
|
50
|
+
raise Fluent::ConfigError, "Directory is not writable for plugin storage file '#{@path}'" unless File.stat(dir).writable?
|
51
|
+
end
|
52
|
+
|
53
|
+
@leveldb = LevelDB::DB.new(@path)
|
54
|
+
object = @leveldb.get(@root_key)
|
55
|
+
if object
|
56
|
+
begin
|
57
|
+
data = Yajl::Parser.parse(object)
|
58
|
+
raise Fluent::ConfigError, "Invalid contents (not object) in plugin leveldb storage: '#{@path}'" unless data.is_a?(Hash)
|
59
|
+
rescue => e
|
60
|
+
log.error "failed to read data from plugin redis storage", path: @path, error: e
|
61
|
+
raise Fluent::ConfigError, "Unexpected error: failed to read data from plugin leveldb storage: '#{@path}'"
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
def multi_workers_ready?
|
67
|
+
@multi_workers_available
|
68
|
+
end
|
69
|
+
|
70
|
+
def persistent_always?
|
71
|
+
true
|
72
|
+
end
|
73
|
+
|
74
|
+
def load
|
75
|
+
begin
|
76
|
+
json_string = @leveldb.get(@root_key)
|
77
|
+
json = Yajl::Parser.parse(json_string)
|
78
|
+
unless json.is_a?(Hash)
|
79
|
+
log.error "broken content for plugin storage (Hash required: ignored)", type: json.class
|
80
|
+
log.debug "broken content", content: json_string
|
81
|
+
return
|
82
|
+
end
|
83
|
+
@store = json
|
84
|
+
rescue => e
|
85
|
+
log.error "failed to load data for plugin storage from leveldb", path: @path, error: e
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
def save
|
90
|
+
begin
|
91
|
+
json_string = Yajl::Encoder.encode(@store)
|
92
|
+
@leveldb.batch do
|
93
|
+
@leveldb.put(@root_key, json_string)
|
94
|
+
end
|
95
|
+
rescue => e
|
96
|
+
log.error "failed to save data for plugin storage to leveldb", path: @path, error: e
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
def get(key)
|
101
|
+
@store[key.to_s]
|
102
|
+
end
|
103
|
+
|
104
|
+
def fetch(key, defval)
|
105
|
+
@store.fetch(key.to_s, defval)
|
106
|
+
end
|
107
|
+
|
108
|
+
def put(key, value)
|
109
|
+
@store[key.to_s] = value
|
110
|
+
end
|
111
|
+
|
112
|
+
def delete(key)
|
113
|
+
@store.delete(key.to_s)
|
114
|
+
end
|
115
|
+
|
116
|
+
def update(key, &block)
|
117
|
+
@store[key.to_s] = block.call(@store[key.to_s])
|
118
|
+
end
|
119
|
+
end
|
120
|
+
end
|
121
|
+
end
|
metadata
ADDED
@@ -0,0 +1,131 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: fluent-plugin-storage-leveldb
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Hiroshi Hatake
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-04-10 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.14'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.14'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '12.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '12.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: test-unit
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 3.2.0
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 3.2.0
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: fluentd
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 0.14.12
|
62
|
+
- - "<"
|
63
|
+
- !ruby/object:Gem::Version
|
64
|
+
version: '2'
|
65
|
+
type: :runtime
|
66
|
+
prerelease: false
|
67
|
+
version_requirements: !ruby/object:Gem::Requirement
|
68
|
+
requirements:
|
69
|
+
- - ">="
|
70
|
+
- !ruby/object:Gem::Version
|
71
|
+
version: 0.14.12
|
72
|
+
- - "<"
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '2'
|
75
|
+
- !ruby/object:Gem::Dependency
|
76
|
+
name: leveldb
|
77
|
+
requirement: !ruby/object:Gem::Requirement
|
78
|
+
requirements:
|
79
|
+
- - "~>"
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: 0.1.9
|
82
|
+
type: :runtime
|
83
|
+
prerelease: false
|
84
|
+
version_requirements: !ruby/object:Gem::Requirement
|
85
|
+
requirements:
|
86
|
+
- - "~>"
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: 0.1.9
|
89
|
+
description: Fluentd storage plugin for LevelDB.
|
90
|
+
email:
|
91
|
+
- cosmo0920.oucc@gmail.com
|
92
|
+
executables: []
|
93
|
+
extensions: []
|
94
|
+
extra_rdoc_files: []
|
95
|
+
files:
|
96
|
+
- ".gitignore"
|
97
|
+
- ".travis.yml"
|
98
|
+
- Gemfile
|
99
|
+
- LICENSE.txt
|
100
|
+
- README.md
|
101
|
+
- Rakefile
|
102
|
+
- bin/console
|
103
|
+
- bin/setup
|
104
|
+
- fluent-plugin-storage-leveldb.gemspec
|
105
|
+
- lib/fluent/plugin/storage_leveldb.rb
|
106
|
+
homepage: https://github.com/cosmo0920/fluent-plugin-storage-leveldb
|
107
|
+
licenses:
|
108
|
+
- MIT
|
109
|
+
metadata:
|
110
|
+
allowed_push_host: https://rubygems.org
|
111
|
+
post_install_message:
|
112
|
+
rdoc_options: []
|
113
|
+
require_paths:
|
114
|
+
- lib
|
115
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
116
|
+
requirements:
|
117
|
+
- - ">="
|
118
|
+
- !ruby/object:Gem::Version
|
119
|
+
version: '0'
|
120
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
125
|
+
requirements: []
|
126
|
+
rubyforge_project:
|
127
|
+
rubygems_version: 2.6.11
|
128
|
+
signing_key:
|
129
|
+
specification_version: 4
|
130
|
+
summary: Fluentd storage plugin for LevelDB.
|
131
|
+
test_files: []
|