LCOV - code coverage report
Current view: top level - source/extensions/stat_sinks/wasm - config.cc (source / functions) Hit Total Coverage
Test: coverage.dat Lines: 4 35 11.4 %
Date: 2024-01-05 06:35:25 Functions: 2 4 50.0 %

          Line data    Source code
       1             : #include "source/extensions/stat_sinks/wasm/config.h"
       2             : 
       3             : #include <memory>
       4             : 
       5             : #include "envoy/extensions/stat_sinks/wasm/v3/wasm.pb.validate.h"
       6             : #include "envoy/registry/registry.h"
       7             : #include "envoy/server/factory_context.h"
       8             : 
       9             : #include "source/extensions/common/wasm/wasm.h"
      10             : #include "source/extensions/stat_sinks/wasm/wasm_stat_sink_impl.h"
      11             : 
      12             : namespace Envoy {
      13             : namespace Extensions {
      14             : namespace StatSinks {
      15             : namespace Wasm {
      16             : 
      17             : Stats::SinkPtr
      18             : WasmSinkFactory::createStatsSink(const Protobuf::Message& proto_config,
      19           0 :                                  Server::Configuration::ServerFactoryContext& context) {
      20           0 :   const auto& config =
      21           0 :       MessageUtil::downcastAndValidate<const envoy::extensions::stat_sinks::wasm::v3::Wasm&>(
      22           0 :           proto_config, context.messageValidationContext().staticValidationVisitor());
      23             : 
      24           0 :   auto plugin = std::make_shared<Common::Wasm::Plugin>(
      25           0 :       config.config(), envoy::config::core::v3::TrafficDirection::UNSPECIFIED, context.localInfo(),
      26           0 :       nullptr);
      27             : 
      28           0 :   auto wasm_sink = std::make_unique<WasmStatSink>(plugin, nullptr);
      29             : 
      30           0 :   auto callback = [&wasm_sink, &context, plugin](Common::Wasm::WasmHandleSharedPtr base_wasm) {
      31           0 :     if (!base_wasm) {
      32           0 :       if (plugin->fail_open_) {
      33           0 :         ENVOY_LOG(error, "Unable to create Wasm Stat Sink {}", plugin->name_);
      34           0 :       } else {
      35           0 :         ENVOY_LOG(critical, "Unable to create Wasm Stat Sink {}", plugin->name_);
      36           0 :       }
      37           0 :       return;
      38           0 :     }
      39           0 :     wasm_sink->setSingleton(Common::Wasm::getOrCreateThreadLocalPlugin(
      40           0 :         base_wasm, plugin, context.mainThreadDispatcher()));
      41           0 :   };
      42             : 
      43           0 :   if (!Common::Wasm::createWasm(plugin, context.scope().createScope(""), context.clusterManager(),
      44           0 :                                 context.initManager(), context.mainThreadDispatcher(),
      45           0 :                                 context.api(), context.lifecycleNotifier(), remote_data_provider_,
      46           0 :                                 std::move(callback))) {
      47           0 :     throw Common::Wasm::WasmException(
      48           0 :         fmt::format("Unable to create Wasm Stat Sink {}", plugin->name_));
      49           0 :   }
      50             : 
      51           0 :   context.api().customStatNamespaces().registerStatNamespace(
      52           0 :       Extensions::Common::Wasm::CustomStatNamespace);
      53           0 :   return wasm_sink;
      54           0 : }
      55             : 
      56           1 : ProtobufTypes::MessagePtr WasmSinkFactory::createEmptyConfigProto() {
      57           1 :   return std::make_unique<envoy::extensions::stat_sinks::wasm::v3::Wasm>();
      58           1 : }
      59             : 
      60          38 : std::string WasmSinkFactory::name() const { return WasmName; }
      61             : 
      62             : /**
      63             :  * Static registration for the wasm access log. @see RegisterFactory.
      64             :  */
      65             : REGISTER_FACTORY(WasmSinkFactory, Server::Configuration::StatsSinkFactory);
      66             : 
      67             : } // namespace Wasm
      68             : } // namespace StatSinks
      69             : } // namespace Extensions
      70             : } // namespace Envoy

Generated by: LCOV version 1.15