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

          Line data    Source code
       1             : #pragma once
       2             : 
       3             : #include <memory>
       4             : 
       5             : #include "envoy/http/header_map.h"
       6             : #include "envoy/upstream/upstream.h"
       7             : 
       8             : namespace Envoy {
       9             : namespace Grpc {
      10             : 
      11             : struct StatNames;
      12             : 
      13             : /**
      14             :  * Captures grpc-related structures with cardinality of one per server.
      15             :  */
      16             : class Context {
      17             : public:
      18         481 :   virtual ~Context() = default;
      19             : 
      20             :   enum class Protocol { Grpc, GrpcWeb };
      21             : 
      22             :   struct RequestStatNames;
      23             : 
      24             :   /**
      25             :    * Parses out request grpc service-name and method from the path, returning a
      26             :    * populated RequestStatNames if successful. See the implementation
      27             :    * (source/common/grpc/common.h) for the definition of RequestStatNames. It is
      28             :    * hidden in the implementation since it references StatName, which is defined
      29             :    * only in the stats implementation.
      30             :    *
      31             :    * @param path the request path.
      32             :    * @return the request names, expressed as StatName.
      33             :    */
      34             :   virtual absl::optional<RequestStatNames>
      35             :   resolveDynamicServiceAndMethod(const Http::HeaderEntry* path) PURE;
      36             : 
      37             :   /**
      38             :    * Parses out request grpc service-name and method from the path with dots
      39             :    * replaced by underscores in grpc service-name, returning a populated
      40             :    * RequestStatName if successful. See
      41             :    * the implementation (source/common/grpc/common.h) for the definition of
      42             :    * RequestStatNames. It is hidden in the implementation since it references StatName, which is
      43             :    * defined only in the stats implementation.
      44             :    *
      45             :    * @param path the request path.
      46             :    * @return the request names, expressed as StatName.
      47             :    */
      48             :   virtual absl::optional<RequestStatNames>
      49             :   resolveDynamicServiceAndMethodWithDotReplaced(const Http::HeaderEntry* path) PURE;
      50             : 
      51             :   /**
      52             :    * Charge a success/failure stat to a cluster/service/method.
      53             :    * @param cluster supplies the target cluster.
      54             :    * @param protocol supplies the downstream protocol in use.
      55             :    * @param request_names supplies the request names.
      56             :    * @param grpc_status supplies the gRPC status.
      57             :    */
      58             :   virtual void chargeStat(const Upstream::ClusterInfo& cluster, Protocol protocol,
      59             :                           const absl::optional<RequestStatNames>& request_names,
      60             :                           const Http::HeaderEntry* grpc_status) PURE;
      61             : 
      62             :   /**
      63             :    * Charge a success/failure stat to a cluster/service/method.
      64             :    * @param cluster supplies the target cluster.
      65             :    * @param protocol supplies the downstream protocol in use.
      66             :    * @param request_names supplies the request names.
      67             :    * @param success supplies whether the call succeeded.
      68             :    */
      69             :   virtual void chargeStat(const Upstream::ClusterInfo& cluster, Protocol protocol,
      70             :                           const absl::optional<RequestStatNames>& request_names, bool success) PURE;
      71             : 
      72             :   /**
      73             :    * Charge a success/failure stat to a cluster/service/method.
      74             :    * @param cluster supplies the target cluster.
      75             :    * @param request_names supplies the request names.
      76             :    * @param success supplies whether the call succeeded.
      77             :    */
      78             :   virtual void chargeStat(const Upstream::ClusterInfo& cluster,
      79             :                           const absl::optional<RequestStatNames>& request_names, bool success) PURE;
      80             : 
      81             :   /**
      82             :    * Charge a request message stat to a cluster/service/method.
      83             :    * @param cluster supplies the target cluster.
      84             :    * @param request_names supplies the request names.
      85             :    * @param amount supplies the number of the request messages.
      86             :    */
      87             :   virtual void chargeRequestMessageStat(const Upstream::ClusterInfo& cluster,
      88             :                                         const absl::optional<RequestStatNames>& request_names,
      89             :                                         uint64_t amount) PURE;
      90             : 
      91             :   /**
      92             :    * Charge a response message stat to a cluster/service/method.
      93             :    * @param cluster supplies the target cluster.
      94             :    * @param request_names supplies the request names.
      95             :    * @param amount supplies the number of the response messages.
      96             :    */
      97             :   virtual void chargeResponseMessageStat(const Upstream::ClusterInfo& cluster,
      98             :                                          const absl::optional<RequestStatNames>& request_names,
      99             :                                          uint64_t amount) PURE;
     100             : 
     101             :   /**
     102             :    * Charge upstream stat to a cluster/service/method.
     103             :    * @param cluster supplies the target cluster.
     104             :    * @param request_names supplies the request names.
     105             :    * @param duration supplies the duration of the upstream request.
     106             :    */
     107             :   virtual void chargeUpstreamStat(const Upstream::ClusterInfo& cluster,
     108             :                                   const absl::optional<RequestStatNames>& request_names,
     109             :                                   std::chrono::milliseconds duration) PURE;
     110             : 
     111             :   /**
     112             :    * @return a struct containing StatNames for gRPC stat tokens.
     113             :    */
     114             :   virtual StatNames& statNames() PURE;
     115             : };
     116             : 
     117             : using ContextPtr = std::unique_ptr<Context>;
     118             : 
     119             : } // namespace Grpc
     120             : } // namespace Envoy

Generated by: LCOV version 1.15