diff options
Diffstat (limited to 'zenserver/upstream/upstreamcache.h')
| -rw-r--r-- | zenserver/upstream/upstreamcache.h | 82 |
1 files changed, 53 insertions, 29 deletions
diff --git a/zenserver/upstream/upstreamcache.h b/zenserver/upstream/upstreamcache.h index 20c89a574..16d8c7929 100644 --- a/zenserver/upstream/upstreamcache.h +++ b/zenserver/upstream/upstreamcache.h @@ -4,6 +4,7 @@ #include <zencore/iobuffer.h> #include <zencore/iohash.h> +#include <zencore/stats.h> #include <zencore/zencore.h> #include <zenutil/cache/cache.h> @@ -35,7 +36,6 @@ struct UpstreamCacheOptions uint32_t ThreadCount = 4; bool ReadUpstream = true; bool WriteUpstream = true; - bool StatsEnabled = false; }; struct UpstreamError @@ -63,24 +63,6 @@ struct PutUpstreamCacheResult bool Success = false; }; -struct UpstreamEndpointHealth -{ - std::string Reason; - bool Ok = false; -}; - -struct UpstreamEndpointStats -{ - std::atomic_uint64_t HitCount{}; - std::atomic_uint64_t MissCount{}; - std::atomic_uint64_t UpCount{}; - std::atomic_uint64_t ErrorCount{}; - std::atomic_uint64_t UpBytes{}; - std::atomic_uint64_t DownBytes{}; - std::atomic_uint64_t TimeUpMs{}; - std::atomic_uint64_t TimeDownMs{}; -}; - struct CacheRecordGetCompleteParams { const CacheKey& Key; @@ -100,6 +82,51 @@ struct CachePayloadGetCompleteParams using OnCachePayloadGetComplete = std::function<void(CachePayloadGetCompleteParams&&)>; +struct UpstreamEndpointStats +{ + metrics::OperationTiming CacheGetRequestTiming; + metrics::OperationTiming CachePutRequestTiming; + metrics::Counter CacheGetTotalBytes; + metrics::Counter CachePutTotalBytes; + metrics::Counter CacheGetCount; + metrics::Counter CacheHitCount; + metrics::Counter CacheErrorCount; +}; + +enum class UpstreamEndpointState : uint32_t +{ + kDisabled, + kUnauthorized, + kError, + kOk +}; + +inline std::string_view +ToString(UpstreamEndpointState State) +{ + using namespace std::literals; + + switch (State) + { + case UpstreamEndpointState::kDisabled: + return "Disabled"sv; + case UpstreamEndpointState::kUnauthorized: + return "Unauthorized"sv; + case UpstreamEndpointState::kError: + return "Error"sv; + case UpstreamEndpointState::kOk: + return "Ok"sv; + default: + return "Unknown"sv; + } +} + +struct UpstreamEndpointStatus +{ + std::string Reason; + UpstreamEndpointState State; +}; + struct UpstreamEndpointInfo { std::string Name; @@ -116,11 +143,11 @@ public: virtual const UpstreamEndpointInfo& GetEndpointInfo() const = 0; - virtual UpstreamEndpointHealth Initialize() = 0; + virtual UpstreamEndpointStatus Initialize() = 0; - virtual bool IsHealthy() const = 0; + virtual UpstreamEndpointState GetState() = 0; - virtual UpstreamEndpointHealth CheckHealth() = 0; + virtual UpstreamEndpointStatus GetStatus() = 0; virtual GetUpstreamCacheResult GetCacheRecord(CacheKey CacheKey, ZenContentType Type) = 0; @@ -150,10 +177,12 @@ class UpstreamCache public: virtual ~UpstreamCache() = default; - virtual bool Initialize() = 0; + virtual void Initialize() = 0; virtual void RegisterEndpoint(std::unique_ptr<UpstreamEndpoint> Endpoint) = 0; + virtual void IterateEndpoints(std::function<bool(UpstreamEndpoint&)>&& Fn) = 0; + virtual GetUpstreamCacheResult GetCacheRecord(CacheKey CacheKey, ZenContentType Type) = 0; virtual void GetCacheRecords(std::span<CacheKey> CacheKeys, @@ -167,12 +196,7 @@ public: std::span<size_t> RequestIndex, OnCachePayloadGetComplete&& OnComplete) = 0; - struct EnqueueResult - { - bool Success = false; - }; - - virtual EnqueueResult EnqueueUpstream(UpstreamCacheRecord CacheRecord) = 0; + virtual void EnqueueUpstream(UpstreamCacheRecord CacheRecord) = 0; virtual void GetStatus(CbObjectWriter& CbO) = 0; }; |