Monitoring System 0.1.0
System resource monitoring with pluggable collectors and alerting
Loading...
Searching...
No Matches
test_alert_manager.cpp File Reference
#include <gtest/gtest.h>
#include <kcenon/monitoring/alert/alert_manager.h>
#include <kcenon/monitoring/alert/alert_triggers.h>
#include <atomic>
#include <chrono>
#include <memory>
#include <mutex>
#include <string>
#include <thread>
#include <vector>
Include dependency graph for test_alert_manager.cpp:

Go to the source code of this file.

Classes

class  AlertManagerLifecycleTest
 
class  AlertManagerRuleTest
 
class  AlertManagerProcessingTest
 
class  AlertManagerResolutionTest
 
class  AlertManagerSilenceTest
 
class  AlertManagerNotifierTest
 

Functions

 TEST (AlertManagerConfigTest, DefaultConfigIsValid)
 
 TEST (AlertManagerConfigTest, ZeroEvaluationIntervalInvalid)
 
 TEST (AlertManagerConfigTest, ZeroRepeatIntervalInvalid)
 
 TEST (AlertManagerConfigTest, ZeroMaxAlertsInvalid)
 
 TEST (AlertManagerConfigTest, ZeroMaxSilencesInvalid)
 
 TEST (AlertManagerMetricsTest, DefaultZero)
 
 TEST (AlertManagerMetricsTest, CopyConstructor)
 
 TEST_F (AlertManagerLifecycleTest, DefaultConstruction)
 
 TEST_F (AlertManagerLifecycleTest, ConstructWithConfig)
 
 TEST_F (AlertManagerLifecycleTest, StartAndStop)
 
 TEST_F (AlertManagerLifecycleTest, DoubleStartFails)
 
 TEST_F (AlertManagerLifecycleTest, StopWithoutStartIsOk)
 
 TEST_F (AlertManagerLifecycleTest, DestructorStopsManager)
 
 TEST_F (AlertManagerRuleTest, AddRule)
 
 TEST_F (AlertManagerRuleTest, AddNullRuleFails)
 
 TEST_F (AlertManagerRuleTest, GetExistingRule)
 
 TEST_F (AlertManagerRuleTest, GetNonexistentRuleReturnsNull)
 
 TEST_F (AlertManagerRuleTest, RemoveExistingRule)
 
 TEST_F (AlertManagerRuleTest, RemoveNonexistentRuleFails)
 
 TEST_F (AlertManagerRuleTest, GetAllRules)
 
 TEST_F (AlertManagerRuleTest, GetRulesEmpty)
 
 TEST (AlertRuleTest, FluentBuilder)
 
 TEST (AlertRuleTest, ValidateSuccess)
 
 TEST (AlertRuleTest, ValidateEmptyNameFails)
 
 TEST (AlertRuleTest, ValidateNoTriggerFails)
 
 TEST (AlertRuleTest, ValidateInvalidConfigFails)
 
 TEST (AlertRuleTest, CreateAlertFromRule)
 
 TEST (AlertRuleTest, CreateAlertWithoutGroupUsesName)
 
 TEST (AlertRuleTest, DisabledRule)
 
 TEST (AlertRuleTest, DefaultSeverityIsWarning)
 
 TEST (AlertRuleConfigTest, DefaultConfigIsValid)
 
 TEST (AlertRuleConfigTest, ZeroEvalIntervalInvalid)
 
 TEST (AlertRuleConfigTest, ZeroRepeatIntervalInvalid)
 
 TEST (AlertRuleGroupTest, Construction)
 
 TEST (AlertRuleGroupTest, AddRule)
 
 TEST (AlertRuleGroupTest, AddNullRuleIgnored)
 
 TEST (AlertRuleGroupTest, CommonInterval)
 
 TEST (AlertRuleGroupTest, CommonIntervalNotSetByDefault)
 
 TEST (AlertRuleGroupTest, AddRuleGroupToManager)
 
 TEST_F (AlertManagerProcessingTest, ProcessMetricBelowThreshold)
 
 TEST_F (AlertManagerProcessingTest, ProcessMetricAboveThreshold)
 
 TEST_F (AlertManagerProcessingTest, ProcessUnknownMetric)
 
 TEST_F (AlertManagerProcessingTest, ProcessBatchMetrics)
 
 TEST_F (AlertManagerProcessingTest, MetricsTrackRulesEvaluated)
 
 TEST_F (AlertManagerResolutionTest, ResolveNonexistentAlert)
 
 TEST_F (AlertManagerResolutionTest, GetAlertByFingerprint)
 
 TEST_F (AlertManagerSilenceTest, CreateSilence)
 
 TEST_F (AlertManagerSilenceTest, CreateSilenceReturnsId)
 
 TEST_F (AlertManagerSilenceTest, DeleteSilence)
 
 TEST_F (AlertManagerSilenceTest, DeleteNonexistentSilence)
 
 TEST_F (AlertManagerSilenceTest, GetSilences)
 
 TEST_F (AlertManagerSilenceTest, GetSilencesEmpty)
 
 TEST_F (AlertManagerSilenceTest, IsSilencedMatchingAlert)
 
 TEST_F (AlertManagerSilenceTest, IsNotSilencedNonMatchingAlert)
 
 TEST_F (AlertManagerSilenceTest, IsNotSilencedNoSilences)
 
 TEST_F (AlertManagerNotifierTest, AddNotifier)
 
 TEST_F (AlertManagerNotifierTest, AddNullNotifierFails)
 
 TEST_F (AlertManagerNotifierTest, RemoveNotifier)
 
 TEST_F (AlertManagerNotifierTest, RemoveNonexistentNotifier)
 
 TEST_F (AlertManagerNotifierTest, GetNotifiers)
 
 TEST (CallbackNotifierTest, NotifyInvokesCallback)
 
 TEST (CallbackNotifierTest, NotifyGroupInvokesGroupCallback)
 
 TEST (CallbackNotifierTest, NotifyGroupFallsBackToIndividual)
 
 TEST (CallbackNotifierTest, NameIsCorrect)
 
 TEST (CallbackNotifierTest, IsReadyWithCallback)
 
 TEST (CallbackNotifierTest, NotReadyWithoutCallback)
 
 TEST (CallbackNotifierTest, NotifyWithNullCallbackFails)
 
 TEST (LogNotifierTest, DefaultName)
 
 TEST (LogNotifierTest, CustomName)
 
 TEST (LogNotifierTest, IsAlwaysReady)
 
 TEST (AlertManagerMetricProviderTest, SetMetricProvider)
 
 TEST (AlertManagerConfigAccessTest, DefaultConfig)
 
 TEST (AlertManagerConfigAccessTest, CustomConfig)
 
 TEST (AlertManagerMetricsTrackingTest, InitialMetricsAreZero)
 
 TEST (AlertManagerMetricsTrackingTest, MetricsIncrementOnProcessing)
 
 TEST (AlertManagerEventBusTest, SetEventBusDoesNotCrash)
 
 TEST (AlertManagerNonCopyableTest, VerifyTraits)
 

