logstash-filter-translate 3.3.1 → 3.4.0

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
  SHA256:
3
- metadata.gz: 77bd945dee5e20dbc7eb6837c655e807373ee8923dcbd498c9fcf5b1065c6661
4
- data.tar.gz: 878df6d8dfcc5fa53bb617163b0ddfe6feeb8e876aed9668b337f66dc8472221
3
+ metadata.gz: f628dd5414571a8ad48ac804294f9404b4eaa460457e15955824d8a2ff5b6809
4
+ data.tar.gz: 6e762d49f1030f379fb5033c75c177f4eca134672bb446a27bb7c69821858f03
5
5
  SHA512:
6
- metadata.gz: d45ec30865d73884f9564f3680fdc1fb230c9fa71507c86d475e6ec0759d13863080f8c237ab34b38ccad08bca0781ab1d8a8523955841db2d0a0334091a9cf3
7
- data.tar.gz: 443284f8db270ec6081a2017bd6597733be886643232d97a7630c99e1b194970183e0a7d070ed511bdb1d8069e7f929a991d608798a35d8bd5408878806945d5
6
+ metadata.gz: d8a2a50b3668fa320d10587fd903d0a47a84b5cb0416876aea7ebdfad73a0692379c4e34b60aaa3b49a6297a7deb418ce87bbcc40947a85c673af549b00bc358
7
+ data.tar.gz: bc28c2a3e20d1b8f2b5d3c713978e32e5fee1ed2ea95d74af446f5a686096ee6ae7e179cf828aba5c2857f187a1449b61ab22e0d19e16fbaf5e1c8e540971471
data/CHANGELOG.md CHANGED
@@ -1,3 +1,6 @@
1
+ ## 3.4.0
2
+ - Refactor: leverage scheduler mixin [#93](https://github.com/logstash-plugins/logstash-filter-translate/pull/93)
3
+
1
4
  ## 3.3.1
2
5
  - Refactor: reading .csv for JRuby 9.3 compatibility [#94](https://github.com/logstash-plugins/logstash-filter-translate/pull/94)
3
6
 
@@ -1,15 +1,14 @@
1
1
  # encoding: utf-8
2
- require 'concurrent/atomic/atomic_boolean'
3
- require 'rufus-scheduler'
4
2
  require "logstash/util/loggable"
5
3
  require "logstash/filters/fetch_strategy/file"
6
4
 
7
- java_import 'java.util.concurrent.locks.ReentrantReadWriteLock'
8
-
9
5
  module LogStash module Filters module Dictionary
10
6
  class DictionaryFileError < StandardError; end
11
7
 
12
8
  class File
9
+
10
+ include LogStash::Util::Loggable
11
+
13
12
  def self.create(path, refresh_interval, refresh_behaviour, exact, regex)
14
13
  if /\.y[a]?ml$/.match(path)
15
14
  instance = YamlFile.new(path, refresh_interval, exact, regex)
@@ -30,14 +29,12 @@ module LogStash module Filters module Dictionary
30
29
  end
31
30
  end
32
31
 
33
- include LogStash::Util::Loggable
34
32
  attr_reader :dictionary, :fetch_strategy
35
33
 
36
34
  def initialize(path, refresh_interval, exact, regex)
37
35
  @dictionary_path = path
38
36
  @refresh_interval = refresh_interval
39
37
  @short_refresh = @refresh_interval <= 300
40
- @stopping = Concurrent::AtomicBoolean.new # ported from jdbc_static, need a way to prevent a scheduled execution from running a load.
41
38
  rw_lock = java.util.concurrent.locks.ReentrantReadWriteLock.new
42
39
  @write_lock = rw_lock.writeLock
43
40
  @dictionary = Hash.new
@@ -51,13 +48,6 @@ module LogStash module Filters module Dictionary
51
48
  end
52
49
  @fetch_strategy = klass.new(*args)
53
50
  load_dictionary(raise_exception = true)
54
- stop_scheduler(initial = true)
55
- start_scheduler unless @refresh_interval <= 0 # disabled, a scheduler interval of zero makes no sense
56
- end
57
-
58
- def stop_scheduler(initial = false)
59
- @stopping.make_true unless initial
60
- @scheduler.shutdown(:wait) if @scheduler
61
51
  end
62
52
 
63
53
  def load_dictionary(raise_exception=false)
@@ -88,13 +78,6 @@ module LogStash module Filters module Dictionary
88
78
 
89
79
  private
90
80
 
91
- def start_scheduler
92
- @scheduler = Rufus::Scheduler.new
93
- @scheduler.interval("#{@refresh_interval}s", :overlap => false) do
94
- reload_dictionary
95
- end
96
- end
97
-
98
81
  def merge_dictionary
99
82
  @write_lock.lock
100
83
  begin
@@ -116,14 +99,15 @@ module LogStash module Filters module Dictionary
116
99
  end
117
100
  end
118
101
 
102
+ # scheduler executes this method, periodically
119
103
  def reload_dictionary
120
- return if @stopping.true?
121
104
  if @short_refresh
122
105
  load_dictionary if needs_refresh?
123
106
  else
124
107
  load_dictionary
125
108
  end
126
109
  end
110
+ public :reload_dictionary
127
111
 
128
112
  def needs_refresh?
129
113
  @dictionary_mtime != ::File.mtime(@dictionary_path).to_f
@@ -4,6 +4,7 @@ require "logstash/namespace"
4
4
  require 'logstash/plugin_mixins/ecs_compatibility_support'
5
5
  require 'logstash/plugin_mixins/validator_support/field_reference_validation_adapter'
6
6
  require 'logstash/plugin_mixins/deprecation_logger_support'
7
+ require 'logstash/plugin_mixins/scheduler'
7
8
 
8
9
  require "logstash/filters/dictionary/memory"
9
10
  require "logstash/filters/dictionary/file"
@@ -44,6 +45,8 @@ class Translate < LogStash::Filters::Base
44
45
 
45
46
  extend LogStash::PluginMixins::ValidatorSupport::FieldReferenceValidationAdapter
46
47
 
48
+ include LogStash::PluginMixins::Scheduler
49
+
47
50
  config_name "translate"
48
51
 
49
52
  # The name of the logstash event field containing the value to be compared for a
@@ -228,11 +231,11 @@ class Translate < LogStash::Filters::Base
228
231
  else
229
232
  @logger.debug? && @logger.debug("#{self.class.name}: Dictionary translation method - Fuzzy")
230
233
  end
231
- end # def register
232
234
 
233
- def close
234
- @lookup.stop_scheduler
235
- end
235
+ if @lookup.respond_to?(:reload_dictionary) && @refresh_interval > 0 # a scheduler interval of zero makes no sense
236
+ scheduler.interval("#{@refresh_interval}s", overlap: false) { @lookup.reload_dictionary }
237
+ end
238
+ end # def register
236
239
 
237
240
  def filter(event)
238
241
  return unless @updater.test_for_inclusion(event, @override)
@@ -1,7 +1,7 @@
1
1
  Gem::Specification.new do |s|
2
2
 
3
3
  s.name = 'logstash-filter-translate'
4
- s.version = '3.3.1'
4
+ s.version = '3.4.0'
5
5
  s.licenses = ['Apache License (2.0)']
6
6
  s.summary = "Replaces field contents based on a hash or YAML file"
7
7
  s.description = "This gem is a Logstash plugin required to be installed on top of the Logstash core pipeline using $LS_HOME/bin/logstash-plugin install gemname. This gem is not a stand-alone program"
@@ -24,7 +24,7 @@ Gem::Specification.new do |s|
24
24
  s.add_runtime_dependency 'logstash-mixin-ecs_compatibility_support', '~> 1.2'
25
25
  s.add_runtime_dependency 'logstash-mixin-validator_support', '~> 1.0'
26
26
  s.add_runtime_dependency 'logstash-mixin-deprecation_logger_support', '~> 1.0'
27
- s.add_runtime_dependency 'rufus-scheduler'
27
+ s.add_runtime_dependency "logstash-mixin-scheduler", '~> 1.0'
28
28
 
29
29
  s.add_development_dependency 'logstash-devutils'
30
30
  s.add_development_dependency 'rspec-sequencing'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: logstash-filter-translate
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.3.1
4
+ version: 3.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Elastic
@@ -75,17 +75,17 @@ dependencies:
75
75
  - !ruby/object:Gem::Dependency
76
76
  requirement: !ruby/object:Gem::Requirement
77
77
  requirements:
78
- - - ">="
78
+ - - "~>"
79
79
  - !ruby/object:Gem::Version
80
- version: '0'
81
- name: rufus-scheduler
80
+ version: '1.0'
81
+ name: logstash-mixin-scheduler
82
82
  prerelease: false
83
83
  type: :runtime
84
84
  version_requirements: !ruby/object:Gem::Requirement
85
85
  requirements:
86
- - - ">="
86
+ - - "~>"
87
87
  - !ruby/object:Gem::Version
88
- version: '0'
88
+ version: '1.0'
89
89
  - !ruby/object:Gem::Dependency
90
90
  requirement: !ruby/object:Gem::Requirement
91
91
  requirements: