Skip to content
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

Enable deprecation log indexing by default #78319

Closed
Closed
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
94404f4
draft
pgomulka Sep 9, 2021
aa33bcf
default
pgomulka Sep 27, 2021
9546c5d
Merge remote-tracking branch 'upstream/master' into enable_deprecatio…
pgomulka Sep 27, 2021
5317180
use settings consumer
pgomulka Sep 28, 2021
66c1963
Merge remote-tracking branch 'upstream/master' into enable_deprecatio…
pgomulka Sep 28, 2021
b094f07
register setting
pgomulka Sep 28, 2021
42ca5f2
imports
pgomulka Sep 28, 2021
78ad881
enable settings on startup
pgomulka Sep 28, 2021
0091139
testcase
pgomulka Sep 28, 2021
a822e9d
remove comment
pgomulka Sep 28, 2021
aae2ec7
spotless
pgomulka Sep 28, 2021
736e508
docs
pgomulka Sep 28, 2021
5e747d6
Merge remote-tracking branch 'upstream/master' into enable_deprecatio…
pgomulka Sep 28, 2021
d8307ee
still failing test
pgomulka Sep 28, 2021
c7f12b7
code style
pgomulka Sep 28, 2021
41706ae
Merge remote-tracking branch 'upstream/master' into enable_deprecatio…
pgomulka Oct 1, 2021
d7d3b8d
fix tests
pgomulka Oct 1, 2021
5901d0e
cleanup
pgomulka Oct 1, 2021
86527e9
Merge remote-tracking branch 'upstream/master' into enable_deprecatio…
pgomulka Oct 4, 2021
4fda733
remove assertion on startup
pgomulka Oct 4, 2021
b1624ce
move test to separate class
pgomulka Oct 4, 2021
a1c6829
style
pgomulka Oct 4, 2021
a913634
fix client in a test
pgomulka Oct 4, 2021
0595739
javadocs
pgomulka Oct 4, 2021
0030f00
Merge branch 'master' into enable_deprecation_indexing_by_default
elasticmachine Oct 4, 2021
789a3c4
do not delete logs deprecation ds
pgomulka Oct 5, 2021
ba94da6
Merge branch 'enable_deprecation_indexing_by_default' of github.com:p…
pgomulka Oct 5, 2021
31851e2
Merge remote-tracking branch 'upstream/master' into enable_deprecatio…
pgomulka Oct 5, 2021
ba4334e
deprecated settings test with cleanup
pgomulka Oct 5, 2021
18c4177
fix default value for setting
pgomulka Oct 5, 2021
0436f7b
fix some tests
pgomulka Oct 5, 2021
f76e48c
fix doc test
pgomulka Oct 5, 2021
fd63dac
delete hidden data stream
pgomulka Oct 6, 2021
7011616
Merge remote-tracking branch 'upstream/master' into enable_deprecatio…
pgomulka Oct 6, 2021
faf5a32
compile fix
pgomulka Oct 6, 2021
0c77b99
delete data stream *
pgomulka Oct 6, 2021
a2d3803
auto expand replica
pgomulka Oct 6, 2021
935f802
imports and todo
pgomulka Oct 6, 2021
2515dfd
Merge remote-tracking branch 'upstream/master' into enable_deprecatio…
pgomulka Oct 6, 2021
b34bd64
flush processor when disabeling the indexing
pgomulka Oct 6, 2021
bf33cf0
use exact template in docs on DELETE/_index_template/*
pgomulka Oct 6, 2021
c93abdd
remove index_template cleanup in gradle as it should be handled in tests
pgomulka Oct 6, 2021
3144ec8
disable deprecation indxing in docs and runtime fields
pgomulka Oct 6, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@
import static org.elasticsearch.common.logging.DeprecatedMessage.X_OPAQUE_ID_FIELD_NAME;

@Plugin(name = "RateLimitingFilter", category = Node.CATEGORY, elementType = Filter.ELEMENT_TYPE)
public class RateLimitingFilter extends AbstractFilter {
public class RateLimitingFilter extends AbstractFilter {

private volatile boolean useXOpaqueId = true;

private final Set<String> lruKeyCache = Collections.newSetFromMap(Collections.synchronizedMap(new LinkedHashMap<>() {
@Override
Expand Down Expand Up @@ -57,16 +59,23 @@ public Result filter(Message message) {
if (message instanceof ESLogMessage) {
final ESLogMessage esLogMessage = (ESLogMessage) message;

String xOpaqueId = esLogMessage.get(X_OPAQUE_ID_FIELD_NAME);
final String key = esLogMessage.get(KEY_FIELD_NAME);

return lruKeyCache.add(xOpaqueId + key) ? Result.ACCEPT : Result.DENY;
final String key = getKey(esLogMessage);
return lruKeyCache.add(key) ? Result.ACCEPT : Result.DENY;

} else {
return Result.NEUTRAL;
}
}

private String getKey(ESLogMessage esLogMessage) {
final String key = esLogMessage.get(KEY_FIELD_NAME);
if (useXOpaqueId) {
String xOpaqueId = esLogMessage.get(X_OPAQUE_ID_FIELD_NAME);
return xOpaqueId + key;
}
return key;
}

@Override
public Result filter(LogEvent event) {
return filter(event.getMessage());
Expand All @@ -84,4 +93,8 @@ public static RateLimitingFilter createFilter(
) {
return new RateLimitingFilter(match, mismatch);
}

public void setUseXOpaqueId(boolean useXOpaqueId) {
this.useXOpaqueId = useXOpaqueId;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -147,4 +147,26 @@ public void testFilterCanBeReset() {
// Third time, it is allowed again
assertThat(filter.filter(message), equalTo(Result.ACCEPT));
}

public void testMessagesXOpaqueIsIgnoredWhenDisabled() {
RateLimitingFilter filter = new RateLimitingFilter();
filter.setUseXOpaqueId(false);
filter.start();

// Should NOT be rate-limited because it's not in the cache
Message message = DeprecatedMessage.of(DeprecationCategory.OTHER, "key 0", "opaque-id 0", "msg 0");
assertThat(filter.filter(message), equalTo(Result.ACCEPT));

// Should be rate-limited because it was just added to the cache
message = DeprecatedMessage.of(DeprecationCategory.OTHER, "key 0", "opaque-id 0", "msg 0");
assertThat(filter.filter(message), equalTo(Result.DENY));

// Should be rate-limited because X-Opaque-Id is not used
message = DeprecatedMessage.of(DeprecationCategory.OTHER, "key 0", "opaque-id 1", "msg 0");
assertThat(filter.filter(message), equalTo(Result.DENY));

// Should NOT be rate-limited because "key 1" it not in the cache
message = DeprecatedMessage.of(DeprecationCategory.OTHER, "key 1", "opaque-id 1", "msg 0");
assertThat(filter.filter(message), equalTo(Result.ACCEPT));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,16 @@ public class DeprecationIndexingComponent extends AbstractLifecycleComponent imp

public static final Setting<Boolean> WRITE_DEPRECATION_LOGS_TO_INDEX = Setting.boolSetting(
"cluster.deprecation_indexing.enabled",
false,
true,
Setting.Property.NodeScope,
Setting.Property.Dynamic
);
public static final Setting<Boolean> USE_X_OPAQUE_ID_IN_FILTERING = Setting.boolSetting(
"cluster.deprecation_indexing.x_opaque_id_used.enabled",
true,
Setting.Property.NodeScope,
Setting.Property.Dynamic
);

private final DeprecationIndexingAppender appender;
private final BulkProcessor processor;
private final RateLimitingFilter filter;
Expand Down Expand Up @@ -110,6 +115,8 @@ public void clusterChanged(ClusterChangedEvent event) {
}
appender.setEnabled(newEnabled);
}
final boolean useXOpaqueId = USE_X_OPAQUE_ID_IN_FILTERING.get(state.getMetadata().settings());
pgomulka marked this conversation as resolved.
Show resolved Hide resolved
this.filter.setUseXOpaqueId(useXOpaqueId);
}

/**
Expand Down