Skip to content

feat(query): populate timestamps for config analysis search#2025

Merged
adityathebe merged 2 commits into
mainfrom
fix/config-analysis-search-timestamps
Jun 26, 2026
Merged

feat(query): populate timestamps for config analysis search#2025
adityathebe merged 2 commits into
mainfrom
fix/config-analysis-search-timestamps

Conversation

@adityathebe

@adityathebe adityathebe commented Jun 26, 2026

Copy link
Copy Markdown
Member

Problem

SearchResources (POST /resources/search) populates created_at/updated_at/deleted_at on the selected resources for every resource kind except config analysis. So config insight searches (e.g. faro catalog insights search) always came back without timestamps, even when Timestamps: true was requested — every other kind (configs, components, checks, changes, playbooks, connections) calls setTimestamps, the config_analysis branch did not.

Change

Add the missing setTimestamps call in the config_analysis branch.

config_analysis has no created_at/updated_at columns — its only timestamps are first_observed and last_observed — so we map:

  • first_observedcreated_at
  • last_observedupdated_at

This keeps the response shape uniform with the other resource kinds.

Tests

Extended the existing SearchResourceSelectors timestamp specs to cover config analysis:

  • "populates timestamps when requested" asserts created_at/updated_at are set and first_observed < last_observed (confirming mapping direction).
  • "omits timestamps by default" asserts they stay nil when Timestamps is not set.

Both pass against the embedded test DB.

Downstream

Unblocks the faro catalog insights search timestamp fix in mission-control.

Summary by CodeRabbit

  • Bug Fixes
    • Search results now include timestamps for configuration analysis items when timestamps are requested.
    • Returned timestamps now consistently map to the correct observed time fields in results.
    • Timestamp data remains omitted by default when not requested.

@coderabbitai

coderabbitai Bot commented Jun 26, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Warning

Review limit reached

@adityathebe, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 12 minutes and 40 seconds. Learn how PR review limits work.

Your organization has used up its prepaid credits, and credit purchases are no longer available. Enable the review add-on in the billing tab to keep reviews running — you're only billed for reviews past your plan's rate limits ($0.25/file).

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based credits.

🚦 How do rate limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: d59d5989-2f69-4ad6-85ed-2a95f041a692

📥 Commits

Reviewing files that changed from the base of the PR and between 9cf5e30 and ac733e0.

📒 Files selected for processing (2)
  • query/resource_selector.go
  • tests/query_resource_selector_test.go

Walkthrough

SearchResources now sets timestamps for ConfigAnalysis results when requested. The resource selector tests now cover ConfigAnalysis in the timestamped and default request paths, including JSON output and nil timestamp behavior.

Changes

ConfigAnalysis timestamp propagation

Layer / File(s) Summary
Timestamp mapping
query/resource_selector.go
SearchResources sets ConfigAnalysis CreatedAt and UpdatedAt from FirstObserved and LastObserved when timestamps are enabled.
Timestamp coverage
tests/query_resource_selector_test.go
The timestamped case adds ConfigAnalysis assertions for mapped timestamps and JSON fields, and the default case asserts ConfigAnalysis timestamps remain unset.

Possibly related PRs

  • flanksource/duty#2020: Adds related config_analysis handling in SearchResources and touches the same resource selection path.
  • flanksource/duty#2024: Modifies the same selector flow and timestamp assertions for SelectedResource output.

Suggested reviewers

  • moshloop
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main change: populating timestamps for config analysis search results.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/config-analysis-search-timestamps
✨ Simplify code
  • Create PR with simplified code
  • Commit simplified code in branch fix/config-analysis-search-timestamps

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.

@github-actions

github-actions Bot commented Jun 26, 2026

Copy link
Copy Markdown

Benchstat (RLS)

Base: fd5e4f494c2740582dac0d65c0cbe18bcd3946da
Head: ac733e0c53f7593fd7ac56a5ceb83c5c79058082

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

