feat(agentready): add project-level filtering to Grafana dashboards#94
feat(agentready): add project-level filtering to Grafana dashboards#94CryptoRodeo wants to merge 3 commits into
Conversation
Add ${project} template variable and project_mapping JOINs to all three
dashboards (fleet-overview, findings-analysis, repo-detail) so panels
scope data to the selected DevLake project.
Assisted-By: Claude Opus 4.6
Signed-off-by: Bryan Ramos <bramos@redhat.com>
|
/review |
|
/review |
|
/agentic_review |
|
/agentic_review |
Code Review by Qodo
Context used✅ Compliance rules (platform):
110 rules 1. Changes under plugins/agentready
|
| "targets": [ | ||
| { | ||
| "rawSql": "SELECT\n f.attribute_name,\n COUNT(*) AS failure_count\nFROM _tool_agentready_findings f\nWHERE f.status = 'fail'\nGROUP BY f.attribute_id, f.attribute_name\nORDER BY failure_count DESC\nLIMIT 15", | ||
| "rawSql": "SELECT\n f.attribute_name,\n COUNT(*) AS failure_count\nFROM _tool_agentready_findings f\nJOIN project_mapping pm ON f.repo_id = pm.row_id AND pm.`table` = 'repos'\nWHERE f.status = 'fail' AND pm.project_name in (${project})\nGROUP BY f.attribute_id, f.attribute_name\nORDER BY failure_count DESC\nLIMIT 15", |
There was a problem hiding this comment.
1. Changes under plugins/agentready 📘 Rule violation § Compliance
This PR modifies files under backend/plugins/agentready/, which is outside the allowed owned plugin directories for this change. This violates the restriction that only backend/plugins/aireview/, backend/plugins/codecov/, and backend/plugins/testregistry/ may be touched.
Agent Prompt
## Issue description
The PR updates files under `backend/plugins/agentready/`, but compliance requires that changes be restricted to owned plugin directories only.
## Issue Context
Allowed directories per compliance are:
- `backend/plugins/aireview/`
- `backend/plugins/codecov/`
- `backend/plugins/testregistry/`
Any modifications outside these paths violate the rule.
## Fix Focus Areas
- backend/plugins/agentready/grafana/findings-analysis.json[24-130]
- backend/plugins/agentready/grafana/fleet-overview.json[29-213]
- backend/plugins/agentready/grafana/repo-detail.json[196-221]
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools
There was a problem hiding this comment.
This PR modifies files under backend/plugins/agentready/, which is outside the allowed owned
plugin directories for this change.
Is there a rule I can add so the agentready plugin can be modified? 👀
There was a problem hiding this comment.
@CryptoRodeo it looks like when we made this repo agentready lol.
Looks like we need to update the root AGENTS.md file. Qodo seems to be pulling the rules from there. And then probably need to add skills/AGENTs.md for this plugin as well
There was a problem hiding this comment.
That's it, I'll create a another PR to update that after, thanks!
| "datasource": "mysql", | ||
| "definition": "select distinct name from projects", | ||
| "hide": 0, | ||
| "includeAll": true, | ||
| "label": "Project", | ||
| "multi": true, | ||
| "name": "project", | ||
| "options": [], | ||
| "query": "select distinct name from projects", |
There was a problem hiding this comment.
2. Project var wrong datasource 🐞 Bug ≡ Correctness
The new project template variable is hard-coded to the Grafana datasource named mysql, while the
dashboards otherwise use the selectable ${DS_DEVLAKE} datasource. In environments where the
DevLake datasource is not literally named mysql, the project dropdown query fails and panels using
${project} won’t render correctly.
Agent Prompt
### Issue description
The `project` template variable uses a hard-coded datasource (`"mysql"`) instead of the dashboard’s datasource variable (`${DS_DEVLAKE}`), causing the variable query (and dependent panels) to fail when the datasource name differs.
### Issue Context
These dashboards already define `DS_DEVLAKE` as a datasource template variable and use `${DS_DEVLAKE}` for panel queries (and for `repo_id` in repo-detail). The `project` variable should query `projects` from the same selected datasource.
### Fix
Update the `project` variable in all three dashboards to use `${DS_DEVLAKE}` as its datasource (consistent with panels / other variables).
### Fix Focus Areas
- backend/plugins/agentready/grafana/findings-analysis.json[110-129]
- backend/plugins/agentready/grafana/fleet-overview.json[192-212]
- backend/plugins/agentready/grafana/repo-detail.json[196-216]
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools
There was a problem hiding this comment.
Updated, switched to a format that follows the other plugins.
| "targets": [ | ||
| { | ||
| "rawSql": "SELECT\n a.certification_level AS metric,\n COUNT(*) AS value\nFROM _tool_agentready_assessments a\nINNER JOIN (\n SELECT repo_id, MAX(assessed_at) as max_assessed\n FROM _tool_agentready_assessments WHERE id != ''\n GROUP BY repo_id\n) latest ON a.repo_id = latest.repo_id AND a.assessed_at = latest.max_assessed\nGROUP BY a.certification_level", | ||
| "rawSql": "SELECT\n a.certification_level AS metric,\n COUNT(*) AS value\nFROM _tool_agentready_assessments a\nJOIN project_mapping pm ON a.repo_id = pm.row_id AND pm.`table` = 'repos'\nINNER JOIN (\n SELECT aa.repo_id, MAX(aa.assessed_at) as max_assessed\n FROM _tool_agentready_assessments aa\n JOIN project_mapping pm2 ON aa.repo_id = pm2.row_id AND pm2.`table` = 'repos'\n WHERE aa.id != '' AND pm2.project_name in (${project})\n GROUP BY aa.repo_id\n) latest ON a.repo_id = latest.repo_id AND a.assessed_at = latest.max_assessed\nWHERE pm.project_name in (${project})\nGROUP BY a.certification_level", |
There was a problem hiding this comment.
3. Project join inflates aggregates 🐞 Bug ≡ Correctness
Several panel queries join project_mapping and then use COUNT(*)/AVG(...), which duplicates rows when a repo appears in more than one of the selected projects (the project variable is multi-select and defaults to All). This inflates counts (e.g., certification distribution) and weights averages (e.g., avg score / pass rates) by “number of selected projects a repo belongs to” instead of “per repo”.
Agent Prompt
### Issue description
Queries that `JOIN project_mapping` and then aggregate with `COUNT(*)` or `AVG(...)` will over-count/over-weight when the same repo is mapped to multiple selected projects. This is especially problematic because the `project` variable is multi-select and defaults to `All`.
### Issue Context
`project_mapping` is keyed by `(project_name, table, row_id)`, so the same `row_id` can legitimately map to multiple `project_name` values. Under `pm.project_name IN (${project})`, a single assessment/finding row can match multiple mapping rows and be duplicated.
### Fix
Prefer filtering via `EXISTS` (or a join to a `SELECT DISTINCT row_id ...` derived table) so each underlying fact row is counted once. For example:
- Replace `JOIN project_mapping pm ... WHERE pm.project_name in (${project})` with:
`WHERE EXISTS (SELECT 1 FROM project_mapping pm WHERE pm.row_id = a.repo_id AND pm.\`table\`='repos' AND pm.project_name IN (${project}))`
- Where a join is necessary, join against a de-duplicated mapping subquery:
`JOIN (SELECT DISTINCT row_id FROM project_mapping WHERE \`table\`='repos' AND project_name IN (${project})) pm ON pm.row_id = a.repo_id`
### Fix Focus Areas
- backend/plugins/agentready/grafana/fleet-overview.json[29-29]
- backend/plugins/agentready/grafana/fleet-overview.json[71-71]
- backend/plugins/agentready/grafana/findings-analysis.json[24-24]
- backend/plugins/agentready/grafana/findings-analysis.json[45-45]
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools
…ource convention Replace non-standard __inputs + DS_DEVLAKE template variable pattern with direct "mysql" datasource references, matching all other DevLake dashboards. The DS_DEVLAKE indirection added no value since DevLake provisions the datasource as "mysql" via grafana/provisioning Signed-off-by: Bryan Ramos <bramos@redhat.com>
… multi-project repos Panels in fleet-overview and findings-analysis joined project_mapping in the outer query, duplicating rows when a repo belonged to more than one selected project. This inflated AVG scores, COUNT totals, and produced duplicate table rows. Fleet-overview fix: remove redundant outer pm JOIN, the "latest assessment" subquery already filters by project. Findings-analysis fix: replace JOIN with EXISTS so project filtering does not multiply rows. Signed-off-by: Bryan Ramos <bramos@redhat.com>
|
Closing, all work moving to #97 |
pr-type/bug-fix,pr-type/feature-development, etc.Summary
What does this PR do?
Add ${project} template variable and project_mapping JOINs to all three dashboards (fleet-overview, findings-analysis, repo-detail) so panels scope data to the selected DevLake project.
Does this close any open issues?
Closes KFLUXDP-1008
Screenshots
project-filter-test.mp4
Other Information
Any other information that is important to this PR.
Assisted-By: Claude Opus 4.6