-
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
More browser / parser friendly return format for timestamps #273
Comments
It's also inconsistent that the 'start' and 'end' query parameters are in Unix epoch nanoseconds, but the returned ts values are ISO datetime. It's certainly painful to keep converting back and forth. The problem with using Unix nanoseconds with Javascript is that IEEE double has only 53 bits of precision, and the current time requires 61 bits. This means you lose precision when going via JSON to systems which implement double floating numeric values like Javascript - although you should still get roughly microsecond precision.
It's not even JSON; it's loki/prometheus labels format. Labels: JSON would be: |
I wonder if the JSON for labels might be easier to work with it if the JSON representation was closer to the Labels structure in prom to keep ordering. (https://github.com/prometheus/prometheus/blob/master/pkg/labels/labels.go#L43). So instead of turning something like |
The fact that labels are not JSON makes it harder to build a valid string of labels too: e.g. see #927 However, labels are also a mini query language in their own right: e.g. I don't think the ordering of labels is important: |
@torkelo @dprokop @aocenas @slim-bean @joe-elliott We had a discussion today and I think the suggestion will be to change the
to
Values will be in nanoseconds string. |
This will only be true for the new API endpoint, the current one won't change. |
When you say "nanoseconds float", bear in mind that an IEEE double has only 53 bits of precision, and in the current era, time will be rounded to about a quarter of a microsecond.
If the new API uses this form consistently, I'd be fine with that - although there seems to be little point storing exact nanoseconds if these are not exposed in the API. Would query Double Extended (80 bit) would have enough precision, but not many clients will implement that. |
discussed with @torkelo and @aocenas -- we think sending nanoseconds as strings is a good solution:
This makes parsing dates to epoch something like:
and later when we add nanosecond support we can look at nano-date |
Thanks: I think nanoseconds as strings is fine. It would be great if the rest of the API could be similarly updated (e.g. |
Good point, @joe-elliott what’s your take on the the push API? |
I'm not opposed to moving the push API forward to this new format, but I think we should do it in a new issue/PR. I believe the push API exclusively uses grpc objects for both json and protobuf unmarshalling. The PR I've put together would have to touch entirely new parts of the codebase to start handling that logic. |
…rs-5.8 [release-5.8] Backport PR grafana#12164 and grafana#12216
Currently loki returns timestamps in a string format, these date strings can be quite expensive to parse when dealing with many thousands of entries.
In the browser timestamps are in millisecond epochs so that would be the deals format to return values in (ie in plain json numbers). Since the internal format is in nanoseconds this will lose some precision (that we throw away anyway when parsing this to a local date). So not sure what the best approach here is. Maybe some query flag that will control the ts format & precision.
A related issue is how labels are currently returned in string that has to be json parsed separately (from the rest of the body). If dealing with a large number of streams this could also be a minor performance issue but mostly I think this just looks very strange from an API perspective to have this be a string that contains json and not be proper part of the json response.
The text was updated successfully, but these errors were encountered: