LCOV - code coverage report
Current view: top level - source/common/grpc - context_impl.h (source / functions) Hit Total Coverage
Test: coverage.dat Lines: 5 5 100.0 %
Date: 2024-01-05 06:35:25 Functions: 3 3 100.0 %

          Line data    Source code
       1             : #pragma once
       2             : 
       3             : #include <cstdint>
       4             : #include <memory>
       5             : #include <string>
       6             : 
       7             : #include "envoy/grpc/context.h"
       8             : #include "envoy/http/header_map.h"
       9             : 
      10             : #include "source/common/common/hash.h"
      11             : #include "source/common/grpc/stat_names.h"
      12             : #include "source/common/stats/symbol_table.h"
      13             : #include "source/common/stats/utility.h"
      14             : 
      15             : #include "absl/types/optional.h"
      16             : 
      17             : namespace Envoy {
      18             : namespace Grpc {
      19             : 
      20             : struct Context::RequestStatNames {
      21             :   Stats::Element service_; // supplies the service name.
      22             :   Stats::Element method_;  // supplies the method name.
      23             : };
      24             : 
      25             : class ContextImpl : public Context {
      26             : public:
      27             :   explicit ContextImpl(Stats::SymbolTable& symbol_table);
      28             : 
      29             :   // Context
      30             :   void chargeStat(const Upstream::ClusterInfo& cluster, Protocol protocol,
      31             :                   const absl::optional<RequestStatNames>& request_names,
      32             :                   const Http::HeaderEntry* grpc_status) override;
      33             :   void chargeStat(const Upstream::ClusterInfo& cluster, Protocol protocol,
      34             :                   const absl::optional<RequestStatNames>& request_names, bool success) override;
      35             :   void chargeStat(const Upstream::ClusterInfo& cluster,
      36             :                   const absl::optional<RequestStatNames>& request_names, bool success) override;
      37             :   void chargeRequestMessageStat(const Upstream::ClusterInfo& cluster,
      38             :                                 const absl::optional<RequestStatNames>& request_names,
      39             :                                 uint64_t amount) override;
      40             :   void chargeResponseMessageStat(const Upstream::ClusterInfo& cluster,
      41             :                                  const absl::optional<RequestStatNames>& request_names,
      42             :                                  uint64_t amount) override;
      43             :   void chargeUpstreamStat(const Upstream::ClusterInfo& cluster,
      44             :                           const absl::optional<RequestStatNames>& request_names,
      45             :                           std::chrono::milliseconds duration) override;
      46             : 
      47             :   /**
      48             :    * Resolve the gRPC service and method from the HTTP2 :path header.
      49             :    * @param path supplies the :path header.
      50             :    * @return if both gRPC serve and method have been resolved successfully returns
      51             :    *   a populated RequestStatNames, otherwise returns an empty optional.
      52             :    */
      53             :   absl::optional<RequestStatNames>
      54             :   resolveDynamicServiceAndMethod(const Http::HeaderEntry* path) override;
      55             : 
      56             :   /**
      57             :    * Resolve the gRPC service and method from the HTTP2 :path header. Replace dots in the gRPC
      58             :    * service name if there are any.
      59             :    * @param path supplies the :path header.
      60             :    * @return if both gRPC serve and method have been resolved successfully returns
      61             :    *   a populated RequestStatNames, otherwise returns an empty optional.
      62             :    */
      63             :   absl::optional<RequestStatNames>
      64             :   resolveDynamicServiceAndMethodWithDotReplaced(const Http::HeaderEntry* path) override;
      65             : 
      66           1 :   Stats::StatName successStatName(bool success) const { return success ? success_ : failure_; }
      67           3 :   Stats::StatName protocolStatName(Protocol protocol) const {
      68           3 :     return protocol == Context::Protocol::Grpc ? grpc_ : grpc_web_;
      69           3 :   }
      70             : 
      71         132 :   StatNames& statNames() override { return stat_names_; }
      72             : 
      73             : private:
      74             :   // Creates an array of stat-name elements, comprising the protocol, optional
      75             :   // service and method, and a suffix.
      76             :   Stats::ElementVec statElements(Protocol protocol,
      77             :                                  const absl::optional<RequestStatNames>& request_names,
      78             :                                  Stats::Element suffix);
      79             : 
      80             :   Stats::StatNamePool stat_name_pool_;
      81             :   const Stats::StatName grpc_;
      82             :   const Stats::StatName grpc_web_;
      83             :   const Stats::StatName success_;
      84             :   const Stats::StatName failure_;
      85             :   const Stats::StatName total_;
      86             :   const Stats::StatName zero_;
      87             :   const Stats::StatName request_message_count_;
      88             :   const Stats::StatName response_message_count_;
      89             :   const Stats::StatName upstream_rq_time_;
      90             : 
      91             :   StatNames stat_names_;
      92             : };
      93             : 
      94             : } // namespace Grpc
      95             : } // namespace Envoy

Generated by: LCOV version 1.15