athena audit logs - query rate limiter#24918
Conversation
|
@smallinsky @rosstimothy in dfc304c I have reworked it to use wrap logger inside limiter. It turned out quite a lot of additional code. Let me know what do you think? |
| if cfg.LimiterBurst <= 0 { | ||
| return trace.BadParameter("limiterBurst cannot be less or equal to 0") | ||
| } | ||
| if math.Abs(cfg.LimiterRate) < 1e-9 { |
There was a problem hiding this comment.
Wonder if we can't just change the cfg.LimiterRate type to uint.
There was a problem hiding this comment.
sorry for missing docs for that config. LimiterRate defines how many tokens and added per seconds.
I am checking it with 1e-9 just to have very small delta when comparing float against 0. On one hand it should be equal to 0 because if it's not present in url params, it will be default, so 0. @rosstimothy do you think I should just better document it?
@smallinsky i don't think you can define rps using uint, someone may want to set it 0.5 for example. And defining it in miliseconds will be even more confusing.
One thing that we can do is use helper fn from rate package Every. You define interval (time.Duration) at which token is filled. Do you think it will be easier to understand?
There was a problem hiding this comment.
0.5 RPS or 10.1 RPS values as rate limit should be quite rate but I don't have strong about it so please free to ignore my comment.
I don't thing that we can do is use helper fn from rate package Every. You define interval (time.Duration) at which token is filled. Do you think it will be easier to understand?
I think that current behaviour with 1s time unit is fine and readable. It should be quite easy to extend in the future but if we don't have case for Athena we should skip it for now and keep it simple.
| if cfg.LimiterBurst <= 0 { | ||
| return trace.BadParameter("limiterBurst cannot be less or equal to 0") | ||
| } | ||
| if math.Abs(cfg.LimiterRate) < 1e-9 { |
There was a problem hiding this comment.
Wonder if we can't just change the cfg.LimiterRate type to uint.
| } | ||
|
|
||
| type SearchEventsLimiterConfig struct { | ||
| LimiterRate float64 |
There was a problem hiding this comment.
We we need float64 type ? Making ing uint will allow to simplify the CheckAndSetDefaults logic
|
@rosstimothy 4fa09ec |
|
@smallinsky @rosstimothy in 26b6d79 similary to how our per IP limiter does: https://github.com/gravitational/oxy/blob/c59990dc8c641ec79a7f6eee48a20c7e8f4c69c6/ratelimit/tokenlimiter.go#L31, I just used more descriptive names. Let me know what do you think? |
rosstimothy
left a comment
There was a problem hiding this comment.
LGTM but seems like there is now a broken test case:
=== RUN TestAthenaAuditLogSetup/config_with_rate_limit_-_should_use_events.SearchEventsLimiter
{"caller":"athena/consumer.go:506","component":"athena","error":"operation error SQS: ReceiveMessage, failed to resolve service endpoint, an AWS region is required, but was not found","level":"error","message":"Failure processing SQS messages","timestamp":"2023-04-27T10:16:33Z"}
service_test.go:322:
Error Trace: /__w/teleport/teleport/lib/service/service_test.go:322
/__w/teleport/teleport/lib/service/service_test.go:338
Error: Received unexpected error:
LimiterRefillAmount must be greater than 0 if LimiterBurst is used
Test: TestAthenaAuditLogSetup/config_with_rate_limit_-_should_use_events.SearchEventsLimiter
{"caller":"athena/consumer.go:506","component":"athena","error":"operation error SQS: ReceiveMessage, failed to resolve service endpoint, an AWS region is required, but was not found","level":"error","message":"Failure processing SQS messages","timestamp":"2023-04-27T10:16:33Z"}
--- FAIL: TestAthenaAuditLogSetup/config_with_rate_limit_-_should_use_events.SearchEventsLimiter (0.00s)
fixed in d7e491e |
d7e491e to
d6c775c
Compare
|
@tobiaszheller See the table below for backport results.
|
|
@tobiaszheller See the table below for backport results.
|
Part of https://github.com/gravitational/teleport.e/issues/894
RFD: https://github.com/gravitational/teleport/blob/master/rfd/0118-scalable-audit-logs.md
This PR adds rate limit feature to athena audit logs on searching events.
Rate limit is needed to allow throttling of tenants in Cloud.