Function Documentation

◆ TEST() [1/42]

TEST ( AlertManagerConfigAccessTest ,
CustomConfig  )

Definition at line 721 of file test_alert_manager.cpp.

721 {
723 config.default_evaluation_interval = 5s;
724 config.max_alerts_per_rule = 50;
725
726 alert_manager manager(config);
727 EXPECT_EQ(manager.config().default_evaluation_interval, 5s);
728 EXPECT_EQ(manager.config().max_alerts_per_rule, 50u);
729}
Central coordinator for the alert pipeline.
Configuration for the alert manager.
std::chrono::milliseconds default_evaluation_interval
Default eval interval.
size_t max_alerts_per_rule
Max alerts per rule.

References kcenon::monitoring::alert_manager::config(), kcenon::monitoring::alert_manager_config::default_evaluation_interval, and kcenon::monitoring::alert_manager_config::max_alerts_per_rule.

Here is the call graph for this function:

◆ TEST() [2/42]

TEST ( AlertManagerConfigAccessTest ,
DefaultConfig  )

Definition at line 714 of file test_alert_manager.cpp.

714 {
715 alert_manager manager;
716 auto& config = manager.config();
717 EXPECT_TRUE(config.validate());
718 EXPECT_EQ(config.default_evaluation_interval, 15000ms);
719}
const alert_manager_config & config() const
Get configuration.

References kcenon::monitoring::alert_manager::config().

Here is the call graph for this function:

◆ TEST() [3/42]

TEST ( AlertManagerConfigTest ,
DefaultConfigIsValid  )

Definition at line 41 of file test_alert_manager.cpp.

41 {
43 EXPECT_TRUE(config.validate());
44}
bool validate() const
Validate configuration.

References kcenon::monitoring::alert_manager_config::validate().

Here is the call graph for this function:

◆ TEST() [4/42]

TEST ( AlertManagerConfigTest ,
ZeroEvaluationIntervalInvalid  )

Definition at line 46 of file test_alert_manager.cpp.

46 {
48 config.default_evaluation_interval = 0ms;
49 EXPECT_FALSE(config.validate());
50}

References kcenon::monitoring::alert_manager_config::default_evaluation_interval, and kcenon::monitoring::alert_manager_config::validate().

Here is the call graph for this function:

◆ TEST() [5/42]

TEST ( AlertManagerConfigTest ,
ZeroMaxAlertsInvalid  )

Definition at line 58 of file test_alert_manager.cpp.

58 {
60 config.max_alerts_per_rule = 0;
61 EXPECT_FALSE(config.validate());
62}

References kcenon::monitoring::alert_manager_config::max_alerts_per_rule, and kcenon::monitoring::alert_manager_config::validate().

Here is the call graph for this function:

◆ TEST() [6/42]

TEST ( AlertManagerConfigTest ,
ZeroMaxSilencesInvalid  )

Definition at line 64 of file test_alert_manager.cpp.

64 {
66 config.max_silences = 0;
67 EXPECT_FALSE(config.validate());
68}
size_t max_silences
Max active silences.

References kcenon::monitoring::alert_manager_config::max_silences, and kcenon::monitoring::alert_manager_config::validate().

Here is the call graph for this function:

◆ TEST() [7/42]

TEST ( AlertManagerConfigTest ,
ZeroRepeatIntervalInvalid  )

Definition at line 52 of file test_alert_manager.cpp.

52 {
54 config.default_repeat_interval = 0ms;
55 EXPECT_FALSE(config.validate());
56}
std::chrono::milliseconds default_repeat_interval
Default repeat interval.

References kcenon::monitoring::alert_manager_config::default_repeat_interval, and kcenon::monitoring::alert_manager_config::validate().

Here is the call graph for this function:

◆ TEST() [8/42]

TEST ( AlertManagerEventBusTest ,
SetEventBusDoesNotCrash  )

Definition at line 761 of file test_alert_manager.cpp.

761 {
762 alert_manager manager;
763 // Passing nullptr should be handled gracefully
764 manager.set_event_bus(nullptr);
765 SUCCEED();
766}
void set_event_bus(std::shared_ptr< interface_event_bus > event_bus)
Set event bus for publishing alert events.

References kcenon::monitoring::alert_manager::set_event_bus().

Here is the call graph for this function:

◆ TEST() [9/42]

TEST ( AlertManagerMetricProviderTest ,
SetMetricProvider  )

Definition at line 694 of file test_alert_manager.cpp.

694 {
695 alert_manager manager;
696 bool called = false;
697
698 manager.set_metric_provider([&](const std::string& name)
699 -> std::optional<double> {
700 called = true;
701 if (name == "cpu") return 95.0;
702 return std::nullopt;
703 });
704
705 // The provider is used internally by the evaluation loop
706 // Just verify it doesn't crash to set
707 SUCCEED();
708}
void set_metric_provider(metric_provider_func provider)
Set the metric provider function.

References kcenon::monitoring::alert_manager::set_metric_provider().

Here is the call graph for this function:

◆ TEST() [10/42]

TEST ( AlertManagerMetricsTest ,
CopyConstructor  )

Definition at line 84 of file test_alert_manager.cpp.

