-
Notifications
You must be signed in to change notification settings - Fork 8.8k
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 timezones support to promql #10163
Conversation
95d2202
to
45dfc39
Compare
Signed-off-by: Sylvain Rabot <sylvain@abstraction.fr>
Thanks! Others always have more to say about timezones than me, but I do remember a previous conversation about just this: That second comment from Björn about the edge cases that a simple offset function wouldn't cover is especially relevant to think about. |
Also a lot of discussion can be found on this design doc: https://docs.google.com/document/d/1xfw1Lb1GIRZB_-4iFVGkgwnpwuBemWfxYqFdBm7APsE/edit#heading=h.bupciudrwmna tl;dr: This is not as easy as it looks. That's just very generally about the state of this problem. I haven't looked into this PR in particular, but I'll put this on my review queue for a proper review. (Sadly, my backlog is quite significant here.) |
Quite frankly I fail to see what is "not that easy". I don't claim to see all the possible timezone problems one can have but as a +5 years old daily prometheus user, give me this or any equivalent ( |
@sylr Yeah, if I understand correctly, because you provide a full While I'm not the timezone guy, there are still at least some things I'd like a reviewer to take into account:
That said, if those concerns are at least acknowledged and deemed fine, I would be happy if timezone functionality (such as this or another viable alternative) would make it into Prometheus, so that users can stop using weird workarounds such as the one mentioned in #8871 (comment). |
Here are the possible choices I see:
The status quo of not having timezone support in PromQL is not an option (according to me).
Honestly I don't know. However, I would be surprised to find an all-purpose language without the basic functions to do timezone diffs in its standard library.
Timezone definitions shouldn't be anyone else's responsibility but the OS. |
Yeah, fair views. What do people thinking about adding |
I'm all for it if it can get things moving on the matter. |
Signed-off-by: Sylvain Rabot <sylvain@abstraction.fr>
The discussion about timezone support has happened at many places already:
All of these demonstrate the problems, but also provide a lot of ideas and insights how to approach them. I don't think it's helpful to start another lengthy discussion in this PR and disregard everything that has been discussed before. (Stating that "quite frankly I fail to see what is 'not that easy'" won't convince the participants of above discussions that they were all wrong all the time.) I think the next step should be to finalize a design doc (by amending the existing one or rewriting it – the existing one was around the basic idea of providing a timezone on the command line, which hit a lot of resistance, so that approach would just be one of the possible alternatives to be presented in the design doc). Thanks to feature flags, we can certainly experiment with features where we are unsure if they will work or if they will be useful. However, in this case, we already know about concrete problems, and various ideas have been expressed how to address them. Those ideas need to be discussed rather than disregarded. Simply implementing a feature while "failing to see the problem" isn't helping. |
Naming nit:
The name should be something like |
According to my tests (on MacOS) |
I'm afraid the approach in this PR has precisely the problems I have described in #8871 (comment), just that it obfuscates things a bit more by returning something that looks like a UNIX time but it is shifted by a certain offset. I think #8871 is actually better than this PR because it makes explicit what it does. However, both approaches suffer from the problem that they calculate the offset for the evaluation time, but in many queries, you would like to know the offset for another point in time. Quoting from the linked comment:
Reworded for this PR, it would read: "It is 2021-03-28, 01:30h UTC. As already discussed in that comment, a more viable solution is to provide a location to functions like Of course, the best case would be if someone came up with a more elegant solution that could also answer questions like "how much time has passed since midnight (or since the beginning of the month)?", but I said that before. This might be too involved for now, but I would feel much better if someone came to that conclusion who actually understands the whole discussion and the problems raised. |
We would need to have the embedded TZ for windows (via build commands) + have a dedicated flag (for all os'es) to pass a recent tzdata file. Somehow it would be great to expose the tz version as metric. |
About how to provide the TZ data: The design doc already contains an interesting discussion with a conclusion in the comments. Search for "Should we provide the embedded tzdata for windows users?" and also read the comments there. |
Returning a fake unix timestamp offested by the diff of TZ - UTC is not a good way to do things. Signed-off-by: Sylvain Rabot <sylvain@abstraction.fr>
Signed-off-by: Sylvain Rabot <sylvain@abstraction.fr>
How would you propagate the feature flag value to |
Signed-off-by: Sylvain Rabot <sylvain@abstraction.fr>
Signed-off-by: Sylvain Rabot <sylvain@abstraction.fr>
Signed-off-by: Sylvain Rabot <sylvain@abstraction.fr>
I disagree with this. As per wikipedia, within the tz database, a time zone is any national region where local clocks have all agreed since 1970. In general, Timezone is way more clear than location and more user-friendly. https://en.wikipedia.org/wiki/Tz_database#File_formats |
I think it would be cleaner to have the exception handled by the engine rather than by the parser. |
WRT https://en.wikipedia.org/wiki/Tz_database#File_formats : Indeed, the TZ database uses locations to name timezones. However, https://pkg.go.dev/time has a usage that corresponds to what I had said. Therefore, "tz" or "timezone" is ambiguous outside of the immediate context of the TZ database. "location" is not ambiguous and I would prefer if we used that. |
Signed-off-by: Sylvain Rabot <sylvain@abstraction.fr>
It seems that this is still using parser, while other experimental features like @ fail at the engine side. Additionally, engine already has a mechanism for feature enabling (see EngineOpts). |
You want to overwrite the Parser's Functions from the engine ? |
I think we should maybe have a second FunctionCalls in the engine that can be used to process this. The initial Functioncalls would fail if there is at tz passed. |
Thanks for all the work you are investing here. However, I'm concerned that we go deep into details here without having an agreed-upon design doc. We are discussing general aspects mixed up with implementation details here, which makes it hard to follow for a wider audience. Plus, a PR is just not the right form to make important design decisions. Ideas seem to take shape here, so I guess it won't be that hard to write them down in a design doc, with their reasoning, so that the can be presented to the developer community, discussed in a more visible and more focused way, get buy-in from the community as a whole, and ideally get final agreement at a dev summit. All of this reminds me that we should really better document our proposal process, cf. #8986 |
How about much simpler solution - to add timezone_offset function, which would return the offset in seconds for the specified timezone. For example, An additional benefit for having a separate This feature is already implemented in VictoriaMetrics, so you can play with it there. Additionally, it would be great if Prometheus would support time-related constants anywhere in the query. For example,
Or, if you know needed timezone offset, you could write something like the following |
The solution of using the timezone_offset function to calculate time in a specific time zone may not be suitable for all use cases, as it may not be compatible with metrics collected prior to Daylight Saving Time (DST) changes. This is because the timezone_offset function provides the offset for the current query time and not the metric time. As a result, if a metric was collected prior to a DST change, the calculation of time in a specific time zone using timezone_offset would be incorrect. |
Aside: Issues with |
As said at #10163 (comment)
Given there has been a lot of debate and no progress, we decided at the bug-scrub meeting to close this PR until a design is agreed. |
This function aims to solve problems for those who need to account for DST in their queries.