Skip to content
This repository was archived by the owner on Oct 6, 2023. It is now read-only.

Commit d24da52

Browse files
committed
fix(broker/bam): fix inherited downtimes duplicated
* enh(broker/bam): log on cache more explicit * fix(bam): engine restart does not duplicate ba downtimes * fix(bam): downtime are well restored after a restart of cbd * enh(bam): flat_hash_map is better for host/svc mapping * cleanup(various): logs and coding style * enh(bam): better iteration while erasing data * cleanup(ceof): no more needed * fix(applier::endpoint): protection of stop() call REFS: MON-12068
1 parent 538ef38 commit d24da52

File tree

40 files changed

+135
-948
lines changed

40 files changed

+135
-948
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ the kpi were in critical, the state appeared as OK.
3535
The cache in bam is lighter, metrics are no
3636
more loaded. And queries to load the cache are parallelized.
3737

38+
Inherited downtimes were duplicated on cbd reload. This is fixed.
39+
3840
*mysql_connection*
3941

4042
A timeout is added on mysql\_ping and this function is less called than before.

CMakeLists.txt

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -389,12 +389,6 @@ set(LIBROKER_SOURCES
389389
${SRC_DIR}/bbdo/version_response.cc
390390
${SRC_DIR}/broker_impl.cc
391391
${SRC_DIR}/brokerrpc.cc
392-
${SRC_DIR}/ceof/ceof_deserializer.cc
393-
${SRC_DIR}/ceof/ceof_iterator.cc
394-
${SRC_DIR}/ceof/ceof_parser.cc
395-
${SRC_DIR}/ceof/ceof_serializer.cc
396-
${SRC_DIR}/ceof/ceof_token.cc
397-
${SRC_DIR}/ceof/ceof_writer.cc
398392
${SRC_DIR}/compression/factory.cc
399393
${SRC_DIR}/compression/opener.cc
400394
${SRC_DIR}/compression/stack_array.cc
@@ -479,14 +473,6 @@ set(LIBROKER_SOURCES
479473
${INC_DIR}/bbdo/version_response.hh
480474
${INC_DIR}/broker_impl.hh
481475
${INC_DIR}/brokerrpc.hh
482-
${INC_DIR}/ceof/ceof_deserializer.hh
483-
${INC_DIR}/ceof/ceof_iterator.hh
484-
${INC_DIR}/ceof/ceof_parser.hh
485-
${INC_DIR}/ceof/ceof_serializable.hh
486-
${INC_DIR}/ceof/ceof_serializer.hh
487-
${INC_DIR}/ceof/ceof_token.hh
488-
${INC_DIR}/ceof/ceof_visitor.hh
489-
${INC_DIR}/ceof/ceof_writer.hh
490476
${INC_DIR}/compression/factory.hh
491477
${INC_DIR}/compression/opener.hh
492478
${INC_DIR}/compression/stack_array.hh

bam/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ add_library("${BAM}" SHARED
162162
)
163163
set_target_properties("${BAM}" PROPERTIES
164164
PREFIX "")
165+
target_link_libraries("${BAM}" ${absl_LIBS})
165166

166167
# Testing.
167168
if (WITH_SQL_TESTS)

bam/inc/com/centreon/broker/bam/configuration/applier/ba.hh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,8 @@ class ba {
6767
std::shared_ptr<neb::host> _ba_host(uint32_t host_id);
6868
std::shared_ptr<neb::service> _ba_service(uint32_t ba_id,
6969
uint32_t host_id,
70-
uint32_t service_id);
70+
uint32_t service_id,
71+
bool in_downtime = false);
7172
void _internal_copy(ba const& other);
7273
std::shared_ptr<bam::ba> _new_ba(configuration::ba const& cfg,
7374
service_book& book);

bam/inc/com/centreon/broker/bam/hst_svc_mapping.hh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,7 @@
1919
#ifndef CCB_BAM_HST_SVC_MAPPING_HH
2020
#define CCB_BAM_HST_SVC_MAPPING_HH
2121

22-
#include "com/centreon/broker/misc/pair.hh"
23-
#include <unordered_map>
22+
#include <absl/container/flat_hash_map.h>
2423
#include <string>
2524
#include <utility>
2625

@@ -37,10 +36,11 @@ namespace bam {
3736
* Allow to find an ID of a host or service by its name.
3837
*/
3938
class hst_svc_mapping {
40-
std::unordered_map<std::pair<std::string, std::string>, std::pair<uint32_t, uint32_t>>
39+
absl::flat_hash_map<std::pair<std::string, std::string>,
40+
std::pair<uint32_t, uint32_t>>
4141
_mapping;
4242

43-
std::unordered_map<std::pair<uint32_t, uint32_t>, bool> _activated_mapping;
43+
absl::flat_hash_map<std::pair<uint32_t, uint32_t>, bool> _activated_mapping;
4444

4545
public:
4646
hst_svc_mapping() = default;

bam/inc/com/centreon/broker/bam/kpi_service.hh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#define CCB_BAM_KPI_SERVICE_HH
2121

2222
#include <array>
23+
#include <absl/container/flat_hash_set.h>
2324
#include "com/centreon/broker/bam/kpi.hh"
2425
#include "com/centreon/broker/bam/kpi_event.hh"
2526
#include "com/centreon/broker/bam/service_listener.hh"
@@ -50,6 +51,7 @@ class kpi_service : public service_listener, public kpi {
5051

5152
bool _acknowledged;
5253
bool _downtimed;
54+
absl::flat_hash_set<uint32_t> _downtime_ids;
5355
std::array<double, 5> _impacts;
5456
timestamp _last_check;
5557
std::string _output;

bam/src/ba.cc

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -508,13 +508,17 @@ void ba::visit(io::stream* visitor) {
508508
short hard_state(get_state_hard());
509509
bool state_changed(false);
510510
if (!_event) {
511+
log_v2::bam()->trace("BAM: ba::visit no event => creation of one");
511512
if (_last_kpi_update.is_null())
512513
_last_kpi_update = time(nullptr);
513514
_open_new_event(visitor, hard_state);
514515
}
515516
// If state changed, close event and open a new one.
516517
else if (_in_downtime != _event->in_downtime ||
517518
hard_state != _event->status) {
519+
log_v2::bam()->trace(
520+
"BAM: ba::visit event needs update downtime: {}, state: {}",
521+
_in_downtime != _event->in_downtime, hard_state != _event->status);
518522
state_changed = true;
519523
_event->end_time = _last_kpi_update;
520524
visitor->write(std::static_pointer_cast<io::data>(_event));
@@ -546,7 +550,7 @@ void ba::visit(io::stream* visitor) {
546550

547551
// Generate virtual service status event.
548552
if (_generate_virtual_status) {
549-
std::shared_ptr<neb::service_status> status(new neb::service_status);
553+
auto status{std::make_shared<neb::service_status>()};
550554
status->active_checks_enabled = false;
551555
status->check_interval = 0.0;
552556
status->check_type = 1; // Passive.
@@ -558,6 +562,7 @@ void ba::visit(io::stream* visitor) {
558562
status->flap_detection_enabled = false;
559563
status->has_been_checked = true;
560564
status->host_id = _host_id;
565+
status->downtime_depth = _in_downtime;
561566
// status->host_name = XXX;
562567
status->is_flapping = false;
563568
if (_event)
@@ -602,7 +607,7 @@ void ba::visit(io::stream* visitor) {
602607
void ba::service_update(const std::shared_ptr<neb::downtime>& dt,
603608
io::stream* visitor) {
604609
(void)visitor;
605-
if ((dt->host_id == _host_id) && (dt->service_id == _service_id)) {
610+
if (dt->host_id == _host_id && dt->service_id == _service_id) {
606611
// Log message.
607612
log_v2::bam()->debug(
608613
"BAM: BA {} '{}' is getting notified of a downtime on its service ({}, "
@@ -645,8 +650,10 @@ void ba::save_inherited_downtime(persistent_cache& cache) const {
645650
*
646651
* @param[in] dwn The inherited downtime.
647652
*/
648-
void ba::set_inherited_downtime(inherited_downtime const& dwn) {
653+
void ba::set_inherited_downtime(const inherited_downtime& dwn) {
649654
_inherited_downtime.reset(new inherited_downtime(dwn));
655+
if (_inherited_downtime->in_downtime)
656+
_in_downtime = true;
650657
}
651658

652659
/**

bam/src/bool_expression.cc

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@ bool bool_expression::child_has_update(computable* child, io::stream* visitor) {
4646
// class, as the bool_* classes already cache most of them.
4747
if (child == _expression.get()) {
4848
// Logging.
49-
log_v2::bam()->debug("BAM: boolean expression {} is getting notified of child update", _id);
49+
log_v2::bam()->debug(
50+
"BAM: boolean expression {} is getting notified of child update", _id);
5051
}
5152
return true;
5253
}
@@ -58,8 +59,8 @@ bool bool_expression::child_has_update(computable* child, io::stream* visitor) {
5859
*/
5960
impact_values::state bool_expression::get_state() const {
6061
return (_expression->value_hard() == _impact_if)
61-
? bool_expression::state::state_critical
62-
: bool_expression::state::state_ok;
62+
? bool_expression::state::state_critical
63+
: bool_expression::state::state_ok;
6364
}
6465

6566
/**

bam/src/configuration/applier/ba.cc

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -84,19 +84,15 @@ void applier::ba::apply(bam::configuration::state::bas const& my_bas,
8484
std::list<bam::configuration::ba> to_modify;
8585

8686
// Iterate through configuration.
87-
for (bam::configuration::state::bas::iterator it(to_create.begin()),
88-
end(to_create.end());
89-
it != end;) {
90-
std::map<uint32_t, applied>::iterator cfg_it(to_delete.find(it->first));
87+
for (auto it = to_create.begin(), end = to_create.end(); it != end;) {
88+
auto cfg_it = to_delete.find(it->first);
9189
// Found = modify (or not).
9290
if (cfg_it != to_delete.end()) {
9391
// Configuration mismatch, modify object.
9492
if (cfg_it->second.cfg != it->second)
9593
to_modify.push_back(it->second);
9694
to_delete.erase(cfg_it);
97-
bam::configuration::state::bas::iterator tmp = it;
98-
++it;
99-
to_create.erase(tmp);
95+
it = to_create.erase(it);
10096
}
10197
// Not found = create.
10298
else
@@ -220,13 +216,17 @@ std::shared_ptr<neb::host> applier::ba::_ba_host(uint32_t host_id) {
220216
*/
221217
std::shared_ptr<neb::service> applier::ba::_ba_service(uint32_t ba_id,
222218
uint32_t host_id,
223-
uint32_t service_id) {
224-
std::shared_ptr<neb::service> s(new neb::service);
219+
uint32_t service_id,
220+
bool in_downtime) {
221+
log_v2::bam()->trace("_ba_service ba {}, service {}:{} with downtime {}",
222+
ba_id, host_id, service_id, in_downtime);
223+
auto s{std::make_shared<neb::service>()};
225224
s->host_id = host_id;
226225
s->service_id = service_id;
227226
s->service_description = fmt::format("ba_{}", ba_id);
228227
s->display_name = s->service_description;
229228
s->last_update = time(nullptr);
229+
s->downtime_depth = in_downtime ? 1 : 0;
230230
return s;
231231
}
232232

@@ -282,6 +282,7 @@ void applier::ba::save_to_cache(persistent_cache& cache) {
282282
* @param[in] cache The cache.
283283
*/
284284
void applier::ba::load_from_cache(persistent_cache& cache) {
285+
log_v2::bam()->trace("BAM: loading inherited downtimes from cache");
285286
std::shared_ptr<io::data> d;
286287
cache.get(d);
287288
while (d) {
@@ -294,6 +295,9 @@ void applier::ba::load_from_cache(persistent_cache& cache) {
294295
log_v2::bam()->debug("BAM: found an inherited downtime for BA {}",
295296
found->first);
296297
found->second.obj->set_inherited_downtime(dwn);
298+
auto s = _ba_service(found->first, found->second.cfg.get_host_id(),
299+
found->second.cfg.get_service_id(), dwn.in_downtime);
300+
multiplexing::publisher().write(s);
297301
}
298302
cache.get(d);
299303
}

bam/src/configuration/applier/bool_expression.cc

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
#include "com/centreon/broker/bam/exp_builder.hh"
2525
#include "com/centreon/broker/bam/exp_parser.hh"
2626
#include "com/centreon/broker/bam/service_book.hh"
27-
#include "com/centreon/broker/logging/logging.hh"
2827
#include "com/centreon/broker/log_v2.hh"
2928

3029
using namespace com::centreon::broker;
@@ -86,8 +85,8 @@ void applier::bool_expression::apply(
8685
for (std::map<uint32_t, applied>::iterator it(to_delete.begin()),
8786
end(to_delete.end());
8887
it != end; ++it) {
89-
log_v2::bam()->info(
90-
"BAM: removing boolean expression {}", it->second.cfg.get_id());
88+
log_v2::bam()->info("BAM: removing boolean expression {}",
89+
it->second.cfg.get_id());
9190
for (std::list<bool_service::ptr>::const_iterator
9291
it2(it->second.svc.begin()),
9392
end2(it->second.svc.end());
@@ -102,8 +101,7 @@ void applier::bool_expression::apply(
102101
for (bam::configuration::state::bool_exps::iterator it(to_create.begin()),
103102
end(to_create.end());
104103
it != end; ++it) {
105-
log_v2::bam()->info(
106-
"BAM: creating new boolean expression {}", it->first);
104+
log_v2::bam()->info("BAM: creating new boolean expression {}", it->first);
107105
std::shared_ptr<bam::bool_expression> new_bool_exp(
108106
new bam::bool_expression);
109107
try {
@@ -131,9 +129,6 @@ void applier::bool_expression::apply(
131129
"BAM: could not create boolean expression {} so it will be "
132130
"discarded: {}",
133131
it->first, e.what());
134-
logging::error(logging::high)
135-
<< "BAM: could not create boolean expression " << it->first
136-
<< " so it will be discarded: " << e.what();
137132
}
138133
new_bool_exp->set_id(it->first);
139134
new_bool_exp->set_impact_if(it->second.get_impact_if());
@@ -178,11 +173,9 @@ void applier::bool_expression::_resolve_expression_calls() {
178173
_name_to_ids.find((*call_it)->get_name());
179174
if (found == _name_to_ids.end()) {
180175
log_v2::bam()->error(
181-
"BAM: could not resolve the external boolean called '{}' for expression '{}'", (*call_it)->get_name(), it->second.cfg.get_name());
182-
logging::error(logging::high)
183-
<< "BAM: could not resolve the external boolean called '"
184-
<< (*call_it)->get_name() << "' for expression '"
185-
<< it->second.cfg.get_name() << "'";
176+
"BAM: could not resolve the external boolean called '{}' for "
177+
"expression '{}'",
178+
(*call_it)->get_name(), it->second.cfg.get_name());
186179
break;
187180
} else {
188181
(*call_it)->set_expression(

0 commit comments

Comments
 (0)