-
Notifications
You must be signed in to change notification settings - Fork 351
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
filters/auth: cache yaml config #3225
Conversation
c6f326f
to
fab869c
Compare
👍 |
filters/auth/jwt_metrics.go
Outdated
@@ -27,34 +28,31 @@ type ( | |||
) | |||
|
|||
func NewJwtMetrics() filters.Spec { | |||
return &jwtMetricsSpec{} | |||
return &jwtMetricsSpec{ | |||
yamlConfig: newYamlConfig[jwtMetricsFilter](64), |
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.
64 is an arbitrary cache size here. In case number of distinct yaml configurations exceeds it the caching still has value because it will hold recently parsed configurations.
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.
Decided that currently it does not make sense to make it configurable, we can do it later if needed.
Signed-off-by: Alexander Yastrebov <alexander.yastrebov@zalando.de>
42b81bd
to
c6228d1
Compare
Cache parsed yaml config for `jwtMetrics` and `oauthTokeninfoValidate` filters to avoid parsing the same configuration over and over when these filters are appended as default filters to all routes. ``` │ HEAD~1 │ HEAD │ │ sec/op │ sec/op vs base │ JwtMetrics_CreateFilter-8 30777.00n ± 6% 18.45n ± 11% -99.94% (p=0.000 n=10) │ HEAD~1 │ HEAD │ │ B/op │ B/op vs base │ JwtMetrics_CreateFilter-8 24.33Ki ± 0% 0.00Ki ± 0% -100.00% (p=0.000 n=10) │ HEAD~1 │ HEAD │ │ allocs/op │ allocs/op vs base │ JwtMetrics_CreateFilter-8 180.0 ± 0% 0.0 ± 0% -100.00% (p=0.000 n=10) ``` Signed-off-by: Alexander Yastrebov <alexander.yastrebov@zalando.de>
c6228d1
to
1ed2e45
Compare
// yamlConfigParser parses and caches yaml configurations of type T. | ||
// Use [newYamlConfigParser] to create instances and ensure that *T implements [yamlConfig]. | ||
type yamlConfigParser[T any] struct { | ||
initialize func(*T) error |
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.
why do we need to enforce this?
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.
The idea is to ensure that user of yamlConfigParser is aware that config values must be immutable.
👍 |
1 similar comment
👍 |
+ zalando/skipper#3227 + zalando/skipper#3225 + zalando/skipper#3234 + zalando/skipper#3239 + zalando/skipper#3240 + zalando/skipper#3241 + zalando/skipper#3242 + zalando/skipper#3245 + zalando/skipper#3246 + zalando/skipper#3247 + zalando/skipper#3249 + zalando/skipper#3248 FYI zalando/skipper@v0.21.198...v0.21.208 Signed-off-by: Roman Zavodskikh <roman.zavodskikh@zalando.de>
+ zalando/skipper#3227 + zalando/skipper#3225 + zalando/skipper#3234 + zalando/skipper#3239 + zalando/skipper#3240 + zalando/skipper#3241 + zalando/skipper#3242 + zalando/skipper#3245 + zalando/skipper#3246 + zalando/skipper#3247 + zalando/skipper#3249 + zalando/skipper#3248 FYI zalando/skipper@v0.21.198...v0.21.208 Signed-off-by: Roman Zavodskikh <roman.zavodskikh@zalando.de>
+ zalando/skipper#3227 + zalando/skipper#3225 + zalando/skipper#3234 + zalando/skipper#3239 + zalando/skipper#3240 + zalando/skipper#3241 + zalando/skipper#3242 + zalando/skipper#3245 + zalando/skipper#3246 + zalando/skipper#3247 + zalando/skipper#3249 + zalando/skipper#3248 FYI zalando/skipper@v0.21.198...v0.21.208 canary was updated #8214 Signed-off-by: Roman Zavodskikh <roman.zavodskikh@zalando.de>
* filters/auth: benchmark jwtMetrics filter creation Signed-off-by: Alexander Yastrebov <alexander.yastrebov@zalando.de> * filters/auth: cache yaml config Cache parsed yaml config for `jwtMetrics` and `oauthTokeninfoValidate` filters to avoid parsing the same configuration over and over when these filters are appended as default filters to all routes. ``` │ HEAD~1 │ HEAD │ │ sec/op │ sec/op vs base │ JwtMetrics_CreateFilter-8 30777.00n ± 6% 18.45n ± 11% -99.94% (p=0.000 n=10) │ HEAD~1 │ HEAD │ │ B/op │ B/op vs base │ JwtMetrics_CreateFilter-8 24.33Ki ± 0% 0.00Ki ± 0% -100.00% (p=0.000 n=10) │ HEAD~1 │ HEAD │ │ allocs/op │ allocs/op vs base │ JwtMetrics_CreateFilter-8 180.0 ± 0% 0.0 ± 0% -100.00% (p=0.000 n=10) ``` Signed-off-by: Alexander Yastrebov <alexander.yastrebov@zalando.de> --------- Signed-off-by: Alexander Yastrebov <alexander.yastrebov@zalando.de>
Cache parsed yaml config for
jwtMetrics
andoauthTokeninfoValidate
filters to avoid parsing the same configuration over and over when these filters are appended as default filters to all routes.