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

Write deprecation logs to a data stream #58924

Closed
Closed
Show file tree
Hide file tree
Changes from 61 commits
Commits
Show all changes
66 commits
Select commit Hold shift + click to select a range
36ac092
Introduce DeprecationIndexingService
pugnascotia Jun 17, 2020
cf5a677
First go at ensuring the data stream template is loaded
pugnascotia Jun 17, 2020
86c3d7d
Tweaks index name
pugnascotia Jun 30, 2020
d74dc9a
WIP - Adding tests for DeprecationIndexingService
pugnascotia Jul 2, 2020
6457f97
More tests
pugnascotia Jul 2, 2020
f0e0192
Fix template index pattern
pugnascotia Jul 2, 2020
581be1f
Merge remote-tracking branch 'upstream/master' into index-deprecation…
pugnascotia Jul 2, 2020
14c929a
Rework deprecation code so that log handlers are more generic
pugnascotia Jul 3, 2020
e902fb9
Move DeprecationIndexingService to x-pack depreacation plugin
pugnascotia Jul 3, 2020
40bea2c
Don't need a custom template any more :tada:
pugnascotia Jul 7, 2020
013bf55
Remove unused import
pugnascotia Jul 7, 2020
4c189da
Merge remote-tracking branch 'upstream/master' into index-deprecation…
pugnascotia Jul 7, 2020
d61b145
License header fix
pugnascotia Jul 7, 2020
ae62d06
Remove unused imports
pugnascotia Jul 7, 2020
32d8316
Add Javadoc
pugnascotia Jul 7, 2020
25ea88f
Silence log checker error
pugnascotia Jul 7, 2020
dce2a5d
Merge remote-tracking branch 'upstream/master' into index-deprecation…
pugnascotia Jul 7, 2020
3482d31
Subtitute log message params, simplify things
pugnascotia Jul 8, 2020
34e5529
Merge remote-tracking branch 'upstream/master' into index-deprecation…
pugnascotia Jul 8, 2020
f7f9ea7
Fixes
pugnascotia Jul 8, 2020
46c5aca
Use BulkProcessor in DeprecationIndexingService
pugnascotia Jul 9, 2020
c8d8086
Use the opaque ID from the EsLogMessage
pugnascotia Jul 9, 2020
4bf9b34
Record cluster and node IDs
pugnascotia Jul 13, 2020
75eac35
Tweaks
pugnascotia Jul 14, 2020
abd8381
Merge remote-tracking branch 'upstream/master' into index-deprecation…
pugnascotia Jul 14, 2020
8e4339f
WIP - trying a log4j implementation
pugnascotia Jul 15, 2020
d33b72b
Reimplement deprecation logging using log4j
pugnascotia Jul 17, 2020
379ca5d
Merge remote-tracking branch 'upstream/master' into index-deprecation…
pugnascotia Jul 17, 2020
4aead94
Reimplement using log4j abstractions
pugnascotia Jul 20, 2020
e8d246b
Polishing
pugnascotia Jul 20, 2020
31ff5fe
Merge remote-tracking branch 'upstream/master' into index-deprecation…
pugnascotia Jul 21, 2020
95e3fc3
More polishing
pugnascotia Jul 21, 2020
c0b8f65
Include key in DeprecatedMessage.of(...)
pugnascotia Jul 21, 2020
07c34cc
Merge remote-tracking branch 'upstream/master' into index-deprecation…
pugnascotia Jul 22, 2020
d6a75bd
Strip out UnionFilter
pugnascotia Jul 22, 2020
074ef8d
Build deprecation msg docs using EcsJsonLayout
pugnascotia Jul 22, 2020
516ce6d
Checkstyle
pugnascotia Jul 22, 2020
a750f49
Update docker log4j configs
pugnascotia Jul 22, 2020
2352a20
Fix libs tests
pugnascotia Jul 23, 2020
3b80fdd
Configure HeaderWarningAppender in ESTestCase
pugnascotia Jul 23, 2020
1a3f2da
Fix docker log4j deprecation levels
pugnascotia Jul 23, 2020
3db6c7a
Test fixes
pugnascotia Jul 23, 2020
edd0466
Merge remote-tracking branch 'upstream/master' into index-deprecation…
pugnascotia Jul 27, 2020
0d70f53
Merge remote-tracking branch 'upstream/master' into index-deprecation…
pugnascotia Jul 31, 2020
5529912
WIP - trying to write an integration test
pugnascotia Aug 3, 2020
3452367
Implement indexing test
pugnascotia Aug 4, 2020
d17a5e8
WIP - trying to rewrite DeprecationHttpIT as a rest test
pugnascotia Aug 5, 2020
8f70584
Tests execute against custom plugin, but need fixed
pugnascotia Aug 7, 2020
4f6f501
Rework deprecation HTTP tests
pugnascotia Aug 12, 2020
98def13
Merge remote-tracking branch 'upstream/master' into index-deprecation…
pugnascotia Aug 12, 2020
97f4934
Merge remote-tracking branch 'upstream/master' into index-deprecation…
pugnascotia Aug 12, 2020
26a3495
Tweaks
pugnascotia Aug 12, 2020
c070571
Merge branch 'index-deprecation-logs-v2-tests' into index-deprecation…
pugnascotia Aug 12, 2020
022793e
Fix tests finally, by resetting the rate limiting filter
pugnascotia Aug 13, 2020
d8eee69
Merge remote-tracking branch 'upstream/master' into index-deprecation…
pugnascotia Aug 13, 2020
afc4dcf
Add test
pugnascotia Aug 13, 2020
2d1d3fb
Merge remote-tracking branch 'upstream/master' into index-deprecation…
pugnascotia Aug 13, 2020
3c8069b
Fix license checks
pugnascotia Aug 13, 2020
2dac9a3
Formatting
pugnascotia Aug 13, 2020
f0f3edb
Remove redundant line
pugnascotia Aug 13, 2020
9877d57
Merge branch 'master' into index-deprecation-logs-v2
elasticmachine Aug 14, 2020
1309355
Remove unused import
pugnascotia Aug 17, 2020
bd8e3c9
Merge remote-tracking branch 'upstream/master' into index-deprecation…
pugnascotia Aug 18, 2020
76993c9
Add warning headers solely through the log4j appender
pugnascotia Aug 18, 2020
e695753
Merge branch 'master' into index-deprecation-logs-v2
elasticmachine Aug 19, 2020
3ff1015
Fixes to JsonLoggerTest
pugnascotia Aug 19, 2020
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
7 changes: 6 additions & 1 deletion distribution/docker/src/docker/config/log4j2.properties
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,15 @@ appender.deprecation_rolling.type = Console
appender.deprecation_rolling.name = deprecation_rolling
appender.deprecation_rolling.layout.type = ECSJsonLayout
appender.deprecation_rolling.layout.type_name = deprecation
appender.deprecation_rolling.filter.rate_limit.type = RateLimitingFilter

appender.header_warning.type = HeaderWarningAppender
appender.header_warning.name = header_warning

logger.deprecation.name = org.elasticsearch.deprecation
logger.deprecation.level = warn
logger.deprecation.level = deprecation
logger.deprecation.appenderRef.deprecation_rolling.ref = deprecation_rolling
logger.deprecation.appenderRef.header_warning.ref = header_warning
logger.deprecation.additivity = false

appender.index_search_slowlog_rolling.type = Console
Expand Down
7 changes: 6 additions & 1 deletion distribution/docker/src/docker/config/oss/log4j2.properties
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,15 @@ appender.deprecation_rolling.type = Console
appender.deprecation_rolling.name = deprecation_rolling
appender.deprecation_rolling.layout.type = ECSJsonLayout
appender.deprecation_rolling.layout.type_name = deprecation
appender.deprecation_rolling.filter.rate_limit.type = RateLimitingFilter

appender.header_warning.type = HeaderWarningAppender
appender.header_warning.name = header_warning

logger.deprecation.name = org.elasticsearch.deprecation
logger.deprecation.level = warn
logger.deprecation.level = deprecation
logger.deprecation.appenderRef.deprecation_rolling.ref = deprecation_rolling
logger.deprecation.appenderRef.header_warning.ref = header_warning
logger.deprecation.additivity = false

appender.index_search_slowlog_rolling.type = Console
Expand Down
7 changes: 6 additions & 1 deletion distribution/src/config/log4j2.properties
Original file line number Diff line number Diff line change
Expand Up @@ -63,18 +63,23 @@ appender.deprecation_rolling.name = deprecation_rolling
appender.deprecation_rolling.fileName = ${sys:es.logs.base_path}${sys:file.separator}${sys:es.logs.cluster_name}_deprecation.json
appender.deprecation_rolling.layout.type = ECSJsonLayout
appender.deprecation_rolling.layout.type_name = deprecation
appender.deprecation_rolling.filter.rate_limit.type = RateLimitingFilter
pugnascotia marked this conversation as resolved.
Show resolved Hide resolved

