Monitoring System 0.1.0
System resource monitoring with pluggable collectors and alerting
Loading...
Searching...
No Matches
unreliable_service Class Reference
Collaboration diagram for unreliable_service:
Collaboration graph

Public Member Functions

 unreliable_service (double failure_rate)
 
kcenon::common::Result< std::string > call ()
 
void set_failure_rate (double rate)
 

Private Attributes

std::mt19937 rng_
 
std::uniform_real_distribution dist_
 
double failure_rate_
 
std::atomic< int > call_count_ {0}
 

Detailed Description

Constructor & Destructor Documentation

◆ unreliable_service()

unreliable_service::unreliable_service ( double failure_rate)
inlineexplicit
Examples
graceful_degradation_example.cpp.

Definition at line 43 of file graceful_degradation_example.cpp.

44 : rng_(std::random_device{}())
45 , dist_(0.0, 1.0)
46 , failure_rate_(failure_rate) {}
std::uniform_real_distribution dist_

Member Function Documentation

◆ call()

kcenon::common::Result< std::string > unreliable_service::call ( )
inline
Examples
graceful_degradation_example.cpp.

Definition at line 48 of file graceful_degradation_example.cpp.

48 {
50 std::this_thread::sleep_for(50ms);
51
52 if (dist_(rng_) < failure_rate_) {
53 return kcenon::common::Result<std::string>::err(
54 error_info{monitoring_error_code::service_unavailable,
55 "Service temporarily unavailable"}.to_common_error()
56 );
57 }
58
59 return kcenon::common::ok(std::string("Service response: SUCCESS"));
60 }
Extended error information with context.
common::error_info to_common_error() const
Convert to common_system error_info.

References call_count_, dist_, failure_rate_, rng_, and kcenon::monitoring::error_info::to_common_error().

Referenced by demonstrate_combined_patterns().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ set_failure_rate()

void unreliable_service::set_failure_rate ( double rate)
inline
Examples
graceful_degradation_example.cpp.

Definition at line 62 of file graceful_degradation_example.cpp.

62 {
63 failure_rate_ = rate;
64 }

References failure_rate_.

Member Data Documentation

◆ call_count_

std::atomic<int> unreliable_service::call_count_ {0}
private
Examples
graceful_degradation_example.cpp.

Definition at line 40 of file graceful_degradation_example.cpp.

40{0};

Referenced by call().

◆ dist_

std::uniform_real_distribution unreliable_service::dist_
private
Examples
graceful_degradation_example.cpp.

Definition at line 38 of file graceful_degradation_example.cpp.

Referenced by call().

◆ failure_rate_

double unreliable_service::failure_rate_
private
Examples
graceful_degradation_example.cpp.

Definition at line 39 of file graceful_degradation_example.cpp.

Referenced by call(), and set_failure_rate().

◆ rng_

std::mt19937 unreliable_service::rng_
private
Examples
graceful_degradation_example.cpp.

Definition at line 37 of file graceful_degradation_example.cpp.

Referenced by call().


The documentation for this class was generated from the following file: