1
#include "source/extensions/health_check/event_sinks/file/file_sink_impl.h"
2

            
3
#include "envoy/registry/registry.h"
4

            
5
#include "source/common/protobuf/utility.h"
6

            
7
namespace Envoy {
8
namespace Upstream {
9

            
10
8
void HealthCheckEventFileSink::log(envoy::data::core::v3::HealthCheckEvent event) {
11
8
#ifdef ENVOY_ENABLE_YAML
12
  // Make sure the type enums make it into the JSON
13
8
  const auto json =
14
8
      MessageUtil::getJsonStringFromMessageOrError(event, /* pretty_print */ false,
15
8
                                                   /* always_print_primitive_fields */ true);
16
8
  file_->write(fmt::format("{}\n", json));
17
8
#endif
18
8
};
19

            
20
HealthCheckEventSinkPtr HealthCheckEventFileSinkFactory::createHealthCheckEventSink(
21
2
    const Protobuf::Any& config, Server::Configuration::HealthCheckerFactoryContext& context) {
22
2
  const auto& validator_config = Envoy::MessageUtil::anyConvertAndValidate<
23
2
      envoy::extensions::health_check::event_sinks::file::v3::HealthCheckEventFileSink>(
24
2
      config, context.messageValidationVisitor());
25
2
  return std::make_unique<HealthCheckEventFileSink>(validator_config, context.accessLogManager());
26
2
}
27

            
28
REGISTER_FACTORY(HealthCheckEventFileSinkFactory, HealthCheckEventSinkFactory);
29

            
30
} // namespace Upstream
31
} // namespace Envoy