Coverage Report

Created: 2024-09-19 09:45

/proc/self/cwd/source/extensions/tracers/xray/config.cc
Line
Count
Source (jump to first uncovered line)
1
#include "source/extensions/tracers/xray/config.h"
2
3
#include <string>
4
5
#include "envoy/config/core/v3/address.pb.h"
6
#include "envoy/config/trace/v3/xray.pb.h"
7
#include "envoy/config/trace/v3/xray.pb.validate.h"
8
#include "envoy/registry/registry.h"
9
10
#include "source/common/common/utility.h"
11
#include "source/common/config/datasource.h"
12
#include "source/extensions/tracers/xray/xray_tracer_impl.h"
13
14
namespace Envoy {
15
namespace Extensions {
16
namespace Tracers {
17
namespace XRay {
18
19
4
XRayTracerFactory::XRayTracerFactory() : FactoryBase("envoy.tracers.xray") {}
20
21
Tracing::DriverSharedPtr
22
XRayTracerFactory::createTracerDriverTyped(const envoy::config::trace::v3::XRayConfig& proto_config,
23
0
                                           Server::Configuration::TracerFactoryContext& context) {
24
0
  std::string sampling_rules_json;
25
0
  TRY_NEEDS_AUDIT {
26
0
    sampling_rules_json =
27
0
        THROW_OR_RETURN_VALUE(Config::DataSource::read(proto_config.sampling_rule_manifest(), true,
28
0
                                                       context.serverFactoryContext().api()),
29
0
                              std::string);
30
0
  }
31
0
  END_TRY catch (EnvoyException& e) {
32
0
    ENVOY_LOG(error, "Failed to read sampling rules manifest because of {}.", e.what());
33
0
  }
34
35
0
  if (proto_config.daemon_endpoint().protocol() != envoy::config::core::v3::SocketAddress::UDP) {
36
0
    throw EnvoyException("X-Ray daemon endpoint must be a UDP socket address");
37
0
  }
38
39
0
  if (proto_config.daemon_endpoint().port_specifier_case() !=
40
0
      envoy::config::core::v3::SocketAddress::PortSpecifierCase::kPortValue) {
41
0
    throw EnvoyException("X-Ray daemon port must be specified as number. Not a named port.");
42
0
  }
43
44
0
  const std::string endpoint = fmt::format("{}:{}", proto_config.daemon_endpoint().address(),
45
0
                                           proto_config.daemon_endpoint().port_value());
46
47
0
  auto aws = absl::flat_hash_map<std::string, ProtobufWkt::Value>{};
48
0
  for (const auto& field : proto_config.segment_fields().aws().fields()) {
49
0
    aws.emplace(field.first, field.second);
50
0
  }
51
0
  const auto& origin = proto_config.segment_fields().origin();
52
0
  XRayConfiguration xconfig{endpoint, proto_config.segment_name(), sampling_rules_json, origin,
53
0
                            std::move(aws)};
54
55
0
  return std::make_shared<XRay::Driver>(xconfig, context);
56
0
}
57
58
/**
59
 * Static registration for the XRay tracer. @see RegisterFactory.
60
 */
61
REGISTER_FACTORY(XRayTracerFactory, Server::Configuration::TracerFactory);
62
63
} // namespace XRay
64
} // namespace Tracers
65
} // namespace Extensions
66
} // namespace Envoy