Skip to content

Commit bff7b3a

Browse files
committed
feat(logging/logback): remove test cases related to key-value pair deduplication and refactor
1 parent d34d4de commit bff7b3a

4 files changed

Lines changed: 6 additions & 46 deletions

File tree

powertools-logging/powertools-logging-logback/src/main/java/software/amazon/lambda/powertools/logging/logback/LambdaEcsEncoder.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ private void serializeKeyValuePairs(ILoggingEvent event, JsonSerializer serializ
149149
.filter(Objects::nonNull)
150150
.map(kvp -> new AbstractMap.SimpleEntry<>(String.valueOf(kvp.key), kvp.value))
151151
.filter(kvp -> !PowertoolsLoggedFields.stringValues().contains(kvp.getKey()))
152-
.sorted(Comparator.comparing(AbstractMap.SimpleEntry::getKey))
152+
.sorted(Map.Entry.comparingByKey())
153153
.forEach(kvp -> serializeKVPEntry(kvp.getKey(), kvp.getValue(), serializer));
154154
}
155155

powertools-logging/powertools-logging-logback/src/main/java/software/amazon/lambda/powertools/logging/logback/LambdaJsonEncoder.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ private void serializeKeyValuePairs(ILoggingEvent event, JsonSerializer serializ
107107
.filter(Objects::nonNull)
108108
.map(kvp -> new AbstractMap.SimpleEntry<>(String.valueOf(kvp.key), kvp.value))
109109
.filter(kvp -> !PowertoolsLoggedFields.stringValues().contains(kvp.getKey()))
110-
.sorted(Comparator.comparing(AbstractMap.SimpleEntry::getKey))
110+
.sorted(Map.Entry.comparingByKey())
111111
.forEach(kvp -> serializeKVPEntry(kvp.getKey(), kvp.getValue(), serializer));
112112
}
113113

powertools-logging/powertools-logging-logback/src/test/java/software/amazon/lambda/powertools/logging/internal/LambdaEcsEncoderTest.java

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -188,16 +188,8 @@ void shouldLogKeyValuePairs() {
188188
LambdaEcsEncoder encoder = new LambdaEcsEncoder();
189189
encoder.start();
190190

191-
Object[] arguments = {
192-
"argument_01",
193-
StructuredArguments.entry("structured_argument_01_retain", "retained"),
194-
StructuredArguments.entry("structured_argument_02_overwrite", "to_be_overwritten")
195-
};
196191
LoggingEvent keyValuePairsLoggingEvent = new LoggingEvent("fqcn", logger, Level.INFO, "Key Value Pairs Test with argument: {}",
197-
null, arguments);
198-
199-
MDC.put("mdc_01_retain", "retained");
200-
MDC.put("mdc_02_overwrite", "to_be_overwritten");
192+
null, new Object[0]);
201193

