logstash-core 2.4.1-java → 5.0.0.alpha1-java
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.
Potentially problematic release.
This version of logstash-core might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/lib/logstash-core/version.rb +1 -1
- data/lib/logstash/agent.rb +124 -411
- data/lib/logstash/api/init.ru +31 -0
- data/lib/logstash/api/lib/app.rb +40 -0
- data/lib/logstash/api/lib/app/command.rb +29 -0
- data/lib/logstash/api/lib/app/command_factory.rb +29 -0
- data/lib/logstash/api/lib/app/commands/stats/events_command.rb +13 -0
- data/lib/logstash/api/lib/app/commands/stats/hotthreads_command.rb +120 -0
- data/lib/logstash/api/lib/app/commands/stats/memory_command.rb +25 -0
- data/lib/logstash/api/lib/app/commands/system/basicinfo_command.rb +15 -0
- data/lib/logstash/api/lib/app/commands/system/plugins_command.rb +28 -0
- data/lib/logstash/api/lib/app/modules/node.rb +25 -0
- data/lib/logstash/api/lib/app/modules/node_stats.rb +51 -0
- data/lib/logstash/api/lib/app/modules/plugins.rb +15 -0
- data/lib/logstash/api/lib/app/modules/stats.rb +21 -0
- data/lib/logstash/api/lib/app/root.rb +13 -0
- data/lib/logstash/api/lib/app/service.rb +61 -0
- data/lib/logstash/api/lib/app/stats.rb +56 -0
- data/lib/logstash/api/lib/helpers/app_helpers.rb +23 -0
- data/lib/logstash/codecs/base.rb +1 -29
- data/lib/logstash/config/config_ast.rb +18 -31
- data/lib/logstash/config/loader.rb +3 -5
- data/lib/logstash/config/mixin.rb +25 -64
- data/lib/logstash/filter_delegator.rb +65 -0
- data/lib/logstash/inputs/base.rb +1 -1
- data/lib/logstash/inputs/metrics.rb +47 -0
- data/lib/logstash/instrument/collector.rb +109 -0
- data/lib/logstash/instrument/metric.rb +102 -0
- data/lib/logstash/instrument/metric_store.rb +228 -0
- data/lib/logstash/instrument/metric_type.rb +24 -0
- data/lib/logstash/instrument/metric_type/base.rb +35 -0
- data/lib/logstash/instrument/metric_type/counter.rb +29 -0
- data/lib/logstash/instrument/metric_type/gauge.rb +22 -0
- data/lib/logstash/instrument/metric_type/mean.rb +33 -0
- data/lib/logstash/instrument/namespaced_metric.rb +54 -0
- data/lib/logstash/instrument/null_metric.rb +4 -3
- data/lib/logstash/instrument/periodic_poller/base.rb +57 -0
- data/lib/logstash/instrument/periodic_poller/jvm.rb +92 -0
- data/lib/logstash/instrument/periodic_poller/os.rb +13 -0
- data/lib/logstash/instrument/periodic_poller/periodic_poller_observer.rb +19 -0
- data/lib/logstash/instrument/periodic_pollers.rb +26 -0
- data/lib/logstash/instrument/snapshot.rb +16 -0
- data/lib/logstash/json.rb +2 -3
- data/lib/logstash/namespace.rb +1 -0
- data/lib/logstash/output_delegator.rb +16 -3
- data/lib/logstash/outputs/base.rb +1 -32
- data/lib/logstash/pipeline.rb +67 -8
- data/lib/logstash/plugin.rb +57 -19
- data/lib/logstash/runner.rb +348 -84
- data/lib/logstash/util.rb +9 -0
- data/lib/logstash/util/duration_formatter.rb +15 -0
- data/lib/logstash/util/java_version.rb +2 -4
- data/lib/logstash/util/loggable.rb +29 -0
- data/lib/logstash/version.rb +1 -1
- data/lib/logstash/webserver.rb +98 -0
- data/locales/en.yml +42 -24
- data/logstash-core.gemspec +9 -6
- data/spec/api/lib/api/node_spec.rb +64 -0
- data/spec/api/lib/api/node_stats_spec.rb +68 -0
- data/spec/api/lib/api/plugins_spec.rb +57 -0
- data/spec/api/lib/api/root_spec.rb +20 -0
- data/spec/api/lib/api/stats_spec.rb +19 -0
- data/spec/api/lib/commands/events_spec.rb +17 -0
- data/spec/api/lib/commands/jvm_spec.rb +45 -0
- data/spec/api/spec_helper.rb +128 -0
- data/spec/logstash/agent_spec.rb +62 -169
- data/spec/logstash/config/config_ast_spec.rb +2 -47
- data/spec/logstash/config/mixin_spec.rb +0 -157
- data/spec/logstash/filter_delegator_spec.rb +143 -0
- data/spec/logstash/inputs/metrics_spec.rb +52 -0
- data/spec/logstash/instrument/collector_spec.rb +49 -0
- data/spec/logstash/instrument/metric_spec.rb +110 -0
- data/spec/logstash/instrument/metric_store_spec.rb +163 -0
- data/spec/logstash/instrument/metric_type/counter_spec.rb +40 -0
- data/spec/logstash/instrument/metric_type/gauge_spec.rb +40 -0
- data/spec/logstash/instrument/namespaced_metric_spec.rb +25 -0
- data/spec/logstash/instrument/null_metric_spec.rb +9 -51
- data/spec/logstash/json_spec.rb +14 -0
- data/spec/logstash/output_delegator_spec.rb +6 -3
- data/spec/logstash/outputs/base_spec.rb +0 -107
- data/spec/logstash/pipeline_spec.rb +204 -33
- data/spec/logstash/plugin_spec.rb +80 -15
- data/spec/logstash/runner_spec.rb +134 -38
- data/spec/logstash/shutdown_watcher_spec.rb +0 -1
- data/spec/logstash/util/duration_formatter_spec.rb +11 -0
- data/spec/logstash/util/java_version_spec.rb +10 -2
- data/spec/logstash/util_spec.rb +28 -0
- data/spec/support/matchers.rb +30 -0
- metadata +154 -20
- data/lib/logstash/logging/json.rb +0 -21
- data/lib/logstash/special_agent.rb +0 -8
- data/lib/logstash/util/safe_uri.rb +0 -50
- data/spec/logstash/codecs/base_spec.rb +0 -74
- data/spec/static/i18n_spec.rb +0 -25
@@ -0,0 +1,110 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require "logstash/instrument/metric"
|
3
|
+
require "logstash/instrument/collector"
|
4
|
+
require_relative "../../support/matchers"
|
5
|
+
require "spec_helper"
|
6
|
+
|
7
|
+
describe LogStash::Instrument::Metric do
|
8
|
+
let(:collector) { [] }
|
9
|
+
let(:namespace) { :root }
|
10
|
+
|
11
|
+
subject { LogStash::Instrument::Metric.new(collector) }
|
12
|
+
|
13
|
+
context "#increment" do
|
14
|
+
it "a counter by 1" do
|
15
|
+
metric = subject.increment(:root, :error_rate)
|
16
|
+
expect(collector).to be_a_metric_event([:root, :error_rate], :counter, :increment, 1)
|
17
|
+
end
|
18
|
+
|
19
|
+
it "a counter by a provided value" do
|
20
|
+
metric = subject.increment(:root, :error_rate, 20)
|
21
|
+
expect(collector).to be_a_metric_event([:root, :error_rate], :counter, :increment, 20)
|
22
|
+
end
|
23
|
+
|
24
|
+
it "raises an exception if the key is an empty string" do
|
25
|
+
expect { subject.increment(:root, "", 20) }.to raise_error(LogStash::Instrument::MetricNoKeyProvided)
|
26
|
+
end
|
27
|
+
|
28
|
+
it "raise an exception if the key is nil" do
|
29
|
+
expect { subject.increment(:root, nil, 20) }.to raise_error(LogStash::Instrument::MetricNoKeyProvided)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
context "#decrement" do
|
34
|
+
it "a counter by 1" do
|
35
|
+
metric = subject.decrement(:root, :error_rate)
|
36
|
+
expect(collector).to be_a_metric_event([:root, :error_rate], :counter, :decrement, 1)
|
37
|
+
end
|
38
|
+
|
39
|
+
it "a counter by a provided value" do
|
40
|
+
metric = subject.decrement(:root, :error_rate, 20)
|
41
|
+
expect(collector).to be_a_metric_event([:root, :error_rate], :counter, :decrement, 20)
|
42
|
+
end
|
43
|
+
|
44
|
+
it "raises an exception if the key is an empty string" do
|
45
|
+
expect { subject.decrement(:root, "", 20) }.to raise_error(LogStash::Instrument::MetricNoKeyProvided)
|
46
|
+
end
|
47
|
+
|
48
|
+
it "raise an exception if the key is nil" do
|
49
|
+
expect { subject.decrement(:root, nil, 20) }.to raise_error(LogStash::Instrument::MetricNoKeyProvided)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
context "#gauge" do
|
54
|
+
it "set the value of a key" do
|
55
|
+
metric = subject.gauge(:root, :size_queue, 20)
|
56
|
+
expect(collector).to be_a_metric_event([:root, :size_queue], :gauge, :set, 20)
|
57
|
+
end
|
58
|
+
|
59
|
+
it "raises an exception if the key is an empty string" do
|
60
|
+
expect { subject.gauge(:root, "", 20) }.to raise_error(LogStash::Instrument::MetricNoKeyProvided)
|
61
|
+
end
|
62
|
+
|
63
|
+
it "raise an exception if the key is nil" do
|
64
|
+
expect { subject.gauge(:root, nil, 20) }.to raise_error(LogStash::Instrument::MetricNoKeyProvided)
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
context "#time" do
|
69
|
+
let(:sleep_time) { 2 }
|
70
|
+
let(:sleep_time_ms) { sleep_time * 1_000_000 }
|
71
|
+
|
72
|
+
it "records the duration" do
|
73
|
+
subject.time(:root, :duration_ms) { sleep(sleep_time) }
|
74
|
+
|
75
|
+
expect(collector.last).to be_within(sleep_time_ms).of(sleep_time_ms + 5000)
|
76
|
+
expect(collector[0]).to match(:root)
|
77
|
+
expect(collector[1]).to be(:duration_ms)
|
78
|
+
expect(collector[2]).to be(:mean)
|
79
|
+
end
|
80
|
+
|
81
|
+
it "returns the value of the executed block" do
|
82
|
+
expect(subject.time(:root, :testing) { "hello" }).to eq("hello")
|
83
|
+
end
|
84
|
+
|
85
|
+
it "return a TimedExecution" do
|
86
|
+
execution = subject.time(:root, :duration_ms)
|
87
|
+
sleep(sleep_time)
|
88
|
+
execution.stop
|
89
|
+
|
90
|
+
expect(collector.last).to be_within(sleep_time_ms).of(sleep_time_ms + 0.1)
|
91
|
+
expect(collector[0]).to match(:root)
|
92
|
+
expect(collector[1]).to be(:duration_ms)
|
93
|
+
expect(collector[2]).to be(:mean)
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
context "#namespace" do
|
98
|
+
let(:sub_key) { :my_sub_key }
|
99
|
+
|
100
|
+
it "creates a new metric object and append the `sub_key` to the `base_key`" do
|
101
|
+
expect(subject.namespace(sub_key).namespace_name).to eq([sub_key])
|
102
|
+
end
|
103
|
+
|
104
|
+
it "uses the same collector as the creator class" do
|
105
|
+
child = subject.namespace(sub_key)
|
106
|
+
metric = child.increment(:error_rate)
|
107
|
+
expect(collector).to be_a_metric_event([sub_key, :error_rate], :counter, :increment, 1)
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
@@ -0,0 +1,163 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require "logstash/instrument/metric_store"
|
3
|
+
require "logstash/instrument/metric_type/base"
|
4
|
+
|
5
|
+
describe LogStash::Instrument::MetricStore do
|
6
|
+
let(:namespaces) { [ :root, :pipelines, :pipeline_01 ] }
|
7
|
+
let(:key) { :events_in }
|
8
|
+
let(:counter) { LogStash::Instrument::MetricType::Counter.new(namespaces, key) }
|
9
|
+
|
10
|
+
context "when the metric object doesn't exist" do
|
11
|
+
it "store the object" do
|
12
|
+
expect(subject.fetch_or_store(namespaces, key, counter)).to eq(counter)
|
13
|
+
end
|
14
|
+
|
15
|
+
it "support a block as argument" do
|
16
|
+
expect(subject.fetch_or_store(namespaces, key) { counter }).to eq(counter)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
context "when the metric object exist in the namespace" do
|
21
|
+
let(:new_counter) { LogStash::Instrument::MetricType::Counter.new(namespaces, key) }
|
22
|
+
|
23
|
+
it "return the object" do
|
24
|
+
subject.fetch_or_store(namespaces, key, counter)
|
25
|
+
expect(subject.fetch_or_store(namespaces, key, new_counter)).to eq(counter)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
context "when the namespace end node isn't a map" do
|
30
|
+
let(:conflicting_namespaces) { [:root, :pipelines, :pipeline_01, :events_in] }
|
31
|
+
|
32
|
+
it "raise an exception" do
|
33
|
+
subject.fetch_or_store(namespaces, key, counter)
|
34
|
+
expect { subject.fetch_or_store(conflicting_namespaces, :new_key, counter) }.to raise_error(LogStash::Instrument::MetricStore::NamespacesExpectedError)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
context "retrieving events" do
|
39
|
+
let(:metric_events) {
|
40
|
+
[
|
41
|
+
[[:node, :sashimi, :pipelines, :pipeline01, :plugins, :"logstash-output-elasticsearch"], :event_in, :increment],
|
42
|
+
[[:node, :sashimi, :pipelines, :pipeline01], :processed_events_in, :increment],
|
43
|
+
[[:node, :sashimi, :pipelines, :pipeline01], :processed_events_out, :increment],
|
44
|
+
[[:node, :sashimi, :pipelines, :pipeline02], :processed_events_out, :increment],
|
45
|
+
]
|
46
|
+
}
|
47
|
+
|
48
|
+
before :each do
|
49
|
+
# Lets add a few metrics in the store before trying to find them
|
50
|
+
metric_events.each do |namespaces, metric_key, action|
|
51
|
+
metric = subject.fetch_or_store(namespaces, metric_key, LogStash::Instrument::MetricType::Counter.new(namespaces, metric_key))
|
52
|
+
metric.execute(action)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
describe "#get" do
|
57
|
+
context "when the path exist" do
|
58
|
+
it "retrieves end of of a branch" do
|
59
|
+
metrics = subject.get(:node, :sashimi, :pipelines, :pipeline01, :plugins, :"logstash-output-elasticsearch")
|
60
|
+
expect(metrics).to match(a_hash_including(:node => a_hash_including(:sashimi => a_hash_including(:pipelines => a_hash_including(:pipeline01 => a_hash_including(:plugins => a_hash_including(:"logstash-output-elasticsearch" => anything)))))))
|
61
|
+
end
|
62
|
+
|
63
|
+
it "retrieves branch" do
|
64
|
+
metrics = subject.get(:node, :sashimi, :pipelines, :pipeline01)
|
65
|
+
expect(metrics).to match(a_hash_including(:node => a_hash_including(:sashimi => a_hash_including(:pipelines => a_hash_including(:pipeline01 => anything)))))
|
66
|
+
end
|
67
|
+
|
68
|
+
it "allow to retrieve a specific metrics" do
|
69
|
+
metrics = subject.get(:node, :sashimi, :pipelines, :pipeline01, :plugins, :"logstash-output-elasticsearch", :event_in)
|
70
|
+
expect(metrics).to match(a_hash_including(:node => a_hash_including(:sashimi => a_hash_including(:pipelines => a_hash_including(:pipeline01 => a_hash_including(:plugins => a_hash_including(:"logstash-output-elasticsearch" => a_hash_including(:event_in => be_kind_of(LogStash::Instrument::MetricType::Base)))))))))
|
71
|
+
end
|
72
|
+
|
73
|
+
context "with filtered keys" do
|
74
|
+
it "allows to retrieve multiple keys on the same level" do
|
75
|
+
metrics = subject.get(:node, :sashimi, :pipelines, :"pipeline01,pipeline02")
|
76
|
+
expect(metrics).to match(a_hash_including(:node => a_hash_including(:sashimi => a_hash_including(:pipelines => a_hash_including(:pipeline01 => anything, :pipeline02 => anything)))))
|
77
|
+
end
|
78
|
+
|
79
|
+
it "supports space in the keys" do
|
80
|
+
metrics = subject.get(:node, :sashimi, :pipelines, :"pipeline01, pipeline02 ")
|
81
|
+
expect(metrics).to match(a_hash_including(:node => a_hash_including(:sashimi => a_hash_including(:pipelines => a_hash_including(:pipeline01 => anything, :pipeline02 => anything)))))
|
82
|
+
end
|
83
|
+
|
84
|
+
it "retrieves only the requested keys" do
|
85
|
+
metrics = subject.get(:node, :sashimi, :pipelines, :"pipeline01,pipeline02", :processed_events_in)
|
86
|
+
expect(metrics[:node][:sashimi][:pipelines].keys).to include(:pipeline01, :pipeline02)
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
context "when the path doesnt exist" do
|
91
|
+
it "raise an exception" do
|
92
|
+
expect { subject.get(:node, :sashimi, :dontexist) }.to raise_error(LogStash::Instrument::MetricStore::MetricNotFound, /dontexist/)
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
describe "#get_with_path" do
|
98
|
+
context "when the path exist" do
|
99
|
+
it "removes the first `/`" do
|
100
|
+
metrics = subject.get_with_path("/node/sashimi/")
|
101
|
+
expect(metrics).to match(a_hash_including(:node => a_hash_including(:sashimi => anything)))
|
102
|
+
end
|
103
|
+
|
104
|
+
it "retrieves end of of a branch" do
|
105
|
+
metrics = subject.get_with_path("node/sashimi/pipelines/pipeline01/plugins/logstash-output-elasticsearch")
|
106
|
+
expect(metrics).to match(a_hash_including(:node => a_hash_including(:sashimi => a_hash_including(:pipelines => a_hash_including(:pipeline01 => a_hash_including(:plugins => a_hash_including(:"logstash-output-elasticsearch" => anything)))))))
|
107
|
+
end
|
108
|
+
|
109
|
+
it "retrieves branch" do
|
110
|
+
metrics = subject.get_with_path("node/sashimi/pipelines/pipeline01")
|
111
|
+
expect(metrics).to match(a_hash_including(:node => a_hash_including(:sashimi => a_hash_including(:pipelines => a_hash_including(:pipeline01 => anything)))))
|
112
|
+
end
|
113
|
+
|
114
|
+
it "allow to retrieve a specific metrics" do
|
115
|
+
metrics = subject.get_with_path("node/sashimi/pipelines/pipeline01/plugins/logstash-output-elasticsearch/event_in")
|
116
|
+
expect(metrics).to match(a_hash_including(:node => a_hash_including(:sashimi => a_hash_including(:pipelines => a_hash_including(:pipeline01 => a_hash_including(:plugins => a_hash_including(:"logstash-output-elasticsearch" => a_hash_including(:event_in => be_kind_of(LogStash::Instrument::MetricType::Base)))))))))
|
117
|
+
end
|
118
|
+
|
119
|
+
context "with filtered keys" do
|
120
|
+
it "allows to retrieve multiple keys on the same level" do
|
121
|
+
metrics = subject.get_with_path("node/sashimi/pipelines/pipeline01,pipeline02/plugins/logstash-output-elasticsearch/event_in")
|
122
|
+
expect(metrics).to match(a_hash_including(:node => a_hash_including(:sashimi => a_hash_including(:pipelines => a_hash_including(:pipeline01 => anything, :pipeline02 => anything)))))
|
123
|
+
end
|
124
|
+
|
125
|
+
it "supports space in the keys" do
|
126
|
+
metrics = subject.get_with_path("node/sashimi/pipelines/pipeline01, pipeline02 /plugins/logstash-output-elasticsearch/event_in")
|
127
|
+
expect(metrics).to match(a_hash_including(:node => a_hash_including(:sashimi => a_hash_including(:pipelines => a_hash_including(:pipeline01 => anything, :pipeline02 => anything)))))
|
128
|
+
end
|
129
|
+
|
130
|
+
it "retrieves only the requested keys" do
|
131
|
+
metrics = subject.get(:node, :sashimi, :pipelines, :"pipeline01,pipeline02", :processed_events_in)
|
132
|
+
expect(metrics[:node][:sashimi][:pipelines].keys).to include(:pipeline01, :pipeline02)
|
133
|
+
end
|
134
|
+
end
|
135
|
+
end
|
136
|
+
end
|
137
|
+
|
138
|
+
context "when the path doesnt exist" do
|
139
|
+
it "raise an exception" do
|
140
|
+
expect { subject.get_with_path("node/sashimi/dontexist, pipeline02 /plugins/logstash-output-elasticsearch/event_in") }.to raise_error(LogStash::Instrument::MetricStore::MetricNotFound, /dontexist/)
|
141
|
+
end
|
142
|
+
end
|
143
|
+
end
|
144
|
+
|
145
|
+
describe "#each" do
|
146
|
+
it "retrieves all the metric" do
|
147
|
+
expect(subject.each.size).to eq(metric_events.size)
|
148
|
+
end
|
149
|
+
|
150
|
+
it "returns metric types" do
|
151
|
+
metrics = []
|
152
|
+
subject.each { |i| metrics << i }
|
153
|
+
expect(metrics.size).to eq(metric_events.size)
|
154
|
+
end
|
155
|
+
|
156
|
+
it "retrieves all the metrics from a specific branch" do
|
157
|
+
metrics = []
|
158
|
+
subject.each("node/sashimi/pipelines/pipeline01") { |i| metrics << i }
|
159
|
+
expect(metrics.size).to eq(3)
|
160
|
+
end
|
161
|
+
end
|
162
|
+
end
|
163
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require "logstash/instrument/metric_type/counter"
|
3
|
+
require "spec_helper"
|
4
|
+
|
5
|
+
describe LogStash::Instrument::MetricType::Counter do
|
6
|
+
let(:namespaces) { [:root, :pipelines, :pipeline_01] }
|
7
|
+
let(:key) { :mykey }
|
8
|
+
|
9
|
+
subject { LogStash::Instrument::MetricType::Counter.new(namespaces, key) }
|
10
|
+
|
11
|
+
describe "#increment" do
|
12
|
+
it "increment the counter" do
|
13
|
+
expect{ subject.increment }.to change { subject.value }.by(1)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
describe "#decrement" do
|
18
|
+
it "decrement the counter" do
|
19
|
+
expect{ subject.decrement }.to change { subject.value }.by(-1)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
context "When serializing to JSON" do
|
24
|
+
it "serializes the value" do
|
25
|
+
expect(LogStash::Json.dump(subject)).to eq("0")
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
context "When creating a hash " do
|
30
|
+
it "creates the hash from all the values" do
|
31
|
+
metric_hash = {
|
32
|
+
"key" => key,
|
33
|
+
"namespaces" => namespaces,
|
34
|
+
"value" => 0,
|
35
|
+
"type" => "counter"
|
36
|
+
}
|
37
|
+
expect(subject.to_hash).to match(metric_hash)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require "logstash/instrument/metric_type/gauge"
|
3
|
+
require "logstash/json"
|
4
|
+
require "spec_helper"
|
5
|
+
|
6
|
+
describe LogStash::Instrument::MetricType::Gauge do
|
7
|
+
let(:namespaces) { [:root, :pipelines, :pipeline_01] }
|
8
|
+
let(:key) { :mykey }
|
9
|
+
let(:value) { "hello" }
|
10
|
+
|
11
|
+
subject { described_class.new(namespaces, key) }
|
12
|
+
|
13
|
+
before :each do
|
14
|
+
subject.execute(:set, value)
|
15
|
+
end
|
16
|
+
|
17
|
+
describe "#execute" do
|
18
|
+
it "set the value of the gauge" do
|
19
|
+
expect(subject.value).to eq(value)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
context "When serializing to JSON" do
|
24
|
+
it "serializes the value" do
|
25
|
+
expect(LogStash::Json.dump(subject)).to eq("\"#{value}\"")
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
context "When creating a hash " do
|
30
|
+
it "creates the hash from all the values" do
|
31
|
+
metric_hash = {
|
32
|
+
"key" => key,
|
33
|
+
"namespaces" => namespaces,
|
34
|
+
"value" => value,
|
35
|
+
"type" => "gauge"
|
36
|
+
}
|
37
|
+
expect(subject.to_hash).to match(metric_hash)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require "logstash/instrument/namespaced_metric"
|
3
|
+
require "logstash/instrument/metric"
|
4
|
+
require_relative "../../support/matchers"
|
5
|
+
require "spec_helper"
|
6
|
+
|
7
|
+
describe LogStash::Instrument::NamespacedMetric do
|
8
|
+
let(:namespace) { :stats }
|
9
|
+
let(:collector) { [] }
|
10
|
+
let(:metric) { LogStash::Instrument::Metric.new(collector) }
|
11
|
+
|
12
|
+
subject { described_class.new(metric, namespace) }
|
13
|
+
|
14
|
+
it "defines the same interface as `Metric`" do
|
15
|
+
expect(described_class).to implement_interface_of(LogStash::Instrument::Metric)
|
16
|
+
end
|
17
|
+
|
18
|
+
it "returns a TimedException when we call without a block" do
|
19
|
+
expect(subject.time(:duration_ms)).to be_kind_of(LogStash::Instrument::Metric::TimedExecution)
|
20
|
+
end
|
21
|
+
|
22
|
+
it "returns the value of the block" do
|
23
|
+
expect(subject.time(:duration_ms) { "hello" }).to eq("hello")
|
24
|
+
end
|
25
|
+
end
|
@@ -1,63 +1,21 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
require "logstash/instrument/null_metric"
|
3
|
+
require "logstash/instrument/namespaced_metric"
|
4
|
+
require_relative "../../support/matchers"
|
3
5
|
|
4
6
|
describe LogStash::Instrument::NullMetric do
|
5
|
-
|
6
|
-
|
7
|
-
describe "#increment" do
|
8
|
-
it "allows to increment a key with no amount" do
|
9
|
-
expect { subject.increment(key, 100) }.not_to raise_error
|
10
|
-
end
|
11
|
-
|
12
|
-
it "allow to increment a key" do
|
13
|
-
expect { subject.increment(key) }.not_to raise_error
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
describe "#decrement" do
|
18
|
-
it "allows to decrement a key with no amount" do
|
19
|
-
expect { subject.decrement(key, 100) }.not_to raise_error
|
20
|
-
end
|
21
|
-
|
22
|
-
it "allow to decrement a key" do
|
23
|
-
expect { subject.decrement(key) }.not_to raise_error
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
describe "#gauge" do
|
28
|
-
it "allows to set a value" do
|
29
|
-
expect { subject.gauge(key, "pluto") }.not_to raise_error
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
describe "#report_time" do
|
34
|
-
it "allow to record time" do
|
35
|
-
expect { subject.report_time(key, 1000) }.not_to raise_error
|
36
|
-
end
|
7
|
+
it "defines the same interface as `Metric`" do
|
8
|
+
expect(described_class).to implement_interface_of(LogStash::Instrument::NamespacedMetric)
|
37
9
|
end
|
38
10
|
|
39
11
|
describe "#time" do
|
40
|
-
it "
|
41
|
-
expect
|
42
|
-
subject.time(key) { 1+1 }
|
43
|
-
end.not_to raise_error
|
12
|
+
it "returns the value of the block without recording any metrics" do
|
13
|
+
expect(subject.time(:execution_time) { "hello" }).to eq("hello")
|
44
14
|
end
|
45
15
|
|
46
|
-
it "
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
it "allow to record time with no block given" do
|
51
|
-
expect do
|
52
|
-
clock = subject.time(key)
|
53
|
-
clock.stop
|
54
|
-
end.not_to raise_error
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
|
-
describe "#namespace" do
|
59
|
-
it "return a NullMetric" do
|
60
|
-
expect(subject.namespace(key)).to be_kind_of LogStash::Instrument::NullMetric
|
16
|
+
it "return a TimedExecution" do
|
17
|
+
execution = subject.time(:do_something)
|
18
|
+
expect { execution.stop }.not_to raise_error
|
61
19
|
end
|
62
20
|
end
|
63
21
|
end
|