1
#pragma once
2

            
3
#include <map>
4
#include <memory>
5
#include <string>
6

            
7
#include "envoy/common/time.h"
8
#include "envoy/data/core/v3/health_check_event.pb.h"
9
#include "envoy/server/health_checker_config.h"
10
#include "envoy/upstream/health_check_event_sink.h"
11

            
12
#include "source/common/common/thread.h"
13
#include "source/common/protobuf/protobuf.h"
14

            
15
#include "absl/base/thread_annotations.h"
16
#include "cilium/api/health_check_sink.pb.h"
17
#include "cilium/api/health_check_sink.pb.validate.h" // IWYU pragma: keep
18
#include "cilium/uds_client.h"
19

            
20
namespace Envoy {
21
namespace Cilium {
22

            
23
class HealthCheckEventPipeSinkFactory;
24

            
25
class HealthCheckEventPipeSink : public Upstream::HealthCheckEventSink {
26
public:
27
  void log(envoy::data::core::v3::HealthCheckEvent event) override;
28

            
29
protected:
30
  friend class HealthCheckEventPipeSinkFactory;
31
  friend class HealthCheckEventPipeSink_logTest_Test;
32
  explicit HealthCheckEventPipeSink(const cilium::HealthCheckEventPipeSink& config,
33
                                    TimeSource& time_source);
34

            
35
private:
36
  static Thread::MutexBasicLockable udss_mutex;
37
  static std::map<std::string, std::weak_ptr<UDSClient>> udss ABSL_GUARDED_BY(udss_mutex);
38

            
39
  std::shared_ptr<UDSClient> uds_client_;
40
};
41

            
42
class HealthCheckEventPipeSinkFactory : public Upstream::HealthCheckEventSinkFactory {
43
public:
44
1
  HealthCheckEventPipeSinkFactory() = default;
45

            
46
  Upstream::HealthCheckEventSinkPtr
47
  createHealthCheckEventSink(const ProtobufWkt::Any& config,
48
                             Server::Configuration::HealthCheckerFactoryContext& context) override;
49

            
50
1
  std::string name() const override { return "cilium.health_check.event_sink.pipe"; }
51

            
52
2
  ProtobufTypes::MessagePtr createEmptyConfigProto() override {
53
2
    return ProtobufTypes::MessagePtr{new cilium::HealthCheckEventPipeSink()};
54
2
  }
55
};
56

            
57
} // namespace Cilium
58
} // namespace Envoy