1
#pragma once
2

            
3
#include <atomic>
4
#include <cstdint>
5
#include <string>
6

            
7
namespace Envoy {
8
namespace Extensions {
9
namespace Tracers {
10
namespace OpenTelemetry {
11

            
12
/**
13
 * @brief Contains the configuration for the sampler. Might be extended in a future version
14
 *
15
 */
16
class SamplerConfig {
17
public:
18
  static constexpr uint32_t ROOT_SPANS_PER_MINUTE_DEFAULT = 1000;
19

            
20
  explicit SamplerConfig(uint32_t default_root_spans_per_minute)
21
48
      : default_root_spans_per_minute_(default_root_spans_per_minute > 0
22
48
                                           ? default_root_spans_per_minute
23
48
                                           : ROOT_SPANS_PER_MINUTE_DEFAULT),
24
48
        root_spans_per_minute_(default_root_spans_per_minute_) {}
25

            
26
  SamplerConfig(const SamplerConfig&) = delete;
27
  SamplerConfig& operator=(const SamplerConfig&) = delete;
28

            
29
  /**
30
   * @brief Parses a json string containing the expected root spans per minute.
31
   *
32
   * @param json A string containing the configuration.
33
   *
34
   * @return true if parsing was successful, false otherwise
35
   */
36
  bool parse(const std::string& json);
37

            
38
  /**
39
   * @brief Returns wanted root spans per minute
40
   *
41
   * @return uint32_t wanted root spans per minute
42
   */
43
1437
  uint32_t getRootSpansPerMinute() const { return root_spans_per_minute_.load(); }
44

            
45
private:
46
  const uint32_t default_root_spans_per_minute_;
47
  std::atomic<uint32_t> root_spans_per_minute_;
48
};
49

            
50
} // namespace OpenTelemetry
51
} // namespace Tracers
52
} // namespace Extensions
53
} // namespace Envoy