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

fix(grafana): remove extra date condition that is applied together wi… #8147

Merged
merged 1 commit into from
Oct 21, 2024

Conversation

vvshulga
Copy link
Contributor

Summary

On some Grafana dashboards we are using 2 date conditions:

  1. $__timeFilter(pr.created_date) AND
  2. created_date >= DATE_ADD(DATE_ADD($__timeFrom(), INTERVAL -DAY($__timeFrom())+1 DAY), INTERVAL +1 MONTH)
    second function return incorrect dates or dates in the future (especially for short interval <= 7 days).
    $__timeFilter(date) filters correctly depends on selected date time range.
    We have to remove this extra condition.

Does this close any open issues?

Closes #8144

Other Information

Several plugins: AzureDevops, Bamboo, BitBucket, GitHub, Gitlab, Jenkins use the same function
DATE_ADD(DATE_ADD($__timeFrom(), INTERVAL -DAY($__timeFrom())+1 DAY), INTERVAL +1 MONTH)
and there is comment the following condition to remove the month with incomplete data, however, it's unclear how it works.
This PR does not touch plugins file, it should be clarified further.

@dosubot dosubot bot added size:M This PR changes 30-99 lines, ignoring generated files. component/ext This issue or PR relates to external components, such as Grafana pr-type/bug-fix This PR fixes a bug labels Oct 17, 2024
Copy link
Contributor

@Startrekzky Startrekzky left a comment

Choose a reason for hiding this comment

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

LGTM. I checked all the changes in the review mode, not in Grafana dashboards.

@@ -644,7 +644,7 @@
"hide": false,
"metricColumn": "none",
"rawQuery": true,
"rawSql": "with _prs as(\n SELECT\n pr.id,\n pr.created_date as pr_issued_date,\n -- convert null to 0 if a PR has no deploy_time to make sure cycle_time equals the sum of the four sub-metrics\n\t\tcoalesce(prm.pr_deploy_time/60,0) as deploy_time\n FROM pull_requests pr\n left join project_pr_metrics prm on pr.id = prm.id\n join project_mapping pm on pr.base_repo_id = pm.row_id and pm.table = 'repos' \n WHERE\n $__timeFilter(pr.created_date)\n and pr.created_date >= DATE_ADD(DATE_ADD($__timeFrom(), INTERVAL -DAY($__timeFrom())+1 DAY), INTERVAL +1 MONTH)\n and pm.project_name in (${project})\n GROUP BY 1,2,3\n)\n\nSELECT \n avg(deploy_time) as 'PR Deploy Time(h)'\nFROM _prs",
"rawSql": "with _prs as(\n SELECT\n pr.id,\n pr.created_date as pr_issued_date,\n -- convert null to 0 if a PR has no deploy_time to make sure cycle_time equals the sum of the four sub-metrics\n\t\tcoalesce(prm.pr_deploy_time/60,0) as deploy_time\n FROM pull_requests pr\n left join project_pr_metrics prm on pr.id = prm.id\n join project_mapping pm on pr.base_repo_id = pm.row_id and pm.table = 'repos' \n WHERE\n $__timeFilter(pr.created_date)\n and pm.project_name in (${project})\n GROUP BY 1,2,3\n)\n\nSELECT \n avg(deploy_time) as 'PR Deploy Time(h)'\nFROM _prs",
Copy link
Contributor

Choose a reason for hiding this comment

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

I agree that you can remove this condition in the 'stat' panels.

@dosubot dosubot bot added the lgtm This PR has been approved by a maintainer label Oct 21, 2024
@Startrekzky Startrekzky merged commit 49d9ffc into apache:main Oct 21, 2024
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component/ext This issue or PR relates to external components, such as Grafana lgtm This PR has been approved by a maintainer pr-type/bug-fix This PR fixes a bug size:M This PR changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug][Grafana] pr created_date is compared with incorrect date, sometimes with the future
3 participants