84 {
85 alert_manager_metrics original;
86 original.rules_evaluated = 10;
87 original.alerts_created = 5;
88
89 alert_manager_metrics copy(original);
90 EXPECT_EQ(copy.rules_evaluated.load(), 10u);
91 EXPECT_EQ(copy.alerts_created.load(), 5u);
92}
Metrics for alert manager operations.

References kcenon::monitoring::alert_manager_metrics::alerts_created, and kcenon::monitoring::alert_manager_metrics::rules_evaluated.

◆ TEST() [11/42]

TEST ( AlertManagerMetricsTest ,
DefaultZero  )

◆ TEST() [12/42]

TEST ( AlertManagerMetricsTrackingTest ,
InitialMetricsAreZero  )

Definition at line 735 of file test_alert_manager.cpp.

735 {
736 alert_manager manager;
737 auto metrics = manager.get_metrics();
738 EXPECT_EQ(metrics.rules_evaluated.load(), 0u);
739 EXPECT_EQ(metrics.alerts_created.load(), 0u);
740 EXPECT_EQ(metrics.alerts_resolved.load(), 0u);
741}
alert_manager_metrics get_metrics() const
Get manager metrics.

References kcenon::monitoring::alert_manager::get_metrics().

Here is the call graph for this function:

◆ TEST() [13/42]

TEST ( AlertManagerMetricsTrackingTest ,
MetricsIncrementOnProcessing  )

Definition at line 743 of file test_alert_manager.cpp.

743 {
744 alert_manager manager;
745
746 auto rule = std::make_shared<alert_rule>("test_rule");
747 rule->set_metric_name("test_metric")
748 .set_trigger(threshold_trigger::above(80.0));
749 manager.add_rule(rule);
750
751 manager.process_metric("test_metric", 50.0);
752
753 auto metrics = manager.get_metrics();
754 EXPECT_GE(metrics.rules_evaluated.load(), 1u);
755}
common::VoidResult add_rule(std::shared_ptr< alert_rule > rule)
Add an alert rule.
common::VoidResult process_metric(const std::string &metric_name, double value)
Process a metric value.
static std::shared_ptr< threshold_trigger > above(double threshold)
Create trigger for value > threshold.

References kcenon::monitoring::threshold_trigger::above(), kcenon::monitoring::alert_manager::add_rule(), kcenon::monitoring::alert_manager::get_metrics(), and kcenon::monitoring::alert_manager::process_metric().

Here is the call graph for this function:

◆ TEST() [14/42]

TEST ( AlertManagerNonCopyableTest ,
VerifyTraits  )

Definition at line 772 of file test_alert_manager.cpp.

772 {
773 EXPECT_FALSE(std::is_copy_constructible_v<alert_manager>);
774 EXPECT_FALSE(std::is_copy_assignable_v<alert_manager>);
775 EXPECT_FALSE(std::is_move_constructible_v<alert_manager>);
776 EXPECT_FALSE(std::is_move_assignable_v<alert_manager>);
777}

◆ TEST() [15/42]

TEST ( AlertRuleConfigTest ,
DefaultConfigIsValid  )

Definition at line 323 of file test_alert_manager.cpp.

323 {
324 alert_rule_config config;
325 EXPECT_TRUE(config.validate());
326}
Configuration for an alert rule.
Definition alert_rule.h:36
bool validate() const
Validate configuration.
Definition alert_rule.h:47

References kcenon::monitoring::alert_rule_config::validate().

Here is the call graph for this function:

◆ TEST() [16/42]

TEST ( AlertRuleConfigTest ,
ZeroEvalIntervalInvalid  )

Definition at line 328 of file test_alert_manager.cpp.

328 {
329 alert_rule_config config;
330 config.evaluation_interval = 0ms;
331 EXPECT_FALSE(config.validate());
332}
std::chrono::milliseconds evaluation_interval
How often to evaluate.
Definition alert_rule.h:37

References kcenon::monitoring::alert_rule_config::evaluation_interval, and kcenon::monitoring::alert_rule_config::validate().

Here is the call graph for this function:

◆ TEST() [17/42]

TEST ( AlertRuleConfigTest ,
ZeroRepeatIntervalInvalid  )

Definition at line 334 of file test_alert_manager.cpp.

334 {
335 alert_rule_config config;
336 config.repeat_interval = 0ms;
337 EXPECT_FALSE(config.validate());
338}
std::chrono::milliseconds repeat_interval
Notification repeat interval.
Definition alert_rule.h:39

References kcenon::monitoring::alert_rule_config::repeat_interval, and kcenon::monitoring::alert_rule_config::validate().

Here is the call graph for this function:

◆ TEST() [18/42]

TEST ( AlertRuleGroupTest ,
AddNullRuleIgnored  )

Definition at line 361 of file test_alert_manager.cpp.

361 {
362 alert_rule_group group("test");
363 group.add_rule(nullptr);
364 EXPECT_TRUE(group.empty());
365}
A group of related alert rules.
Definition alert_rule.h:356

References kcenon::monitoring::alert_rule_group::add_rule(), and kcenon::monitoring::alert_rule_group::empty().

Here is the call graph for this function:

◆ TEST() [19/42]

TEST ( AlertRuleGroupTest ,
AddRule  )

Definition at line 351 of file test_alert_manager.cpp.

351 {
352 alert_rule_group group("infra");
353 auto rule = std::make_shared<alert_rule>("test");
354 group.add_rule(rule);
355 EXPECT_EQ(group.size(), 1u);
356 EXPECT_FALSE(group.empty());
357 // Rule should have its group set
358 EXPECT_EQ(rule->group(), "infra");
359}

References kcenon::monitoring::alert_rule_group::add_rule(), kcenon::monitoring::alert_rule_group::empty(), and kcenon::monitoring::alert_rule_group::size().

Here is the call graph for this function:

◆ TEST() [20/42]

TEST ( AlertRuleGroupTest ,
AddRuleGroupToManager  )

Definition at line 386 of file test_alert_manager.cpp.

386 {
387 alert_manager manager;
388 auto group = std::make_shared<alert_rule_group>("infra");
389 auto rule = std::make_shared<alert_rule>("test");
390 rule->set_trigger(threshold_trigger::above(80.0))
391 .set_metric_name("cpu");
392 group->add_rule(rule);
393
394 auto result = manager.add_rule_group(group);
395 EXPECT_TRUE(result.is_ok());
396}
common::VoidResult add_rule_group(std::shared_ptr< alert_rule_group > group)
Add a rule group.

References kcenon::monitoring::threshold_trigger::above(), and kcenon::monitoring::alert_manager::add_rule_group().

Here is the call graph for this function:

◆ TEST() [21/42]

TEST ( AlertRuleGroupTest ,
CommonInterval  )

Definition at line 367 of file test_alert_manager.cpp.

367 {
368 alert_rule_group group("infra");
369 auto rule1 = std::make_shared<alert_rule>("r1");
370 auto rule2 = std::make_shared<alert_rule>("r2");
371 group.add_rule(rule1);
372 group.add_rule(rule2);
373 group.set_common_interval(30s);
374
375 EXPECT_TRUE(group.common_interval().has_value());
376 EXPECT_EQ(*group.common_interval(), 30s);
377 EXPECT_EQ(rule1->config().evaluation_interval, 30s);
378 EXPECT_EQ(rule2->config().evaluation_interval, 30s);
379}

References kcenon::monitoring::alert_rule_group::add_rule(), kcenon::monitoring::alert_rule_group::common_interval(), and kcenon::monitoring::alert_rule_group::set_common_interval().

Here is the call graph for this function:

◆ TEST() [22/42]

TEST ( AlertRuleGroupTest ,
CommonIntervalNotSetByDefault  )

Definition at line 381 of file test_alert_manager.cpp.

381 {
382 alert_rule_group group("test");
383 EXPECT_FALSE(group.common_interval().has_value());
384}

References kcenon::monitoring::alert_rule_group::common_interval().

Here is the call graph for this function:

◆ TEST() [23/42]

TEST ( AlertRuleGroupTest ,
Construction  )

Definition at line 344 of file test_alert_manager.cpp.

344 {
345 alert_rule_group group("infra");
346 EXPECT_EQ(group.name(), "infra");
347 EXPECT_TRUE(group.empty());
348 EXPECT_EQ(group.size(), 0u);
349}

References kcenon::monitoring::alert_rule_group::empty(), kcenon::monitoring::alert_rule_group::name(), and kcenon::monitoring::alert_rule_group::size().

Here is the call graph for this function:

◆ TEST() [24/42]

TEST ( AlertRuleTest ,
CreateAlertFromRule  )

Definition at line 283 of file test_alert_manager.cpp.

283 {
284 alert_rule rule("cpu_high");
285 rule.set_metric_name("cpu_usage")
286 .set_severity(alert_severity::critical)
287 .set_summary("CPU high")
288 .add_label("service", "api")
289 .set_group("infra")
290 .set_trigger(threshold_trigger::above(80.0));
291
292 auto a = rule.create_alert(95.0);
293 EXPECT_EQ(a.name, "cpu_high");
294 EXPECT_EQ(a.severity, alert_severity::critical);
295 EXPECT_EQ(a.value, 95.0);
296 EXPECT_EQ(a.rule_name, "cpu_high");
297 EXPECT_EQ(a.group_key, "infra");
298 EXPECT_EQ(a.labels.get("service"), "api");
299}
Defines conditions and behavior for alert triggering.
Definition alert_rule.h:82

References kcenon::monitoring::threshold_trigger::above(), kcenon::monitoring::alert_rule::add_label(), kcenon::monitoring::alert_rule::create_alert(), kcenon::monitoring::alert_rule::set_group(), kcenon::monitoring::alert_rule::set_metric_name(), kcenon::monitoring::alert_rule::set_severity(), kcenon::monitoring::alert_rule::set_summary(), and kcenon::monitoring::alert_rule::set_trigger().

Here is the call graph for this function:

◆ TEST() [25/42]

TEST ( AlertRuleTest ,
CreateAlertWithoutGroupUsesName  )

Definition at line 301 of file test_alert_manager.cpp.

301 {
302 alert_rule rule("test_rule");
303 rule.set_trigger(threshold_trigger::above(80.0));
304 auto a = rule.create_alert(90.0);
305 EXPECT_EQ(a.group_key, "test_rule");
306}

References kcenon::monitoring::threshold_trigger::above(), kcenon::monitoring::alert_rule::create_alert(), and kcenon::monitoring::alert_rule::set_trigger().

Here is the call graph for this function:

◆ TEST() [26/42]

TEST ( AlertRuleTest ,
DefaultSeverityIsWarning  )

Definition at line 314 of file test_alert_manager.cpp.

314 {
315 alert_rule rule("test");
316 EXPECT_EQ(rule.severity(), alert_severity::warning);
317}

References kcenon::monitoring::alert_rule::severity().

Here is the call graph for this function:

◆ TEST() [27/42]

TEST ( AlertRuleTest ,
DisabledRule  )

Definition at line 308 of file test_alert_manager.cpp.

308 {
309 alert_rule rule("test");
310 rule.set_enabled(false);
311 EXPECT_FALSE(rule.is_enabled());
312}

References kcenon::monitoring::alert_rule::is_enabled(), and kcenon::monitoring::alert_rule::set_enabled().

Here is the call graph for this function:

◆ TEST() [28/42]

TEST ( AlertRuleTest ,
FluentBuilder  )

Definition at line 226 of file test_alert_manager.cpp.

226 {
227 alert_rule rule("cpu_high");
228 rule.set_metric_name("cpu_usage")
229 .set_severity(alert_severity::critical)
230 .set_summary("CPU usage too high")
231 .set_description("CPU usage exceeded threshold")
232 .set_runbook_url("https://runbooks.example.com/cpu")
233 .add_label("team", "infra")
234 .add_label("env", "prod")
235 .set_group("system_health")
236 .set_evaluation_interval(15s)
237 .set_for_duration(5min)
238 .set_repeat_interval(10min)
239 .set_enabled(true)
240 .set_trigger(threshold_trigger::above(80.0));
241
242 EXPECT_EQ(rule.name(), "cpu_high");
243 EXPECT_EQ(rule.metric_name(), "cpu_usage");
244 EXPECT_EQ(rule.severity(), alert_severity::critical);
245 EXPECT_EQ(rule.annotations().summary, "CPU usage too high");
246 EXPECT_EQ(rule.annotations().description, "CPU usage exceeded threshold");
247 EXPECT_EQ(*rule.annotations().runbook_url, "https://runbooks.example.com/cpu");
248 EXPECT_EQ(rule.labels().get("team"), "infra");
249 EXPECT_EQ(rule.labels().get("env"), "prod");
250 EXPECT_EQ(rule.group(), "system_health");
251 EXPECT_TRUE(rule.is_enabled());
252 EXPECT_NE(rule.trigger(), nullptr);
253}

References kcenon::monitoring::threshold_trigger::above(), kcenon::monitoring::alert_rule::add_label(), kcenon::monitoring::alert_rule::annotations(), kcenon::monitoring::alert_annotations::description, kcenon::monitoring::alert_labels::get(), kcenon::monitoring::alert_rule::group(), kcenon::monitoring::alert_rule::is_enabled(), kcenon::monitoring::alert_rule::labels(), kcenon::monitoring::alert_rule::metric_name(), kcenon::monitoring::alert_rule::name(), kcenon::monitoring::alert_annotations::runbook_url, kcenon::monitoring::alert_rule::set_description(), kcenon::monitoring::alert_rule::set_enabled(), kcenon::monitoring::alert_rule::set_evaluation_interval(), kcenon::monitoring::alert_rule::set_for_duration(), kcenon::monitoring::alert_rule::set_group(), kcenon::monitoring::alert_rule::set_metric_name(), kcenon::monitoring::alert_rule::set_repeat_interval(), kcenon::monitoring::alert_rule::set_runbook_url(), kcenon::monitoring::alert_rule::set_severity(), kcenon::monitoring::alert_rule::set_summary(), kcenon::monitoring::alert_rule::set_trigger(), kcenon::monitoring::alert_rule::severity(), kcenon::monitoring::alert_annotations::summary, and kcenon::monitoring::alert_rule::trigger().

Here is the call graph for this function:

◆ TEST() [29/42]

TEST ( AlertRuleTest ,
ValidateEmptyNameFails  )

Definition at line 262 of file test_alert_manager.cpp.

262 {
263 alert_rule rule("");
264 rule.set_trigger(threshold_trigger::above(80.0));
265 auto result = rule.validate();
266 EXPECT_FALSE(result.is_ok());
267}

References kcenon::monitoring::threshold_trigger::above(), kcenon::monitoring::alert_rule::set_trigger(), and kcenon::monitoring::alert_rule::validate().

Here is the call graph for this function:

◆ TEST() [30/42]

TEST ( AlertRuleTest ,
ValidateInvalidConfigFails  )

Definition at line 275 of file test_alert_manager.cpp.

275 {
276 alert_rule rule("test");
277 rule.set_trigger(threshold_trigger::above(80.0))
278 .set_evaluation_interval(0ms);
279 auto result = rule.validate();
280 EXPECT_FALSE(result.is_ok());
281}

References kcenon::monitoring::threshold_trigger::above(), kcenon::monitoring::alert_rule::set_evaluation_interval(), kcenon::monitoring::alert_rule::set_trigger(), and kcenon::monitoring::alert_rule::validate().

Here is the call graph for this function:

◆ TEST() [31/42]

TEST ( AlertRuleTest ,
ValidateNoTriggerFails  )

Definition at line 269 of file test_alert_manager.cpp.

269 {
270 alert_rule rule("test");
271 auto result = rule.validate();
272 EXPECT_FALSE(result.is_ok());
273}

References kcenon::monitoring::alert_rule::validate().

Here is the call graph for this function:

◆ TEST() [32/42]

TEST ( AlertRuleTest ,
ValidateSuccess  )

Definition at line 255 of file test_alert_manager.cpp.

255 {
256 alert_rule rule("test");
257 rule.set_trigger(threshold_trigger::above(80.0));
258 auto result = rule.validate();
259 EXPECT_TRUE(result.is_ok());
260}

References kcenon::monitoring::threshold_trigger::above(), kcenon::monitoring::alert_rule::set_trigger(), and kcenon::monitoring::alert_rule::validate().

Here is the call graph for this function:

◆ TEST() [33/42]

TEST ( CallbackNotifierTest ,
IsReadyWithCallback  )

Definition at line 651 of file test_alert_manager.cpp.

651 {
652 auto notifier = std::make_shared<callback_notifier>(
653 "test", [](const alert&) {});
654 EXPECT_TRUE(notifier->is_ready());
655}
Core alert data structure.

◆ TEST() [34/42]

TEST ( CallbackNotifierTest ,
NameIsCorrect  )

Definition at line 645 of file test_alert_manager.cpp.

645 {
646 auto notifier = std::make_shared<callback_notifier>(
647 "my_notifier", [](const alert&) {});
648 EXPECT_EQ(notifier->name(), "my_notifier");
649}

◆ TEST() [35/42]

TEST ( CallbackNotifierTest ,
NotifyGroupFallsBackToIndividual  )

Definition at line 629 of file test_alert_manager.cpp.

629 {
630 std::atomic<int> individual_count{0};
631 auto notifier = std::make_shared<callback_notifier>(
632 "test_cb",
633 [&](const alert& /*a*/) { individual_count++; },
634 nullptr); // No group callback
635
636 alert_group group("test");
637 group.add_alert(alert{});
638 group.add_alert(alert{});
639
640 auto result = notifier->notify_group(group);
641 EXPECT_TRUE(result.is_ok());
642 EXPECT_EQ(individual_count.load(), 2);
643}
Group of related alerts for batch notification.

◆ TEST() [36/42]

TEST ( CallbackNotifierTest ,
NotifyGroupInvokesGroupCallback  )

Definition at line 616 of file test_alert_manager.cpp.

