File tree 3 files changed +59
-2
lines changed
3 files changed +59
-2
lines changed Original file line number Diff line number Diff line change @@ -31,11 +31,11 @@ def self.statsd
31
31
@statsd ||= Statsd . new ( Statsd ::DEFAULT_HOST , Statsd ::DEFAULT_HOST , namespace : STATSD_NAMESPACE )
32
32
end
33
33
34
- def self . statsd_host = ( host )
34
+ def self . host = ( host )
35
35
statsd . host = host
36
36
end
37
37
38
- def self . statsd_port = ( port )
38
+ def self . port = ( port )
39
39
statsd . port = port
40
40
end
41
41
Original file line number Diff line number Diff line change
1
+ require "socket"
2
+
3
+ class FakeDatadogAgent
4
+ attr_reader :host , :port , :metrics
5
+
6
+ def initialize
7
+ @host = "127.0.0.1"
8
+ @port = 9999
9
+ @socket = UDPSocket . new
10
+ @thread = nil
11
+ @metrics = [ ]
12
+
13
+ @socket . bind ( @host , @port )
14
+ end
15
+
16
+ def start
17
+ @thread = Thread . new { loop { receive } }
18
+ @thread . abort_on_exception = true
19
+ end
20
+
21
+ def wait_for_metrics
22
+ sleep 0.1 until @metrics . count > 0
23
+ end
24
+
25
+ private
26
+
27
+ def receive
28
+ data , sender = @socket . recvfrom ( 512 )
29
+
30
+ data . split ( "\n " ) . each do |message |
31
+ metric = message . split ( ":" ) . first
32
+ @metrics << metric if metric
33
+ end
34
+ end
35
+ end
Original file line number Diff line number Diff line change
1
+ require "kafka/datadog"
2
+ require "socket"
3
+ require "fake_datadog_agent"
4
+
5
+ describe "Reporting metrics to Datadog" , functional : true do
6
+ example "reporting connection metrics" do
7
+ agent = FakeDatadogAgent . new
8
+
9
+ Kafka ::Datadog . port = agent . port
10
+
11
+ agent . start
12
+
13
+ kafka . topics
14
+
15
+ agent . wait_for_metrics
16
+
17
+ expect ( agent . metrics ) . to include ( "ruby_kafka.api.calls" )
18
+ expect ( agent . metrics ) . to include ( "ruby_kafka.api.latency" )
19
+ expect ( agent . metrics ) . to include ( "ruby_kafka.api.request_size" )
20
+ expect ( agent . metrics ) . to include ( "ruby_kafka.api.response_size" )
21
+ end
22
+ end
You can’t perform that action at this time.
0 commit comments