202194
keyValuePairsLoggingEvent.setKeyValuePairs(List.of(
203195
new KeyValuePair("key_01_string", "value_01"),
@@ -207,9 +199,7 @@ void shouldLogKeyValuePairs() {
207199
new KeyValuePair("", "value_05_empty_key"),
208200
new KeyValuePair(null, "value_06_null_key"),
209201
new KeyValuePair("key_07_boolean_true", true),
210-
new KeyValuePair("key_08_boolean_false", false),
211-
new KeyValuePair("mdc_02_overwrite", "overwritten_by_kvp"),
212-
new KeyValuePair("structured_argument_02_overwrite", "overwritten_by_kvp")
202+
new KeyValuePair("key_08_boolean_false", false)
213203
));
214204

215205
// WHEN
@@ -218,14 +208,6 @@ void shouldLogKeyValuePairs() {
218208

219209
// THEN
220210
assertThat(result)
221-
// Arguments
222-
.contains("Key Value Pairs Test with argument: argument_01")
223-
.contains("\"structured_argument_01_retain\":\"retained\"")
224-
// .doesNotContain("\"structured_argument_02_overwrite\":\"to_be_overwritten\"") // TODO: Deduplication not implemented for arguments
225-
// MDC
226-
.contains("\"mdc_01_retain\":\"retained\"")
227-
// .doesNotContain("\"mdc_02_overwrite\":\"to_be_overwritten\"") // TODO: Deduplication not implemented for MDC
228-
// Key Value Pairs
229211
.contains("\"key_01_string\":\"value_01\"")
230212
.contains("\"key_02_numeric\":2")
231213
.contains("\"key_03_decimal\":2.333")
@@ -234,8 +216,6 @@ void shouldLogKeyValuePairs() {
234216
.contains("\"null\":\"value_06_null_key\"")
235217
.contains("\"key_07_boolean_true\":true")
236218
.contains("\"key_08_boolean_false\":false")
237-
.contains("\"mdc_02_overwrite\":\"overwritten_by_kvp\"")
238-
.contains("\"structured_argument_02_overwrite\":\"overwritten_by_kvp\"")
239219
;
240220
}
241221

powertools-logging/powertools-logging-logback/src/test/java/software/amazon/lambda/powertools/logging/internal/LambdaJsonEncoderTest.java

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -450,16 +450,8 @@ void shouldLogKeyValuePairs() {
450450
LambdaJsonEncoder encoder = new LambdaJsonEncoder();
451451
encoder.start();
452452

453-
Object[] arguments = {
454-
"argument_01",
455-
StructuredArguments.entry("structured_argument_01_retain", "retained"),
456-
StructuredArguments.entry("structured_argument_02_overwrite", "to_be_overwritten")
457-
};
458453
LoggingEvent keyValuePairsLoggingEvent = new LoggingEvent("fqcn", logger, Level.INFO, "Key Value Pairs Test with argument: {}",
459-
null, arguments);
460-
461-
MDC.put("mdc_01_retain", "retained");
462-
MDC.put("mdc_02_overwrite", "to_be_overwritten");
454+
null, new Object[0]);
463455

464456
keyValuePairsLoggingEvent.setKeyValuePairs(List.of(
465457
new KeyValuePair("key_01_string", "value_01"),
@@ -469,9 +461,7 @@ void shouldLogKeyValuePairs() {
469461
new KeyValuePair("", "value_05_empty_key"),
470462
new KeyValuePair(null, "value_06_null_key"),
471463
new KeyValuePair("key_07_boolean_true", true),
472-
new KeyValuePair("key_08_boolean_false", false),
473-
new KeyValuePair("mdc_02_overwrite", "overwritten_by_kvp"),
474-
new KeyValuePair("structured_argument_02_overwrite", "overwritten_by_kvp")
464+
new KeyValuePair("key_08_boolean_false", false)
475465
));
476466

477467
// WHEN
@@ -480,14 +470,6 @@ void shouldLogKeyValuePairs() {
480470

481471
// THEN
482472
assertThat(result)
483-
// Arguments
484-
.contains("Key Value Pairs Test with argument: argument_01")
485-
.contains("\"structured_argument_01_retain\":\"retained\"")
486-
// .doesNotContain("\"structured_argument_02_overwrite\":\"to_be_overwritten\"") // TODO: Deduplication not implemented for arguments
487-
// MDC
488-
.contains("\"mdc_01_retain\":\"retained\"")
489-
// .doesNotContain("\"mdc_02_overwrite\":\"to_be_overwritten\"") // TODO: Deduplication not implemented for MDC
490-
// Key Value Pairs
491473
.contains("\"key_01_string\":\"value_01\"")
492474
.contains("\"key_02_numeric\":2")
493475
.contains("\"key_03_decimal\":2.333")
@@ -496,8 +478,6 @@ void shouldLogKeyValuePairs() {
496478
.contains("\"null\":\"value_06_null_key\"")
497479
.contains("\"key_07_boolean_true\":true")
498480
.contains("\"key_08_boolean_false\":false")
499-
.contains("\"mdc_02_overwrite\":\"overwritten_by_kvp\"")
500-
.contains("\"structured_argument_02_overwrite\":\"overwritten_by_kvp\"")
501481
;
502482
}
503483

0 commit comments

Comments
 (0)