Skip to content
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

MySQL/Postgres/MSSQL: Add parsing for day, weeks and year intervals in macros #13086

Merged
merged 1 commit into from
May 30, 2019

Conversation

bernardd
Copy link
Contributor

This should resolve #11431 by converting day and year intervals into hours before they're passed to time.ParseDuration. Any other intervals, including invalid ones, are passed through unchanged so that the error result remains the same.

@CLAassistant
Copy link

CLAassistant commented Aug 30, 2018

CLA assistant check
Thank you for your submission, we really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@torkelo torkelo requested review from bergquist and svenklemm and removed request for bergquist August 30, 2018 07:03
@torkelo
Copy link
Member

torkelo commented Aug 30, 2018

@bergquist might be relevant for prometheus, graphite & influxdb as well? maybe even the alert scheduler as well (so we can support 1d in more places)

@marefr
Copy link
Contributor

marefr commented Aug 30, 2018

As Carl wrote in #11431 (comment), there's a reason go doesn't support this. As long as it's very clear that this support is simple and don't adjust for daylight savings I guess it's a useful feature.

@bernardd
Copy link
Contributor Author

As Carl wrote in #11431 (comment), there's a reason go doesn't support this.

Sure, but Grafana already does support it in a bunch of other places. All this is doing is bringing a few macro functions in line with the rest of the system in terms of that support.

Copy link
Contributor

@svenklemm svenklemm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we define day as 24 hours we could easily support at least week here aswell and maybe even month as e.g. 31 days

@bernardd
Copy link
Contributor Author

bernardd commented Sep 4, 2018

I'm happy to add other periods - week, month etc, if you like but initially I was just aiming for parity with the existing interval types that were used by $__interval and the auto value for Interval variables since those seemed to be the most "obvious" use cases (to my mind, at least).

@bergquist
Copy link
Contributor

bergquist commented Sep 4, 2018

I agree that we need to add support for d and maybe weeks for SQL datasources since it's already supported in other areas of Grafana. I'm not sure about adding it to alerting since running alert rules every day seems like a minor edge case while rendering aggregated data per day/week is much more common.

I'm not sure how it would be implemented but I think it should be placed in another package and return a time.Duration rather than a string.

@bergquist
Copy link
Contributor

I've been thinking about this and I think we should use the https://github.com/karrick/tparse library. Any chance you can update this PR to use tparse.Parse instead of NormalizeInterval ?

@bernardd bernardd force-pushed the add-day-year-interval-parsing branch 2 times, most recently from c036652 to 1ad21de Compare September 11, 2018 06:39
@bernardd
Copy link
Contributor Author

bernardd commented Sep 11, 2018

Any chance you can update this PR to use tparse.Parse instead of NormalizeInterval ?

So I've done this, but I can't for the life of me figure out how to get the dependency auto pulled into the vendor subdirectory. This is my first time playing with either go or Grafana so if someone can point me in the right direction, I'd appreciate it.

The code itself is a little bit of a hack because tparse deals mostly in absolute times, so getting it to spit out a pure duration takes a little bit of work. It does seem to do the trick, however.

@bergquist
Copy link
Contributor

@svenklemm what do you think about this?

In this solution month's depends on the length of the current month. This is far from optimal since the result when aggregating on month's period over year's will get skewed.

@svenklemm
Copy link
Contributor

I think month should either calculate months properly by basing the calculation on selected timerange or be a fixed interval like 28days (for symmetry with 4 weeks) or 30 or 31 days

@marefr
Copy link
Contributor

marefr commented Jan 29, 2019

What's needed/left to do for getting this into a merge:able state?

@bernardd
Copy link
Contributor Author

What's needed/left to do for getting this into a merge:able state?

I have no idea - happy to make any required changes if someone tells me what they are.

@SilverFire
Copy link
Contributor

I would also like to see this PR merged and will help to apply the required changes.

Maybe, we can ask to review this PR once more?

@ozenati
Copy link

ozenati commented Apr 17, 2019

Is there any news about this PR?

@bergquist
Copy link
Contributor

I do understand the frustration in this PR's and I've been glancing back to it from time to times but I can't get over the fact that parsing months with this solution will be problematic since it will be based on the current month. Which I dont think is a good solution. If we restricted this PR to only support days and weeks this would be an easy merge but since its support Months, I'm hesitant. While I'm sure everyone in this issue understands why aggregations might be skewed based on this I'm not sure the avg Grafana user will and their perception will be that Grafana does something wrong.

