fluent-plugin-prometheus 1.7.0 → 1.8.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,101 +0,0 @@
1
- require 'spec_helper'
2
- require 'fluent/plugin/in_prometheus'
3
- require 'fluent/test/driver/input'
4
-
5
- require 'net/http'
6
-
7
- describe Fluent::Plugin::PrometheusInput do
8
- CONFIG = %[
9
- type prometheus
10
- ]
11
-
12
- LOCAL_CONFIG = %[
13
- type prometheus
14
- bind 127.0.0.1
15
- ]
16
-
17
- let(:config) { CONFIG }
18
- let(:port) { 24231 }
19
- let(:driver) { Fluent::Test::Driver::Input.new(Fluent::Plugin::PrometheusInput).configure(config) }
20
-
21
- describe '#configure' do
22
- describe 'bind' do
23
- let(:config) { CONFIG + %[
24
- bind 127.0.0.1
25
- ] }
26
- it 'should be configurable' do
27
- expect(driver.instance.bind).to eq('127.0.0.1')
28
- end
29
- end
30
-
31
- describe 'port' do
32
- let(:config) { CONFIG + %[
33
- port 8888
34
- ] }
35
- it 'should be configurable' do
36
- expect(driver.instance.port).to eq(8888)
37
- end
38
- end
39
-
40
- describe 'metrics_path' do
41
- let(:config) { CONFIG + %[
42
- metrics_path /_test
43
- ] }
44
- it 'should be configurable' do
45
- expect(driver.instance.metrics_path).to eq('/_test')
46
- end
47
- end
48
- end
49
-
50
- describe '#run' do
51
- context '/metrics' do
52
- let(:config) { LOCAL_CONFIG }
53
- it 'returns 200' do
54
- driver.run(timeout: 1) do
55
- Net::HTTP.start("127.0.0.1", port) do |http|
56
- req = Net::HTTP::Get.new("/metrics")
57
- res = http.request(req)
58
- expect(res.code).to eq('200')
59
- end
60
- end
61
- end
62
- end
63
-
64
- context '/foo' do
65
- let(:config) { LOCAL_CONFIG }
66
- it 'does not return 200' do
67
- driver.run(timeout: 1) do
68
- Net::HTTP.start("127.0.0.1", port) do |http|
69
- req = Net::HTTP::Get.new("/foo")
70
- res = http.request(req)
71
- expect(res.code).not_to eq('200')
72
- end
73
- end
74
- end
75
- end
76
- end
77
-
78
- describe '#run_multi_workers' do
79
- context '/metrics' do
80
- Fluent::SystemConfig.overwrite_system_config('workers' => 4) do
81
- let(:config) { CONFIG + %[
82
- port #{port - 2}
83
- ] }
84
-
85
- it 'should configure port using sequential number' do
86
- driver = Fluent::Test::Driver::Input.new(Fluent::Plugin::PrometheusInput)
87
- driver.instance.instance_eval{ @_fluentd_worker_id = 2 }
88
- driver.configure(config)
89
- expect(driver.instance.port).to eq(port)
90
- driver.run(timeout: 1) do
91
- Net::HTTP.start("127.0.0.1", port) do |http|
92
- req = Net::HTTP::Get.new("/metrics")
93
- res = http.request(req)
94
- expect(res.code).to eq('200')
95
- end
96
- end
97
- end
98
- end
99
- end
100
- end
101
- end