appender.deprecation_rolling.filePattern = ${sys:es.logs.base_path}${sys:file.separator}${sys:es.logs.cluster_name}_deprecation-%i.json.gz
appender.deprecation_rolling.policies.type = Policies
appender.deprecation_rolling.policies.size.type = SizeBasedTriggeringPolicy
appender.deprecation_rolling.policies.size.size = 1GB
appender.deprecation_rolling.strategy.type = DefaultRolloverStrategy
appender.deprecation_rolling.strategy.max = 4

pugnascotia marked this conversation as resolved.
Show resolved Hide resolved
appender.header_warning.type = HeaderWarningAppender
appender.header_warning.name = header_warning
#################################################

logger.deprecation.name = org.elasticsearch.deprecation
logger.deprecation.level = warn
logger.deprecation.level = deprecation
logger.deprecation.appenderRef.deprecation_rolling.ref = deprecation_rolling
logger.deprecation.appenderRef.header_warning.ref = header_warning
logger.deprecation.additivity = false

######## Search slowlog JSON ####################
Expand Down
8 changes: 8 additions & 0 deletions libs/x-content/src/main/resources/log4j2.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
appender.header_warning.type = HeaderWarningAppender
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you explain why this file is needed?

appender.header_warning.name = header_warning

logger.deprecation.name = deprecation
logger.deprecation.level = deprecation
logger.deprecation.appenderRef.deprecation_file.ref = deprecation_file
logger.deprecation.appenderRef.header_warning.ref = header_warning
logger.deprecation.additivity = false
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
import java.util.stream.Collectors;
import java.util.stream.IntStream;

import static org.elasticsearch.common.logging.DeprecationLogger.DEPRECATION;
import static org.hamcrest.Matchers.endsWith;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.hasItem;
Expand Down Expand Up @@ -119,7 +120,7 @@ public void testConcurrentDeprecationLogger() throws IOException, UserException,
final List<Integer> ids = IntStream.range(0, 128).boxed().collect(Collectors.toList());
Randomness.shuffle(ids);
final ThreadContext threadContext = new ThreadContext(Settings.EMPTY);
DeprecationLogger.setThreadContext(threadContext);
HeaderWarning.setThreadContext(threadContext);
try {
barrier.await();
} catch (final BrokenBarrierException | InterruptedException e) {
Expand Down Expand Up @@ -180,8 +181,8 @@ public void testConcurrentDeprecationLogger() throws IOException, UserException,
for (int i = 0; i < 128; i++) {
assertLogLine(
deprecationEvents.get(i),
Level.WARN,
"org.elasticsearch.common.logging.ThrottlingLogger\\$2\\.run",
DEPRECATION,
"org.elasticsearch.common.logging.DeprecationLogger\\$DeprecationLoggerBuilder.withDeprecation",
"This is a maybe logged deprecation message" + i);
}

Expand All @@ -191,49 +192,6 @@ public void testConcurrentDeprecationLogger() throws IOException, UserException,

}

public void testDeprecationLoggerMaybeLog() throws IOException, UserException {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed this test because the rate-limiting functionality now lives in a dedicated Filter.

setupLogging("deprecation");

final DeprecationLogger deprecationLogger = DeprecationLogger.getLogger("deprecation");

final int iterations = randomIntBetween(1, 16);

for (int i = 0; i < iterations; i++) {
deprecationLogger.deprecate("key", "This is a maybe logged deprecation message");
assertWarnings("This is a maybe logged deprecation message");
}
for (int k = 0; k < 128; k++) {
for (int i = 0; i < iterations; i++) {
deprecationLogger.deprecate("key" + k, "This is a maybe logged deprecation message" + k);
assertWarnings("This is a maybe logged deprecation message" + k);
}
}
for (int i = 0; i < iterations; i++) {
deprecationLogger.deprecate("key", "This is a maybe logged deprecation message");
assertWarnings("This is a maybe logged deprecation message");
}

final String deprecationPath =
System.getProperty("es.logs.base_path") +
System.getProperty("file.separator") +
System.getProperty("es.logs.cluster_name") +
"_deprecation.log";
final List<String> deprecationEvents = Files.readAllLines(PathUtils.get(deprecationPath));
assertThat(deprecationEvents.size(), equalTo(1 + 128 + 1));
assertLogLine(
deprecationEvents.get(0),
Level.WARN,
"org.elasticsearch.common.logging.ThrottlingLogger\\$2\\.run",
"This is a maybe logged deprecation message");
for (int k = 0; k < 128; k++) {
assertLogLine(
deprecationEvents.get(1 + k),
Level.WARN,
"org.elasticsearch.common.logging.ThrottlingLogger\\$2\\.run",
"This is a maybe logged deprecation message" + k);
}
}

