Monitoring System 0.1.0
System resource monitoring with pluggable collectors and alerting
Loading...
Searching...
No Matches
CacheService Class Reference

Simulated Cache service. More...

Collaboration diagram for CacheService:
Collaboration graph

Public Member Functions

trace_span cache_lookup (const trace_context &parent_ctx, const std::string &key)
 Check cache for user data.
 

Static Private Member Functions

static std::string generate_span_id ()
 

Private Attributes

std::string service_name_ = "cache_service"
 

Detailed Description

Simulated Cache service.

Examples
multi_service_tracing_example.cpp.

Definition at line 235 of file multi_service_tracing_example.cpp.

Member Function Documentation

◆ cache_lookup()

trace_span CacheService::cache_lookup ( const trace_context & parent_ctx,
const std::string & key )
inline

Check cache for user data.

Examples
multi_service_tracing_example.cpp.

Definition at line 243 of file multi_service_tracing_example.cpp.

243 {
244 std::cout << "\n[" << service_name_ << "] Cache lookup" << std::endl;
245
246 // Create child span
247 trace_span span;
248 span.trace_id = parent_ctx.trace_id;
249 span.span_id = generate_span_id();
250 span.parent_span_id = parent_ctx.span_id;
251 span.operation_name = "cache_get";
253 span.start_time = std::chrono::system_clock::now();
254
255 // Inherit baggage
256 span.baggage = parent_ctx.baggage;
257
258 // Add cache-specific tags
259 span.tags["cache.type"] = "redis";
260 span.tags["cache.key"] = key;
261
262 std::cout << " → Created child span: " << span.span_id << std::endl;
263
264 // Simulate cache miss
265 std::this_thread::sleep_for(2ms);
266
267 span.end_time = std::chrono::system_clock::now();
268 span.calculate_duration();
269 span.status = trace_span::status_code::ok;
270 span.tags["cache.hit"] = "false";
271
272 std::cout << " ○ Cache miss (duration: "
273 << span.duration.count() << "µs)" << std::endl;
274
275 return span;
276 }
static std::string generate_span_id()
std::unordered_map< std::string, std::string > baggage
Trace span representing a unit of work in distributed tracing.
void calculate_duration()
Calculate duration if span is finished.
std::unordered_map< std::string, std::string > tags
std::unordered_map< std::string, std::string > baggage
std::chrono::system_clock::time_point end_time
std::chrono::microseconds duration
std::chrono::system_clock::time_point start_time

References kcenon::monitoring::trace_context::baggage, kcenon::monitoring::trace_span::baggage, kcenon::monitoring::trace_span::calculate_duration(), kcenon::monitoring::trace_span::duration, kcenon::monitoring::trace_span::end_time, generate_span_id(), kcenon::monitoring::trace_span::operation_name, kcenon::monitoring::trace_span::parent_span_id, kcenon::monitoring::trace_span::service_name, service_name_, kcenon::monitoring::trace_context::span_id, kcenon::monitoring::trace_span::span_id, kcenon::monitoring::trace_span::start_time, kcenon::monitoring::trace_span::status, kcenon::monitoring::trace_span::tags, kcenon::monitoring::trace_context::trace_id, and kcenon::monitoring::trace_span::trace_id.

Referenced by simulate_multi_service_request().

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

◆ generate_span_id()

static std::string CacheService::generate_span_id ( )
inlinestaticprivate
Examples
multi_service_tracing_example.cpp.

Definition at line 279 of file multi_service_tracing_example.cpp.

279 {
280 std::string id;
281 for (int i = 0; i < 16; ++i) {
282 id += "0123456789abcdef"[rand() % 16];
283 }
284 return id;
285 }

Referenced by cache_lookup().

Here is the caller graph for this function:

Member Data Documentation

◆ service_name_

std::string CacheService::service_name_ = "cache_service"
private
Examples
multi_service_tracing_example.cpp.

Definition at line 237 of file multi_service_tracing_example.cpp.

Referenced by cache_lookup().


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