-
Notifications
You must be signed in to change notification settings - Fork 3.5k
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
Logstash: 8.10.2: Issues with fasterxml: Can not write a field name, expecting a value #15405
Comments
The issue comes from the jackson upgrade from 2.14.1 in LS 8.9.3 to jrjackson 2.15.2 in LS 8.10.0.
|
There are a few known issues of breaking changes in 2.15.0:
But all of these have been fixed, while this particular issue still happens with 2.15.3 |
Here is a test that shows the failure: diff --git a/logstash-core/src/test/java/org/logstash/log/CustomLogEventTests.java b/logstash-core/src/test/java/org/logstash/log/CustomLogEventTests.java
index a2af82ea4..4fbd828ff 100644
--- a/logstash-core/src/test/java/org/logstash/log/CustomLogEventTests.java
+++ b/logstash-core/src/test/java/org/logstash/log/CustomLogEventTests.java
@@ -47,6 +47,8 @@ import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.junit.LoggerContextRule;
import org.apache.logging.log4j.test.appender.ListAppender;
+import org.jruby.Ruby;
+import org.jruby.RubySymbol;
import org.junit.ClassRule;
import org.junit.Test;
import org.logstash.ObjectMappers;
@@ -90,6 +92,10 @@ public class CustomLogEventTests {
logger.error("here is a map: {}", Collections.singletonMap(2, 5));
logger.warn("ignored params {}", 4, 6, 8);
+ Ruby runtime = Ruby.newInstance();
+ RubySymbol mainSymbol = RubySymbol.newSymbol(runtime, "main");
+ logger.warn("test", Collections.singletonMap("foo", mainSymbol));
+
List<String> messages = appender.getMessages();
Map<String, Object> firstMessage =
@@ -132,5 +138,9 @@ public class CustomLogEventTests {
assertEquals(5, fifthMessage.size());
logEvent = Collections.singletonMap("message", "ignored params 4");
assertEquals(logEvent, fifthMessage.get("logEvent"));
+
+ Map<String, Object> sixthMessage =
+ ObjectMappers.JSON_MAPPER.readValue(messages.get(5), Map.class);
+ assertEquals(4, sixthMessage.size());
}
} |
I'm going to try to summarize the root cause of this issue here. Logstash has a custom Jackson serializer for logs events - CustomLogEventSerializer, which is responsible for serializing the logs messages produced by the LogstashMessageFactory. If the log message has a logger.debug("Executing action", :action => action, :fail => false) When this message is delegated to We have no control on those parameters types, it might be anything, JRuby objects, maps, lists, etc. This process is likely to fail due to infinite recursion for all It's from where the But why it used to work, and now it's failing? In reality, it probably never worked pretty well. What brought this issue up was a small change in Jackson, which affected the serialization order of The following object: public static class Example {
protected int first = 1;
protected transient int second = 2;
protected int third = 3;
public int getFirst() {
return first;
}
public int getSecond() {
return second;
}
public int getThird() {
return third;
}
} In Jackson 2.14.1, serializes as: {"first":1,"second":2,"third":3} and in Jackson 2.15.3 {"first":1,"third":3,"second":2} Before that change, the For Logstash, it means that a few transient I can think of a few possible solutions for this issue, one could be just improving the retry mechanism to make it work, which is not optimal as recursive loops are happening there. And a more complex one that could customize the serialization, ignoring non-needed fields and using the ruby's Logstash does have a few serializers implement already for JRuby objects, but they're not being used, as Log4j has its own I'll keep this issue updated regarding the solution. |
The customer noticed that the
|
Hey @denisgils! I'd say it's a different bug. Although both issues are related, printing the password indicates that Logstash does not register any Jackson serializer for |
Hello,
setting
log.format: "json"
throws lot of"com.fasterxml.j ackson.core.JsonGenerationException: Can not write a field name, expecting a value
steps to verify this issue with official docker image (8.10.2)
Create custom logstash.yml file and make sure, the
log.format: "json"
is set (this triggers the error).create a custom pipeline configuration
Run logstash via
You will directly see that error
See also official Elastic case:
01495152
Kind regards
Robert
The text was updated successfully, but these errors were encountered: