logstash-core 5.6.16-java → 6.0.0.alpha1-java
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/gemspec_jars.rb +4 -7
- data/lib/logstash-core/logstash-core.jar +0 -0
- data/lib/logstash-core/version.rb +4 -8
- data/lib/logstash-core_jars.rb +12 -26
- data/lib/logstash/agent.rb +261 -246
- data/lib/logstash/api/commands/default_metadata.rb +1 -1
- data/lib/logstash/api/commands/hot_threads_reporter.rb +5 -11
- data/lib/logstash/api/commands/node.rb +3 -2
- data/lib/logstash/api/commands/stats.rb +3 -2
- data/lib/logstash/bootstrap_check/bad_java.rb +16 -0
- data/lib/logstash/bootstrap_check/bad_ruby.rb +12 -0
- data/lib/logstash/bootstrap_check/default_config.rb +17 -0
- data/lib/logstash/compiler.rb +38 -0
- data/lib/logstash/compiler/lscl.rb +566 -0
- data/lib/logstash/compiler/lscl/lscl_grammar.rb +3503 -0
- data/lib/logstash/compiler/treetop_monkeypatches.rb +92 -0
- data/lib/logstash/config/config_ast.rb +4 -82
- data/lib/logstash/config/mixin.rb +73 -41
- data/lib/logstash/config/pipeline_config.rb +48 -0
- data/lib/logstash/config/source/base.rb +16 -0
- data/lib/logstash/config/source/local.rb +215 -0
- data/lib/logstash/config/source_loader.rb +125 -0
- data/lib/logstash/converge_result.rb +103 -0
- data/lib/logstash/environment.rb +6 -19
- data/lib/logstash/errors.rb +2 -0
- data/lib/logstash/execution_context.rb +4 -7
- data/lib/logstash/filter_delegator.rb +6 -9
- data/lib/logstash/inputs/base.rb +0 -2
- data/lib/logstash/instrument/collector.rb +5 -7
- data/lib/logstash/instrument/metric_store.rb +12 -12
- data/lib/logstash/instrument/metric_type/mean.rb +0 -5
- data/lib/logstash/instrument/namespaced_metric.rb +0 -4
- data/lib/logstash/instrument/namespaced_null_metric.rb +0 -4
- data/lib/logstash/instrument/null_metric.rb +0 -10
- data/lib/logstash/instrument/periodic_poller/cgroup.rb +85 -168
- data/lib/logstash/instrument/periodic_poller/jvm.rb +5 -5
- data/lib/logstash/instrument/periodic_poller/pq.rb +3 -7
- data/lib/logstash/instrument/periodic_pollers.rb +1 -3
- data/lib/logstash/instrument/wrapped_write_client.rb +24 -33
- data/lib/logstash/logging/logger.rb +15 -47
- data/lib/logstash/namespace.rb +0 -1
- data/lib/logstash/output_delegator.rb +5 -7
- data/lib/logstash/outputs/base.rb +0 -2
- data/lib/logstash/pipeline.rb +159 -87
- data/lib/logstash/pipeline_action.rb +13 -0
- data/lib/logstash/pipeline_action/base.rb +29 -0
- data/lib/logstash/pipeline_action/create.rb +47 -0
- data/lib/logstash/pipeline_action/reload.rb +48 -0
- data/lib/logstash/pipeline_action/stop.rb +23 -0
- data/lib/logstash/plugin.rb +0 -1
- data/lib/logstash/plugins/hooks_registry.rb +6 -0
- data/lib/logstash/plugins/registry.rb +0 -1
- data/lib/logstash/program.rb +14 -0
- data/lib/logstash/queue_factory.rb +5 -1
- data/lib/logstash/runner.rb +58 -80
- data/lib/logstash/settings.rb +3 -27
- data/lib/logstash/state_resolver.rb +41 -0
- data/lib/logstash/util/java_version.rb +6 -0
- data/lib/logstash/util/safe_uri.rb +12 -148
- data/lib/logstash/util/thread_dump.rb +4 -7
- data/lib/logstash/util/wrapped_acked_queue.rb +36 -39
- data/lib/logstash/util/wrapped_synchronous_queue.rb +29 -39
- data/lib/logstash/version.rb +10 -8
- data/locales/en.yml +3 -54
- data/logstash-core.gemspec +8 -35
- data/spec/{logstash/api/modules → api/lib/api}/logging_spec.rb +10 -1
- data/spec/{logstash/api/modules → api/lib/api}/node_plugins_spec.rb +2 -1
- data/spec/{logstash/api/modules → api/lib/api}/node_spec.rb +3 -3
- data/spec/{logstash/api/modules → api/lib/api}/node_stats_spec.rb +3 -7
- data/spec/{logstash/api/modules → api/lib/api}/plugins_spec.rb +3 -4
- data/spec/{logstash/api/modules → api/lib/api}/root_spec.rb +2 -2
- data/spec/api/lib/api/support/resource_dsl_methods.rb +87 -0
- data/spec/{logstash/api/commands/stats_spec.rb → api/lib/commands/stats.rb} +2 -7
- data/spec/{logstash/api → api/lib}/errors_spec.rb +1 -1
- data/spec/{logstash/api → api/lib}/rack_app_spec.rb +0 -0
- data/spec/api/spec_helper.rb +106 -0
- data/spec/logstash/agent/converge_spec.rb +286 -0
- data/spec/logstash/agent/metrics_spec.rb +244 -0
- data/spec/logstash/agent_spec.rb +213 -225
- data/spec/logstash/compiler/compiler_spec.rb +584 -0
- data/spec/logstash/config/config_ast_spec.rb +8 -47
- data/spec/logstash/config/mixin_spec.rb +2 -42
- data/spec/logstash/config/pipeline_config_spec.rb +75 -0
- data/spec/logstash/config/source/local_spec.rb +395 -0
- data/spec/logstash/config/source_loader_spec.rb +122 -0
- data/spec/logstash/converge_result_spec.rb +179 -0
- data/spec/logstash/event_spec.rb +0 -66
- data/spec/logstash/execution_context_spec.rb +8 -12
- data/spec/logstash/filter_delegator_spec.rb +12 -24
- data/spec/logstash/inputs/base_spec.rb +7 -5
- data/spec/logstash/instrument/periodic_poller/cgroup_spec.rb +92 -225
- data/spec/logstash/instrument/periodic_poller/jvm_spec.rb +1 -1
- data/spec/logstash/instrument/periodic_poller/os_spec.rb +32 -29
- data/spec/logstash/instrument/wrapped_write_client_spec.rb +33 -33
- data/spec/logstash/legacy_ruby_event_spec.rb +13 -4
- data/spec/logstash/output_delegator_spec.rb +11 -20
- data/spec/logstash/outputs/base_spec.rb +7 -5
- data/spec/logstash/pipeline_action/create_spec.rb +83 -0
- data/spec/logstash/pipeline_action/reload_spec.rb +83 -0
- data/spec/logstash/pipeline_action/stop_spec.rb +37 -0
- data/spec/logstash/pipeline_pq_file_spec.rb +1 -1
- data/spec/logstash/pipeline_spec.rb +81 -137
- data/spec/logstash/plugin_spec.rb +2 -1
- data/spec/logstash/plugins/hooks_registry_spec.rb +6 -0
- data/spec/logstash/queue_factory_spec.rb +13 -1
- data/spec/logstash/runner_spec.rb +29 -140
- data/spec/logstash/settings/writable_directory_spec.rb +10 -13
- data/spec/logstash/settings_spec.rb +0 -91
- data/spec/logstash/state_resolver_spec.rb +156 -0
- data/spec/logstash/timestamp_spec.rb +2 -6
- data/spec/logstash/util/java_version_spec.rb +22 -0
- data/spec/logstash/util/safe_uri_spec.rb +0 -56
- data/spec/logstash/util/wrapped_synchronous_queue_spec.rb +22 -0
- data/spec/support/helpers.rb +9 -11
- data/spec/support/matchers.rb +96 -6
- data/spec/support/mocks_classes.rb +80 -0
- data/spec/support/shared_contexts.rb +2 -27
- metadata +100 -149
- data/lib/logstash/config/loader.rb +0 -107
- data/lib/logstash/config/modules_common.rb +0 -103
- data/lib/logstash/config/source/modules.rb +0 -55
- data/lib/logstash/config/string_escape.rb +0 -27
- data/lib/logstash/dependency_report.rb +0 -131
- data/lib/logstash/dependency_report_runner.rb +0 -17
- data/lib/logstash/elasticsearch_client.rb +0 -142
- data/lib/logstash/instrument/global_metrics.rb +0 -13
- data/lib/logstash/instrument/periodic_poller/dlq.rb +0 -24
- data/lib/logstash/modules/cli_parser.rb +0 -74
- data/lib/logstash/modules/elasticsearch_config.rb +0 -22
- data/lib/logstash/modules/elasticsearch_importer.rb +0 -37
- data/lib/logstash/modules/elasticsearch_resource.rb +0 -10
- data/lib/logstash/modules/file_reader.rb +0 -36
- data/lib/logstash/modules/kibana_base.rb +0 -24
- data/lib/logstash/modules/kibana_client.rb +0 -124
- data/lib/logstash/modules/kibana_config.rb +0 -105
- data/lib/logstash/modules/kibana_dashboards.rb +0 -36
- data/lib/logstash/modules/kibana_importer.rb +0 -17
- data/lib/logstash/modules/kibana_resource.rb +0 -10
- data/lib/logstash/modules/kibana_settings.rb +0 -40
- data/lib/logstash/modules/logstash_config.rb +0 -120
- data/lib/logstash/modules/resource_base.rb +0 -38
- data/lib/logstash/modules/scaffold.rb +0 -52
- data/lib/logstash/modules/settings_merger.rb +0 -23
- data/lib/logstash/modules/util.rb +0 -17
- data/lib/logstash/util/dead_letter_queue_manager.rb +0 -61
- data/lib/logstash/util/environment_variables.rb +0 -43
- data/spec/logstash/config/loader_spec.rb +0 -38
- data/spec/logstash/config/string_escape_spec.rb +0 -24
- data/spec/logstash/instrument/periodic_poller/dlq_spec.rb +0 -17
- data/spec/logstash/modules/logstash_config_spec.rb +0 -56
- data/spec/logstash/modules/scaffold_spec.rb +0 -234
- data/spec/logstash/pipeline_dlq_commit_spec.rb +0 -109
- data/spec/logstash/settings/splittable_string_array_spec.rb +0 -51
- data/spec/logstash/util/wrapped_acked_queue_spec.rb +0 -49
- data/versions-gem-copy.yml +0 -12
data/lib/logstash/settings.rb
CHANGED
@@ -2,14 +2,11 @@
|
|
2
2
|
require "logstash/util/loggable"
|
3
3
|
require "fileutils"
|
4
4
|
require "logstash/util/byte_value"
|
5
|
-
require "logstash/util/environment_variables"
|
6
5
|
require "logstash/util/time_value"
|
7
6
|
|
8
7
|
module LogStash
|
9
8
|
class Settings
|
10
9
|
|
11
|
-
include LogStash::Util::EnvironmentVariables
|
12
|
-
|
13
10
|
def initialize
|
14
11
|
@settings = {}
|
15
12
|
# Theses settings were loaded from the yaml file
|
@@ -50,6 +47,7 @@ module LogStash
|
|
50
47
|
def clone
|
51
48
|
get_subset(".*")
|
52
49
|
end
|
50
|
+
alias_method :dup, :clone
|
53
51
|
|
54
52
|
def get_default(setting_name)
|
55
53
|
get_setting(setting_name).default
|
@@ -110,10 +108,7 @@ module LogStash
|
|
110
108
|
|
111
109
|
def from_yaml(yaml_path)
|
112
110
|
settings = read_yaml(::File.join(yaml_path, "logstash.yml"))
|
113
|
-
self.merge(
|
114
|
-
deep_replace(flatten_hash(settings)),
|
115
|
-
true
|
116
|
-
)
|
111
|
+
self.merge(flatten_hash(settings), true)
|
117
112
|
self
|
118
113
|
end
|
119
114
|
|
@@ -534,27 +529,8 @@ module LogStash
|
|
534
529
|
end
|
535
530
|
end
|
536
531
|
end
|
537
|
-
|
538
|
-
class SplittableStringArray < ArrayCoercible
|
539
|
-
DEFAULT_TOKEN = ","
|
540
|
-
|
541
|
-
def initialize(name, klass, default, strict=true, tokenizer = DEFAULT_TOKEN, &validator_proc)
|
542
|
-
@element_class = klass
|
543
|
-
@token = tokenizer
|
544
|
-
super(name, klass, default, strict, &validator_proc)
|
545
|
-
end
|
546
|
-
|
547
|
-
def coerce(value)
|
548
|
-
if value.is_a?(Array)
|
549
|
-
value
|
550
|
-
elsif value.nil?
|
551
|
-
[]
|
552
|
-
else
|
553
|
-
value.split(@token).map(&:strip)
|
554
|
-
end
|
555
|
-
end
|
556
|
-
end
|
557
532
|
end
|
558
533
|
|
534
|
+
|
559
535
|
SETTINGS = Settings.new
|
560
536
|
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
module LogStash
|
3
|
+
# In the beginning I was using this code as a method in the Agent class directly
|
4
|
+
# But with the plugins system I think we should be able to swap what kind of action would be run.
|
5
|
+
#
|
6
|
+
# Lets take the example of dynamic source, where the pipeline config and settings are located and
|
7
|
+
# managed outside of the machine.
|
8
|
+
class StateResolver
|
9
|
+
def initialize(metric)
|
10
|
+
@metric = metric
|
11
|
+
end
|
12
|
+
|
13
|
+
def resolve(pipelines, pipeline_configs)
|
14
|
+
actions = []
|
15
|
+
|
16
|
+
pipeline_configs.each do |pipeline_config|
|
17
|
+
pipeline = pipelines[pipeline_config.pipeline_id]
|
18
|
+
|
19
|
+
if pipeline.nil?
|
20
|
+
actions << LogStash::PipelineAction::Create.new(pipeline_config, @metric)
|
21
|
+
else
|
22
|
+
# TODO(ph): The pipeline should keep a reference to the original PipelineConfig
|
23
|
+
# and we could use straight comparison.
|
24
|
+
if pipeline_config.config_hash != pipeline.config_hash
|
25
|
+
actions << LogStash::PipelineAction::Reload.new(pipeline_config, @metric)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
running_pipelines = pipeline_configs.collect(&:pipeline_id)
|
31
|
+
|
32
|
+
# If one of the running pipeline is not in the pipeline_configs, we assume that we need to
|
33
|
+
# stop it.
|
34
|
+
pipelines.keys
|
35
|
+
.select { |pipeline_id| !running_pipelines.include?(pipeline_id) }
|
36
|
+
.each { |pipeline_id| actions << LogStash::PipelineAction::Stop.new(pipeline_id) }
|
37
|
+
|
38
|
+
actions.sort # See logstash/pipeline_action.rb
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -32,6 +32,12 @@ module LogStash::Util::JavaVersion
|
|
32
32
|
}
|
33
33
|
end
|
34
34
|
|
35
|
+
def self.validate_java_version!
|
36
|
+
if bad_java_version?(version)
|
37
|
+
raise "Java version 1.8.0 or later is required. (You are running: #{version})"
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
35
41
|
# Determine if the given java version string is a bad version of java
|
36
42
|
# If it is, return true, if it isn't return false.
|
37
43
|
# Accepts nil, returning nil.
|
@@ -11,23 +11,21 @@ class LogStash::Util::SafeURI
|
|
11
11
|
|
12
12
|
extend Forwardable
|
13
13
|
|
14
|
+
def_delegators :@uri, :coerce, :query=, :route_from, :port=, :default_port, :select, :normalize!, :absolute?, :registry=, :path, :password, :hostname, :merge, :normalize, :host, :component_ary, :userinfo=, :query, :set_opaque, :+, :merge!, :-, :password=, :parser, :port, :set_host, :set_path, :opaque=, :scheme, :fragment=, :set_query, :set_fragment, :userinfo, :hostname=, :set_port, :path=, :registry, :opaque, :route_to, :set_password, :hierarchical?, :set_user, :set_registry, :set_userinfo, :fragment, :component, :user=, :set_scheme, :absolute, :host=, :relative?, :scheme=, :user
|
14
15
|
|
15
16
|
attr_reader :uri
|
16
|
-
|
17
|
+
|
17
18
|
public
|
18
|
-
def initialize(arg)
|
19
|
+
def initialize(arg)
|
19
20
|
@uri = case arg
|
20
21
|
when String
|
21
22
|
arg = "//#{arg}" if HOSTNAME_PORT_REGEX.match(arg)
|
22
|
-
|
23
|
-
when java.net.URI
|
24
|
-
arg
|
23
|
+
URI.parse(arg)
|
25
24
|
when URI
|
26
|
-
|
25
|
+
arg
|
27
26
|
else
|
28
|
-
raise ArgumentError, "Expected a string
|
27
|
+
raise ArgumentError, "Expected a string or URI, got a #{arg.class} creating a URL"
|
29
28
|
end
|
30
|
-
raise ArgumentError, "URI is not valid - host is not specified" if @uri.host.nil?
|
31
29
|
end
|
32
30
|
|
33
31
|
def to_s
|
@@ -39,11 +37,11 @@ class LogStash::Util::SafeURI
|
|
39
37
|
end
|
40
38
|
|
41
39
|
def sanitized
|
42
|
-
return uri unless password # nothing to sanitize here!
|
40
|
+
return uri unless uri.password # nothing to sanitize here!
|
43
41
|
|
44
|
-
|
45
|
-
|
46
|
-
|
42
|
+
safe = uri.clone
|
43
|
+
safe.password = PASS_PLACEHOLDER
|
44
|
+
safe
|
47
45
|
end
|
48
46
|
|
49
47
|
def ==(other)
|
@@ -51,142 +49,8 @@ class LogStash::Util::SafeURI
|
|
51
49
|
end
|
52
50
|
|
53
51
|
def clone
|
54
|
-
|
55
|
-
self.class.new(
|
56
|
-
end
|
57
|
-
|
58
|
-
def update(field, value)
|
59
|
-
new_scheme = scheme
|
60
|
-
new_user = user
|
61
|
-
new_password = password
|
62
|
-
new_host = host
|
63
|
-
new_port = port
|
64
|
-
new_path = path
|
65
|
-
new_query = query
|
66
|
-
new_fragment = fragment
|
67
|
-
|
68
|
-
case field
|
69
|
-
when :scheme
|
70
|
-
new_scheme = value
|
71
|
-
when :user
|
72
|
-
new_user = value
|
73
|
-
when :password
|
74
|
-
new_password = value
|
75
|
-
when :host
|
76
|
-
new_host = value
|
77
|
-
when :port
|
78
|
-
new_port = value
|
79
|
-
when :path
|
80
|
-
new_path = value
|
81
|
-
when :query
|
82
|
-
new_query = value
|
83
|
-
when :fragment
|
84
|
-
new_fragment = value
|
85
|
-
end
|
86
|
-
|
87
|
-
user_info = new_user
|
88
|
-
if new_user && new_password
|
89
|
-
user_info += ":" + new_password
|
90
|
-
end
|
91
|
-
|
92
|
-
@uri = make_uri(new_scheme, user_info, new_host, new_port, new_path, new_query, new_fragment)
|
93
|
-
end
|
94
|
-
|
95
|
-
def user
|
96
|
-
if userinfo
|
97
|
-
userinfo.split(":")[0]
|
98
|
-
end
|
99
|
-
end
|
100
|
-
|
101
|
-
def user=(new_user)
|
102
|
-
update(:user, new_user)
|
103
|
-
end
|
104
|
-
|
105
|
-
def password
|
106
|
-
if userinfo
|
107
|
-
userinfo.split(":")[1]
|
108
|
-
end
|
109
|
-
end
|
110
|
-
|
111
|
-
def password=(new_password)
|
112
|
-
update(:password, new_password)
|
113
|
-
end
|
114
|
-
|
115
|
-
def hostname
|
116
|
-
# Alias from the ruby library
|
117
|
-
host
|
118
|
-
end
|
119
|
-
|
120
|
-
def host=(new_host)
|
121
|
-
update(:host, new_host)
|
122
|
-
end
|
123
|
-
|
124
|
-
def port
|
125
|
-
# In java this is an int
|
126
|
-
uri.port < 1 ? nil : uri.port
|
127
|
-
end
|
128
|
-
|
129
|
-
def port=(new_port)
|
130
|
-
update(:port, new_port)
|
131
|
-
end
|
132
|
-
|
133
|
-
def path=(new_path)
|
134
|
-
update(:path, new_path)
|
135
|
-
end
|
136
|
-
|
137
|
-
def query=(new_query)
|
138
|
-
update(:query, new_query)
|
139
|
-
end
|
140
|
-
|
141
|
-
def fragment=(new_fragment)
|
142
|
-
update(:fragment, new_fragment)
|
143
|
-
end
|
144
|
-
|
145
|
-
# Same algorithm as Ruby's URI class uses
|
146
|
-
def normalize!
|
147
|
-
if path && path == ''
|
148
|
-
path = '/'
|
149
|
-
end
|
150
|
-
if scheme && scheme != scheme.downcase
|
151
|
-
scheme = self.scheme.downcase
|
152
|
-
end
|
153
|
-
if host && host != host.downcase
|
154
|
-
host = self.host.downcase
|
155
|
-
end
|
156
|
-
end
|
157
|
-
|
158
|
-
def normalize
|
159
|
-
d = self.dup
|
160
|
-
d.normalize!
|
161
|
-
d
|
162
|
-
end
|
163
|
-
|
164
|
-
def path
|
165
|
-
@uri.raw_path
|
166
|
-
end
|
167
|
-
|
168
|
-
def query
|
169
|
-
@uri.raw_query
|
170
|
-
end
|
171
|
-
|
172
|
-
def fragment
|
173
|
-
@uri.raw_fragment
|
174
|
-
end
|
175
|
-
|
176
|
-
def userinfo
|
177
|
-
@uri.raw_user_info
|
178
|
-
end
|
179
|
-
|
180
|
-
def_delegators :@uri, :absolute?, :scheme, :host
|
181
|
-
|
182
|
-
private
|
183
|
-
|
184
|
-
# Jruby doesn't guess the constructor correctly if there are some nil things in place
|
185
|
-
# hence, this method
|
186
|
-
def make_uri(scheme, user_info, host, port, path, query, fragment)
|
187
|
-
# It is lot legal to have a path not starting with a /
|
188
|
-
prefixed_path = path && path[0] != "/" ? "/#{path}" : path
|
189
|
-
java.net.URI.new(scheme, user_info, host, port || -1, prefixed_path, query, fragment)
|
52
|
+
cloned_uri = uri.clone
|
53
|
+
self.class.new(cloned_uri)
|
190
54
|
end
|
191
55
|
end
|
192
56
|
|
@@ -1,6 +1,4 @@
|
|
1
1
|
# encoding: utf-8
|
2
|
-
java_import 'org.logstash.instrument.reports.ThreadsReport'
|
3
|
-
|
4
2
|
module LogStash
|
5
3
|
module Util
|
6
4
|
class ThreadDump
|
@@ -12,20 +10,19 @@ module LogStash
|
|
12
10
|
|
13
11
|
def initialize(options={})
|
14
12
|
@options = options
|
15
|
-
@dump = options.fetch(:dump,
|
13
|
+
@dump = options.fetch(:dump, JRMonitor.threads.generate({}))
|
16
14
|
@top_count = options.fetch(:threads, THREADS_COUNT_DEFAULT)
|
17
15
|
@ignore = options.fetch(:ignore_idle_threads, IGNORE_IDLE_THREADS_DEFAULT)
|
18
16
|
end
|
19
17
|
|
20
18
|
def each(&block)
|
21
19
|
i=0
|
22
|
-
dump.
|
23
|
-
thread_name = hash["thread.name"]
|
20
|
+
dump.each_pair do |thread_name, _hash|
|
24
21
|
break if i >= top_count
|
25
22
|
if ignore
|
26
|
-
next if idle_thread?(thread_name,
|
23
|
+
next if idle_thread?(thread_name, _hash)
|
27
24
|
end
|
28
|
-
block.call(
|
25
|
+
block.call(thread_name, _hash)
|
29
26
|
i += 1
|
30
27
|
end
|
31
28
|
end
|
@@ -20,6 +20,12 @@ module LogStash; module Util
|
|
20
20
|
class QueueClosedError < ::StandardError; end
|
21
21
|
class NotImplementedError < ::StandardError; end
|
22
22
|
|
23
|
+
def self.create_memory_based(path, capacity, max_events, max_bytes)
|
24
|
+
self.allocate.with_queue(
|
25
|
+
LogStash::AckedMemoryQueue.new(path, capacity, max_events, max_bytes)
|
26
|
+
)
|
27
|
+
end
|
28
|
+
|
23
29
|
def self.create_file_based(path, capacity, max_events, checkpoint_max_writes, checkpoint_max_acks, checkpoint_max_interval, max_bytes)
|
24
30
|
self.allocate.with_queue(
|
25
31
|
LogStash::AckedQueue.new(path, capacity, max_events, checkpoint_max_writes, checkpoint_max_acks, checkpoint_max_interval, max_bytes)
|
@@ -51,6 +57,24 @@ module LogStash; module Util
|
|
51
57
|
end
|
52
58
|
alias_method(:<<, :push)
|
53
59
|
|
60
|
+
# TODO - fix doc for this noop method
|
61
|
+
# Offer an object to the queue, wait for the specified amount of time.
|
62
|
+
# If adding to the queue was successful it will return true, false otherwise.
|
63
|
+
#
|
64
|
+
# @param [Object] Object to add to the queue
|
65
|
+
# @param [Integer] Time in milliseconds to wait before giving up
|
66
|
+
# @return [Boolean] True if adding was successful if not it return false
|
67
|
+
def offer(obj, timeout_ms)
|
68
|
+
raise NotImplementedError.new("The offer method is not implemented. There is no non blocking write operation yet.")
|
69
|
+
end
|
70
|
+
|
71
|
+
# Blocking
|
72
|
+
def take
|
73
|
+
check_closed("read a batch")
|
74
|
+
# TODO - determine better arbitrary timeout millis
|
75
|
+
@queue.read_batch(1, 200).get_elements.first
|
76
|
+
end
|
77
|
+
|
54
78
|
# Block for X millis
|
55
79
|
def poll(millis)
|
56
80
|
check_closed("read")
|
@@ -76,10 +100,6 @@ module LogStash; module Util
|
|
76
100
|
end
|
77
101
|
end
|
78
102
|
|
79
|
-
def is_empty?
|
80
|
-
@queue.is_empty?
|
81
|
-
end
|
82
|
-
|
83
103
|
def close
|
84
104
|
@queue.close
|
85
105
|
@closed.make_true
|
@@ -107,12 +127,7 @@ module LogStash; module Util
|
|
107
127
|
end
|
108
128
|
|
109
129
|
def empty?
|
110
|
-
@mutex.
|
111
|
-
begin
|
112
|
-
@queue.is_empty?
|
113
|
-
ensure
|
114
|
-
@mutex.unlock
|
115
|
-
end
|
130
|
+
@mutex.synchronize { @queue.is_fully_acked? }
|
116
131
|
end
|
117
132
|
|
118
133
|
def set_batch_dimensions(batch_size, wait_for)
|
@@ -137,11 +152,8 @@ module LogStash; module Util
|
|
137
152
|
end
|
138
153
|
|
139
154
|
def inflight_batches
|
140
|
-
@mutex.
|
141
|
-
begin
|
155
|
+
@mutex.synchronize do
|
142
156
|
yield(@inflight_batches)
|
143
|
-
ensure
|
144
|
-
@mutex.unlock
|
145
157
|
end
|
146
158
|
end
|
147
159
|
|
@@ -161,24 +173,16 @@ module LogStash; module Util
|
|
161
173
|
end
|
162
174
|
|
163
175
|
batch = new_batch
|
164
|
-
@mutex.
|
165
|
-
begin
|
166
|
-
batch.read_next
|
167
|
-
ensure
|
168
|
-
@mutex.unlock
|
169
|
-
end
|
176
|
+
@mutex.synchronize { batch.read_next }
|
170
177
|
start_metrics(batch)
|
171
178
|
batch
|
172
179
|
end
|
173
180
|
|
174
181
|
def start_metrics(batch)
|
175
|
-
@mutex.
|
176
|
-
begin
|
182
|
+
@mutex.synchronize do
|
177
183
|
# there seems to be concurrency issues with metrics, keep it in the mutex
|
178
184
|
set_current_thread_inflight_batch(batch)
|
179
185
|
start_clock
|
180
|
-
ensure
|
181
|
-
@mutex.unlock
|
182
186
|
end
|
183
187
|
end
|
184
188
|
|
@@ -187,30 +191,29 @@ module LogStash; module Util
|
|
187
191
|
end
|
188
192
|
|
189
193
|
def close_batch(batch)
|
190
|
-
@mutex.
|
191
|
-
begin
|
194
|
+
@mutex.synchronize do
|
192
195
|
batch.close
|
196
|
+
|
193
197
|
# there seems to be concurrency issues with metrics, keep it in the mutex
|
194
198
|
@inflight_batches.delete(Thread.current)
|
195
199
|
stop_clock(batch)
|
196
|
-
ensure
|
197
|
-
@mutex.unlock
|
198
200
|
end
|
199
201
|
end
|
200
202
|
|
201
203
|
def start_clock
|
202
|
-
@inflight_clocks[Thread.current] =
|
204
|
+
@inflight_clocks[Thread.current] = [
|
205
|
+
@event_metric.time(:duration_in_millis),
|
206
|
+
@pipeline_metric.time(:duration_in_millis)
|
207
|
+
]
|
203
208
|
end
|
204
209
|
|
205
210
|
def stop_clock(batch)
|
206
211
|
unless @inflight_clocks[Thread.current].nil?
|
207
212
|
if batch.size > 0
|
208
|
-
#
|
213
|
+
# onl/y stop (which also records) the metrics if the batch is non-empty.
|
209
214
|
# start_clock is now called at empty batch creation and an empty batch could
|
210
215
|
# stay empty all the way down to the close_batch call.
|
211
|
-
|
212
|
-
@event_metric.report_time(:duration_in_millis, time_taken)
|
213
|
-
@pipeline_metric.report_time(:duration_in_millis, time_taken)
|
216
|
+
@inflight_clocks[Thread.current].each(&:stop)
|
214
217
|
end
|
215
218
|
@inflight_clocks.delete(Thread.current)
|
216
219
|
end
|
@@ -281,12 +284,6 @@ module LogStash; module Util
|
|
281
284
|
# @cancelled[event] = true
|
282
285
|
end
|
283
286
|
|
284
|
-
def to_a
|
285
|
-
events = []
|
286
|
-
each {|e| events << e}
|
287
|
-
events
|
288
|
-
end
|
289
|
-
|
290
287
|
def each(&blk)
|
291
288
|
# take care not to cause @originals or @generated to change during iteration
|
292
289
|
|