-
Notifications
You must be signed in to change notification settings - Fork 3.7k
feat(distributor): Add simulated latency #16733
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
Conversation
This change adds the ability to configure simulated latency on a per-tenant basis in the distributor. This is useful for testing and simulating real-world conditions. The implementation: - Adds a new `simulated_latency` field to the Limits struct using model.Duration - Adds a SimulatedLatency method to the Overrides struct - Adds the SimulatedLatency method to the Limits interface - Implements a waitSimulatedLatency method in the Distributor - Adds a defer call in the Push method to apply the latency at the end of processing The latency is applied at the end of request processing to ensure that all requests take at least the configured latency time, but without adding additional latency to requests that are already slow. When the configured latency is 0s, the feature is disabled.
@@ -485,11 +485,30 @@ func (p *pushTracker) doneWithResult(err error) { | |||
} | |||
} | |||
|
|||
func (d *Distributor) waitSimulatedLatency(ctx context.Context, tenantID string, start time.Time) { | |||
latency := d.validator.Limits.SimulatedPushLatency(tenantID) | |||
if latency > 0 { |
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.
I believe this line can be removed as the condition is tested again when we check if wait > 0
. For example, when latency
is 0, then wait
is negative.
However, I suppose someone could set latency
to a negative number though? Is that a concern?
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.
Oh I see, you are using 0
as a special value to disable the feature.
func (d *Distributor) Push(ctx context.Context, req *logproto.PushRequest) (*logproto.PushResponse, error) { | ||
tenantID, err := tenant.TenantID(ctx) | ||
if err != nil { | ||
return nil, err | ||
} | ||
start := time.Now() | ||
defer d.waitSimulatedLatency(ctx, tenantID, start) |
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.
Btw it's OK to use time.Now()
as the argument to a deferred call. Go evaluates arguments for deferred functions when the defer
is pushed onto the call stack, not when it is executed.
defer d.waitSimulatedLatency(ctx, tenantID, start) | |
defer d.waitSimulatedLatency(ctx, tenantID, time.Now()) |
This change adds the ability to configure simulated latency on a per-tenant basis in the distributor. This is useful for testing and simulating real-world conditions.
The implementation:
simulated_latency
field to the Limits struct using model.DurationThe latency is applied at the end of request processing to ensure that all requests take at least the configured latency time, but without adding additional latency to requests that are already slow.
When the configured latency is 0s, the feature is disabled.