public void testDeprecatedSettings() throws IOException, UserException {
setupLogging("settings");

Expand All @@ -256,8 +214,8 @@ public void testDeprecatedSettings() throws IOException, UserException {
assertThat(deprecationEvents.size(), equalTo(1));
assertLogLine(
deprecationEvents.get(0),
Level.WARN,
"org.elasticsearch.common.logging.ThrottlingLogger\\$2\\.run",
DEPRECATION,
"org.elasticsearch.common.logging.DeprecationLogger\\$DeprecationLoggerBuilder.withDeprecation",
"\\[deprecated.foo\\] setting was deprecated in Elasticsearch and will be removed in a future release! " +
"See the breaking changes documentation for the next major version.");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,11 @@ appender.deprecation_file.fileName = ${sys:es.logs.base_path}${sys:file.separato
appender.deprecation_file.layout.type = PatternLayout
appender.deprecation_file.layout.pattern = [%p][%l] [%test_thread_info]%marker %m%n

appender.header_warning.type = HeaderWarningAppender
appender.header_warning.name = header_warning

logger.deprecation.name = deprecation
logger.deprecation.level = warn
logger.deprecation.appenderRef.deprecation_file.ref = deprecation_file
logger.deprecation.appenderRef.header_warning.ref = header_warning
logger.deprecation.additivity = false
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,13 @@ appender.deprecation_file.name = deprecation_file
appender.deprecation_file.fileName = ${sys:es.logs.base_path}${sys:file.separator}${sys:es.logs.cluster_name}_deprecation.log
appender.deprecation_file.layout.type = PatternLayout
appender.deprecation_file.layout.pattern = [%p][%l] [%test_thread_info]%marker %m%n
appender.deprecation_file.filter.rate_limit.type = RateLimitingFilter

appender.header_warning.type = HeaderWarningAppender
appender.header_warning.name = header_warning

logger.deprecation.name = deprecation
logger.deprecation.level = warn
logger.deprecation.level = deprecation
logger.deprecation.appenderRef.deprecation_file.ref = deprecation_file
logger.deprecation.appenderRef.header_warning.ref = header_warning
logger.deprecation.additivity = false
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,11 @@ appender.deprecation_file.fileName = ${sys:es.logs.base_path}${sys:file.separato
appender.deprecation_file.layout.type = PatternLayout
appender.deprecation_file.layout.pattern = [%p][%l] %marker%m%n

appender.header_warning.type = HeaderWarningAppender
appender.header_warning.name = header_warning

logger.deprecation.name = deprecation
logger.deprecation.level = warn
logger.deprecation.appenderRef.deprecation_file.ref = deprecation_file
logger.deprecation.appenderRef.header_warning.ref = header_warning
logger.deprecation.additivity = false
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,14 @@ appender.deprecation_file.name = deprecation_file
appender.deprecation_file.fileName = ${sys:es.logs.base_path}${sys:file.separator}${sys:es.logs.cluster_name}_deprecation.log
appender.deprecation_file.layout.type = PatternLayout
appender.deprecation_file.layout.pattern = [%p][%l] [%test_thread_info]%marker %m%n
appender.deprecation_file.filter.rate_limit.type = RateLimitingFilter

appender.header_warning.type = HeaderWarningAppender
appender.header_warning.name = header_warning

logger.deprecation.name = org.elasticsearch.deprecation.common.settings
logger.deprecation.level = warn
logger.deprecation.level = deprecation
logger.deprecation.appenderRef.deprecation_console.ref = console
logger.deprecation.appenderRef.deprecation_file.ref = deprecation_file
logger.deprecation.appenderRef.header_warning.ref = header_warning
logger.deprecation.additivity = false
4 changes: 4 additions & 0 deletions qa/logging-config/custom-log4j2.properties
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,14 @@ appender.deprecation_rolling_old.policies.size.size = 1GB
appender.deprecation_rolling_old.strategy.type = DefaultRolloverStrategy
appender.deprecation_rolling_old.strategy.max = 4
#################################################
appender.header_warning.type = HeaderWarningAppender
appender.header_warning.name = header_warning
#################################################
logger.deprecation.name = org.elasticsearch.deprecation
logger.deprecation.level = warn
logger.deprecation.appenderRef.deprecation_rolling.ref = deprecation_rolling
logger.deprecation.appenderRef.deprecation_rolling_old.ref = deprecation_rolling_old
logger.deprecation.appenderRef.header_warning.ref = header_warning
logger.deprecation.additivity = false

######## Search slowlog JSON ####################
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
import java.util.stream.Collectors;
import java.util.stream.Stream;

import static org.elasticsearch.common.logging.DeprecationLogger.DEPRECATION;
import static org.hamcrest.Matchers.allOf;
import static org.hamcrest.Matchers.contains;
import static org.hamcrest.Matchers.hasEntry;
Expand Down Expand Up @@ -87,18 +88,19 @@ public void tearDown() throws Exception {

public void testDeprecatedMessage() throws IOException {
final Logger testLogger = LogManager.getLogger("deprecation.test");
testLogger.info(DeprecatedMessage.of("someId","deprecated message1"));
testLogger.log(DEPRECATION, DeprecatedMessage.of("someKey", "someId","deprecated message1"));

final Path path = PathUtils.get(System.getProperty("es.logs.base_path"),
System.getProperty("es.logs.cluster_name") + "_deprecated.json");

try (Stream<Map<String, String>> stream = JsonLogsStream.mapStreamFrom(path)) {
List<Map<String, String>> jsonLogs = stream
.collect(Collectors.toList());

assertThat(jsonLogs, contains(
allOf(
hasEntry("type", "deprecation"),
hasEntry("log.level", "INFO"),
hasEntry("log.level", "DEPRECATION"),
hasEntry("log.logger", "deprecation.test"),
hasEntry("cluster.name", "elasticsearch"),
hasEntry("node.name", "sample-name"),
Expand All @@ -107,6 +109,8 @@ public void testDeprecatedMessage() throws IOException {
)
);
}

assertWarnings("deprecated message1");
}

public void testBuildingMessage() throws IOException {
Expand Down Expand Up @@ -169,10 +173,11 @@ public void testCustomMessageWithMultipleFields() throws IOException {

public void testDeprecatedMessageWithoutXOpaqueId() throws IOException {
final Logger testLogger = LogManager.getLogger("deprecation.test");
testLogger.info( DeprecatedMessage.of("someId","deprecated message1"));
testLogger.info( DeprecatedMessage.of("","deprecated message2"));
testLogger.info( DeprecatedMessage.of(null,"deprecated message3"));
testLogger.info("deprecated message4");
testLogger.log(DEPRECATION, DeprecatedMessage.of("a key", "someOtherId","deprecated message1"));
testLogger.log(DEPRECATION, DeprecatedMessage.of("a key", "", "deprecated message2"));
// This next message will be filtered out, because a null opaque ID has the same effect as an empty ID.
testLogger.log(DEPRECATION, DeprecatedMessage.of("a key", null,"deprecated message3"));
testLogger.log(DEPRECATION,"deprecated message4");

final Path path = PathUtils.get(System.getProperty("es.logs.base_path"),
System.getProperty("es.logs.cluster_name") + "_deprecated.json");
Expand All @@ -183,15 +188,15 @@ public void testDeprecatedMessageWithoutXOpaqueId() throws IOException {
assertThat(jsonLogs, contains(
allOf(
hasEntry("type", "deprecation"),
hasEntry("log.level", "INFO"),
hasEntry("log.level", "DEPRECATION"),
hasEntry("log.logger", "deprecation.test"),
hasEntry("cluster.name", "elasticsearch"),
hasEntry("node.name", "sample-name"),
hasEntry("message", "deprecated message1"),
hasEntry("x-opaque-id", "someId")),
hasEntry("x-opaque-id", "someOtherId")),
allOf(
hasEntry("type", "deprecation"),
hasEntry("log.level", "INFO"),
hasEntry("log.level", "DEPRECATION"),
hasEntry("log.logger", "deprecation.test"),
hasEntry("cluster.name", "elasticsearch"),
hasEntry("node.name", "sample-name"),
Expand All @@ -200,16 +205,7 @@ public void testDeprecatedMessageWithoutXOpaqueId() throws IOException {
),
allOf(
hasEntry("type", "deprecation"),
hasEntry("log.level", "INFO"),
hasEntry("log.logger", "deprecation.test"),
hasEntry("cluster.name", "elasticsearch"),
hasEntry("node.name", "sample-name"),
hasEntry("message", "deprecated message3"),
not(hasKey("x-opaque-id"))
),
allOf(
hasEntry("type", "deprecation"),
hasEntry("log.level", "INFO"),
hasEntry("log.level", "DEPRECATION"),
hasEntry("log.logger", "deprecation.test"),
hasEntry("cluster.name", "elasticsearch"),
hasEntry("node.name", "sample-name"),
Expand All @@ -218,7 +214,11 @@ public void testDeprecatedMessageWithoutXOpaqueId() throws IOException {
)
)
);

assertThat(jsonLogs, not(contains(hasEntry("message", "deprecated message3"))));
}

assertWarnings("deprecated message1", "deprecated message2", "deprecated message3", "deprecated message4");
}

public void testJsonLayout() throws IOException {
Expand Down Expand Up @@ -342,7 +342,7 @@ public void testDuplicateLogMessages() throws IOException {
ThreadContext threadContext = new ThreadContext(Settings.EMPTY);
try (ThreadContext.StoredContext ignore = threadContext.stashContext()) {
threadContext.putHeader(Task.X_OPAQUE_ID, "ID1");
DeprecationLogger.setThreadContext(threadContext);
HeaderWarning.setThreadContext(threadContext);
deprecationLogger.deprecate("key", "message1");
deprecationLogger.deprecate("key", "message2");
assertWarnings("message1", "message2");
Expand All @@ -356,7 +356,7 @@ public void testDuplicateLogMessages() throws IOException {
assertThat(jsonLogs, contains(
allOf(
hasEntry("type", "deprecation"),
hasEntry("log.level", "WARN"),
hasEntry("log.level", "DEPRECATION"),
hasEntry("log.logger", "deprecation.test"),
hasEntry("cluster.name", "elasticsearch"),
hasEntry("node.name", "sample-name"),
Expand All @@ -366,15 +366,15 @@ public void testDuplicateLogMessages() throws IOException {
);
}
} finally {
DeprecationLogger.removeThreadContext(threadContext);
HeaderWarning.removeThreadContext(threadContext);
}


// For the same key and different X-Opaque-ID should be multiple times per key/x-opaque-id
//continuing with message1-ID1 in logs already, adding a new deprecation log line with message2-ID2
try (ThreadContext.StoredContext ignore = threadContext.stashContext()) {
threadContext.putHeader(Task.X_OPAQUE_ID, "ID2");
DeprecationLogger.setThreadContext(threadContext);
HeaderWarning.setThreadContext(threadContext);
deprecationLogger.deprecate("key", "message1");
deprecationLogger.deprecate("key", "message2");
assertWarnings("message1", "message2");
Expand All @@ -388,7 +388,7 @@ public void testDuplicateLogMessages() throws IOException {
assertThat(jsonLogs, contains(
allOf(
hasEntry("type", "deprecation"),
hasEntry("log.level", "WARN"),
hasEntry("log.level", "DEPRECATION"),
hasEntry("log.logger", "deprecation.test"),
hasEntry("cluster.name", "elasticsearch"),
hasEntry("node.name", "sample-name"),
Expand All @@ -397,7 +397,7 @@ public void testDuplicateLogMessages() throws IOException {
),
allOf(
hasEntry("type", "deprecation"),
hasEntry("log.level", "WARN"),
hasEntry("log.level", "DEPRECATION"),
hasEntry("log.logger", "deprecation.test"),
hasEntry("cluster.name", "elasticsearch"),
hasEntry("node.name", "sample-name"),
Expand All @@ -408,7 +408,7 @@ public void testDuplicateLogMessages() throws IOException {
);
}
} finally {
DeprecationLogger.removeThreadContext(threadContext);
HeaderWarning.removeThreadContext(threadContext);
}
}

Expand Down
Loading