-
Notifications
You must be signed in to change notification settings - Fork 457
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Metric refactor #242
Metric refactor #242
Conversation
Signed-off-by: Pablo Radnic <[email protected]>
Signed-off-by: Pablo Radnic <[email protected]>
Signed-off-by: Pablo Radnic <[email protected]>
Signed-off-by: Pablo Radnic <[email protected]>
Signed-off-by: Pablo Radnic <[email protected]>
Signed-off-by: Pablo Radnic <[email protected]>
Signed-off-by: Pablo Radnic <[email protected]>
@mattklein123 I can help review this Friday |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does extending existing settings with option to include detailed stats come in separate PR?
src/config/config.go
Outdated
@@ -56,5 +47,5 @@ type RateLimitConfigLoader interface { | |||
// @param statsScope supplies the stats scope to use for limit stats during runtime. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: update function documentation with new parameter
src/config/config_impl.go
Outdated
config RateLimitConfigToLoad, parentKey string, descriptors []yamlDescriptor, | ||
statsScope stats.Scope) { | ||
// @param manager that owns the stats.Scope. | ||
func (this *rateLimitDescriptor) loadDescriptors(config RateLimitConfigToLoad, parentKey string, descriptors []yamlDescriptor, manager stats.Manager) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: rename arg name manager ->statsManager
src/config/config_impl.go
Outdated
@@ -268,13 +235,12 @@ func (this *rateLimitConfigImpl) GetLimit( | |||
} | |||
|
|||
if descriptor.GetLimit() != nil { | |||
rateLimitKey := domain + "." + this.descriptorToKey(descriptor) | |||
rateLimitKey := stats.DescriptorKey(domain, descriptor) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what is the reasoning behind moving descriptorToKey
function to stats package?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moved to client package (where it is used currently).
src/config/config_impl.go
Outdated
@@ -316,9 +282,9 @@ func (this *rateLimitConfigImpl) GetLimit( | |||
// @param stats supplies the stats scope to use for limit stats during runtime. | |||
// @return a new config. | |||
func NewRateLimitConfigImpl( | |||
configs []RateLimitConfigToLoad, statsScope stats.Scope) RateLimitConfig { | |||
configs []RateLimitConfigToLoad, manager stats.Manager) RateLimitConfig { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: same as above, rename manager
to smth like statsManager
src/config_check_cmd/main.go
Outdated
dummyStats := stats.NewStore(stats.NewNullSink(), false) | ||
config.NewRateLimitConfigImpl(allConfigs, dummyStats) | ||
settingStruct := settings.NewSettings() | ||
manager := stats.NewStatManager(gostats.NewStore(gostats.NewNullSink(), false), settingStruct) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: inline creation of settings here instead
src/stats/manager_impl.go
Outdated
logger "github.com/sirupsen/logrus" | ||
) | ||
|
||
func NewStatManager(store gostats.Store, s settings.Settings) *ManagerImpl { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
renaming s
settings would probably clash with settings
package, but it could have improved readability
src/stats/manager_impl.go
Outdated
} | ||
|
||
func (this *ManagerImpl) NewShouldRateLimitStats() ShouldRateLimitStats { | ||
s := this.serviceStatsScope.Scope("call.should_rate_limit") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: s-> scope
src/stats/manager_impl.go
Outdated
//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 ManagerImpl. | ||
type RateLimitStats struct { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could be better to group all those struct definitions together either in top of this file or pull them out into manager.go
file
src/stats/manager_impl.go
Outdated
rlStatsScope: serviceScope.Scope("rate_limit"), | ||
legacyStatsScope: serviceScope.Scope("call.should_rate_limit_legacy"), | ||
serviceStatsScope: serviceScope, | ||
detailedMetricsScope: serviceScope.Scope("rate_limit").Scope("detailed"), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should this scope be initialised only if detailed
is set to true?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed all mentions of detailedMetrics
they will be added on the DetailedMetrics PR
src/stats/manager_impl.go
Outdated
legacyStatsScope gostats.Scope | ||
serviceStatsScope gostats.Scope | ||
detailedMetricsScope gostats.Scope | ||
detailed bool |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
how is this field currently used?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed all mentions of detailedMetrics
they will be added on the DetailedMetrics PR
Signed-off-by: Pablo Radnic <[email protected]>
Signed-off-by: Pablo Radnic <[email protected]>
Signed-off-by: Pablo Radnic <[email protected]>
Signed-off-by: Pablo Radnic <[email protected]>
Signed-off-by: Pablo Radnic <[email protected]>
Signed-off-by: Pablo Radnic <[email protected]>
Signed-off-by: Pablo Radnic <[email protected]>
Signed-off-by: Pablo Radnic <[email protected]>
Thank you @nezdolik for the review. Finished working on the requested changes. Alongside the nit's these are the most important points:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PR looks good to me. @mattklein123 @dweitzman would you take a look?
src/stats/manager.go
Outdated
import stats "github.com/lyft/gostats" | ||
import gostats "github.com/lyft/gostats" | ||
|
||
// Manager is the interface that wraps initialization of stat structures |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: add '.' in the end of each doc sentence
Signed-off-by: Pablo Radnic <[email protected]>
c04cf0c
to
56c3e52
Compare
Hi @mattklein123 let me know if we need any more work on this PR or if we can go forwards with the next steps in order to add detailed-metrics feature. |
Hi @mattklein123 what are the next steps you suggest in order to get this feature merged in upstream? |
Merge main, and then I will take a look. /wait |
Signed-off-by: Pablo Radnic <[email protected]>
Signed-off-by: Pablo Radnic <[email protected]>
Please check CI /wait |
Signed-off-by: Pablo Radnic <[email protected]>
Signed-off-by: Pablo Radnic <[email protected]>
func([]config.RateLimitConfigToLoad, stats.Scope) { | ||
barrier.signal() | ||
func([]config.RateLimitConfigToLoad, stats.Manager) { | ||
defer barrier.signal() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mattklein123 I believe the CI build failed because of a race-condition in this test. The scenario is similar to the one fixed in this recently merged PR.
I believe the issue should be resolved with this change.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! Just to make sure I understand, there should be no functional change for this PR, right? In a future PR you will add the ability to have detailed stats?
/wait-any
Correct! This changeset holds no functional changes. The opt-in Detailed Metrics feature will come in the next PR. |
I didn't read all the code, but the overall goal makes sense to me. I'm in favor of anything that isolates the |
Signed-off-by: Pablo Radnic <[email protected]>
Signed-off-by: Pablo Radnic <[email protected]>
As requested here.
In the current version of the system metric production is done ad hoc to comply with specific requirements, Scopes are initialized in service components, Ex: 1, 2, 3; and metrics are directly set by all components as well Ex: 1, 2.
This makes adding service-wide configurations to metric generation (such as Detailed Metrics) particularly difficult. In order to accommodate this feature, we made the following refactor.
This PR refactors metric handling in the ratelimit service, namely: