aboutsummaryrefslogtreecommitdiff
path: root/src/zenhttp/diagsvcs.cpp
diff options
context:
space:
mode:
authorStefan Boberg <[email protected]>2023-10-13 09:55:27 +0200
committerGitHub <[email protected]>2023-10-13 09:55:27 +0200
commit74d104d4eb3735e0881f0e1fccc2df8aa4d3f57d (patch)
treeacae59dac67b4d051403f35e580201c214ec4fda /src/zenhttp/diagsvcs.cpp
parentfaster oplog iteration (#471) (diff)
downloadzen-74d104d4eb3735e0881f0e1fccc2df8aa4d3f57d.tar.xz
zen-74d104d4eb3735e0881f0e1fccc2df8aa4d3f57d.zip
restructured zenhttp (#472)
separating the http server implementations into a directory and moved diagsvcs into zenserver since it's somewhat hard-coded for it
Diffstat (limited to 'src/zenhttp/diagsvcs.cpp')
-rw-r--r--src/zenhttp/diagsvcs.cpp135
1 files changed, 0 insertions, 135 deletions
diff --git a/src/zenhttp/diagsvcs.cpp b/src/zenhttp/diagsvcs.cpp
deleted file mode 100644
index 9a547aa47..000000000
--- a/src/zenhttp/diagsvcs.cpp
+++ /dev/null
@@ -1,135 +0,0 @@
-// Copyright Epic Games, Inc. All Rights Reserved.
-
-#include "zenhttp/diagsvcs.h"
-
-#include <zencore/compactbinary.h>
-#include <zencore/compactbinarybuilder.h>
-#include <zencore/config.h>
-#include <zencore/filesystem.h>
-#include <zencore/logging.h>
-#include <zencore/string.h>
-#include <fstream>
-#include <sstream>
-
-#include <json11.hpp>
-
-namespace zen {
-
-using namespace std::literals;
-
-static bool
-ReadLogFile(const std::string& Path, StringBuilderBase& Out)
-{
- try
- {
- constexpr auto ReadSize = std::size_t{4096};
- auto FileStream = std::ifstream{Path};
-
- std::string Buf(ReadSize, '\0');
- while (FileStream.read(&Buf[0], ReadSize))
- {
- Out.Append(std::string_view(&Buf[0], FileStream.gcount()));
- }
- Out.Append(std::string_view(&Buf[0], FileStream.gcount()));
-
- return true;
- }
- catch (std::exception&)
- {
- Out.Reset();
- return false;
- }
-}
-
-HttpHealthService::HttpHealthService()
-{
- m_Router.RegisterRoute(
- "",
- [](HttpRouterRequest& RoutedReq) {
- HttpServerRequest& HttpReq = RoutedReq.ServerRequest();
- HttpReq.WriteResponse(HttpResponseCode::OK, HttpContentType::kText, u8"OK!"sv);
- },
- HttpVerb::kGet);
-
- m_Router.RegisterRoute(
- "info",
- [this](HttpRouterRequest& RoutedReq) {
- HttpServerRequest& HttpReq = RoutedReq.ServerRequest();
-
- CbObjectWriter Writer;
-
- {
- RwLock::SharedLockScope _(m_InfoLock);
- Writer << "DataRoot"sv << m_HealthInfo.DataRoot.string();
- Writer << "AbsLogPath"sv << m_HealthInfo.AbsLogPath.string();
- Writer << "BuildVersion"sv << m_HealthInfo.BuildVersion;
- Writer << "HttpServerClass"sv << m_HealthInfo.HttpServerClass;
- }
-
- HttpReq.WriteResponse(HttpResponseCode::OK, Writer.Save());
- },
- HttpVerb::kGet);
-
- m_Router.RegisterRoute(
- "log",
- [this](HttpRouterRequest& RoutedReq) {
- HttpServerRequest& HttpReq = RoutedReq.ServerRequest();
-
- zen::Log().flush();
-
- std::filesystem::path Path = [&] {
- RwLock::SharedLockScope _(m_InfoLock);
- return m_HealthInfo.AbsLogPath.empty() ? m_HealthInfo.DataRoot / "logs/zenserver.log" : m_HealthInfo.AbsLogPath;
- }();
-
- ExtendableStringBuilder<4096> Sb;
- if (ReadLogFile(Path.string(), Sb) && Sb.Size() > 0)
- {
- HttpReq.WriteResponse(HttpResponseCode::OK, HttpContentType::kText, Sb.ToView());
- }
- else
- {
- HttpReq.WriteResponse(HttpResponseCode::NotFound);
- }
- },
- HttpVerb::kGet);
-
- m_Router.RegisterRoute(
- "version",
- [this](HttpRouterRequest& RoutedReq) {
- HttpServerRequest& HttpReq = RoutedReq.ServerRequest();
- if (HttpReq.GetQueryParams().GetValue("detailed") == "true")
- {
- HttpReq.WriteResponse(HttpResponseCode::OK, HttpContentType::kText, ZEN_CFG_VERSION_BUILD_STRING_FULL);
- }
- else
- {
- HttpReq.WriteResponse(HttpResponseCode::OK, HttpContentType::kText, ZEN_CFG_VERSION);
- }
- },
- HttpVerb::kGet);
-}
-
-void
-HttpHealthService::SetHealthInfo(HealthServiceInfo&& Info)
-{
- RwLock::ExclusiveLockScope _(m_InfoLock);
- m_HealthInfo = std::move(Info);
-}
-
-const char*
-HttpHealthService::BaseUri() const
-{
- return "/health/";
-}
-
-void
-HttpHealthService::HandleRequest(HttpServerRequest& Request)
-{
- if (!m_Router.HandleRequest(Request))
- {
- Request.WriteResponse(HttpResponseCode::OK, HttpContentType::kText, u8"OK!"sv);
- }
-}
-
-} // namespace zen