616 {
617 std::atomic<int> group_count{0};
618 auto notifier = std::make_shared<callback_notifier>(
619 "test_cb",
620 [](const alert&) {},
621 [&](const alert_group& /*g*/) { group_count++; });
622
623 alert_group group("test");
624 auto result = notifier->notify_group(group);
625 EXPECT_TRUE(result.is_ok());
626 EXPECT_EQ(group_count.load(), 1);
627}

◆ TEST() [37/42]

TEST ( CallbackNotifierTest ,
NotifyInvokesCallback  )

Definition at line 604 of file test_alert_manager.cpp.

604 {
605 std::atomic<int> count{0};
606 auto notifier = std::make_shared<callback_notifier>(
607 "test_cb",
608 [&](const alert& /*a*/) { count++; });
609
610 alert test_alert;
611 auto result = notifier->notify(test_alert);
612 EXPECT_TRUE(result.is_ok());
613 EXPECT_EQ(count.load(), 1);
614}

◆ TEST() [38/42]

TEST ( CallbackNotifierTest ,
NotifyWithNullCallbackFails  )

Definition at line 663 of file test_alert_manager.cpp.

663 {
664 auto notifier = std::make_shared<callback_notifier>(
665 "test", nullptr);
666 alert a;
667 auto result = notifier->notify(a);
668 EXPECT_FALSE(result.is_ok());
669}

◆ TEST() [39/42]

TEST ( CallbackNotifierTest ,
NotReadyWithoutCallback  )

Definition at line 657 of file test_alert_manager.cpp.

657 {
658 auto notifier = std::make_shared<callback_notifier>(
659 "test", nullptr);
660 EXPECT_FALSE(notifier->is_ready());
661}

◆ TEST() [40/42]

TEST ( LogNotifierTest ,
CustomName  )

Definition at line 680 of file test_alert_manager.cpp.

680 {
681 log_notifier notifier("custom_logger");
682 EXPECT_EQ(notifier.name(), "custom_logger");
683}
Simple notifier that logs alerts.

References kcenon::monitoring::log_notifier::name().

Here is the call graph for this function:

◆ TEST() [41/42]

TEST ( LogNotifierTest ,
DefaultName  )

Definition at line 675 of file test_alert_manager.cpp.

675 {
676 log_notifier notifier;
677 EXPECT_EQ(notifier.name(), "log_notifier");
678}
std::string name() const override
Get the name of this log notifier.

References kcenon::monitoring::log_notifier::name().

Here is the call graph for this function:

◆ TEST() [42/42]

TEST ( LogNotifierTest ,
IsAlwaysReady  )

Definition at line 685 of file test_alert_manager.cpp.

685 {
686 log_notifier notifier;
687 EXPECT_TRUE(notifier.is_ready());
688}
bool is_ready() const override
Check if the log notifier is ready.

References kcenon::monitoring::log_notifier::is_ready().

Here is the call graph for this function:

◆ TEST_F() [1/35]

TEST_F ( AlertManagerLifecycleTest ,
ConstructWithConfig  )

Definition at line 112 of file test_alert_manager.cpp.

112 {
113 alert_manager manager(config_);
114 EXPECT_FALSE(manager.is_running());
115 EXPECT_EQ(manager.config().default_evaluation_interval, 100ms);
116}

References kcenon::monitoring::alert_manager::config(), kcenon::monitoring::alert_manager_config::default_evaluation_interval, and kcenon::monitoring::alert_manager::is_running().

Here is the call graph for this function:

◆ TEST_F() [2/35]

TEST_F ( AlertManagerLifecycleTest ,
DefaultConstruction  )

Definition at line 107 of file test_alert_manager.cpp.

107 {
108 alert_manager manager;
109 EXPECT_FALSE(manager.is_running());
110}
bool is_running() const
Check if manager is running.

References kcenon::monitoring::alert_manager::is_running().

Here is the call graph for this function:

◆ TEST_F() [3/35]

TEST_F ( AlertManagerLifecycleTest ,
DestructorStopsManager  )

Definition at line 142 of file test_alert_manager.cpp.

142 {
143 {
144 alert_manager manager(config_);
145 manager.start();
146 EXPECT_TRUE(manager.is_running());
147 }
148 // Destructor should cleanly stop without crash
149 SUCCEED();
150}

References kcenon::monitoring::alert_manager::is_running(), and kcenon::monitoring::alert_manager::start().

Here is the call graph for this function:

◆ TEST_F() [4/35]

TEST_F ( AlertManagerLifecycleTest ,
DoubleStartFails  )

Definition at line 129 of file test_alert_manager.cpp.

129 {
130 alert_manager manager(config_);
131 EXPECT_TRUE(manager.start().is_ok());
132 EXPECT_FALSE(manager.start().is_ok());
133 manager.stop();
134}

References kcenon::monitoring::alert_manager::start(), and kcenon::monitoring::alert_manager::stop().

Here is the call graph for this function:

◆ TEST_F() [5/35]

TEST_F ( AlertManagerLifecycleTest ,
StartAndStop  )

Definition at line 118 of file test_alert_manager.cpp.

118 {
119 alert_manager manager(config_);
120 auto start_result = manager.start();
121 EXPECT_TRUE(start_result.is_ok());
122 EXPECT_TRUE(manager.is_running());
123
124 auto stop_result = manager.stop();
125 EXPECT_TRUE(stop_result.is_ok());
126 EXPECT_FALSE(manager.is_running());
127}

References kcenon::monitoring::alert_manager::is_running(), kcenon::monitoring::alert_manager::start(), and kcenon::monitoring::alert_manager::stop().

Here is the call graph for this function:

◆ TEST_F() [6/35]

TEST_F ( AlertManagerLifecycleTest ,
StopWithoutStartIsOk  )

Definition at line 136 of file test_alert_manager.cpp.

136 {
137 alert_manager manager(config_);
138 auto result = manager.stop();
139 EXPECT_TRUE(result.is_ok());
140}

References kcenon::monitoring::alert_manager::stop().

Here is the call graph for this function:

◆ TEST_F() [7/35]

TEST_F ( AlertManagerNotifierTest ,
AddNotifier  )

Definition at line 569 of file test_alert_manager.cpp.

