1
#pragma once
2

            
3
#include <string>
4

            
5
#include "envoy/stats/primitive_stats.h"
6
#include "envoy/upstream/load_balancer.h"
7
#include "envoy/upstream/upstream.h"
8

            
9
namespace Envoy {
10
namespace Upstream {
11

            
12
using CommonLbConfigProto = envoy::config::cluster::v3::Cluster::CommonLbConfig;
13

            
14
/**
15
 * Utility functions for hosts.
16
 */
17
class HostUtility {
18
public:
19
  using HostStatusSet = std::bitset<32>;
20

            
21
  /**
22
   * Convert a host's health flags into a debug string.
23
   */
24
  static std::string healthFlagsToString(const Host& host);
25

            
26
  // A utility function to create override host status from lb config.
27
  static HostStatusSet createOverrideHostStatus(const CommonLbConfigProto& common_config);
28

            
29
  /**
30
   * A utility function to select override host from host map according to load balancer context.
31
   *
32
   * @return pair<HostConstSharedPtr, bool> the first element is the selected host and the second
33
   *         element is a boolean indicating whether the host should be selected strictly or not.
34
   */
35
  static std::pair<HostConstSharedPtr, bool>
36
  selectOverrideHost(const HostMap* host_map, HostStatusSet status, LoadBalancerContext* context);
37

            
38
  // Iterate over all per-endpoint metrics, for clusters with `per_endpoint_stats` enabled.
39
  static void
40
  forEachHostMetric(const ClusterManager& cluster_manager,
41
                    const std::function<void(Stats::PrimitiveCounterSnapshot&& metric)>& counter_cb,
42
                    const std::function<void(Stats::PrimitiveGaugeSnapshot&& metric)>& gauge_cb);
43
};
44

            
45
} // namespace Upstream
46
} // namespace Envoy