Skip to content

feat(job-history): add job_history_summary view#1898

Merged
moshloop merged 1 commit intomainfrom
feat/job-history-summary-view
Apr 17, 2026
Merged

feat(job-history): add job_history_summary view#1898
moshloop merged 1 commit intomainfrom
feat/job-history-summary-view

Conversation

@adityathebe
Copy link
Copy Markdown
Member

@adityathebe adityathebe commented Apr 17, 2026

Adds a new job_history_summary view grouped by name, including:

  • total jobs
  • per-status counts (running, success, warning, failed, stale, skipped)
  • last_run_at
  • average_duration

Also maps job_history_summary in RBAC (policy.ObjectMonitor).

Summary by CodeRabbit

Release Notes

  • New Features
    • Added job history summary view providing aggregated statistics including total job count, per-status breakdown (running, success, warning, failed, stale, skipped), last run timestamp, and average duration metrics.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Apr 17, 2026

Walkthrough

This PR introduces a new job_history_summary view that aggregates job history metrics by job name, computing totals, per-status counts, last run time, and average duration. The RBAC configuration is updated to recognize this view for policy management.

Changes

Cohort / File(s) Summary
RBAC Configuration
rbac/objects.go
Added mapping for job_history_summary to policy.ObjectMonitor in the resource object map.
Database Views
views/015_job_history.sql
Created new job_history_summary view aggregating job history by name with total count, per-status counts (RUNNING, SUCCESS, WARNING, FAILED, STALE, SKIPPED), last run timestamp, and average duration in milliseconds.
🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and specifically describes the main change: adding a new job_history_summary view to the codebase.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/job-history-summary-view
✨ Simplify code
  • Create PR with simplified code
  • Commit simplified code in branch feat/job-history-summary-view

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions
Copy link
Copy Markdown

github-actions bot commented Apr 17, 2026

Benchstat (Other)

Base: b8ae2d6bef450f29f5b8786301c6397f1ebad782
Head: 46753e14e5c78650b741215febf8f09a6fe9d26f

✅ No significant performance changes detected

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              │
InsertionForRowsWithAliases/external_users.aliases-4       558.3µ ±  7%   559.2µ ±  7%       ~ (p=0.818 n=6)
InsertionForRowsWithAliases/config_items.external_id-4     1.083m ± 11%   1.073m ± 11%       ~ (p=1.000 n=6)
ResourceSelectorConfigs/name-4                             217.4µ ±  2%   215.8µ ±  2%       ~ (p=0.394 n=6)
ResourceSelectorConfigs/name_and_type-4                    234.1µ ±  5%   234.8µ ±  2%       ~ (p=0.589 n=6)
ResourceSelectorConfigs/tags-4                             28.72m ±  2%   29.00m ±  6%       ~ (p=0.240 n=6)
ResourceSelectorQueryBuild/name-4                          42.09µ ±  0%   42.19µ ±  1%       ~ (p=0.485 n=6)
ResourceSelectorQueryBuild/name_and_type-4                 62.01µ ±  1%   61.95µ ±  1%       ~ (p=0.699 n=6)
ResourceSelectorQueryBuild/tags-4                          16.83µ ±  1%   16.73µ ±  1%       ~ (p=0.310 n=6)
geomean                                                    281.0µ         280.7µ        -0.08%

@github-actions
Copy link
Copy Markdown

github-actions bot commented Apr 17, 2026

Benchstat (RLS)

Base: b8ae2d6bef450f29f5b8786301c6397f1ebad782
Head: 46753e14e5c78650b741215febf8f09a6fe9d26f

⚠️ 7 regression(s) detected (threshold: >5%)

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%

@moshloop moshloop enabled auto-merge (rebase) April 17, 2026 08:51
@moshloop moshloop force-pushed the feat/job-history-summary-view branch from 37c9f14 to 46753e1 Compare April 17, 2026 08:51
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

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

📥 Commits

Reviewing files that changed from the base of the PR and between b8ae2d6 and 46753e1.

📒 Files selected for processing (2)
  • rbac/objects.go
  • views/015_job_history.sql

Comment thread views/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
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

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.

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
🤖 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.

@moshloop moshloop merged commit 495cf26 into main Apr 17, 2026
17 of 18 checks passed
@moshloop moshloop deleted the feat/job-history-summary-view branch April 17, 2026 08:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants