diff options
| author | Stefan Boberg <[email protected]> | 2021-10-11 13:18:37 +0200 |
|---|---|---|
| committer | Stefan Boberg <[email protected]> | 2021-10-11 13:18:37 +0200 |
| commit | 37bf16575d226e6b53579eb913f70f869d3c3ec4 (patch) | |
| tree | a677062fe7a0c4c318b7a36cb94a18fd203996dc | |
| parent | Added lofreq timer update to httpsys main loop (diff) | |
| download | zen-37bf16575d226e6b53579eb913f70f869d3c3ec4.tar.xz zen-37bf16575d226e6b53579eb913f70f869d3c3ec4.zip | |
stats: Added support for handler unregistration
| -rw-r--r-- | zenserver/cache/structuredcache.cpp | 8 | ||||
| -rw-r--r-- | zenserver/monitoring/httpstats.cpp | 16 | ||||
| -rw-r--r-- | zenserver/monitoring/httpstats.h | 1 | ||||
| -rw-r--r-- | zenserver/monitoring/httpstatus.cpp | 16 | ||||
| -rw-r--r-- | zenserver/monitoring/httpstatus.h | 1 |
5 files changed, 36 insertions, 6 deletions
diff --git a/zenserver/cache/structuredcache.cpp b/zenserver/cache/structuredcache.cpp index 4a2a3748a..5166bee42 100644 --- a/zenserver/cache/structuredcache.cpp +++ b/zenserver/cache/structuredcache.cpp @@ -161,13 +161,16 @@ HttpStructuredCacheService::HttpStructuredCacheService(ZenCacheStore& InCac , m_CidStore(InCidStore) , m_UpstreamCache(std::move(UpstreamCache)) { - StatsService.RegisterHandler("z$", *this); - StatusService.RegisterHandler("z$", *this); + m_StatsService.RegisterHandler("z$", *this); + m_StatusService.RegisterHandler("z$", *this); } HttpStructuredCacheService::~HttpStructuredCacheService() { ZEN_INFO("closing structured cache"); + + m_StatsService.UnregisterHandler("z$", *this); + m_StatusService.UnregisterHandler("z$", *this); } const char* @@ -275,6 +278,7 @@ HttpStructuredCacheService::HandleCacheRecordRequest(HttpServerRequest& Request, HandleGetCacheRecord(Request, Ref, Policy); } break; + case kPut: HandlePutCacheRecord(Request, Ref, Policy); break; diff --git a/zenserver/monitoring/httpstats.cpp b/zenserver/monitoring/httpstats.cpp index de04294d0..4d985f8c2 100644 --- a/zenserver/monitoring/httpstats.cpp +++ b/zenserver/monitoring/httpstats.cpp @@ -26,6 +26,15 @@ HttpStatsService::RegisterHandler(std::string_view Id, IHttpStatsProvider& Provi } void +HttpStatsService::UnregisterHandler(std::string_view Id, IHttpStatsProvider& Provider) +{ + ZEN_UNUSED(Provider); + + RwLock::ExclusiveLockScope _(m_Lock); + m_Providers.erase(std::string(Id)); +} + +void HttpStatsService::HandleRequest(HttpServerRequest& Request) { using namespace std::literals; @@ -36,9 +45,12 @@ HttpStatsService::HandleRequest(HttpServerRequest& Request) { case HttpVerb::kHead: case HttpVerb::kGet: - if (auto It = m_Providers.find(std::string{Key}); It != end(m_Providers)) { - return It->second->HandleStatsRequest(Request); + RwLock::SharedLockScope _(m_Lock); + if (auto It = m_Providers.find(std::string{Key}); It != end(m_Providers)) + { + return It->second->HandleStatsRequest(Request); + } } [[fallthrough]]; diff --git a/zenserver/monitoring/httpstats.h b/zenserver/monitoring/httpstats.h index 1c3c79dd0..732815a9a 100644 --- a/zenserver/monitoring/httpstats.h +++ b/zenserver/monitoring/httpstats.h @@ -23,6 +23,7 @@ public: virtual const char* BaseUri() const override; virtual void HandleRequest(HttpServerRequest& Request) override; void RegisterHandler(std::string_view Id, IHttpStatsProvider& Provider); + void UnregisterHandler(std::string_view Id, IHttpStatsProvider& Provider); private: spdlog::logger& m_Log; diff --git a/zenserver/monitoring/httpstatus.cpp b/zenserver/monitoring/httpstatus.cpp index e12662b1c..8b10601dd 100644 --- a/zenserver/monitoring/httpstatus.cpp +++ b/zenserver/monitoring/httpstatus.cpp @@ -26,6 +26,15 @@ HttpStatusService::RegisterHandler(std::string_view Id, IHttpStatusProvider& Pro } void +HttpStatusService::UnregisterHandler(std::string_view Id, IHttpStatusProvider& Provider) +{ + ZEN_UNUSED(Provider); + + RwLock::ExclusiveLockScope _(m_Lock); + m_Providers.erase(std::string(Id)); +} + +void HttpStatusService::HandleRequest(HttpServerRequest& Request) { using namespace std::literals; @@ -36,9 +45,12 @@ HttpStatusService::HandleRequest(HttpServerRequest& Request) { case HttpVerb::kHead: case HttpVerb::kGet: - if (auto It = m_Providers.find(std::string{Key}); It != end(m_Providers)) { - return It->second->HandleStatusRequest(Request); + RwLock::SharedLockScope _(m_Lock); + if (auto It = m_Providers.find(std::string{Key}); It != end(m_Providers)) + { + return It->second->HandleStatusRequest(Request); + } } [[fallthrough]]; diff --git a/zenserver/monitoring/httpstatus.h b/zenserver/monitoring/httpstatus.h index 8f069f760..b04e45324 100644 --- a/zenserver/monitoring/httpstatus.h +++ b/zenserver/monitoring/httpstatus.h @@ -23,6 +23,7 @@ public: virtual const char* BaseUri() const override; virtual void HandleRequest(HttpServerRequest& Request) override; void RegisterHandler(std::string_view Id, IHttpStatusProvider& Provider); + void UnregisterHandler(std::string_view Id, IHttpStatusProvider& Provider); private: spdlog::logger& m_Log; |