diff options
| author | Alexey Efimov <[email protected]> | 2022-03-24 12:43:54 +0300 |
|---|---|---|
| committer | Alexey Efimov <[email protected]> | 2022-03-24 12:43:54 +0300 |
| commit | 43a2b5dd73d8a7aa80d4c1ba4ee70428fffbd17e (patch) | |
| tree | abebfb404c82a24c52c2372f497eadefd899dfb3 /library/cpp/actors/http/http_proxy.cpp | |
| parent | 057f22cbb5bfa82df4bfde220d5aaaa08f34257b (diff) | |
switch metrics registry to shared_ptr KIKIMR-14218
ref:5ef16c21e373b05982980dcd3016950f15a884e8
Diffstat (limited to 'library/cpp/actors/http/http_proxy.cpp')
| -rw-r--r-- | library/cpp/actors/http/http_proxy.cpp | 62 |
1 files changed, 34 insertions, 28 deletions
diff --git a/library/cpp/actors/http/http_proxy.cpp b/library/cpp/actors/http/http_proxy.cpp index 36c6855d93f..e0204f6ed0d 100644 --- a/library/cpp/actors/http/http_proxy.cpp +++ b/library/cpp/actors/http/http_proxy.cpp @@ -26,8 +26,8 @@ public: Become(&THttpProxy::StateWork); } - THttpProxy(NMonitoring::TMetricRegistry& sensors) - : Sensors(sensors) + THttpProxy(std::weak_ptr<NMonitoring::TMetricRegistry> registry) + : Registry(std::move(registry)) {} protected: @@ -175,29 +175,35 @@ protected: const static TString urlNotFound = "not-found"; const TString& url = (sensors.Status == "404" ? urlNotFound : sensors.Url); - Sensors.Rate({ - {"sensor", "count"}, - {"direction", sensors.Direction}, - {"peer", sensors.Host}, - {"url", url}, - {"status", sensors.Status} - })->Inc(); - Sensors.HistogramRate({ - {"sensor", "time_us"}, - {"direction", sensors.Direction}, - {"peer", sensors.Host}, - {"url", url}, - {"status", sensors.Status} - }, - NMonitoring::ExplicitHistogram({1, 5, 10, 50, 100, 500, 1000, 5000, 10000, 30000, 60000}))->Record(sensors.Time.MicroSeconds()); - Sensors.HistogramRate({ - {"sensor", "time_ms"}, - {"direction", sensors.Direction}, - {"peer", sensors.Host}, - {"url", url}, - {"status", sensors.Status} - }, - NMonitoring::ExplicitHistogram({1, 5, 10, 50, 100, 500, 1000, 5000, 10000, 30000, 60000}))->Record(sensors.Time.MilliSeconds()); + std::shared_ptr<NMonitoring::TMetricRegistry> registry = Registry.lock(); + if (registry) { + registry->Rate( + { + {"sensor", "count"}, + {"direction", sensors.Direction}, + {"peer", sensors.Host}, + {"url", url}, + {"status", sensors.Status} + })->Inc(); + registry->HistogramRate( + { + {"sensor", "time_us"}, + {"direction", sensors.Direction}, + {"peer", sensors.Host}, + {"url", url}, + {"status", sensors.Status} + }, + NMonitoring::ExplicitHistogram({1, 5, 10, 50, 100, 500, 1000, 5000, 10000, 30000, 60000}))->Record(sensors.Time.MicroSeconds()); + registry->HistogramRate( + { + {"sensor", "time_ms"}, + {"direction", sensors.Direction}, + {"peer", sensors.Host}, + {"url", url}, + {"status", sensors.Status} + }, + NMonitoring::ExplicitHistogram({1, 5, 10, 50, 100, 500, 1000, 5000, 10000, 30000, 60000}))->Record(sensors.Time.MilliSeconds()); + } } void Handle(NActors::TEvents::TEvPoison::TPtr, const NActors::TActorContext&) { @@ -217,7 +223,7 @@ protected: THashMap<TString, THostEntry> Hosts; THashMap<TString, TActorId> Handlers; THashSet<TActorId> Connections; // outgoing - NMonitoring::TMetricRegistry& Sensors; + std::weak_ptr<NMonitoring::TMetricRegistry> Registry; }; TEvHttpProxy::TEvReportSensors* BuildOutgoingRequestSensors(const THttpOutgoingRequestPtr& request, const THttpIncomingResponsePtr& response) { @@ -240,8 +246,8 @@ TEvHttpProxy::TEvReportSensors* BuildIncomingRequestSensors(const THttpIncomingR ); } -NActors::IActor* CreateHttpProxy(NMonitoring::TMetricRegistry& sensors) { - return new THttpProxy(sensors); +NActors::IActor* CreateHttpProxy(std::weak_ptr<NMonitoring::TMetricRegistry> registry) { + return new THttpProxy(std::move(registry)); } bool IsIPv6(const TString& host) { |