569 {
570 auto notifier = std::make_shared<log_notifier>("test_log");
571 auto result = manager_.add_notifier(notifier);
572 EXPECT_TRUE(result.is_ok());
573}

◆ TEST_F() [8/35]

TEST_F ( AlertManagerNotifierTest ,
AddNullNotifierFails  )

Definition at line 575 of file test_alert_manager.cpp.

575 {
576 auto result = manager_.add_notifier(nullptr);
577 EXPECT_FALSE(result.is_ok());
578}

◆ TEST_F() [9/35]

TEST_F ( AlertManagerNotifierTest ,
GetNotifiers  )

Definition at line 592 of file test_alert_manager.cpp.

592 {
593 manager_.add_notifier(std::make_shared<log_notifier>("n1"));
594 manager_.add_notifier(std::make_shared<log_notifier>("n2"));
595
596 auto notifiers = manager_.get_notifiers();
597 EXPECT_EQ(notifiers.size(), 2u);
598}

◆ TEST_F() [10/35]

TEST_F ( AlertManagerNotifierTest ,
RemoveNonexistentNotifier  )

Definition at line 587 of file test_alert_manager.cpp.

587 {
588 auto result = manager_.remove_notifier("missing");
589 EXPECT_FALSE(result.is_ok());
590}

◆ TEST_F() [11/35]

TEST_F ( AlertManagerNotifierTest ,
RemoveNotifier  )

Definition at line 580 of file test_alert_manager.cpp.

580 {
581 auto notifier = std::make_shared<log_notifier>("removable");
582 manager_.add_notifier(notifier);
583 auto result = manager_.remove_notifier("removable");
584 EXPECT_TRUE(result.is_ok());
585}

◆ TEST_F() [12/35]

TEST_F ( AlertManagerProcessingTest ,
MetricsTrackRulesEvaluated  )

Definition at line 449 of file test_alert_manager.cpp.

449 {
450 manager_.process_metric("cpu_usage", 50.0);
451 auto metrics = manager_.get_metrics();
452 EXPECT_GE(metrics.rules_evaluated.load(), 1u);
453}

◆ TEST_F() [13/35]

TEST_F ( AlertManagerProcessingTest ,
ProcessBatchMetrics  )

Definition at line 439 of file test_alert_manager.cpp.

439 {
440 std::unordered_map<std::string, double> metrics{
441 {"cpu_usage", 95.0},
442 {"memory_usage", 85.0},
443 {"disk_usage", 50.0}};
444
445 auto result = manager_.process_metrics(metrics);
446 EXPECT_TRUE(result.is_ok());
447}

◆ TEST_F() [14/35]

TEST_F ( AlertManagerProcessingTest ,
ProcessMetricAboveThreshold  )

Definition at line 424 of file test_alert_manager.cpp.

424 {
425 auto result = manager_.process_metric("cpu_usage", 95.0);
426 EXPECT_TRUE(result.is_ok());
427
428 auto alerts = manager_.get_active_alerts();
429 // Should have at least one active alert
430 EXPECT_GE(alerts.size(), 0u); // Implementation may require manager to be running
431}

◆ TEST_F() [15/35]

TEST_F ( AlertManagerProcessingTest ,
ProcessMetricBelowThreshold  )

Definition at line 416 of file test_alert_manager.cpp.

416 {
417 auto result = manager_.process_metric("cpu_usage", 50.0);
418 EXPECT_TRUE(result.is_ok());
419
420 auto alerts = manager_.get_active_alerts();
421 EXPECT_TRUE(alerts.empty());
422}

◆ TEST_F() [16/35]

TEST_F ( AlertManagerProcessingTest ,
ProcessUnknownMetric  )

Definition at line 433 of file test_alert_manager.cpp.

433 {
434 // Processing a metric with no matching rule should still succeed
435 auto result = manager_.process_metric("unknown_metric", 42.0);
436 EXPECT_TRUE(result.is_ok());
437}

◆ TEST_F() [17/35]

TEST_F ( AlertManagerResolutionTest ,
GetAlertByFingerprint  )

Definition at line 470 of file test_alert_manager.cpp.

470 {
471 // With no alerts, should return empty optional
472 auto alert_opt = manager_.get_alert("nonexistent");
473 EXPECT_FALSE(alert_opt.has_value());
474}

◆ TEST_F() [18/35]

TEST_F ( AlertManagerResolutionTest ,
ResolveNonexistentAlert  )

Definition at line 464 of file test_alert_manager.cpp.

464 {
465 auto result = manager_.resolve_alert("nonexistent_fingerprint");
466 // Should fail gracefully for nonexistent alert
467 EXPECT_FALSE(result.is_ok());
468}

References kcenon::monitoring::alert_manager::resolve_alert().

Here is the call graph for this function:

◆ TEST_F() [19/35]

TEST_F ( AlertManagerRuleTest ,
AddNullRuleFails  )

Definition at line 177 of file test_alert_manager.cpp.

177 {
178 auto result = manager_.add_rule(nullptr);
179 EXPECT_FALSE(result.is_ok());
180}

◆ TEST_F() [20/35]

TEST_F ( AlertManagerRuleTest ,
AddRule  )

Definition at line 171 of file test_alert_manager.cpp.

171 {
172 auto rule = create_rule("test_rule");
173 auto result = manager_.add_rule(rule);
174 EXPECT_TRUE(result.is_ok());
175}

◆ TEST_F() [21/35]

TEST_F ( AlertManagerRuleTest ,
GetAllRules  )

Definition at line 208 of file test_alert_manager.cpp.

208 {
209 manager_.add_rule(create_rule("rule1"));
210 manager_.add_rule(create_rule("rule2"));
211 manager_.add_rule(create_rule("rule3"));
212
213 auto rules = manager_.get_rules();
214 EXPECT_EQ(rules.size(), 3u);
215}

◆ TEST_F() [22/35]

TEST_F ( AlertManagerRuleTest ,
GetExistingRule  )

Definition at line 182 of file test_alert_manager.cpp.

182 {
183 auto rule = create_rule("get_test");
184 manager_.add_rule(rule);
185
186 auto retrieved = manager_.get_rule("get_test");
187 ASSERT_NE(retrieved, nullptr);
188 EXPECT_EQ(retrieved->name(), "get_test");
189}