Benchmark Base Head Change p-value
RLS/Sample-15000/analysis_types/With_RLS-4 3.910m 4.114m +5.21% 🔴 0.002
RLS/Sample-15000/config_classes/With_RLS-4 137.4m 140.7m +2.43% 0.002
RLS/Sample-15000/catalog_changes/Without_RLS-4 5.279m 5.374m +1.79% 0.004
RLS/Sample-15000/config_changes/Without_RLS-4 5.340m 5.378m +0.71% 0.026
✅ 4 improvement(s)
Benchmark Base Head Change p-value
RLS/Sample-15000/change_types/Without_RLS-4 5.424m 5.261m -3.01% 0.002
RLS/Sample-15000/catalog_changes/With_RLS-4 145.6m 142.8m -1.89% 0.002
RLS/Sample-15000/config_detail/Without_RLS-4 4.832m 4.785m -0.97% 0.041
RLS/Sample-15000/config_summary/With_RLS-4 726.3m 720.6m -0.79% 0.026

Failed: 1 benchmark(s) regressed by more than 5%:
RLS/Sample-15000/analysis_types/With_RLS-4: 3.910m -> 4.114m (+5.21%)

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.279m ± 1%   5.374m ± 1%  +1.79% (p=0.004 n=6)
RLS/Sample-15000/catalog_changes/With_RLS-4         145.6m ± 1%   142.8m ± 0%  -1.89% (p=0.002 n=6)
RLS/Sample-15000/config_changes/Without_RLS-4       5.340m ± 1%   5.378m ± 3%  +0.71% (p=0.026 n=6)
RLS/Sample-15000/config_changes/With_RLS-4          144.4m ± 0%   144.8m ± 1%       ~ (p=0.065 n=6)
RLS/Sample-15000/config_detail/Without_RLS-4        4.832m ± 1%   4.785m ± 1%  -0.97% (p=0.041 n=6)
RLS/Sample-15000/config_detail/With_RLS-4           139.3m ± 1%   139.2m ± 1%       ~ (p=0.699 n=6)
RLS/Sample-15000/config_names/Without_RLS-4         13.86m ± 2%   13.85m ± 2%       ~ (p=0.589 n=6)
RLS/Sample-15000/config_names/With_RLS-4            140.8m ± 1%   140.4m ± 1%       ~ (p=0.699 n=6)
RLS/Sample-15000/config_summary/Without_RLS-4       102.8m ± 2%   100.8m ± 5%       ~ (p=0.394 n=6)
RLS/Sample-15000/config_summary/With_RLS-4          726.3m ± 1%   720.6m ± 1%  -0.79% (p=0.026 n=6)
RLS/Sample-15000/configs/Without_RLS-4              8.886m ± 8%   8.297m ± 8%       ~ (p=0.093 n=6)
RLS/Sample-15000/configs/With_RLS-4                 139.2m ± 1%   138.3m ± 2%       ~ (p=0.310 n=6)
RLS/Sample-15000/analysis_types/Without_RLS-4       3.931m ± 1%   3.923m ± 1%       ~ (p=0.485 n=6)
RLS/Sample-15000/analysis_types/With_RLS-4          3.910m ± 1%   4.114m ± 2%  +5.21% (p=0.002 n=6)
RLS/Sample-15000/analyzer_types/Without_RLS-4       3.766m ± 1%   3.751m ± 1%       ~ (p=0.310 n=6)
RLS/Sample-15000/analyzer_types/With_RLS-4          3.762m ± 2%   3.788m ± 2%       ~ (p=0.180 n=6)
RLS/Sample-15000/change_types/Without_RLS-4         5.424m ± 1%   5.261m ± 1%  -3.01% (p=0.002 n=6)
RLS/Sample-15000/change_types/With_RLS-4            5.321m ± 2%   5.308m ± 4%       ~ (p=0.699 n=6)
RLS/Sample-15000/config_classes/Without_RLS-4       4.150m ± 0%   4.122m ± 2%       ~ (p=0.132 n=6)
RLS/Sample-15000/config_classes/With_RLS-4          137.4m ± 1%   140.7m ± 0%  +2.43% (p=0.002 n=6)
RLS/Sample-15000/config_types/Without_RLS-4         4.827m ± 0%   4.877m ± 3%       ~ (p=0.093 n=6)
RLS/Sample-15000/config_types/With_RLS-4            140.0m ± 1%   139.4m ± 1%       ~ (p=0.093 n=6)
geomean                                             21.34m        21.27m       -0.30%

@github-actions

