@@ -26,6 +26,7 @@ module Logcache
2626 let ( :client_ca ) { File . read ( client_ca_path ) }
2727 let ( :client_key ) { File . read ( client_key_path ) }
2828 let ( :client_cert ) { File . read ( client_cert_path ) }
29+ let ( :mock_logger ) { double ( Steno ::Logger , info : nil ) }
2930
3031 describe '#container_metrics' do
3132 let ( :instance_count ) { 2 }
@@ -36,9 +37,10 @@ module Logcache
3637 with ( client_ca , client_key , client_cert ) .
3738 and_return ( credentials )
3839 expect ( Logcache ::V1 ::Egress ::Stub ) . to receive ( :new ) .
39- with ( "#{ host } :#{ port } " , credentials , channel_args : channel_arg_hash , timeout : 250 ) .
40+ with ( "#{ host } :#{ port } " , credentials , channel_args : channel_arg_hash , timeout : 10 ) .
4041 and_return ( logcache_service )
4142 allow ( Logcache ::V1 ::ReadRequest ) . to receive ( :new ) . and_return ( logcache_request )
43+ allow_any_instance_of ( Client ) . to receive ( :logger ) . and_return ( mock_logger )
4244 end
4345
4446 it 'calls Logcache with the correct parameters and returns envelopes' do
@@ -56,6 +58,17 @@ module Logcache
5658 )
5759 expect ( logcache_service ) . to have_received ( :read ) . with ( logcache_request )
5860 end
61+
62+ it 'logs the response time and metadata' do
63+ client . container_metrics ( source_guid : process . guid , envelope_limit : 1000 , start_time : 100 , end_time : 101 )
64+ expect ( mock_logger ) . to have_received ( :info ) . with (
65+ a_string_matching ( /logcache.response/ ) ,
66+ hash_including (
67+ source_id : process . guid ,
68+ time_taken_in_ms : be_a ( Integer )
69+ )
70+ )
71+ end
5972 end
6073
6174 describe 'when logcache is unavailable' do
@@ -68,7 +81,7 @@ module Logcache
6881 with ( client_ca , client_key , client_cert ) .
6982 and_return ( credentials )
7083 expect ( Logcache ::V1 ::Egress ::Stub ) . to receive ( :new ) .
71- with ( "#{ host } :#{ port } " , credentials , channel_args : channel_arg_hash , timeout : 250 ) .
84+ with ( "#{ host } :#{ port } " , credentials , channel_args : channel_arg_hash , timeout : 10 ) .
7285 and_return ( logcache_service )
7386 allow ( client ) . to receive ( :sleep )
7487 allow ( Logcache ::V1 ::ReadRequest ) . to receive ( :new ) . and_return ( logcache_request )
@@ -99,7 +112,7 @@ module Logcache
99112 with ( client_ca , client_key , client_cert ) .
100113 and_return ( credentials )
101114 expect ( Logcache ::V1 ::Egress ::Stub ) . to receive ( :new ) .
102- with ( "#{ host } :#{ port } " , credentials , channel_args : channel_arg_hash , timeout : 250 ) .
115+ with ( "#{ host } :#{ port } " , credentials , channel_args : channel_arg_hash , timeout : 10 ) .
103116 and_return ( logcache_service )
104117 allow ( client ) . to receive ( :sleep )
105118 allow ( Logcache ::V1 ::ReadRequest ) . to receive ( :new ) . and_return ( logcache_request )
@@ -130,7 +143,7 @@ module Logcache
130143 with ( client_ca , client_key , client_cert ) .
131144 and_return ( credentials )
132145 expect ( Logcache ::V1 ::Egress ::Stub ) . to receive ( :new ) .
133- with ( "#{ host } :#{ port } " , credentials , channel_args : channel_arg_hash , timeout : 250 ) .
146+ with ( "#{ host } :#{ port } " , credentials , channel_args : channel_arg_hash , timeout : 10 ) .
134147 and_return ( logcache_service )
135148 allow ( client ) . to receive ( :sleep )
136149 allow ( Logcache ::V1 ::ReadRequest ) . to receive ( :new ) . and_return ( logcache_request )
@@ -164,7 +177,7 @@ module Logcache
164177 before do
165178 expect ( GRPC ::Core ::ChannelCredentials ) . not_to receive ( :new )
166179 expect ( Logcache ::V1 ::Egress ::Stub ) . to receive ( :new ) .
167- with ( "#{ host } :#{ port } " , :this_channel_is_insecure , timeout : 250 ) .
180+ with ( "#{ host } :#{ port } " , :this_channel_is_insecure , timeout : 10 ) .
168181 and_return ( logcache_service )
169182 allow ( Logcache ::V1 ::ReadRequest ) . to receive ( :new ) . and_return ( logcache_request )
170183 end
0 commit comments