1
#pragma once
2

            
3
#include "envoy/access_log/access_log.h"
4
#include "envoy/extensions/health_check/event_sinks/file/v3/file.pb.h"
5
#include "envoy/extensions/health_check/event_sinks/file/v3/file.pb.validate.h"
6
#include "envoy/upstream/health_check_event_sink.h"
7

            
8
namespace Envoy {
9
namespace Upstream {
10

            
11
class HealthCheckEventFileSink : public HealthCheckEventSink {
12
public:
13
  explicit HealthCheckEventFileSink(
14
      const envoy::extensions::health_check::event_sinks::file::v3::HealthCheckEventFileSink&
15
          config,
16
3
      AccessLog::AccessLogManager& log_manager) {
17
3
    auto file_or_error = log_manager.createAccessLog(
18
3
        Filesystem::FilePathAndType{Filesystem::DestinationType::File, config.event_log_path()});
19
3
    THROW_IF_NOT_OK_REF(file_or_error.status());
20
3
    file_ = file_or_error.value();
21
3
  }
22

            
23
  void log(envoy::data::core::v3::HealthCheckEvent event) override;
24

            
25
private:
26
  AccessLog::AccessLogFileSharedPtr file_;
27
};
28

            
29
class HealthCheckEventFileSinkFactory : public HealthCheckEventSinkFactory {
30
public:
31
5
  HealthCheckEventFileSinkFactory() = default;
32

            
33
  HealthCheckEventSinkPtr
34
  createHealthCheckEventSink(const Protobuf::Any& config,
35
                             Server::Configuration::HealthCheckerFactoryContext& context) override;
36

            
37
6
  std::string name() const override { return "envoy.health_check.event_sink.file"; }
38

            
39
3
  ProtobufTypes::MessagePtr createEmptyConfigProto() override {
40
3
    return ProtobufTypes::MessagePtr{
41
3
        new envoy::extensions::health_check::event_sinks::file::v3::HealthCheckEventFileSink()};
42
3
  }
43
};
44

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