I'm not sure what to do here...

@bernardd
Copy link
Contributor Author

bernardd commented May 8, 2019

If we restricted this PR to only support days and weeks this would be an easy merge but since its support Months

The only reason it supports anything other than days is that you explicitly asked me to alter it to use the tparse.Parse. It originally didn't, for the reasons I gave at #13086 (comment).

@bergquist
Copy link
Contributor

I know. That's my mistake I didn't consider months when I wrote that. I'm sorry about that.
If restrict this to only support days and weeks I'm all for merging this.

If you want to do that I'm happy to make this my highest prio to review it. If not I'll fix this myself once I have spare time.

And once again sorry.

@bernardd bernardd force-pushed the add-day-year-interval-parsing branch from 54ca81a to 5a859b5 Compare May 9, 2019 01:39
@bernardd
Copy link
Contributor Author

bernardd commented May 9, 2019

I know. That's my mistake I didn't consider months when I wrote that. I'm sorry about that.

No worries.

If restrict this to only support days and weeks I'm all for merging this.

I've coded this up, but looking back at the original ticket the initial change was to include days and years, since years are also apparently potentially an auto value, so I've included those too. I don't think anyone's going to be too confused if years in this case are just 365 days - what's a quarter of a day between friends?

@bergquist bergquist changed the title Add parsing for day and year intervals to macros MySQL/Postgres/MSSQL: Add parsing for day, weeks and year intervals in macros May 30, 2019
Copy link
Contributor

@bergquist bergquist left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you so much for your patience! :)

LGTM

@bergquist bergquist merged commit a0bb011 into grafana:master May 30, 2019
ryantxu added a commit to ryantxu/grafana that referenced this pull request Jun 3, 2019
…-grafanaui

