-
Notifications
You must be signed in to change notification settings - Fork 53
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
toStartOfMonth() Returning Incorrect Values #295
Comments
Hi @dbernardi7, The issue's root cause is simple, but I am unsure how we can mitigate it. The problem is If you go and pick in Grafana UI time picker the same timezone as you have in Grafana backend, results should be fine. Most likely, this issue has to be fixed in |
Hey @jkaflik, Thank you so much for your prompt response, I really appreciate it! I went ahead and changed the organizations timezone to UTC and ran a test query to ensure it worked, and sure enough it did! However, while it does work, I can't reason why that would cause the dates to appear as the end of the month as they are in the screenshots above. For example for today's date (February 13th), if it was 2pm PST, which would be 10pm UTC, the starting date of the month should still return the same value: 2023-02-13. My point is that even if the time was hours ahead or behind UTC, but still in the same month, the function should still return the start of the month. And in the rare case that it is the last day of the month PST and in UTC it is now the first of the month, the function should still return the start of the month and not the last day. Thank you again for your timeliness on this and all the information so far! |
If I understand the problem correctly, but let give me a try to explain: Let's assume we have DateTime with any timezone: 2022-07-17 15:00:00 Later, this value is decoded by The solution would be that Grafana UI sends the client timezone, which is used for CH Date decode. Hope this answers your question. Edit: It would make sense to load the date with ClickHouse server timezone. Let me discuss that internally with the team. |
This is a two-part fix. The first part @jkaflik has already started which is updating |
@asimpson the second part - is it something you will work on? |
Let me discuss with @grafana/partner-plugins and see when we can fit it in. |
@asimpson How can we attach additional metadata to a query? Maybe we can consider extending the |
You're totally correct, I was looking at Cloudwatch when I was thinking about it last week just because of the timezone piece. One thing I want to uncover is why Cloudwatch made the decision it did.
I think this is a good idea! I'm curious how this will work out in practice. |
@asimpson what if we change the I'd suggest changing query(
request: DataQueryRequest<TQuery>,
{
headers?: ReadonlyMap<string, string>,
params?: ReadonlyMap<string, string | number | null >,
}
) => Observable<DataQueryResponse> |
I think this would work. We can always refine or refactor if we uncover a better way. |
@mshustov @asimpson, it seems we are about the resolve this fantastic issue :) I will also release clickhouse-go soon. I wanted to update |
What happened: When using
toStartOfMonth()
in a query in Grafana, the result of the query mimicked whattoEndOfMonth()
would produce with all the values indicating the last day of the month. However, when using the ClickHouse CLI the query returned expected beginning of the month values.What you expected to happen: I would've expected to have the first date of the month returned with a
DateTime
input. For example if entering this:2022-12-07 02:15:10
, I would expect to be returned this:2022-12-01
.How to reproduce it (as minimally and precisely as possible): While connecting Grafana to a ClickHouse database have a field that is a
DateTime
data type. Query the field using the functiontoStartOfMonth()
. The result will show the last day of the month of the date that you queried.An example query:
SELECT toStartOfMonth( "DateTime Field" )
FROM datatable
Screenshots
Anything else we need to know?: When using the clickhouse client to perform the same exact query, the correct result is shown. Screenshot below:
Environment:
The text was updated successfully, but these errors were encountered: