-
Notifications
You must be signed in to change notification settings - Fork 24.7k
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
Do no use x-opaque-id
for deduplicating Elastic originating requests
#82855
Changes from 3 commits
909a1f6
d788bf0
0335702
cc82822
e3d95eb
6dcfa57
d184961
f654de4
4667cc0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,6 +25,7 @@ | |
import java.util.Map; | ||
import java.util.Set; | ||
|
||
import static org.elasticsearch.common.logging.DeprecatedMessage.ELASTIC_ORIGIN_FIELD_NAME; | ||
import static org.elasticsearch.common.logging.DeprecatedMessage.KEY_FIELD_NAME; | ||
import static org.elasticsearch.common.logging.DeprecatedMessage.X_OPAQUE_ID_FIELD_NAME; | ||
|
||
|
@@ -35,13 +36,14 @@ | |
* This filter works by using a lruKeyCache - a set of keys which prevents a second message with the same key to be logged. | ||
* The lruKeyCache has a size limited to 128, which when breached will remove the oldest entries. | ||
* | ||
* It is possible to disable use of `x-opaque-id` as a key with {@link RateLimitingFilter#setUseXOpaqueId(boolean) } | ||
* It is possible to disable use of `x-opaque-id` as a key with {@link RateLimitingFilter#setUseXOpaqueIdEnabled(boolean) } | ||
* @see <a href="https://logging.apache.org/log4j/2.x/manual/filters.htmlf">Log4j2 Filters</a> | ||
*/ | ||
@Plugin(name = "RateLimitingFilter", category = Node.CATEGORY, elementType = Filter.ELEMENT_TYPE) | ||
public class RateLimitingFilter extends AbstractFilter { | ||
|
||
private volatile boolean useXOpaqueId = true; | ||
private static final String KIBANA_OPRDUCT_ORIGIN = "kibana"; | ||
// a flag to disable/enable use of xOpaqueId controlled by changing cluster setting | ||
private volatile boolean useXOpaqueIdEnabled = true; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why the addition of "enabled"? The "use" prefix already denotes a boolean. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. true - it does not make sens to me now either. I can't remember what I was thinking when renaming.. |
||
|
||
private final Set<String> lruKeyCache = Collections.newSetFromMap(Collections.synchronizedMap(new LinkedHashMap<>() { | ||
@Override | ||
|
@@ -76,7 +78,8 @@ public Result filter(Message message) { | |
|
||
private String getKey(ESLogMessage esLogMessage) { | ||
final String key = esLogMessage.get(KEY_FIELD_NAME); | ||
if (useXOpaqueId) { | ||
final String productOrigin = esLogMessage.get(ELASTIC_ORIGIN_FIELD_NAME); | ||
if (useXOpaqueIdEnabled && KIBANA_OPRDUCT_ORIGIN.equals(productOrigin) == false) { | ||
String xOpaqueId = esLogMessage.get(X_OPAQUE_ID_FIELD_NAME); | ||
return xOpaqueId + key; | ||
} | ||
|
@@ -101,7 +104,7 @@ public static RateLimitingFilter createFilter( | |
return new RateLimitingFilter(match, mismatch); | ||
} | ||
|
||
public void setUseXOpaqueId(boolean useXOpaqueId) { | ||
this.useXOpaqueId = useXOpaqueId; | ||
public void setUseXOpaqueIdEnabled(boolean useXOpaqueIdEnabled) { | ||
this.useXOpaqueIdEnabled = useXOpaqueIdEnabled; | ||
} | ||
} |
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.
is this a typo or intentional?
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.
that was a typo. The constant is not needed as this change will apply to all elastic originating requests