* grafana/master:
  Annotations: Improve annotation option tooltips (grafana#17384)
  InfluxDB: Fixes single quotes are not escaped (grafana#17398)
  Chore: Bump axios to 0.19.0 (grafana#17403)
  Alerting: golint fixes for alerting (grafana#17246)
  Batch disable users (grafana#17254)
  Chore: Remove unused properties in explore (grafana#17359)
  MySQL/Postgres/MSSQL: Add parsing for day, weeks and year intervals in macros (grafana#13086)
  Security: Prevent csv formula injection attack  (grafana#17363)
ryantxu added a commit to ryantxu/grafana that referenced this pull request Jun 3, 2019
* grafana/master: (73 commits)
  docs: configuring custom headers in the dataproxy (grafana#17367)
  Explore: Queries the datasource once per run query and uses DataStreamObserver (grafana#17263)
  Feature: Adds redux action logging toggle from url params (grafana#17368)
  Build: Adds e2e tests back to master workflow with better error messages and with artifacts (grafana#17374)
  Explore: Handle datasources with long names better in ds picker (grafana#17393)
  Annotations: Improve annotation option tooltips (grafana#17384)
  InfluxDB: Fixes single quotes are not escaped (grafana#17398)
  Chore: Bump axios to 0.19.0 (grafana#17403)
  Alerting: golint fixes for alerting (grafana#17246)
  Batch disable users (grafana#17254)
  Chore: Remove unused properties in explore (grafana#17359)
  MySQL/Postgres/MSSQL: Add parsing for day, weeks and year intervals in macros (grafana#13086)
  Security: Prevent csv formula injection attack  (grafana#17363)
  LDAP: remove unused function (grafana#17351)
  Enterprise: remove gofakeit dep (grafana#17344)
  Explore: Update time range before running queries (grafana#17349)
  Build(package.json): improve npm commands (grafana#17022)
  Chore: upgrade webpack analyser (grafana#17340)
  NewDataSourcePage: Add Grafana Cloud link (grafana#17324)
  CloudWatch: Avoid exception while accessing results (grafana#17283)
  ...
ryantxu added a commit to ryantxu/grafana that referenced this pull request Jun 4, 2019
* grafana/master: (49 commits)
  Build: specify build flag for `docker-compose up` (grafana#17411)
  Add a @grafana/runtime package with backendSrv interface (grafana#16533)
  Database: Initialize xorm with an empty schema for postgres (grafana#17357)
  docs: configuring custom headers in the dataproxy (grafana#17367)
  Explore: Queries the datasource once per run query and uses DataStreamObserver (grafana#17263)
  Feature: Adds redux action logging toggle from url params (grafana#17368)
  Build: Adds e2e tests back to master workflow with better error messages and with artifacts (grafana#17374)
  Explore: Handle datasources with long names better in ds picker (grafana#17393)
  Annotations: Improve annotation option tooltips (grafana#17384)
  InfluxDB: Fixes single quotes are not escaped (grafana#17398)
  Chore: Bump axios to 0.19.0 (grafana#17403)
  Alerting: golint fixes for alerting (grafana#17246)
  Batch disable users (grafana#17254)
  Chore: Remove unused properties in explore (grafana#17359)
  MySQL/Postgres/MSSQL: Add parsing for day, weeks and year intervals in macros (grafana#13086)
  Security: Prevent csv formula injection attack  (grafana#17363)
  LDAP: remove unused function (grafana#17351)
  Enterprise: remove gofakeit dep (grafana#17344)
  Explore: Update time range before running queries (grafana#17349)
  Build(package.json): improve npm commands (grafana#17022)
  ...
ryantxu added a commit to ryantxu/grafana that referenced this pull request Jun 4, 2019
* grafana/master: (108 commits)
  Build: specify build flag for `docker-compose up` (grafana#17411)
  Add a @grafana/runtime package with backendSrv interface (grafana#16533)
  Database: Initialize xorm with an empty schema for postgres (grafana#17357)
  docs: configuring custom headers in the dataproxy (grafana#17367)
  Explore: Queries the datasource once per run query and uses DataStreamObserver (grafana#17263)
  Feature: Adds redux action logging toggle from url params (grafana#17368)
  Build: Adds e2e tests back to master workflow with better error messages and with artifacts (grafana#17374)
  Explore: Handle datasources with long names better in ds picker (grafana#17393)
  Annotations: Improve annotation option tooltips (grafana#17384)
  InfluxDB: Fixes single quotes are not escaped (grafana#17398)
  Chore: Bump axios to 0.19.0 (grafana#17403)
  Alerting: golint fixes for alerting (grafana#17246)
  Batch disable users (grafana#17254)
  Chore: Remove unused properties in explore (grafana#17359)
  MySQL/Postgres/MSSQL: Add parsing for day, weeks and year intervals in macros (grafana#13086)
  Security: Prevent csv formula injection attack  (grafana#17363)
  LDAP: remove unused function (grafana#17351)
  Enterprise: remove gofakeit dep (grafana#17344)
  Explore: Update time range before running queries (grafana#17349)
  Build(package.json): improve npm commands (grafana#17022)
  ...
ryantxu added a commit to ryantxu/grafana that referenced this pull request Jun 4, 2019
* grafana/master: (142 commits)
  Build: specify build flag for `docker-compose up` (grafana#17411)
  Add a @grafana/runtime package with backendSrv interface (grafana#16533)
  Database: Initialize xorm with an empty schema for postgres (grafana#17357)
  docs: configuring custom headers in the dataproxy (grafana#17367)
  Explore: Queries the datasource once per run query and uses DataStreamObserver (grafana#17263)
  Feature: Adds redux action logging toggle from url params (grafana#17368)
  Build: Adds e2e tests back to master workflow with better error messages and with artifacts (grafana#17374)
  Explore: Handle datasources with long names better in ds picker (grafana#17393)
  Annotations: Improve annotation option tooltips (grafana#17384)
  InfluxDB: Fixes single quotes are not escaped (grafana#17398)
  Chore: Bump axios to 0.19.0 (grafana#17403)
  Alerting: golint fixes for alerting (grafana#17246)
  Batch disable users (grafana#17254)
  Chore: Remove unused properties in explore (grafana#17359)
  MySQL/Postgres/MSSQL: Add parsing for day, weeks and year intervals in macros (grafana#13086)
  Security: Prevent csv formula injection attack  (grafana#17363)
  LDAP: remove unused function (grafana#17351)
  Enterprise: remove gofakeit dep (grafana#17344)
  Explore: Update time range before running queries (grafana#17349)
  Build(package.json): improve npm commands (grafana#17022)
  ...
@ying-jeanne ying-jeanne added the pr/external This PR is from external contributor label Apr 29, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
add to changelog datasource/MSSQL Microsoft SQL Server Data Source datasource/MySQL datasource/Postgres pr/external This PR is from external contributor
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Interval parsing error for intervals values expressed in days
9 participants