10#include <userver/cache/update_type.hpp>
11#include <userver/utils/impl/internal_tag.hpp>
12#include <userver/utils/statistics/fwd.hpp>
13#include <userver/utils/statistics/rate_counter.hpp>
15USERVER_NAMESPACE_BEGIN
21struct UpdateStatistics
final {
22 utils::statistics::RateCounter update_attempt_count{0};
23 utils::statistics::RateCounter update_no_changes_count{0};
24 utils::statistics::RateCounter update_failures_count{0};
26 utils::statistics::RateCounter documents_read_count{0};
27 utils::statistics::RateCounter documents_parse_failures{0};
29 std::atomic<std::chrono::steady_clock::time_point> last_update_start_time{{}};
30 std::atomic<std::chrono::steady_clock::time_point> last_successful_update_start_time{{}};
31 std::atomic<std::chrono::milliseconds> last_update_duration{{}};
34void DumpMetric(
utils::statistics::Writer& writer,
const UpdateStatistics& stats);
36struct Statistics
final {
37 UpdateStatistics full_update;
38 UpdateStatistics incremental_update;
39 std::atomic<std::size_t> documents_current_count{0};
42void DumpMetric(
utils::statistics::Writer& writer,
const Statistics& stats);
44enum class UpdateState { kNotFinished, kSuccess, kNoChanges, kFailure };
55class UpdateStatisticsScope
final {
61 ~UpdateStatisticsScope();
64 impl::UpdateState GetState(
utils::impl::InternalTag)
const;
69 void Finish(std::size_t total_documents_count);
90 void DoFinish(impl::UpdateState new_state);
92 impl::Statistics& stats_;
93 impl::UpdateStatistics& update_stats_;
94 impl::UpdateState state_{impl::UpdateState::kNotFinished};
95 const std::chrono::steady_clock::time_point update_start_time_;