Log rate limit sampler rename `qps` to `rpm` (#7384)

This commit is contained in:
kezhenxu94 2021-07-29 18:11:07 +08:00 committed by GitHub
parent 85669fb40f
commit 65e8ab3ecc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 18 additions and 17 deletions

View File

@ -122,6 +122,7 @@ Release Notes.
* Filtering NaN value samples when build SampleFamily
* Add Thread and ClassLoader Metrics for the self-observability and otel-oc-rules
* Simple optimization of trace sql query statement. Avoid "select *" query method
* Breaking Change: rename `qps` to `rpm` in LAL
#### UI

View File

@ -38,11 +38,11 @@ rules:
sampler {
if (log.service == "ImportantApp") {
rateLimit("ImportantAppSampler") {
qps 300
rpm 18000
}
} else {
rateLimit("OtherSampler") {
qps 30
rpm 1800
}
}
}

View File

@ -244,8 +244,8 @@ Sampler allows you to save the logs in a sampling manner. Currently, the samplin
contributions on more sampling strategies. If multiple samplers are specified, the last one determines the final sampling
result. See examples in [Enforcer](#enforcer).
`rateLimit` samples `n` logs at a maximum rate of 1 second. `rateLimit("SamplerID")` requires an ID for the sampler. Sampler
declarations with the same ID share the same sampler instance, thus sharing the same `qps` and resetting logic.
`rateLimit` samples `n` logs at a maximum rate of 1 minute. `rateLimit("SamplerID")` requires an ID for the sampler. Sampler
declarations with the same ID share the same sampler instance, thus sharing the same `rpm` and resetting logic.
Examples:
@ -257,11 +257,11 @@ filter {
sampler {
if (parsed.service == "ImportantApp") {
rateLimit("ImportantAppSampler") {
qps 30 // samples 30 pieces of logs every second for service "ImportantApp"
rpm 1800 // samples 1800 pieces of logs every minute for service "ImportantApp"
}
} else {
rateLimit("OtherSampler") {
qps 3 // samples 3 pieces of logs every second for other services than "ImportantApp"
rpm 180 // samples 180 pieces of logs every minute for other services than "ImportantApp"
}
}
}

View File

@ -31,11 +31,11 @@ import lombok.experimental.Accessors;
import lombok.extern.slf4j.Slf4j;
@Accessors(fluent = true)
@EqualsAndHashCode(of = {"qps"})
@EqualsAndHashCode(of = {"rpm"})
public class RateLimitingSampler implements Sampler {
@Getter
@Setter
private volatile int qps;
private volatile int rpm;
private final AtomicInteger factor = new AtomicInteger();
@ -58,7 +58,7 @@ public class RateLimitingSampler implements Sampler {
@Override
public boolean sample() {
return factor.getAndIncrement() < qps;
return factor.getAndIncrement() < rpm;
}
@Override
@ -80,7 +80,7 @@ public class RateLimitingSampler implements Sampler {
if (!started) {
future = Executors.newSingleThreadScheduledExecutor()
.scheduleAtFixedRate(this::reset, 1, 1, TimeUnit.SECONDS);
.scheduleAtFixedRate(this::reset, 1, 1, TimeUnit.MINUTES);
started = true;
}
}

View File

@ -93,13 +93,13 @@ public class DSLTest {
" // use service:errorCode as sampler id so that each service:errorCode has its own sampler,\n" +
" // e.g. checkoutservice:[upstreamConnectionFailure], checkoutservice:[upstreamRetryLimitExceeded]\n" +
" rateLimit(\"${log.service}:${log.body.json.json}:${log.tags.getData(0).key}:${parsed?.commonProperties?.responseFlags}\") {\n" +
" qps 100\n" +
" rpm 100\n" +
" }\n" +
" } else {\n" +
" // use service:responseCode as sampler id so that each service:responseCode has its own sampler,\n" +
" // e.g. checkoutservice:500, checkoutservice:404.\n" +
" rateLimit(\"${log.service}:${log.body?.type}:${log.traceContext?.traceId}:${parsed?.response?.responseCode}\") {\n" +
" qps 100\n" +
" rpm 100\n" +
" }\n" +
" }\n" +
" }\n" +
@ -146,13 +146,13 @@ public class DSLTest {
" // use service:errorCode as sampler id so that each service:errorCode has its own sampler,\n" +
" // e.g. checkoutservice:[upstreamConnectionFailure], checkoutservice:[upstreamRetryLimitExceeded]\n" +
" rateLimit(\"${log.service}:${(parsed?.commonProperties?.responseFlags as Map)?.keySet()}\") {\n" +
" qps 100\n" +
" rpm 100\n" +
" }\n" +
" } else {\n" +
" // use service:responseCode as sampler id so that each service:responseCode has its own sampler,\n" +
" // e.g. checkoutservice:500, checkoutservice:404.\n" +
" rateLimit(\"${log.service}:${parsed?.response?.responseCode}\") {\n" +
" qps 100\n" +
" rpm 100\n" +
" }\n" +
" }\n" +
" }\n" +

View File

@ -33,13 +33,13 @@ rules:
// use service:errorCode as sampler id so that each service:errorCode has its own sampler,
// e.g. checkoutservice:[upstreamConnectionFailure], checkoutservice:[upstreamRetryLimitExceeded]
rateLimit("${log.service}:${parsed?.commonProperties?.responseFlags?.toString()}") {
qps 100
rpm 6000
}
} else {
// use service:responseCode as sampler id so that each service:responseCode has its own sampler,
// e.g. checkoutservice:500, checkoutservice:404.
rateLimit("${log.service}:${parsed?.response?.responseCode}") {
qps 100
rpm 6000
}
}
}

View File

@ -40,4 +40,4 @@ message RemoteData {
}
message Empty {
}
}