-
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
Refactor: improve plugin logging xp #13038
Conversation
- previously (w a source) we would always end up with an id - (potentially auto) generated from `extractIdFromLIR` - unless an explicit id is set in the configuration the generated default id was a "slow" graph content hash (same configuration would always end up with the same id)
(in tests) as when booting the pipeline
what was meant was likely to do a `self.class.logger` here
also changes the contract from msg.to_str to msg.to_s
also improves performance of plugin.logger invocations
Recycling ids across restarts has proven very useful in the past, especially when users don't follow the "best practice" of defining their own plugin ids. It allows us to use captures of the node stats API to compare flow across restarts, especially in larger pipelines. Is this change intrinsic to ensuring that the logger always has an id? |
Thanks, thought there might be a reason esp. since there was a comment which said smt like "do not walk the AST graph to generate ids as it's slow" and we did it anyway. The annoying thing for me with recycling is that we often get incomplete logs - judging from the generated plugin id I can not tell if it's the same LS instance or a restart has been made ... 😞
We would continue to have 2 ways of auto generating ids - one for manual plugin instantiation, another used w the pipeline. |
... for restore to keep the previously set id
I would be okay with shorter default ids in 8.0 (or perhaps rethinking ids in general), but a restart across minors or on the same version of Logstash should generate the same ids. There may be an opportunity to add a Or we could keep the full-length ids and use log4j formatters to output only the first 16 chars into the log line, which would ensure collisions still get routed to separate files when log-per-pipeline is enabled: -%notEmpty{[%X{pipeline.id}]}
+%notEmpty{[%maxLen{%X{pipeline.id}}{16}]} |
Thanks, that's a 🔐 was assuming changing ids would target a minor (7.15) and be acceptable.
... outputing first 16 chars gets us with: Also id generation is unnecessarily slow - using a 'slow' hashing alg SHA-256 + secure random while none of that in necessary. Anyhow, I will try to split the PR effort to only include the new |
Release notes
What does this PR do?
Improves logging experience for the user (as a minor side effect LS should be faster to generated plugin ids).
generated ids won't be recycled -> on a restart new ids are generated even if the configuration did not change(EDIT: stricken. We rely on recycled ids)previously, the id generation mechanism always fell back to walking the AST to generate an id by hashing the tree
generated plugin ids will be shorter (16 characters) instead of 36 hex chars - logs should be easier to read(EDIT: stricken. loosely a breaking change given above)logger(msg)
contract allows for logging any (to_s
) message not just strings - just like Log4j2 loggers doPluginLogger
gets introduced to always have aplugin.id
logging context wplugin.logger ...
generatePluginId
implementationthere's a change to use the same logic in tests -> tested plugin will no longer have the
name_...
prefixOther changes:
logger.trace?
(previously delegated tologger.isDebugEnabled()
)Breaking changes:
def class.logger(plugin = self)
functional in a backwards compatible wayWhy is it important/What is the impact to the user?
Logs are Logstash's primary way of communicating with the user, always having a plugin id logged greatly improves the user (debugging) experience.
Checklist
I have made corresponding changes to the documentationI have made corresponding change to the default configuration files (and/or docker env variables)Author's Checklist
like we did before this got refactored
How to test this PR locally
Related issues
Logs
Sample (artificial) logging session (just to demonstrate plugins always log with their id as context):