-
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
Add datetime conversion for unwrapping #3866
Conversation
Signed-off-by: Danny Kopping <[email protected]>
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.
I like the idea, but don't want to develop multiple ways to parse these across the code base (i.e. https://grafana.com/docs/loki/latest/clients/promtail/stages/timestamp/). I'd prefer to find a way to align our approaches, perhaps something like
ts() # no arguments, uses the underlying log's timestamp in loki
ts(foo, ISO_ABC) # parses the foo field, using ISO_ABC format
We could fill them with our formats from https://grafana.com/docs/loki/latest/clients/promtail/stages/timestamp/#reference-time
What do you think?
There were some similar proposals previously! |
I like Owen's idea about unifying the parsing. The only problem is users would have to explicitly specify the format of the time, which would make it a little harder for the users to adapt. I doubt many users would be easily able to identify which ISO format the time is in. We can maybe automate the parsing everywhere using the |
Thanks for the thoughts, folks! Apologies for the delayed response.
Thanks @kavirajk! I missed this; I will check those out.
@owen-d I agree 100%. Do you think there's room for adding another "magic" format like what I've suggested below in my response to Sandeep?
@sandeepsukhani totally! I'm thinking of perhaps introducing a "Autodetect" format alongside the predefined list which uses The amount of time I've wasted trying to get date parsing right in Promtail vastly exceeds the amount of time I've spent on configuring the rest of Promtail, so this is something I'd personally love to have streamlined. I'm going to look into implementing @owen-d's suggestion here as I think it's an improvement over my current design, and aligns with the existing patterns better.
|
Love it, I also think date parsing could be leverage during label filtering.
|
@sandeepsukhani good points. Perhaps we can introduce a third form
|
This issue has been automatically marked as stale because it has not had any activity in the past 30 days. It will be closed in 7 days if no further activity occurs. Thank you for your contributions. |
Reopen? |
What this PR does / why we need it:
This PR adds support for parsing dates in log lines.
Given a log line with a timestamp:
If we wanted to find the most recent line for each
method
label, it is not currently possible - to my knowledge.This PR introduces a new
datetime
parser for unwrapping dates into UNIX timestamps, which can be used in aggregations.Of course, as a follow up to this, we may want to expose each line's actual ingested timestamp as a meta-label, like
__ts__
for example. This would obviate the need to parse the timestamp out of the line again.Which issue(s) this PR fixes:
Fixes #
Special notes for your reviewer:
Using time.Parse doesn't work here because timestamps in the log line can be in any format. I opted to use https://github.com/araddon/dateparse as it's very thorough and widely used.
Just threw this together really quick for an experiment so still need to write docs, and maybe expand the tests to include benchmarks and maybe more examples.
Checklist