◆ TEST_F() [23/35]

TEST_F ( AlertManagerRuleTest ,
GetNonexistentRuleReturnsNull  )

Definition at line 191 of file test_alert_manager.cpp.

191 {
192 auto retrieved = manager_.get_rule("missing");
193 EXPECT_EQ(retrieved, nullptr);
194}

◆ TEST_F() [24/35]

TEST_F ( AlertManagerRuleTest ,
GetRulesEmpty  )

Definition at line 217 of file test_alert_manager.cpp.

217 {
218 auto rules = manager_.get_rules();
219 EXPECT_TRUE(rules.empty());
220}

◆ TEST_F() [25/35]

TEST_F ( AlertManagerRuleTest ,
RemoveExistingRule  )

Definition at line 196 of file test_alert_manager.cpp.

196 {
197 manager_.add_rule(create_rule("to_remove"));
198 auto result = manager_.remove_rule("to_remove");
199 EXPECT_TRUE(result.is_ok());
200 EXPECT_EQ(manager_.get_rule("to_remove"), nullptr);
201}

◆ TEST_F() [26/35]

TEST_F ( AlertManagerRuleTest ,
RemoveNonexistentRuleFails  )

Definition at line 203 of file test_alert_manager.cpp.

203 {
204 auto result = manager_.remove_rule("missing");
205 EXPECT_FALSE(result.is_ok());
206}

◆ TEST_F() [27/35]

TEST_F ( AlertManagerSilenceTest ,
CreateSilence  )

Definition at line 485 of file test_alert_manager.cpp.

485 {
486 alert_silence silence;
487 silence.matchers.set("service", "api");
488 silence.comment = "Maintenance window";
489
490 auto result = manager_.create_silence(silence);
491 EXPECT_TRUE(result.is_ok());
492}
void set(const std::string &key, const std::string &value)
Add or update a label.
Silence configuration to suppress alerts.
alert_labels matchers
Labels to match.
std::string comment
Reason for silence.

References kcenon::monitoring::alert_silence::comment, kcenon::monitoring::alert_silence::matchers, and kcenon::monitoring::alert_labels::set().

Here is the call graph for this function:

◆ TEST_F() [28/35]

TEST_F ( AlertManagerSilenceTest ,
CreateSilenceReturnsId  )

Definition at line 494 of file test_alert_manager.cpp.

494 {
495 alert_silence silence;
496 silence.id = 42;
497 auto result = manager_.create_silence(silence);
498 ASSERT_TRUE(result.is_ok());
499 EXPECT_EQ(result.value(), 42u);
500}

References kcenon::monitoring::alert_silence::id.

◆ TEST_F() [29/35]

TEST_F ( AlertManagerSilenceTest ,
DeleteNonexistentSilence  )

Definition at line 511 of file test_alert_manager.cpp.

511 {
512 auto result = manager_.delete_silence(99999);
513 EXPECT_FALSE(result.is_ok());
514}

◆ TEST_F() [30/35]

TEST_F ( AlertManagerSilenceTest ,
DeleteSilence  )

Definition at line 502 of file test_alert_manager.cpp.

502 {
503 alert_silence silence;
504 auto create_result = manager_.create_silence(silence);
505 ASSERT_TRUE(create_result.is_ok());
506
507 auto delete_result = manager_.delete_silence(create_result.value());
508 EXPECT_TRUE(delete_result.is_ok());
509}
Result of collector creation.

◆ TEST_F() [31/35]

TEST_F ( AlertManagerSilenceTest ,
GetSilences  )

Definition at line 516 of file test_alert_manager.cpp.

516 {
517 alert_silence s1;
518 s1.matchers.set("env", "prod");
519 manager_.create_silence(s1);
520
521 alert_silence s2;
522 s2.matchers.set("env", "staging");
523 manager_.create_silence(s2);
524
525 auto silences = manager_.get_silences();
526 EXPECT_EQ(silences.size(), 2u);
527}

References kcenon::monitoring::alert_silence::matchers, and kcenon::monitoring::alert_labels::set().

Here is the call graph for this function:

◆ TEST_F() [32/35]

TEST_F ( AlertManagerSilenceTest ,
GetSilencesEmpty  )

Definition at line 529 of file test_alert_manager.cpp.

529 {
530 auto silences = manager_.get_silences();
531 EXPECT_TRUE(silences.empty());
532}

◆ TEST_F() [33/35]

TEST_F ( AlertManagerSilenceTest ,
IsNotSilencedNonMatchingAlert  )

Definition at line 544 of file test_alert_manager.cpp.

544 {
545 alert_silence silence;
546 silence.matchers.set("service", "api");
547 manager_.create_silence(silence);
548
549 alert a;
550 a.labels.set("service", "web");
551 EXPECT_FALSE(manager_.is_silenced(a));
552}
alert_labels labels
Identifying labels.

References kcenon::monitoring::alert::labels, kcenon::monitoring::alert_silence::matchers, and kcenon::monitoring::alert_labels::set().

Here is the call graph for this function:

◆ TEST_F() [34/35]

TEST_F ( AlertManagerSilenceTest ,
IsNotSilencedNoSilences  )

Definition at line 554 of file test_alert_manager.cpp.

554 {
555 alert a;
556 a.labels.set("service", "api");
557 EXPECT_FALSE(manager_.is_silenced(a));
558}

References kcenon::monitoring::alert::labels, and kcenon::monitoring::alert_labels::set().

Here is the call graph for this function:

◆ TEST_F() [35/35]

TEST_F ( AlertManagerSilenceTest ,
IsSilencedMatchingAlert  )

Definition at line 534 of file test_alert_manager.cpp.

534 {
535 alert_silence silence;
536 silence.matchers.set("service", "api");
537 manager_.create_silence(silence);
538
539 alert a;
540 a.labels.set("service", "api");
541 EXPECT_TRUE(manager_.is_silenced(a));
542}

References kcenon::monitoring::alert::labels, kcenon::monitoring::alert_silence::matchers, and kcenon::monitoring::alert_labels::set().

Here is the call graph for this function: