Skip to content

Commit

Permalink
Add RateLimitingFiltering to plaintext deprecation logs (#69190)
Browse files Browse the repository at this point in the history
The #61474 changed the way we throttle deprecation logs, but missed a
filter to plaintext deprecation logs

closes #69188
  • Loading branch information
pgomulka authored Feb 23, 2021
1 parent d21bec7 commit 5e70eae
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 0 deletions.
1 change: 1 addition & 0 deletions distribution/src/config/log4j2.properties
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ appender.deprecation_rolling_old.name = deprecation_rolling_old
appender.deprecation_rolling_old.fileName = ${sys:es.logs.base_path}${sys:file.separator}${sys:es.logs.cluster_name}_deprecation.log
appender.deprecation_rolling_old.layout.type = PatternLayout
appender.deprecation_rolling_old.layout.pattern = [%d{ISO8601}][%-5p][%-25c{1.}] [%node_name]%marker %m%n
appender.deprecation_rolling_old.filter.rate_limit.type = RateLimitingFilter

appender.deprecation_rolling_old.filePattern = ${sys:es.logs.base_path}${sys:file.separator}${sys:es.logs.cluster_name}\
_deprecation-%i.log.gz
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import org.junit.BeforeClass;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.List;
import java.util.Map;
Expand All @@ -40,6 +41,7 @@
import static org.hamcrest.Matchers.hasEntry;
import static org.hamcrest.Matchers.hasKey;
import static org.hamcrest.Matchers.not;
import static org.hamcrest.core.IsEqual.equalTo;

/**
* This test confirms JSON log structure is properly formatted and can be parsed.
Expand Down Expand Up @@ -290,6 +292,9 @@ public void testDuplicateLogMessages() throws Exception {
)
);
}

long oldStyleDeprecationLogCount = oldStyleDeprecationLogCount();
assertThat(oldStyleDeprecationLogCount, equalTo(1L));
});

// For the same key and different X-Opaque-ID should be multiple times per key/x-opaque-id
Expand Down Expand Up @@ -330,10 +335,20 @@ public void testDuplicateLogMessages() throws Exception {
)
)
);

long oldStyleDeprecationLogCount = oldStyleDeprecationLogCount();
assertThat(oldStyleDeprecationLogCount, equalTo(2L));
}
});
}

private long oldStyleDeprecationLogCount() throws IOException {
try(Stream<String> lines = Files.lines(PathUtils.get(System.getProperty("es.logs.base_path"),
System.getProperty("es.logs.cluster_name") + "_deprecated.log"))){
return lines.count();
}
}

private List<JsonLogLine> collectLines(Stream<JsonLogLine> stream) {
return stream
.skip(1)//skip the first line from super class
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,13 @@ appender.deprecated.layout.type_name = deprecation
appender.deprecated.layout.esmessagefields = x-opaque-id
appender.deprecated.filter.rate_limit.type = RateLimitingFilter

appender.deprecation_rolling_old.type = File
appender.deprecation_rolling_old.name = deprecation_rolling_old
appender.deprecation_rolling_old.fileName = ${sys:es.logs.base_path}${sys:file.separator}${sys:es.logs.cluster_name}_deprecated.log
appender.deprecation_rolling_old.layout.type = PatternLayout
appender.deprecation_rolling_old.layout.pattern = [%d{ISO8601}][%-5p][%-25c{1.}] [%node_name]%marker %m%n
appender.deprecation_rolling_old.filter.rate_limit.type = RateLimitingFilter

appender.deprecatedconsole.type = Console
appender.deprecatedconsole.name = deprecatedconsole
appender.deprecatedconsole.layout.type = ESJsonLayout
Expand Down Expand Up @@ -44,6 +51,7 @@ logger.deprecation.level = deprecation
logger.deprecation.appenderRef.console.ref = console
logger.deprecation.appenderRef.file.ref = file
logger.deprecation.appenderRef.deprecation_rolling.ref = deprecated
logger.deprecation.appenderRef.deprecation_rolling_old.ref = deprecation_rolling_old
logger.deprecation.appenderRef.deprecatedconsole.ref = deprecatedconsole
logger.deprecation.appenderRef.header_warning.ref = header_warning
logger.deprecation.additivity = false
Expand Down

0 comments on commit 5e70eae

Please sign in to comment.