From cceed531be3fc89f034e79a599a72e28ebe7d32b Mon Sep 17 00:00:00 2001 From: Stefan Boberg Date: Mon, 4 Oct 2021 15:24:53 +0200 Subject: monitoring: added stubs for /stats and /status endpoints this is a tactical check-in to allow me to merge some other changes --- zenserver/monitoring/httpstatus.cpp | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 zenserver/monitoring/httpstatus.cpp (limited to 'zenserver/monitoring/httpstatus.cpp') diff --git a/zenserver/monitoring/httpstatus.cpp b/zenserver/monitoring/httpstatus.cpp new file mode 100644 index 000000000..c18bf6c1f --- /dev/null +++ b/zenserver/monitoring/httpstatus.cpp @@ -0,0 +1,33 @@ +// Copyright Epic Games, Inc. All Rights Reserved. + +#include "httpstatus.h" + +namespace zen { + +HttpStatusService::HttpStatusService() : m_Log(logging::Get("status")) +{ +} + +HttpStatusService::~HttpStatusService() +{ +} + +const char* +HttpStatusService::BaseUri() const +{ + return "/statUs/"; +} + +void +HttpStatusService::HandleRequest(HttpServerRequest& Request) +{ + using namespace std::literals; + + switch (Request.RequestVerb()) + { + case HttpVerb::kGet: + return Request.WriteResponse(HttpResponseCode::OK, HttpContentType::kText, u8"OK!"sv); + } +} + +} // namespace zen -- cgit v1.2.3 From f4c6f75ed3620e777d8194bf59a24b7d6dc4200a Mon Sep 17 00:00:00 2001 From: Stefan Boberg Date: Mon, 4 Oct 2021 17:54:21 +0200 Subject: stats: Implemented new stats endpoint Stats are exposed under /stats/{id}, so for example structured cache stats are exposed under /stats/z$ The separate endpoint makes it easier to separate request handling to ensure stats/status endpoints still respond if the regular request queue is somehow saturated or otherwise not behaving There is also a /status endpoint which is similar and is targeted towards lightweight health monitoring --- zenserver/monitoring/httpstatus.cpp | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) (limited to 'zenserver/monitoring/httpstatus.cpp') diff --git a/zenserver/monitoring/httpstatus.cpp b/zenserver/monitoring/httpstatus.cpp index c18bf6c1f..e12662b1c 100644 --- a/zenserver/monitoring/httpstatus.cpp +++ b/zenserver/monitoring/httpstatus.cpp @@ -15,7 +15,14 @@ HttpStatusService::~HttpStatusService() const char* HttpStatusService::BaseUri() const { - return "/statUs/"; + return "/status/"; +} + +void +HttpStatusService::RegisterHandler(std::string_view Id, IHttpStatusProvider& Provider) +{ + RwLock::ExclusiveLockScope _(m_Lock); + m_Providers.insert_or_assign(std::string(Id), &Provider); } void @@ -23,10 +30,20 @@ HttpStatusService::HandleRequest(HttpServerRequest& Request) { using namespace std::literals; + std::string_view Key = Request.RelativeUri(); + switch (Request.RequestVerb()) { + case HttpVerb::kHead: case HttpVerb::kGet: - return Request.WriteResponse(HttpResponseCode::OK, HttpContentType::kText, u8"OK!"sv); + if (auto It = m_Providers.find(std::string{Key}); It != end(m_Providers)) + { + return It->second->HandleStatusRequest(Request); + } + + [[fallthrough]]; + default: + return; } } -- cgit v1.2.3