test/common/config/grpc_mux_impl_test.cc
//  Verifies that warning messages get logged when Envoy detects too many requests.
Verifies that warning messages get logged when Envoy detects too many requests.
Verifies that warning messages get logged when Envoy detects too many requests .
TEST_F(GrpcMuxImplTestWithMockTimeSystem, TooManyRequests) {
  setup();
  EXPECT_CALL(async_stream_, sendMessage(_, false)).Times(AtLeast(100));
  EXPECT_CALL(*async_client_, start(_, _)).WillOnce(Return(&async_stream_));
  EXPECT_CALL(mock_time_system_, monotonicTime())
      .WillRepeatedly(Return(std::chrono::steady_clock::time_point{}));
  const auto onReceiveMessage = [&](uint64_t burst) {
    for (uint64_t i = 0; i < burst; i++) {
      std::unique_ptr<envoy::api::v2::DiscoveryResponse> response(
          new envoy::api::v2::DiscoveryResponse());
      response->set_version_info("baz");
      response->set_nonce("bar");
      response->set_type_url("foo");
      grpc_mux_->onReceiveMessage(std::move(response));
    }
  };
  auto foo_sub = grpc_mux_->subscribe("foo", {"x"}, callbacks_);
  expectSendMessage("foo", {"x"}, "");
  grpc_mux_->start();
  onReceiveMessage(99);
  EXPECT_LOG_CONTAINS("warning", "Too many sendDiscoveryRequest calls for foo",
                      onReceiveMessage(1));
  EXPECT_CALL(mock_time_system_, monotonicTime())
      .Times(4)
      .WillOnce(Return(std::chrono::steady_clock::time_point{}))
      .WillOnce(Return(std::chrono::steady_clock::time_point{std::chrono::seconds(5)}))
      .WillOnce(Return(std::chrono::steady_clock::time_point{std::chrono::seconds(6)}))
      .WillOnce(Return(std::chrono::steady_clock::time_point{std::chrono::seconds(7)}));
  EXPECT_LOG_CONTAINS("warning", "Too many sendDiscoveryRequest calls for foo",
                      onReceiveMessage(1));
  EXPECT_LOG_NOT_CONTAINS("warning", "Too many sendDiscoveryRequest calls for foo",
                          onReceiveMessage(1));
}
TEST_F ( GrpcMuxImplTestWithMockTimeSystem , TooManyRequests ) { setup ( ) ; EXPECT_CALL ( async_stream_ , sendMessage ( _ , false ) ) . Times ( AtLeast ( 100 ) ) ; EXPECT_CALL ( * async_client_ , start ( _ , _ ) ) . WillOnce ( Return ( & async_stream_ ) ) ; EXPECT_CALL ( mock_time_system_ , monotonicTime ( ) ) . WillRepeatedly ( Return ( std :: chrono :: steady_clock :: time_point { } ) ) ; const auto onReceiveMessage = [ & ] ( uint64_t burst ) { for ( uint64_t i = 0 ; i < burst ; i ++ ) { std :: unique_ptr < envoy :: api :: v2 :: DiscoveryResponse > response ( new envoy :: api :: v2 :: DiscoveryResponse ( ) ) ; response -> set_version_info ( " " ) ; response -> set_nonce ( " " ) ; response -> set_type_url ( " " ) ; grpc_mux_ -> onReceiveMessage ( std :: move ( response ) ) ; } } ; auto foo_sub = grpc_mux_ -> subscribe ( " " , { " " } , callbacks_ ) ; expectSendMessage ( " " , { " " } , " " ) ; grpc_mux_ -> start ( ) ; onReceiveMessage ( 99 ) ; EXPECT_LOG_CONTAINS ( " " , " " , onReceiveMessage ( 1 ) ) ; EXPECT_CALL ( mock_time_system_ , monotonicTime ( ) ) . Times ( 4 ) . WillOnce ( Return ( std :: chrono :: steady_clock :: time_point { } ) ) . WillOnce ( Return ( std :: chrono :: steady_clock :: time_point { std :: chrono :: seconds ( 5 ) } ) ) . WillOnce ( Return ( std :: chrono :: steady_clock :: time_point { std :: chrono :: seconds ( 6 ) } ) ) . WillOnce ( Return ( std :: chrono :: steady_clock :: time_point { std :: chrono :: seconds ( 7 ) } ) ) ; EXPECT_LOG_CONTAINS ( " " , " " , onReceiveMessage ( 1 ) ) ; EXPECT_LOG_NOT_CONTAINS ( " " , " " , onReceiveMessage ( 1 ) ) ; }
Verifies that warning messages get logged when Envoy detects too many requests.
Verifies that warning messages get logged when Envoy detects too many requests .
// Exhausts the limit. // API calls go over the limit for the first time. // Logging limiter waits for 5s, so a second warning message is expected. // API calls go over the limit for the second time. // Without waiting full 5s, no rate limit log is expected.