Skip to content

Commit

Permalink
fix(broker/tests): issue between time_t cast from timestamp and fmt::…
Browse files Browse the repository at this point in the history
…format for timestamp fixed
  • Loading branch information
bouda1 committed Feb 7, 2024
1 parent e208f52 commit 942e2e2
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 32 deletions.
21 changes: 4 additions & 17 deletions broker/core/inc/com/centreon/broker/timestamp.hh
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,10 @@ struct timestamp {
static timestamp max() {
return timestamp(std::numeric_limits<time_t>::max());
}

std::string to_string() const {
return is_null() ? "NULL" : fmt::format("{}", _sec);
}
};

/**
Expand All @@ -170,21 +174,4 @@ inline time_t format_as(const timestamp& o) {

} // namespace com::centreon::broker

namespace fmt {
template <>
struct formatter<com::centreon::broker::timestamp> {
constexpr auto parse(format_parse_context& ctx)
-> format_parse_context::iterator {
return ctx.begin();
}

auto format(const com::centreon::broker::timestamp& t,
format_context& ctx) const -> format_context::iterator {
// ctx.out() is an output iterator to write to.
return t.is_null() ? fmt::format_to(ctx.out(), "NULL")
: fmt::format_to(ctx.out(), "{}", t.get_time_t());
}
};
} // namespace fmt

#endif // !CCB_TIMESTAMP_HH
38 changes: 23 additions & 15 deletions broker/unified_sql/src/stream_sql.cc
Original file line number Diff line number Diff line change
Expand Up @@ -583,16 +583,16 @@ void stream::_process_comment(const std::shared_ptr<io::data>& d) {
if (cmmnt.deletion_time.is_null())
b.set_null_i64(3);
else
b.set_value_as_i64(3, cmmnt.deletion_time.get_time_t());
b.set_value_as_i64(3, cmmnt.deletion_time);
if (cmmnt.entry_time.is_null())
b.set_null_i64(4);
else
b.set_value_as_i64(4, cmmnt.entry_time.get_time_t());
b.set_value_as_i64(4, cmmnt.entry_time);
b.set_value_as_i32(5, cmmnt.entry_type);
if (cmmnt.expire_time.is_null())
b.set_null_i64(6);
else
b.set_value_as_i64(6, cmmnt.expire_time.get_time_t());
b.set_value_as_i64(6, cmmnt.expire_time);
b.set_value_as_tiny(7, cmmnt.expires);
b.set_value_as_i64(8, cmmnt.host_id, mapping::entry::invalid_on_zero);
b.set_value_as_i64(9, cmmnt.internal_id);
Expand Down Expand Up @@ -875,28 +875,28 @@ void stream::_process_downtime(const std::shared_ptr<io::data>& d) {
if (dd.actual_end_time.is_null())
b.set_null_i64(0);
else
b.set_value_as_i64(0, dd.actual_end_time.get_time_t());
b.set_value_as_i64(0, dd.actual_end_time);
if (dd.actual_start_time.is_null())
b.set_null_i64(1);
else
b.set_value_as_i64(1, dd.actual_start_time.get_time_t());
b.set_value_as_i64(1, dd.actual_start_time);
b.set_value_as_str(
2, misc::string::escape(dd.author,
get_downtimes_col_size(downtimes_author)));
b.set_value_as_i32(3, dd.downtime_type);
if (dd.deletion_time.is_null())
b.set_null_i64(4);
else
b.set_value_as_i64(4, dd.deletion_time.get_time_t());
b.set_value_as_i64(4, dd.deletion_time);
b.set_value_as_i64(5, dd.duration);
if (dd.end_time.is_null())
b.set_null_i64(6);
else
b.set_value_as_i64(6, dd.end_time.get_time_t());
b.set_value_as_i64(6, dd.end_time);
if (dd.entry_time.is_null())
b.set_null_i64(7);
else
b.set_value_as_i64(7, dd.entry_time.get_time_t());
b.set_value_as_i64(7, dd.entry_time);
b.set_value_as_tiny(8, int(dd.fixed));
b.set_value_as_i64(9, dd.host_id);
b.set_value_as_i64(10, dd.poller_id);
Expand All @@ -905,7 +905,7 @@ void stream::_process_downtime(const std::shared_ptr<io::data>& d) {
if (dd.start_time.is_null())
b.set_null_i64(13);
else
b.set_value_as_i64(13, dd.start_time.get_time_t());
b.set_value_as_i64(13, dd.start_time);
if (dd.triggered_by == 0)
b.set_null_i32(14);
else
Expand All @@ -919,15 +919,20 @@ void stream::_process_downtime(const std::shared_ptr<io::data>& d) {
};
_downtimes->add_bulk_row(binder);
} else {
log_v2::sql()->error("original actual end time {} is null {}",
dd.actual_end_time.get_time_t(),
dd.actual_end_time.is_null());
log_v2::sql()->error("actual end time {}", dd.actual_end_time);
_downtimes->add_multi_row(fmt::format(
"({},{},'{}',{},{},{},{},{},{},{},{},{},{},{},{},{},{},'{}')",
dd.actual_end_time, dd.actual_start_time,
dd.actual_end_time.to_string(), dd.actual_start_time.to_string(),
misc::string::escape(dd.author,
get_downtimes_col_size(downtimes_author)),
dd.downtime_type, dd.deletion_time, dd.duration, dd.end_time,
dd.entry_time, dd.fixed, dd.host_id, dd.poller_id, dd.internal_id,
dd.service_id, dd.start_time, int64_not_minus_one{dd.triggered_by},
dd.was_cancelled, dd.was_started,
dd.downtime_type, dd.deletion_time.to_string(), dd.duration,
dd.end_time.to_string(), dd.entry_time.to_string(), dd.fixed,
dd.host_id, dd.poller_id, dd.internal_id, dd.service_id,
dd.start_time, int64_not_minus_one{dd.triggered_by}, dd.was_cancelled,
dd.was_started,
misc::string::escape(
dd.comment, get_downtimes_col_size(downtimes_comment_data))));
}
Expand Down Expand Up @@ -1000,6 +1005,9 @@ void stream::_process_pb_downtime(const std::shared_ptr<io::data>& d) {
};
_downtimes->add_bulk_row(binder);
} else {
log_v2::sql()->error("PB actual end time {} -> {}",
dt_obj.actual_end_time(),
uint64_not_null_not_neg_1{dt_obj.actual_end_time()});
_downtimes->add_multi_row(fmt::format(
"({},{},'{}',{},{},{},{},{},{},{},{},{},{},{},{},{},{},'{}')",
uint64_not_null_not_neg_1{dt_obj.actual_end_time()},
Expand Down Expand Up @@ -2801,7 +2809,7 @@ void stream::_process_log(const std::shared_ptr<io::data>& d) {
// Push query.
if (_logs->is_bulk()) {
auto binder = [&](database::mysql_bulk_bind& b) {
b.set_value_as_i64(0, le.c_time.get_time_t());
b.set_value_as_i64(0, le.c_time);
b.set_value_as_i64(1, le.host_id);
b.set_value_as_i64(2, le.service_id);
b.set_value_as_str(
Expand Down
5 changes: 5 additions & 0 deletions cmake-vcpkg.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ This program build Centreon-broker
-og : C++14 standard
-clang : Compilation with clang++
-mold : Link made with mold
-legacy-mold : Link made with mold but with an old gcc version
-dr : Debug robot enabled
-sccache : Compilation through sccache
-h|--help : help
Expand Down Expand Up @@ -67,6 +68,10 @@ do
MOLD=-fuse-ld=mold
shift
;;
-legacy-mold)
MOLD="-B /usr/bin/mold"
shift
;;
-sccache)
SC="1"
shift
Expand Down

0 comments on commit 942e2e2

Please sign in to comment.