LCOV - code coverage report
Current view: top level - envoy/upstream - locality.h (source / functions) Hit Total Coverage
Test: coverage.dat Lines: 8 23 34.8 %
Date: 2024-01-05 06:35:25 Functions: 2 566 0.4 %

          Line data    Source code
       1             : #pragma once
       2             : 
       3             : #include "envoy/config/core/v3/base.pb.h"
       4             : 
       5             : #include "source/common/protobuf/utility.h"
       6             : 
       7             : namespace Envoy {
       8             : namespace Upstream {
       9             : 
      10             : // We use a tuple representation for hashing/equality/comparison, since this
      11             : // ensures we are not subject to proto nuances like unknown fields (e.g. from
      12             : // original type information annotations).
      13             : using LocalityTuple = std::tuple<const std::string&, const std::string&, const std::string&>;
      14             : 
      15             : struct LocalityHash {
      16         159 :   size_t operator()(const envoy::config::core::v3::Locality& locality) const {
      17         159 :     return absl::Hash<LocalityTuple>()({locality.region(), locality.zone(), locality.sub_zone()});
      18         159 :   }
      19             : };
      20             : 
      21             : struct LocalityEqualTo {
      22             :   bool operator()(const envoy::config::core::v3::Locality& lhs,
      23           0 :                   const envoy::config::core::v3::Locality& rhs) const {
      24           0 :     const LocalityTuple lhs_tuple = LocalityTuple(lhs.region(), lhs.zone(), lhs.sub_zone());
      25           0 :     const LocalityTuple rhs_tuple = LocalityTuple(rhs.region(), rhs.zone(), rhs.sub_zone());
      26           0 :     return lhs_tuple == rhs_tuple;
      27           0 :   }
      28             : };
      29             : 
      30             : struct LocalityLess {
      31             :   bool operator()(const envoy::config::core::v3::Locality& lhs,
      32         159 :                   const envoy::config::core::v3::Locality& rhs) const {
      33         159 :     const LocalityTuple lhs_tuple = LocalityTuple(lhs.region(), lhs.zone(), lhs.sub_zone());
      34         159 :     const LocalityTuple rhs_tuple = LocalityTuple(rhs.region(), rhs.zone(), rhs.sub_zone());
      35         159 :     return lhs_tuple < rhs_tuple;
      36         159 :   }
      37             : };
      38             : 
      39             : // For tests etc. where this is convenient.
      40             : static inline envoy::config::core::v3::Locality
      41           0 : Locality(const std::string& region, const std::string& zone, const std::string sub_zone) {
      42           0 :   envoy::config::core::v3::Locality locality;
      43           0 :   locality.set_region(region);
      44           0 :   locality.set_zone(zone);
      45           0 :   locality.set_sub_zone(sub_zone);
      46           0 :   return locality;
      47           0 : }
      48             : 
      49             : } // namespace Upstream
      50             : } // namespace Envoy
      51             : 
      52             : // Something heinous this way comes. Required to allow == for LocalityWeightsMap.h in eds.h.
      53             : namespace envoy {
      54             : namespace config {
      55             : namespace core {
      56             : namespace v3 {
      57             : 
      58             : inline bool operator==(const envoy::config::core::v3::Locality& x,
      59           0 :                        const envoy::config::core::v3::Locality& y) {
      60           0 :   return Envoy::Upstream::LocalityEqualTo()(x, y);
      61           0 : }
      62             : 
      63             : } // namespace v3
      64             : } // namespace core
      65             : } // namespace config
      66             : } // namespace envoy

Generated by: LCOV version 1.15