27#include <unordered_map>
31#include <kcenon/common/interfaces/logger_interface.h>
36using log_level = common::interfaces::log_level;
140 std::unordered_map<std::string, std::unordered_map<std::string, double>>
field_rates;
215 config.
rate = sample_rate;
258 config.
rate = sample_rate;
279 return std::move(*
this);
common::interfaces::log_level log_level
sampling_strategy
Defines the sampling algorithm to use.
@ hash_based
Deterministic sampling based on message hash.
@ random
Simple random sampling based on probability.
@ rate_limiting
Rate-based sampling (N logs per time window)
@ adaptive
Adaptive sampling that adjusts based on volume.
Configuration for log sampling behavior.
static sampling_config random_sampling(double sample_rate)
Create a random sampling configuration.
double rate
Base sampling rate (0.0 to 1.0)
static sampling_config rate_limited(std::size_t max_per_second)
Create a rate limiting configuration.
std::size_t adaptive_threshold
Threshold (messages/second) to trigger adaptive sampling.
std::vector< std::string > always_log_fields
std::unordered_map< std::string, std::unordered_map< std::string, double > > field_rates
std::unordered_map< std::string, double > category_rates
std::size_t rate_limit_per_second
Maximum logs per second for rate limiting strategy.
std::size_t rate_limit_window_ms
Time window for rate limiting (milliseconds)
std::uint64_t hash_seed
Seed for hash-based sampling.
static sampling_config hash_based(double sample_rate, std::uint64_t seed=0)
Create a hash-based sampling configuration.
sampling_config with_always_log(std::vector< log_level > levels) const &
Set log levels that bypass sampling (fluent interface, lvalue overload)
bool adaptive_enabled
Enable adaptive sampling.
double adaptive_min_rate
Minimum sampling rate when adaptive sampling is active.
static sampling_config disabled()
Create a default sampling configuration (disabled)
static sampling_config adaptive(std::size_t threshold, double min_rate=0.01)
Create an adaptive sampling configuration.
sampling_strategy strategy
Sampling strategy to use.
sampling_config with_always_log(std::vector< log_level > levels) &&
std::vector< log_level > always_log_levels
Log levels that are never sampled (always logged)
bool enabled
Enable or disable sampling.
Statistics about sampling behavior.
std::uint64_t sampled_count
Number of messages that passed sampling (were logged)
std::uint64_t bypassed_count
Number of messages that bypassed sampling (always_log levels)
double actual_ratio() const
Calculate the actual sampling ratio.
std::uint64_t dropped_count
Number of messages dropped due to sampling.
void reset()
Reset all statistics.
double effective_rate
Current effective sampling rate.
bool is_throttling
Whether adaptive sampling is currently reducing the rate.
std::uint64_t total_count
Total number of log messages considered for sampling.