-
- Notifications
You must be signed in to change notification settings - Fork 1.7k
Adjust GcpLayout JSON to latest format #3586
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for you contribution.
Did you test it on an actual Google Cloud instance? I am not a GCP user, but some of the changes you propose differ from the documented log format.
| Let's wait for @vy's review. @ViliusS, in this repository we require signed commits, so you need to:
|
First, it formats the log timestamp field to the correct format recognized by Fluent-Bit (component of Google Cloud Logging) and Google Ops Agent. Secondly, severity field now must be prefixed with logging.googleapis.com. Third, counter cannot be used for insertId as it is duplicated on different threads. And the last but not the least, exception, thread and logger fields are pretty standard when logging via Logback's JSON layout and Google's Spring GCP libraries. Field name changes now match these other loggers.
718ccbd to 5e0656e Compare
Done. |
| One particular thing that is bothering me about this fix is... it breaks backward compatibility. We can say we're fixing the schema, but for users who have already been using the broken schema, we are gonna create trouble. We can
@ppkarwasz, thoughts? @ViliusS, would you mind adding a changelog entry file (i.e., |
I would call the new format However, I am not entirely sure that this template file belongs to Log4j. The only users that can profit from it are Google Ops Agent users, so we might consider moving the file to that project instead. See also GoogleCloudPlatform/ops-agent#1920 (comment) |
Changelog added. Regarding backward compatibility I see it this way. The proposed changes are not really fixes, they are changes/improvements. Old schema probably worked in some sense, but required a little bit tinkering for proper GCP field mapping on Google side. It is natural that schemas change and they need to be re-adjusted, there is no way to avoid that when dealing with 3rd party services. The real question is when backward compatibility and how it should be broken.
Considering that new adjustments makes it a lot easier to send logs to GCP now without major processing in between, and if they are included in 2.25.0, I think it is fair. @ppkarwasz I wouldn't call it |
Looking at GoogleCloudPlatform/ops-agent#1920 (comment) there are currently three different ways to interpret structured logs in Google Cloud:
So I think we should use a template name that suggests, which of these formats is supported, like
Note: We can also add multiple templates, one for |
| Regarding the |
I thought about this earlier, but for me it looked like too few differences to support different templates. Also, because of those subtle differences, it could be complicated to document for the end users which template in which case needs to be used. Given that OpsAgent is just one tool to process logs, and folks could be using any other log sending methods or processors, like for example native OTLP one, there is a question how many of these JSON templates we should have. That's why I tried to come up with a format which is as close as possible natively supported by Google Cloud Looging itself, so you will need as few pre-processing as possible. Sure, you still need to apply few tricks in every processor (in OpsAgent case for Nevertheless, I will support any decision and can re-adjust current PR if you decide otherwise. |
8b17cb8 to 9e8a03b Compare | @vy, What do you think about two new templates instead of a single one? |
| @ViliusS, @ppkarwasz, I think we better proceed with the current state of this PR – I've approved it. |
* Adjust GcpLayout JSON to latest format First, it formats the log timestamp field to the correct format recognized by Fluent-Bit (component of Google Cloud Logging) and Google Ops Agent. Secondly, severity field now must be prefixed with logging.googleapis.com. Third, counter cannot be used for insertId as it is duplicated on different threads. And the last but not the least, exception, thread and logger fields are pretty standard when logging via Logback's JSON layout and Google's Spring GCP libraries. Field name changes now match these other loggers. * revert severity changes, remove insertId * Remove insertid from tests * fix spotless error * Switch exception field to use exception resolver * try to fix timestamp tests * Fix tests with empty exceptions * Add changelog * Improve changelog. --------- Co-authored-by: Volkan Yazıcı <volkan.yazici@oracle.com>
* Adjust GcpLayout JSON to latest format First, it formats the log timestamp field to the correct format recognized by Fluent-Bit (component of Google Cloud Logging) and Google Ops Agent. Secondly, severity field now must be prefixed with logging.googleapis.com. Third, counter cannot be used for insertId as it is duplicated on different threads. And the last but not the least, exception, thread and logger fields are pretty standard when logging via Logback's JSON layout and Google's Spring GCP libraries. Field name changes now match these other loggers. * revert severity changes, remove insertId * Remove insertid from tests * fix spotless error * Switch exception field to use exception resolver * try to fix timestamp tests * Fix tests with empty exceptions * Add changelog * Improve changelog. --------- Co-authored-by: Vilius Šumskas <vilius@sumskas.eu> Co-authored-by: Volkan Yazıcı <volkan.yazici@oracle.com>




This is my first contribution to Log4J so I'm not 100% sure if I did everything right, but here it goes.
This PR adjusts GcpLayout JSON formatting to match what is expected by GCP.
First, it formats the log timestamp field to the correct format recognized by Fluent-Bit (component of Google Cloud Logging) and Google Ops Agent. I'm not sure how it worked before, probably it didn't, but Google Cloud Logging expects timestampSecond + timestampNanos format. Ops Agent, which also can be used to feed the logs from external Log4J environment via Socket or RollingFile into GCP, also expects the same format. More over, the same timestamp format is always used in Spring GCP libraries.
Secondly, severity field now must be prefixed with
logging.googleapis.com. I'm not 100% sure regarding this, because Spring GCP libraries are still using justseverityfield name. However Ops Agent (link above) already useslogging.googleapis.com/severity, and simpleseverityname is only described in legacy logging agent which is deprecated.Third, counter cannot be used for
logging.googleapis.com/insertIdas it is duplicated on different threads. I've chosen to use time-based UUID, but if that increases garbage collection issues it safely can be removed. GCP will generate their own IDs anyway.And the last but not the least, I have renamed
exception,threadandloggerfields. I saw the PR discussion in #543, however these fields are pretty standard when logging via Logback's JSON layout and then they are reused in Google's Spring GCP libraries. Sadly, I didn't find how to completely removeexceptionfield from JSON output if it's empty. Looks like all empty fields are removed except forpatterntype. I also found https://issues.apache.org/jira/browse/LOG4J2-3053 regarding that, but not sure about its state. This is not a big issue but is preferable for GCP.By the way, Log4J docs are a little bit incorrect. If
messagefield exist, having separateexceptiondoes nothing to catch the error in Google Error Reporting. According to Google docs, ifmessagefield exist it must contain stack trace and only that stack trace is used in the Error Reporting UI. I tested this extensively. But I left separateexceptionfield if one wants to filter it in the logs.All in all, this should provide much better JSON field mapping experience on GCP. If you think this PR is usable I then will go ahead and fix tests for timestamp processing.