From f90824bde6831519205466c8661e55a680bf2422 Mon Sep 17 00:00:00 2001 From: Matthias Andreas Benkard Date: Sun, 23 Jun 2024 16:42:11 +0200 Subject: test: Add benchmark with many log entry fields. Change-Id: I9ef4ff2bc0ccd8c0b674b9e8cd0c1e93fbe445ff --- .../jsonlogging/FormatterBenchmark.java | 8 ++++ .../googlecloud/jsonlogging/FormatterTest.java | 53 ++++++++++++++++++++++ 2 files changed, 61 insertions(+) (limited to 'core/src/test') diff --git a/core/src/test/java/eu/mulk/quarkus/googlecloud/jsonlogging/FormatterBenchmark.java b/core/src/test/java/eu/mulk/quarkus/googlecloud/jsonlogging/FormatterBenchmark.java index 1a1c17c..4900a01 100644 --- a/core/src/test/java/eu/mulk/quarkus/googlecloud/jsonlogging/FormatterBenchmark.java +++ b/core/src/test/java/eu/mulk/quarkus/googlecloud/jsonlogging/FormatterBenchmark.java @@ -13,12 +13,14 @@ public class FormatterBenchmark { private ExtLogRecord simpleLogRecord; private ExtLogRecord structuredLogRecord; + private ExtLogRecord massivelyStructuredLogRecord; private Formatter formatter; @Setup public void setup() { simpleLogRecord = FormatterTest.makeSimpleRecord(); structuredLogRecord = FormatterTest.makeStructuredRecord(); + massivelyStructuredLogRecord = FormatterTest.makeMassivelyStructuredRecord(); formatter = new Formatter(List.of(), List.of()); } @@ -31,4 +33,10 @@ public class FormatterBenchmark { public void structuredLogRecord(Blackhole blackhole) { blackhole.consume(formatter.format(structuredLogRecord)); } + + @Benchmark + public void massivelyStructuredLogRecord(Blackhole blackhole) { + var f = formatter.format(massivelyStructuredLogRecord); + blackhole.consume(f); + } } diff --git a/core/src/test/java/eu/mulk/quarkus/googlecloud/jsonlogging/FormatterTest.java b/core/src/test/java/eu/mulk/quarkus/googlecloud/jsonlogging/FormatterTest.java index 91cc8e4..b755230 100644 --- a/core/src/test/java/eu/mulk/quarkus/googlecloud/jsonlogging/FormatterTest.java +++ b/core/src/test/java/eu/mulk/quarkus/googlecloud/jsonlogging/FormatterTest.java @@ -93,4 +93,57 @@ class FormatterTest { }); return logRecord; } + + @Test + void massivelyStructuredRecord() { + var logRecord = makeMassivelyStructuredRecord(); + + var formatter = new Formatter(List.of(), List.of()); + var formattingResult = formatter.format(logRecord); + assertLinesMatch( + List.of( + "\\{" + + "\"message\":\"Hello, world!\"," + + "\"severity\":\"INFO\"," + + "\"timestamp\":\\{\"seconds\":\\d+,\"nanos\":\\d+\\}," + + "\"logging.googleapis.com/sourceLocation\":" + + "\\{\"file\":\"ReflectionUtils.java\"," + + "\"line\":\"\\d+\"," + + "\"function\":\"org.junit.platform.commons.util.ReflectionUtils.invokeMethod\"" + + "\\}," + + "\"int-0\":0,\"int-1\":1,\"int-2\":2,\"int-3\":3,\"int-4\":4,\"int-5\":5,\"int-6\":6,\"int-7\":7,\"int-8\":8,\"int-9\":9," + + "\"double-10\":10.0,\"double-11\":11.0,\"double-12\":12.0,\"double-13\":13.0,\"double-14\":14.0," + + "\"double-15\":15.0,\"double-16\":16.0,\"double-17\":17.0,\"double-18\":18.0,\"double-19\":19.0," + + "\"boolean-20\":true,\"boolean-21\":false,\"boolean-22\":true,\"boolean-23\":false,\"boolean-24\":true," + + "\"boolean-25\":false,\"boolean-26\":true,\"boolean-27\":false,\"boolean-28\":true,\"boolean-29\":false," + + "\"string-30\":\"30\",\"string-31\":\"31\",\"string-32\":\"32\",\"string-33\":\"33\",\"string-34\":\"34\"," + + "\"string-35\":\"35\",\"string-36\":\"36\",\"string-37\":\"37\",\"string-38\":\"38\",\"string-39\":\"39\"" + + "\\}\n"), + List.of(formattingResult)); + } + + static ExtLogRecord makeMassivelyStructuredRecord() { + var logRecord = FormatterTest.makeSimpleRecord(); + logRecord.setParameters( + new Object[] { + (StructuredParameter) + () -> { + var b = Json.createObjectBuilder(); + for (int i = 0; i < 10; i++) { + b.add("int-" + i, i); + } + for (int i = 10; i < 20; i++) { + b.add("double-" + i, (double) i); + } + for (int i = 20; i < 30; i++) { + b.add("boolean-" + i, i % 2 == 0); + } + for (int i = 30; i < 40; i++) { + b.add("string-" + i, String.valueOf(i)); + } + return b; + } + }); + return logRecord; + } } -- cgit v1.2.3