graphite-api-middleware 1.0.0 → 1.1.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: 2d8f0e57a178f384b38405f15f092e986e88fa5585055cdbe65e893da2db4fa4
4
- data.tar.gz: b278408d5aab2272821259e5f3dc3a4d03e4b63b74ccdc0f69adcef5ba64c4e8
3
+ metadata.gz: 27b2522dd39bed00f6fcccd339081a4cb19931263002640847e8a9a794b6d73a
4
+ data.tar.gz: 8e80ffd81a903196341155cdf575d4b36ff9600a8f5f9bae025d2a26473c9a67
5
5
  SHA512:
6
- metadata.gz: 2e21491fcc8861de88a3b1756da647302aaf0fea3f7bcdf6d87361a6027abf4b82e0a584d857a6e589c567d33d5d55ceff739f6b25c511160257c0fcfb1c9cd2
7
- data.tar.gz: 5a04645a1a4531549134266d76cae67d5777dd35d23a4cbfb4f068ae8a337c25a02c56dfde05506470dcb054362afb250fc9d5b512aa7561c92828205269e616
6
+ metadata.gz: e27478176fcd4d3fed13dc7d082b3a59ca8db502336d8cef778689f1b0b3cb4c1aa18459f5a015c72e22ae99a1b9ccad081a6f594da371778634e259f334e98e
7
+ data.tar.gz: c975f8590a1e13f8f1c55c6e9f2d6c75966e1c2e80e5378edd44d2fa03aa0aa6ff759bdfc2b24faa7622f75475415b34928f16fd18e52cba29ad0ab450d77960
@@ -63,15 +63,16 @@ begin
63
63
  options[:cache] = opts["--cache"].to_i * 3600 if opts["--cache"].to_i > 0
64
64
  options[:default_aggregation_method] = opts["--aggregation-method"].to_sym if opts["--aggregation-method"]
65
65
 
66
- logger = Logger.new options[:log_file] || STDOUT
66
+ logger = Logger.new options[:log_file] || STDOUT
67
67
  logger.level= Logger.const_get options[:log_level].to_s.upcase
68
68
  Process.daemon if options[:daemonize]
69
69
  GraphiteApiMiddleware::Server.start options, logger
70
70
  rescue Docopt::Exit => e
71
71
  puts e.message
72
72
  rescue Interrupt
73
- logger.info "Shutting down..."
74
- Zscheduler.stop
73
+ logger.info "Shutting down..." if defined? logger
75
74
  rescue StandardError => e
76
75
  puts (Docopt::Exit.new e.message).message
76
+ ensure
77
+ GraphiteApiMiddleware::Server.stop rescue nil
77
78
  end
@@ -25,12 +25,12 @@ require 'logger'
25
25
  module GraphiteApiMiddleware
26
26
  class Server < EventMachine::Connection
27
27
 
28
- def initialize buffer, logger
29
- @buffer = buffer and super
28
+ def initialize client, logger
29
+ @client = client
30
30
  @logger = logger
31
31
  end
32
32
 
33
- attr_reader :buffer, :client_id
33
+ attr_reader :client, :client_id
34
34
 
35
35
  def post_init
36
36
  @client_id = peername
@@ -39,11 +39,12 @@ module GraphiteApiMiddleware
39
39
 
40
40
  def receive_data data
41
41
  @logger.debug [:middleware, :message, client_id, data]
42
- buffer.stream data, client_id
42
+ client.stream data, client_id
43
43
  end
44
44
 
45
45
  def unbind
46
46
  @logger.debug [:middleware, :disconnecting, client_id]
47
+ client.cancel
47
48
  end
48
49
 
49
50
  def peername
@@ -62,21 +63,18 @@ module GraphiteApiMiddleware
62
63
  GraphiteAPI::Logger.logger = logger
63
64
  logger.info "Server running on port #{options[:port]}"
64
65
 
65
- buffer = GraphiteAPI::Buffer.new options
66
- group = GraphiteAPI::Connector::Group.new options
66
+ client = GraphiteAPI::Client.new options
67
67
 
68
68
  # Starting server
69
- [:start_server, :open_datagram_socket].each do |m|
70
- EventMachine.send(m, '0.0.0.0', options[:port], self, buffer, logger)
69
+ [:start_server, :open_datagram_socket].each do |method_name|
70
+ EventMachine.send(method_name, '0.0.0.0', options[:port], self, client, logger)
71
71
  end
72
-
73
- # Send metrics to graphite every X seconds
74
- Zscheduler.every(options[:interval], :on_shutdown => true) do
75
- group.publish buffer.pull :string if buffer.new_records?
76
- end
77
-
78
72
  end
79
73
  end
80
74
 
75
+ def self.stop
76
+ EventMachine.stop
77
+ end
78
+
81
79
  end
82
80
  end
@@ -1,3 +1,3 @@
1
- module GraphiteAPIMiddleware
2
- VERSION = "1.0.0"
1
+ module GraphiteApiMiddleware
2
+ VERSION = "1.1.0"
3
3
  end
@@ -16,8 +16,9 @@ module GraphiteApiMiddleware::Tests
16
16
  Utils.stop_em_if_running
17
17
  end
18
18
 
19
- def start_middleware middleware_port, mock_server_port, aggregation_method=nil, interval=2
20
- options = %W(tcp://localhost:#{mock_server_port} --port #{middleware_port} --interval #{interval} -L error)
19
+ def start_middleware middleware_port, servers, aggregation_method=nil, interval=2
20
+ options = Array(servers)
21
+ options += %W(--port #{middleware_port} --interval #{interval} -L error)
21
22
  options += ["--aggregation-method", aggregation_method] if aggregation_method
22
23
  @pid = Process.spawn("ruby", MIDDLEWARE_BIN_FILE, *options)
23
24
  sleep MIDDLEWARE_STARTUP_WAIT
@@ -29,7 +30,7 @@ module GraphiteApiMiddleware::Tests
29
30
  end
30
31
 
31
32
  def test_with_defaults
32
- start_middleware @middleware_port, @mock_server_port
33
+ start_middleware @middleware_port, "tcp://localhost:#{@mock_server_port}"
33
34
  EventMachine.run {
34
35
  EventMachine.start_server("0.0.0.0", @mock_server_port, MockServer, @data)
35
36
  socket = TCPSocket.new("0.0.0.0", @middleware_port)
@@ -49,8 +50,30 @@ module GraphiteApiMiddleware::Tests
49
50
  assert_expected_equals_data expected
50
51
  end
51
52
 
53
+ def test_with_multiple_backends
54
+ backend_ports = [@mock_server_port, Utils.random_non_repeating_port]
55
+ start_middleware @middleware_port, backend_ports.map { |port| "tcp://localhost:#{port}" }
56
+ data_sets = backend_ports.zip([[],[]])
57
+ EventMachine.run {
58
+ data_sets.map { |port, data| EventMachine.start_server("0.0.0.0", port, MockServer, data) }
59
+ socket = TCPSocket.new("0.0.0.0", @middleware_port)
60
+ 1.upto(1000) do
61
+ socket.puts("shuki.tuki1 1.1 123456789\n")
62
+ socket.puts("shuki.tuki2 10 123456789\n")
63
+ socket.puts("shuki.tuki3 10 123456789\n")
64
+ end
65
+ EventMachine::Timer.new(EM_STOP_AFTER, &EM.method(:stop))
66
+ }
67
+ expected = [
68
+ "shuki.tuki1 1100.0 123456780",
69
+ "shuki.tuki2 10000.0 123456780",
70
+ "shuki.tuki3 10000.0 123456780"
71
+ ]
72
+ data_sets.each { |_,data| assert_expected_equals_data expected, data }
73
+ end
74
+
52
75
  def test_with_avg
53
- start_middleware @middleware_port, @mock_server_port, 'avg'
76
+ start_middleware @middleware_port, "tcp://localhost:#{@mock_server_port}", 'avg'
54
77
  EventMachine.run {
55
78
  EventMachine.start_server("0.0.0.0", @mock_server_port, MockServer, @data)
56
79
  socket = TCPSocket.new("0.0.0.0", @middleware_port)
@@ -65,7 +88,7 @@ module GraphiteApiMiddleware::Tests
65
88
  end
66
89
 
67
90
  def test_with_replace
68
- start_middleware @middleware_port, @mock_server_port, 'replace'
91
+ start_middleware @middleware_port, "tcp://localhost:#{@mock_server_port}", 'replace'
69
92
  EventMachine.run {
70
93
  EventMachine.start_server("0.0.0.0", @mock_server_port, MockServer, @data)
71
94
  socket = TCPSocket.new("0.0.0.0", @middleware_port)
@@ -79,8 +102,8 @@ module GraphiteApiMiddleware::Tests
79
102
  assert_expected_equals_data ["shuki.tuki1 5.0 123456780"]
80
103
  end
81
104
 
82
- def assert_expected_equals_data expected
83
- assert_equal expected, @data.map {|o| o.split("\n")}.flatten(1).map(&:strip)
105
+ def assert_expected_equals_data expected, data=@data
106
+ assert_equal expected, data.map {|o| o.split("\n")}.flatten(1).map(&:strip)
84
107
  end
85
108
  end
86
109
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: graphite-api-middleware
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eran Levi
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2019-03-19 00:00:00.000000000 Z
12
+ date: 2019-03-25 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: docopt
@@ -40,33 +40,33 @@ dependencies:
40
40
  - !ruby/object:Gem::Version
41
41
  version: 0.3.3
42
42
  - !ruby/object:Gem::Dependency
43
- name: zscheduler
43
+ name: timers
44
44
  requirement: !ruby/object:Gem::Requirement
45
45
  requirements:
46
- - - ">="
46
+ - - "~>"
47
47
  - !ruby/object:Gem::Version
48
- version: 0.0.7
48
+ version: '4.3'
49
49
  type: :runtime
50
50
  prerelease: false
51
51
  version_requirements: !ruby/object:Gem::Requirement
52
52
  requirements:
53
- - - ">="
53
+ - - "~>"
54
54
  - !ruby/object:Gem::Version
55
- version: 0.0.7
55
+ version: '4.3'
56
56
  - !ruby/object:Gem::Dependency
57
57
  name: graphite-api
58
58
  requirement: !ruby/object:Gem::Requirement
59
59
  requirements:
60
- - - ">="
60
+ - - "~>"
61
61
  - !ruby/object:Gem::Version
62
- version: 1.0.0
62
+ version: '1.1'
63
63
  type: :runtime
64
64
  prerelease: false
65
65
  version_requirements: !ruby/object:Gem::Requirement
66
66
  requirements:
67
- - - ">="
67
+ - - "~>"
68
68
  - !ruby/object:Gem::Version
69
- version: 1.0.0
69
+ version: '1.1'
70
70
  - !ruby/object:Gem::Dependency
71
71
  name: rake
72
72
  requirement: !ruby/object:Gem::Requirement