Coverage Report

Created: 2023-11-12 09:30

/proc/self/cwd/source/extensions/load_balancing_policies/ring_hash/config.h
Line
Count
Source (jump to first uncovered line)
1
#pragma once
2
3
#include <memory>
4
5
#include "envoy/extensions/load_balancing_policies/ring_hash/v3/ring_hash.pb.h"
6
#include "envoy/extensions/load_balancing_policies/ring_hash/v3/ring_hash.pb.validate.h"
7
#include "envoy/upstream/load_balancer.h"
8
9
#include "source/common/upstream/load_balancer_factory_base.h"
10
#include "source/extensions/load_balancing_policies/common/factory_base.h"
11
#include "source/extensions/load_balancing_policies/ring_hash/ring_hash_lb.h"
12
13
namespace Envoy {
14
namespace Extensions {
15
namespace LoadBalancingPolices {
16
namespace RingHash {
17
18
using RingHashLbProto = envoy::extensions::load_balancing_policies::ring_hash::v3::RingHash;
19
20
class Factory : public Upstream::TypedLoadBalancerFactoryBase<RingHashLbProto> {
21
public:
22
4
  Factory() : TypedLoadBalancerFactoryBase("envoy.load_balancing_policies.ring_hash") {}
23
24
  Upstream::ThreadAwareLoadBalancerPtr create(OptRef<const Upstream::LoadBalancerConfig> lb_config,
25
                                              const Upstream::ClusterInfo& cluster_info,
26
                                              const Upstream::PrioritySet& priority_set,
27
                                              Runtime::Loader& runtime,
28
                                              Random::RandomGenerator& random,
29
                                              TimeSource& time_source) override;
30
31
  Upstream::LoadBalancerConfigPtr loadConfig(const Protobuf::Message& config,
32
0
                                             ProtobufMessage::ValidationVisitor&) override {
33
0
    auto active_or_legacy =
34
0
        Common::ActiveOrLegacy<Upstream::RingHashLbProto, Upstream::ClusterProto>::get(&config);
35
36
0
    ASSERT(active_or_legacy.hasLegacy() || active_or_legacy.hasActive());
37
38
0
    return active_or_legacy.hasLegacy()
39
0
               ? Upstream::LoadBalancerConfigPtr{new Upstream::LegacyRingHashLbConfig(
40
0
                     *active_or_legacy.legacy())}
41
0
               : Upstream::LoadBalancerConfigPtr{
42
0
                     new Upstream::TypedRingHashLbConfig(*active_or_legacy.active())};
43
0
  }
44
};
45
46
} // namespace RingHash
47
} // namespace LoadBalancingPolices
48
} // namespace Extensions
49
} // namespace Envoy