LCOV - code coverage report
Current view: top level - source/extensions/matching/input_matchers/runtime_fraction - matcher.h (source / functions) Hit Total Coverage
Test: coverage.dat Lines: 0 9 0.0 %
Date: 2024-01-05 06:35:25 Functions: 0 2 0.0 %

          Line data    Source code
       1             : #pragma once
       2             : 
       3             : #include "envoy/config/core/v3/base.pb.h"
       4             : #include "envoy/matcher/matcher.h"
       5             : #include "envoy/runtime/runtime.h"
       6             : 
       7             : #include "source/common/common/hash.h"
       8             : #include "source/common/matcher/matcher.h"
       9             : 
      10             : namespace Envoy {
      11             : namespace Extensions {
      12             : namespace Matching {
      13             : namespace InputMatchers {
      14             : namespace RuntimeFraction {
      15             : 
      16             : class Matcher : public Envoy::Matcher::InputMatcher {
      17             : public:
      18             :   Matcher(Runtime::Loader& runtime,
      19             :           envoy::config::core::v3::RuntimeFractionalPercent runtime_fraction, uint64_t seed)
      20           0 :       : runtime_(runtime), runtime_fraction_(runtime_fraction), seed_(seed) {}
      21           0 :   bool match(const ::Envoy::Matcher::MatchingDataType& input) override {
      22             :     // Only match if the value is present.
      23           0 :     if (absl::holds_alternative<absl::monostate>(input)) {
      24           0 :       return false;
      25           0 :     }
      26             : 
      27             :     // Otherwise, match if feature is enabled for hash(input).
      28           0 :     const auto hash_value = HashUtil::xxHash64(absl::get<std::string>(input), seed_);
      29           0 :     return runtime_.snapshot().featureEnabled(runtime_fraction_.runtime_key(),
      30           0 :                                               runtime_fraction_.default_value(), hash_value);
      31           0 :   }
      32             : 
      33             : private:
      34             :   Runtime::Loader& runtime_;
      35             :   const envoy::config::core::v3::RuntimeFractionalPercent runtime_fraction_;
      36             :   const uint64_t seed_;
      37             : };
      38             : } // namespace RuntimeFraction
      39             : } // namespace InputMatchers
      40             : } // namespace Matching
      41             : } // namespace Extensions
      42             : } // namespace Envoy

Generated by: LCOV version 1.15