feat(job-history): add job_history_summary view#1898
Conversation
WalkthroughThis PR introduces a new Changes
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
✨ Simplify code
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Benchstat (Other)Base: ✅ No significant performance changes detectedFull benchstat output |
Benchstat (RLS)Base:
|
| Benchmark | Base | Head | Change | p-value |
|---|---|---|---|---|
RLS/Sample-15000/config_changes/Without_RLS-4 |
5.383m | 5.984m | +11.15% 🔴 | 0.002 |
RLS/Sample-15000/catalog_changes/Without_RLS-4 |
5.283m | 5.764m | +9.11% 🔴 | 0.015 |
RLS/Sample-15000/config_detail/Without_RLS-4 |
3.948m | 4.223m | +6.98% 🔴 | 0.002 |
RLS/Sample-15000/config_names/Without_RLS-4 |
12.95m | 13.43m | +3.68% | 0.026 |
RLS/Sample-15000/analyzer_types/Without_RLS-4 |
3.794m | 3.929m | +3.58% | 0.002 |
RLS/Sample-15000/change_types/Without_RLS-4 |
5.331m | 5.501m | +3.19% | 0.004 |
RLS/Sample-15000/config_summary/Without_RLS-4 |
64.13m | 65.32m | +1.85% | 0.004 |
✅ 3 improvement(s)
| Benchmark | Base | Head | Change | p-value |
|---|---|---|---|---|
RLS/Sample-15000/configs/Without_RLS-4 |
7.740m | 7.215m | -6.79% | 0.009 |
RLS/Sample-15000/analysis_types/With_RLS-4 |
4.208m | 3.979m | -5.44% | 0.002 |
RLS/Sample-15000/config_names/With_RLS-4 |
129.5m | 127.3m | -1.64% | 0.002 |
Failed: 3 benchmark(s) regressed by more than 5%:
RLS/Sample-15000/config_changes/Without_RLS-4: 5.383m -> 5.984m (+11.15%)
RLS/Sample-15000/catalog_changes/Without_RLS-4: 5.283m -> 5.764m (+9.11%)
RLS/Sample-15000/config_detail/Without_RLS-4: 3.948m -> 4.223m (+6.98%)
Full benchstat output
goos: linux
goarch: amd64
pkg: github.com/flanksource/duty/bench
cpu: AMD EPYC 7763 64-Core Processor
│ bench-base.txt │ bench-head.txt │
│ sec/op │ sec/op vs base │
RLS/Sample-15000/catalog_changes/Without_RLS-4 5.283m ± 10% 5.764m ± 10% +9.11% (p=0.015 n=6)
RLS/Sample-15000/catalog_changes/With_RLS-4 130.9m ± 1% 131.3m ± 2% ~ (p=0.699 n=6)
RLS/Sample-15000/config_changes/Without_RLS-4 5.383m ± 2% 5.984m ± 4% +11.15% (p=0.002 n=6)
RLS/Sample-15000/config_changes/With_RLS-4 130.0m ± 2% 130.3m ± 1% ~ (p=0.699 n=6)
RLS/Sample-15000/config_detail/Without_RLS-4 3.948m ± 1% 4.223m ± 4% +6.98% (p=0.002 n=6)
RLS/Sample-15000/config_detail/With_RLS-4 125.9m ± 1% 126.5m ± 1% ~ (p=0.818 n=6)
RLS/Sample-15000/config_names/Without_RLS-4 12.95m ± 2% 13.43m ± 4% +3.68% (p=0.026 n=6)
RLS/Sample-15000/config_names/With_RLS-4 129.5m ± 2% 127.3m ± 0% -1.64% (p=0.002 n=6)
RLS/Sample-15000/config_summary/Without_RLS-4 64.13m ± 3% 65.32m ± 1% +1.85% (p=0.004 n=6)
RLS/Sample-15000/config_summary/With_RLS-4 761.4m ± 1% 755.4m ± 1% ~ (p=0.180 n=6)
RLS/Sample-15000/configs/Without_RLS-4 7.740m ± 6% 7.215m ± 2% -6.79% (p=0.009 n=6)
RLS/Sample-15000/configs/With_RLS-4 125.2m ± 1% 125.2m ± 1% ~ (p=1.000 n=6)
RLS/Sample-15000/analysis_types/Without_RLS-4 3.997m ± 4% 3.945m ± 4% ~ (p=0.818 n=6)
RLS/Sample-15000/analysis_types/With_RLS-4 4.208m ± 1% 3.979m ± 3% -5.44% (p=0.002 n=6)
RLS/Sample-15000/analyzer_types/Without_RLS-4 3.794m ± 2% 3.929m ± 1% +3.58% (p=0.002 n=6)
RLS/Sample-15000/analyzer_types/With_RLS-4 3.946m ± 5% 4.042m ± 1% ~ (p=0.394 n=6)
RLS/Sample-15000/change_types/Without_RLS-4 5.331m ± 1% 5.501m ± 10% +3.19% (p=0.004 n=6)
RLS/Sample-15000/change_types/With_RLS-4 6.005m ± 3% 5.968m ± 9% ~ (p=0.937 n=6)
RLS/Sample-15000/config_classes/Without_RLS-4 3.330m ± 1% 3.353m ± 10% ~ (p=0.310 n=6)
RLS/Sample-15000/config_classes/With_RLS-4 126.5m ± 1% 126.3m ± 2% ~ (p=0.699 n=6)
RLS/Sample-15000/config_types/Without_RLS-4 4.232m ± 3% 4.449m ± 10% ~ (p=0.093 n=6)
RLS/Sample-15000/config_types/With_RLS-4 127.9m ± 1% 127.4m ± 1% ~ (p=0.065 n=6)
geomean 19.84m 20.11m +1.36%
37c9f14 to
46753e1
Compare
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@views/015_job_history.sql`:
- Line 213: The average_duration metric currently averages duration_millis
across all rows (including in-flight runs), skewing results; modify the
aggregation for average_duration to exclude non-completed statuses by using a
FILTER clause or conditional aggregation on duration_millis — for example change
ROUND(AVG(duration_millis::numeric), 2) AS average_duration to
ROUND(AVG(duration_millis::numeric) FILTER (WHERE status NOT IN
('RUNNING','SKIPPED','STALE')), 2) AS average_duration (or FILTER WHERE
finished_at IS NOT NULL) so only completed runs contribute; update the
expression referencing average_duration/duration_millis accordingly.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: e12d3e57-42a5-424a-80a7-42168903a145
📒 Files selected for processing (2)
rbac/objects.goviews/015_job_history.sql
| COUNT(*) FILTER (WHERE status = 'STALE') AS stale, | ||
| COUNT(*) FILTER (WHERE status = 'SKIPPED') AS skipped, | ||
| MAX(created_at) AS last_run_at, | ||
| ROUND(AVG(duration_millis::numeric), 2) AS average_duration |
There was a problem hiding this comment.
average_duration may be skewed by in-flight/unfinished jobs.
AVG(duration_millis) includes rows with status = 'RUNNING' (and possibly STALE/SKIPPED), where duration_millis is typically 0 or not yet meaningful. Consider restricting the average to completed runs so the metric reflects real execution time.
♻️ Suggested change
- ROUND(AVG(duration_millis::numeric), 2) AS average_duration
+ ROUND(AVG(duration_millis::numeric) FILTER (WHERE status IN ('SUCCESS', 'WARNING', 'FAILED')), 2) AS average_duration📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| ROUND(AVG(duration_millis::numeric), 2) AS average_duration | |
| ROUND(AVG(duration_millis::numeric) FILTER (WHERE status IN ('SUCCESS', 'WARNING', 'FAILED')), 2) AS average_duration |
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@views/015_job_history.sql` at line 213, The average_duration metric currently
averages duration_millis across all rows (including in-flight runs), skewing
results; modify the aggregation for average_duration to exclude non-completed
statuses by using a FILTER clause or conditional aggregation on duration_millis
— for example change ROUND(AVG(duration_millis::numeric), 2) AS average_duration
to ROUND(AVG(duration_millis::numeric) FILTER (WHERE status NOT IN
('RUNNING','SKIPPED','STALE')), 2) AS average_duration (or FILTER WHERE
finished_at IS NOT NULL) so only completed runs contribute; update the
expression referencing average_duration/duration_millis accordingly.
Adds a new
job_history_summaryview grouped byname, including:running,success,warning,failed,stale,skipped)last_run_ataverage_durationAlso maps
job_history_summaryin RBAC (policy.ObjectMonitor).Summary by CodeRabbit
Release Notes