LCOV - code coverage report
Current view: top level - source/common/http/http2 - conn_pool.cc (source / functions) Hit Total Coverage
Test: coverage.dat Lines: 25 31 80.6 %
Date: 2024-01-05 06:35:25 Functions: 5 5 100.0 %

          Line data    Source code
       1             : #include "source/common/http/http2/conn_pool.h"
       2             : 
       3             : #include <cstdint>
       4             : 
       5             : #include "envoy/event/dispatcher.h"
       6             : #include "envoy/upstream/upstream.h"
       7             : 
       8             : #include "source/common/http/http2/codec_impl.h"
       9             : #include "source/common/runtime/runtime_features.h"
      10             : 
      11             : namespace Envoy {
      12             : namespace Http {
      13             : 
      14             : namespace Http2 {
      15             : 
      16             : uint32_t ActiveClient::calculateInitialStreamsLimit(
      17             :     Http::HttpServerPropertiesCacheSharedPtr http_server_properties_cache,
      18             :     absl::optional<HttpServerPropertiesCache::Origin>& origin,
      19         105 :     Upstream::HostDescriptionConstSharedPtr host) {
      20         105 :   uint32_t initial_streams = host->cluster().http2Options().max_concurrent_streams().value();
      21         105 :   if (http_server_properties_cache && origin.has_value()) {
      22           0 :     uint32_t cached_concurrency =
      23           0 :         http_server_properties_cache->getConcurrentStreams(origin.value());
      24           0 :     if (cached_concurrency != 0 && cached_concurrency < initial_streams) {
      25             :       // Only use the cached concurrency if lowers the streams below the
      26             :       // configured max_concurrent_streams as Envoy should never send more
      27             :       // than max_concurrent_streams at once.
      28           0 :       initial_streams = cached_concurrency;
      29           0 :     }
      30           0 :   }
      31         105 :   uint64_t max_requests = MultiplexedActiveClientBase::maxStreamsPerConnection(
      32         105 :       host->cluster().maxRequestsPerConnection());
      33         105 :   if (max_requests < initial_streams) {
      34         105 :     initial_streams = max_requests;
      35         105 :   }
      36         105 :   return initial_streams;
      37         105 : }
      38             : 
      39             : ActiveClient::ActiveClient(HttpConnPoolImplBase& parent,
      40             :                            OptRef<Upstream::Host::CreateConnectionData> data)
      41             :     : MultiplexedActiveClientBase(
      42             :           parent, calculateInitialStreamsLimit(parent.cache(), parent.origin(), parent.host()),
      43             :           parent.host()->cluster().http2Options().max_concurrent_streams().value(),
      44         105 :           parent.host()->cluster().trafficStats()->upstream_cx_http2_total_, data) {}
      45             : 
      46             : ConnectionPool::InstancePtr
      47             : allocateConnPool(Event::Dispatcher& dispatcher, Random::RandomGenerator& random_generator,
      48             :                  Upstream::HostConstSharedPtr host, Upstream::ResourcePriority priority,
      49             :                  const Network::ConnectionSocket::OptionsSharedPtr& options,
      50             :                  const Network::TransportSocketOptionsConstSharedPtr& transport_socket_options,
      51             :                  Upstream::ClusterConnectivityState& state,
      52             :                  absl::optional<HttpServerPropertiesCache::Origin> origin,
      53         105 :                  Http::HttpServerPropertiesCacheSharedPtr cache) {
      54         105 :   return std::make_unique<FixedHttpConnPoolImpl>(
      55         105 :       host, priority, dispatcher, options, transport_socket_options, random_generator, state,
      56         105 :       [](HttpConnPoolImplBase* pool) {
      57         105 :         return std::make_unique<ActiveClient>(*pool, absl::nullopt);
      58         105 :       },
      59         105 :       [](Upstream::Host::CreateConnectionData& data, HttpConnPoolImplBase* pool) {
      60         105 :         CodecClientPtr codec{new CodecClientProd(
      61         105 :             CodecType::HTTP2, std::move(data.connection_), data.host_description_,
      62         105 :             pool->dispatcher(), pool->randomGenerator(), pool->transportSocketOptions())};
      63         105 :         return codec;
      64         105 :       },
      65         105 :       std::vector<Protocol>{Protocol::Http2}, origin, cache);
      66         105 : }
      67             : 
      68             : } // namespace Http2
      69             : } // namespace Http
      70             : } // namespace Envoy

Generated by: LCOV version 1.15