userver: userver/alerts/source.hpp Source File
Loading...
Searching...
No Matches
source.hpp
Go to the documentation of this file.
1#pragma once
2
5
6#include <chrono>
7#include <string_view>
8
11
12USERVER_NAMESPACE_BEGIN
13
14namespace alerts {
15
16namespace impl {
17struct SourceData {
18 mutable std::atomic<bool> fired{false};
19 std::atomic<std::chrono::steady_clock::time_point> stop_timepoint{{}};
20
21 bool IsExpired() const;
22};
23
24void DumpMetric(utils::statistics::Writer& writer, const SourceData& m);
25} // namespace impl
26
36class Source final {
37public:
38 static constexpr std::chrono::seconds kDefaultDuration{120};
39 static constexpr std::chrono::hours kInfiniteDuration{24 * 365 * 10}; // In 10 years, someone should notice.
40
43 explicit Source(std::string_view name);
44
46 void FireAlert(utils::statistics::MetricsStorage& storage, std::chrono::seconds duration = kDefaultDuration) const;
47
50
51private:
53};
54
55} // namespace alerts
56
57USERVER_NAMESPACE_END