fluent-plugin-storage-memcached 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: d0575e5218b0927557533a19c1135c55f5b09abf
4
+ data.tar.gz: 8192009a393180d49b3a8081d4d9b77ffcd419ff
5
+ SHA512:
6
+ metadata.gz: beeb6b5c4888c9c5373eeccc4325d0dadf85426843a2ab561b9e15745070514aef6d7974c7d820fb0da9c38c6a32394caddb72a82f09c701b4c1270f6eeff628
7
+ data.tar.gz: 7be9d3c6f60283c92f462d72d81e9f65567e5a26e6fea3e2adf6efe4d8337f3ae3297f47bf76af20edfef126edc5078180600a462003c7a4067f36f85643950e
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
@@ -0,0 +1,12 @@
1
+ language: ruby
2
+ services:
3
+ - memcached
4
+ rvm:
5
+ - 2.1
6
+ - 2.2
7
+ - 2.3.3
8
+ - 2.4.0
9
+ gemfile:
10
+ - Gemfile
11
+ before_install:
12
+ - gem update bundler
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in fluent-plugin-storage-memcached.gemspec
4
+ gemspec
@@ -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.
@@ -0,0 +1,49 @@
1
+ # fluent-plugin-storage-memcached
2
+
3
+ [![Build Status](https://travis-ci.org/cosmo0920/fluent-plugin-storage-memcached.svg?branch=master)](https://travis-ci.org/cosmo0920/fluent-plugin-storage-memcached)
4
+
5
+ fluent-plugin-storage-memcached is a fluent plugin to store plugin state into memcached.
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'fluent-plugin-storage-memcached'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install fluent-plugin-storage-memcached
22
+
23
+ ## Configuration
24
+
25
+ ```aconf
26
+ <storage>
27
+ @type memcached
28
+
29
+ path my_key # or conf.arg will be used as redis key
30
+ host localhost # localhost is default
31
+ port 11211 # 11211 is default
32
+ namespace app_v1 # app_v1 is default
33
+ compress true # true is default
34
+ # If sasl enabled memcached server is configured, please specify them.
35
+ # username fluenter
36
+ # password hogefuga
37
+ serializer yajl # yajl is default
38
+ expires_in 0 # 0 is default
39
+ </storage>
40
+ ```
41
+
42
+ ## Contributing
43
+
44
+ Bug reports and pull requests are welcome on GitHub at https://github.com/cosmo0920/fluent-plugin-storage-memcached.
45
+
46
+
47
+ ## License
48
+
49
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+
3
+ require 'rake/testtask'
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,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "fluent/plugin/storage/memcached"
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
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -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-memcached"
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 Memcached.}
12
+ spec.description = %q{Fluentd storage plugin for Memcached.}
13
+ spec.homepage = "https://github.com/cosmo0920/fluent-plugin-storage-memcached"
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.13"
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 "dalli", "~> 2.7.0"
37
+ end
@@ -0,0 +1,127 @@
1
+ require 'json'
2
+ require 'dalli'
3
+ require 'fluent/plugin/storage'
4
+
5
+ module Fluent
6
+ module Plugin
7
+ class MemcachedStorage < Storage
8
+ Fluent::Plugin.register_storage('memcached', self)
9
+
10
+ config_param :path, :string, default: nil
11
+ config_param :host, :array, default: 'localhost'
12
+ config_param :port, :integer, default: 11211
13
+ config_param :namespace, :string, default: 'app_v1'
14
+ config_param :compress, :bool, default: true
15
+ config_param :username, :string, default: nil
16
+ config_param :password, :string, default: nil, secret: true
17
+ config_param :serializer, :enum, list: [:yajl, :json, :marshal], default: :yajl
18
+ config_param :expires_in, :integer, default: 0
19
+ # Set persistent true by default
20
+ config_set_default :persistent, true
21
+
22
+ attr_reader :store # for test
23
+
24
+ def initialize
25
+ super
26
+
27
+ @store = {}
28
+ end
29
+
30
+ def configure(conf)
31
+ super
32
+
33
+ unless @path
34
+ if conf && !conf.arg.empty?
35
+ @path = conf.arg
36
+ else
37
+ raise Fluent::ConfigError, "path or conf.arg for <storage> is required."
38
+ end
39
+ end
40
+
41
+ @serializer = case @serializer
42
+ when :yajl
43
+ Yajl
44
+ when :json
45
+ JSON
46
+ when :marshal
47
+ Marshal
48
+ end
49
+
50
+ options = {
51
+ thread_safe: true,
52
+ namespace: @namespace,
53
+ compress: @compress,
54
+ serializer: @serializer,
55
+ expires_on: @expires_in,
56
+ }
57
+ options[:username] = @username if @username
58
+ options[:password] = @password if @password
59
+
60
+ @memcached = Dalli::Client.new("#{@host}:#{@port}", options)
61
+
62
+ object = @memcached.get(@path)
63
+ if object
64
+ begin
65
+ data = @serializer.load(object)
66
+ raise Fluent::ConfigError, "Invalid contents (not object) in plugin memcached storage: '#{@path}'" unless data.is_a?(Hash) unless data.is_a?(Hash)
67
+ rescue => e
68
+ log.error "failed to read data from plugin redis storage", path: @path, error: e
69
+ raise Fluent::ConfigError, "Unexpected error: failed to read data from plugin memcached storage: '#{@path}'"
70
+ end
71
+ end
72
+ end
73
+
74
+ def multi_workers_ready?
75
+ true
76
+ end
77
+
78
+ def persistent_always?
79
+ true
80
+ end
81
+
82
+ def load
83
+ begin
84
+ json_string = @memcached.get(@path)
85
+ json = @serializer.load(json_string)
86
+ unless json.is_a?(Hash)
87
+ log.error "broken content for plugin storage (Hash required: ignored)", type: json.class
88
+ log.debug "broken content", content: json_string
89
+ return
90
+ end
91
+ @store = json
92
+ rescue => e
93
+ log.error "failed to load data for plugin storage from memcached", path: @path, error: e
94
+ end
95
+ end
96
+
97
+ def save
98
+ begin
99
+ json_string = @serializer.dump(@store)
100
+ @memcached.set(@path, json_string)
101
+ rescue => e
102
+ log.error "failed to save data for plugin storage to memcached", path: @path, error: e
103
+ end
104
+ end
105
+
106
+ def get(key)
107
+ @store[key.to_s]
108
+ end
109
+
110
+ def fetch(key, defval)
111
+ @store.fetch(key.to_s, defval)
112
+ end
113
+
114
+ def put(key, value)
115
+ @store[key.to_s] = value
116
+ end
117
+
118
+ def delete(key)
119
+ @store.delete(key.to_s)
120
+ end
121
+
122
+ def update(key, &block)
123
+ @store[key.to_s] = block.call(@store[key.to_s])
124
+ end
125
+ end
126
+ end
127
+ end
metadata ADDED
@@ -0,0 +1,131 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fluent-plugin-storage-memcached
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-02-20 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.13'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.13'
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: dalli
77
+ requirement: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - "~>"
80
+ - !ruby/object:Gem::Version
81
+ version: 2.7.0
82
+ type: :runtime
83
+ prerelease: false
84
+ version_requirements: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - "~>"
87
+ - !ruby/object:Gem::Version
88
+ version: 2.7.0
89
+ description: Fluentd storage plugin for Memcached.
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-memcached.gemspec
105
+ - lib/fluent/plugin/storage_memcached.rb
106
+ homepage: https://github.com/cosmo0920/fluent-plugin-storage-memcached
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.8
128
+ signing_key:
129
+ specification_version: 4
130
+ summary: Fluentd storage plugin for Memcached.
131
+ test_files: []