From 62b519e18f675cbe4381aa334ad1604e3f2669ea Mon Sep 17 00:00:00 2001 From: Pablo Radnic Date: Mon, 19 Apr 2021 16:14:10 -0300 Subject: [PATCH] Added Documentation on Manager.go Signed-off-by: Pablo Radnic --- src/config/config_impl.go | 1 - src/stats/manager.go | 25 ++++++++++++++++++++----- 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/src/config/config_impl.go b/src/config/config_impl.go index 22262ca9..7b48d326 100644 --- a/src/config/config_impl.go +++ b/src/config/config_impl.go @@ -277,7 +277,6 @@ func (this *rateLimitConfigImpl) GetLimit( return rateLimit } - func descriptorKey(domain string, descriptor *pb_struct.RateLimitDescriptor) string { rateLimitKey := "" for _, entry := range descriptor.Entries { diff --git a/src/stats/manager.go b/src/stats/manager.go index dead43a5..47b91186 100644 --- a/src/stats/manager.go +++ b/src/stats/manager.go @@ -3,11 +3,21 @@ package stats import stats "github.com/lyft/gostats" import gostats "github.com/lyft/gostats" +// Manager is the interface that wraps initialization of stat structures type Manager interface { - NewStats(key string) RateLimitStats + // NewStats provides a RateLimitStats structure associated with a given descriptorKey. + // Multiple calls with the same descriptorKey argument are guaranteed to be equivalent. + NewStats(descriptorKey string) RateLimitStats + // Initializes a ShouldRateLimitStats structure. + // Multiple calls to this method are idempotent NewShouldRateLimitStats() ShouldRateLimitStats + // Initializes a ServiceStats structure. + // Multiple calls to this method are idempotent NewServiceStats() ServiceStats + // Initializes a ShouldRateLimitLegacyStats structure. + // Multiple calls to this method are idempotent NewShouldRateLimitLegacyStats() ShouldRateLimitLegacyStats + // Returns the stats.Store wrapped by the Manager GetStatsStore() stats.Store } @@ -19,17 +29,22 @@ type ManagerImpl struct { shouldRateLimitScope gostats.Scope } +// Stats for panic recoveries. +// Identifies if a recovered panic is a redis.RedisError or a ServiceError. type ShouldRateLimitStats struct { RedisError gostats.Counter ServiceError gostats.Counter } +// Stats for server errors. +// Keeps failure and success metrics. type ServiceStats struct { ConfigLoadSuccess gostats.Counter ConfigLoadError gostats.Counter ShouldRateLimit ShouldRateLimitStats } +// Legacy Stats for ratelimit errors. type ShouldRateLimitLegacyStats struct { ReqConversionError gostats.Counter RespConversionError gostats.Counter @@ -37,9 +52,9 @@ type ShouldRateLimitLegacyStats struct { } // Stats for an individual rate limit config entry. -//todo: Ideally the gostats package fields should be unexported -// the inner value could be interacted with via getters such as rlStats.TotalHits() uint64 -// This ensures that setters such as Inc() and Add() can only be managed by RateLimitStats. +// todo: Ideally the gostats package fields should be unexported +// the inner value could be interacted with via getters such as rlStats.TotalHits() uint64 +// This ensures that setters such as Inc() and Add() can only be managed by RateLimitStats. type RateLimitStats struct { Key string TotalHits gostats.Counter @@ -47,4 +62,4 @@ type RateLimitStats struct { NearLimit gostats.Counter OverLimitWithLocalCache gostats.Counter WithinLimit gostats.Counter -} \ No newline at end of file +}