aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStefan Boberg <[email protected]>2021-09-30 10:39:39 +0200
committerStefan Boberg <[email protected]>2021-09-30 10:39:39 +0200
commit741fa349b8d860730d02a363fb6e5ff8f6f3fc82 (patch)
tree02c79ffdbe4b6c5bc5bfb3932191a97b44579a09
parentmemory: Added experimental mimalloc path to AlignedAllocImpl/AlignedFreeImpl (diff)
downloadzen-741fa349b8d860730d02a363fb6e5ff8f6f3fc82.tar.xz
zen-741fa349b8d860730d02a363fb6e5ff8f6f3fc82.zip
structured cache: Added stats test code (needs additional work / metrics)
-rw-r--r--zenserver/cache/structuredcache.cpp19
-rw-r--r--zenserver/cache/structuredcache.h4
2 files changed, 23 insertions, 0 deletions
diff --git a/zenserver/cache/structuredcache.cpp b/zenserver/cache/structuredcache.cpp
index 74cee6614..eee3f8279 100644
--- a/zenserver/cache/structuredcache.cpp
+++ b/zenserver/cache/structuredcache.cpp
@@ -6,6 +6,7 @@
#include <zencore/compress.h>
#include <zencore/fmtutils.h>
#include <zencore/logging.h>
+#include <zencore/scopeguard.h>
#include <zencore/stream.h>
#include <zencore/timer.h>
#include <zenhttp/httpserver.h>
@@ -193,10 +194,18 @@ HttpStructuredCacheService::HandleRequest(HttpServerRequest& Request)
{
CacheRef Ref;
+ Stopwatch Timer;
+ auto _ = MakeGuard([&] { m_HttpRequests.Update(Timer.GetElapsedTicks()); });
+
if (!ValidateKeyUri(Request, /* out */ Ref))
{
std::string_view Key = Request.RelativeUri();
+ if (Key.empty())
+ {
+ return HandleStatusRequest(Request);
+ }
+
if (std::all_of(begin(Key), end(Key), [](const char c) { return std::isalnum(c); }))
{
// Bucket reference
@@ -829,4 +838,14 @@ HttpStructuredCacheService::ValidateKeyUri(HttpServerRequest& Request, CacheRef&
return true;
}
+
+void
+HttpStructuredCacheService::HandleStatusRequest(zen::HttpServerRequest& Request)
+{
+ CbObjectWriter Cbo;
+ Cbo << "ok" << true << "http_requests" << m_HttpRequests.Count();
+
+ Request.WriteResponse(HttpResponseCode::OK, Cbo.Save());
+}
+
} // namespace zen
diff --git a/zenserver/cache/structuredcache.h b/zenserver/cache/structuredcache.h
index 3fdaa1236..5dfff08ad 100644
--- a/zenserver/cache/structuredcache.h
+++ b/zenserver/cache/structuredcache.h
@@ -2,6 +2,7 @@
#pragma once
+#include <zencore/stats.h>
#include <zenhttp/httpserver.h>
#include <memory>
@@ -78,6 +79,7 @@ private:
void HandleGetCachePayload(zen::HttpServerRequest& Request, const CacheRef& Ref, CachePolicy Policy);
void HandlePutCachePayload(zen::HttpServerRequest& Request, const CacheRef& Ref, CachePolicy Policy);
void HandleCacheBucketRequest(zen::HttpServerRequest& Request, std::string_view Bucket);
+ void HandleStatusRequest(zen::HttpServerRequest& Request);
spdlog::logger& Log() { return m_Log; }
spdlog::logger& m_Log;
@@ -86,6 +88,8 @@ private:
zen::CidStore& m_CidStore;
std::unique_ptr<UpstreamCache> m_UpstreamCache;
uint64_t m_LastScrubTime = 0;
+
+ metrics::Histogram m_HttpRequests;
};
} // namespace zen