10#include <userver/cache/update_type.hpp>
11#include <userver/utils/internal_tag_fwd.hpp>
12#include <userver/utils/statistics/fwd.hpp>
14USERVER_NAMESPACE_BEGIN
20struct UpdateStatistics
final {
21 std::atomic<std::size_t> update_attempt_count{0};
22 std::atomic<std::size_t> update_no_changes_count{0};
23 std::atomic<std::size_t> update_failures_count{0};
25 std::atomic<std::size_t> documents_read_count{0};
26 std::atomic<std::size_t> documents_parse_failures{0};
28 std::atomic<std::chrono::steady_clock::time_point> last_update_start_time{{}};
29 std::atomic<std::chrono::steady_clock::time_point>
30 last_successful_update_start_time{{}};
31 std::atomic<std::chrono::milliseconds> last_update_duration{{}};
34void DumpMetric(
utils::statistics::Writer& writer,
35 const UpdateStatistics& stats);
37struct Statistics
final {
38 UpdateStatistics full_update;
39 UpdateStatistics incremental_update;
40 std::atomic<std::size_t> documents_current_count{0};
43void DumpMetric(
utils::statistics::Writer& writer,
const Statistics& stats);
45enum class UpdateState { kNotFinished, kSuccess, kFailure };
53class UpdateStatisticsScope
final {
57 UpdateStatisticsScope(
impl::Statistics& stats, cache::
UpdateType type);
59 ~UpdateStatisticsScope();
61 impl::UpdateState GetState(
utils::InternalTag)
const;
66 void Finish(std::size_t total_documents_count);
87 void DoFinish(
impl::UpdateState new_state);
89 impl::Statistics& stats_;
90 impl::UpdateStatistics& update_stats_;
91 impl::UpdateState state_{
impl::UpdateState::kNotFinished};
92 const std::chrono::steady_clock::time_point update_start_time_;