Skip to content

Commit 5e70eae

Browse files
authored
Add RateLimitingFiltering to plaintext deprecation logs (#69190)
The #61474 changed the way we throttle deprecation logs, but missed a filter to plaintext deprecation logs closes #69188
1 parent d21bec7 commit 5e70eae

File tree

3 files changed

+24
-0
lines changed

3 files changed

+24
-0
lines changed

distribution/src/config/log4j2.properties

+1
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ appender.deprecation_rolling_old.name = deprecation_rolling_old
8282
appender.deprecation_rolling_old.fileName = ${sys:es.logs.base_path}${sys:file.separator}${sys:es.logs.cluster_name}_deprecation.log
8383
appender.deprecation_rolling_old.layout.type = PatternLayout
8484
appender.deprecation_rolling_old.layout.pattern = [%d{ISO8601}][%-5p][%-25c{1.}] [%node_name]%marker %m%n
85+
appender.deprecation_rolling_old.filter.rate_limit.type = RateLimitingFilter
8586

8687
appender.deprecation_rolling_old.filePattern = ${sys:es.logs.base_path}${sys:file.separator}${sys:es.logs.cluster_name}\
8788
_deprecation-%i.log.gz

qa/logging-config/src/test/java/org/elasticsearch/common/logging/JsonLoggerTests.java

+15
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import org.junit.BeforeClass;
2929

3030
import java.io.IOException;
31+
import java.nio.file.Files;
3132
import java.nio.file.Path;
3233
import java.util.List;
3334
import java.util.Map;
@@ -40,6 +41,7 @@
4041
import static org.hamcrest.Matchers.hasEntry;
4142
import static org.hamcrest.Matchers.hasKey;
4243
import static org.hamcrest.Matchers.not;
44+
import static org.hamcrest.core.IsEqual.equalTo;
4345

4446
/**
4547
* This test confirms JSON log structure is properly formatted and can be parsed.
@@ -290,6 +292,9 @@ public void testDuplicateLogMessages() throws Exception {
290292
)
291293
);
292294
}
295+
296+
long oldStyleDeprecationLogCount = oldStyleDeprecationLogCount();
297+
assertThat(oldStyleDeprecationLogCount, equalTo(1L));
293298
});
294299

295300
// For the same key and different X-Opaque-ID should be multiple times per key/x-opaque-id
@@ -330,10 +335,20 @@ public void testDuplicateLogMessages() throws Exception {
330335
)
331336
)
332337
);
338+
339+
long oldStyleDeprecationLogCount = oldStyleDeprecationLogCount();
340+
assertThat(oldStyleDeprecationLogCount, equalTo(2L));
333341
}
334342
});
335343
}
336344

345+
private long oldStyleDeprecationLogCount() throws IOException {
346+
try(Stream<String> lines = Files.lines(PathUtils.get(System.getProperty("es.logs.base_path"),
347+
System.getProperty("es.logs.cluster_name") + "_deprecated.log"))){
348+
return lines.count();
349+
}
350+
}
351+
337352
private List<JsonLogLine> collectLines(Stream<JsonLogLine> stream) {
338353
return stream
339354
.skip(1)//skip the first line from super class

qa/logging-config/src/test/resources/org/elasticsearch/common/logging/json_layout/log4j2.properties

+8
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,13 @@ appender.deprecated.layout.type_name = deprecation
1717
appender.deprecated.layout.esmessagefields = x-opaque-id
1818
appender.deprecated.filter.rate_limit.type = RateLimitingFilter
1919

20+
appender.deprecation_rolling_old.type = File
21+
appender.deprecation_rolling_old.name = deprecation_rolling_old
22+
appender.deprecation_rolling_old.fileName = ${sys:es.logs.base_path}${sys:file.separator}${sys:es.logs.cluster_name}_deprecated.log
23+
appender.deprecation_rolling_old.layout.type = PatternLayout
24+
appender.deprecation_rolling_old.layout.pattern = [%d{ISO8601}][%-5p][%-25c{1.}] [%node_name]%marker %m%n
25+
appender.deprecation_rolling_old.filter.rate_limit.type = RateLimitingFilter
26+
2027
appender.deprecatedconsole.type = Console
2128
appender.deprecatedconsole.name = deprecatedconsole
2229
appender.deprecatedconsole.layout.type = ESJsonLayout
@@ -44,6 +51,7 @@ logger.deprecation.level = deprecation
4451
logger.deprecation.appenderRef.console.ref = console
4552
logger.deprecation.appenderRef.file.ref = file
4653
logger.deprecation.appenderRef.deprecation_rolling.ref = deprecated
54+
logger.deprecation.appenderRef.deprecation_rolling_old.ref = deprecation_rolling_old
4755
logger.deprecation.appenderRef.deprecatedconsole.ref = deprecatedconsole
4856
logger.deprecation.appenderRef.header_warning.ref = header_warning
4957
logger.deprecation.additivity = false

0 commit comments

Comments
 (0)