github-actions Bot commented Jun 26, 2026

Copy link
Copy Markdown

Benchstat (Other)

Base: fd5e4f494c2740582dac0d65c0cbe18bcd3946da
Head: ac733e0c53f7593fd7ac56a5ceb83c5c79058082

✅ 1 improvement(s)
Benchmark Base Head Change p-value
InsertionOfConfigsWithProperties-4 3.755m 3.727m -0.74% 0.041
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       609.4µ ±  6%   597.8µ ±  2%       ~ (p=0.132 n=6)
InsertionForRowsWithAliases/config_items.external_id-4     1.103m ± 11%   1.121m ± 11%       ~ (p=1.000 n=6)
InsertionOfConfigsWithProperties-4                         3.755m ±  3%   3.727m ±  1%  -0.74% (p=0.041 n=6)
UpdateOfConfigsWithProperties-4                            7.478m ±  2%   7.443m ±  1%       ~ (p=0.240 n=6)
ResourceSelectorConfigs/name-4                             222.2µ ±  3%   219.3µ ±  1%       ~ (p=0.132 n=6)
ResourceSelectorConfigs/name_and_type-4                    239.3µ ±  3%   238.4µ ±  2%       ~ (p=0.699 n=6)
ResourceSelectorConfigs/tags-4                             29.05m ±  5%   30.26m ±  4%       ~ (p=0.240 n=6)
ResourceSelectorQueryBuild/name-4                          43.34µ ±  1%   43.16µ ±  2%       ~ (p=0.310 n=6)
ResourceSelectorQueryBuild/name_and_type-4                 63.55µ ±  1%   63.33µ ±  1%       ~ (p=0.394 n=6)
ResourceSelectorQueryBuild/tags-4                          17.18µ ±  1%   17.34µ ±  1%       ~ (p=0.240 n=6)
geomean                                                    517.6µ         518.1µ        +0.10%

@coderabbitai coderabbitai Bot left a comment

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.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@tests/query_resource_selector_test.go`:
- Around line 494-497: The test is asserting `UpdatedAt` from
`items.ConfigAnalysis[0]`, but `dummy.LogisticsDBRDSAnalysis` only seeds
`FirstObserved` and leaves `LastObserved` nil, so this case should not require
`UpdatedAt` unless the fixture is updated. Adjust
`tests/query_resource_selector_test.go` to keep this fixture-focused assertion
limited to `CreatedAt`, and if you need coverage for `UpdatedAt`, add or update
a separate fixture case using `dummy.LogisticsDBRDSAnalysis` (or the relevant
mapping path) with `LastObserved` explicitly set.
🪄 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: 13fab33e-b8e8-4e84-94a9-e0bf76cc4a8c

📥 Commits

Reviewing files that changed from the base of the PR and between 9384224 and 9cf5e30.

📒 Files selected for processing (2)
  • query/resource_selector.go
  • tests/query_resource_selector_test.go

Comment thread tests/query_resource_selector_test.go Outdated
@adityathebe adityathebe enabled auto-merge (rebase) June 26, 2026 18:59
SearchResources populated CreatedAt/UpdatedAt/DeletedAt for every
resource kind except config analysis, so config insight searches always
came back without timestamps even when Timestamps was requested.

Map first_observed -> created_at and last_observed -> updated_at (the
only timestamps config_analysis carries) via the existing setTimestamps
helper.
The fixture leaves last_observed unset and relied on the column default
to make updated_at non-nil, which was implicit. Seed a dedicated
analysis with explicit first/last observed and assert the exact mapping
instead.
@adityathebe adityathebe force-pushed the fix/config-analysis-search-timestamps branch from 6c25ecb to ac733e0 Compare June 26, 2026 18:59
@adityathebe adityathebe disabled auto-merge June 26, 2026 18:59
@adityathebe adityathebe enabled auto-merge (squash) June 26, 2026 19:00
@github-actions

github-actions Bot commented Jun 26, 2026

Copy link
Copy Markdown

Gavel results

Gavel exited with code .

View full results

@adityathebe adityathebe merged commit 096470a into main Jun 26, 2026
18 of 20 checks passed
@adityathebe adityathebe deleted the fix/config-analysis-search-timestamps branch June 26, 2026 19:04
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.

1 participant