Skip to content

Move input state tracking to the db to avoid node wide fetch on improved inputs page#25338

Merged
kodjo-anipah merged 17 commits intomasterfrom
move_input_states_to_db
Mar 20, 2026
Merged

Move input state tracking to the db to avoid node wide fetch on improved inputs page#25338
kodjo-anipah merged 17 commits intomasterfrom
move_input_states_to_db

Conversation

@kodjo-anipah
Copy link
Member

@kodjo-anipah kodjo-anipah commented Mar 16, 2026

Description

/nocl
part of #25358

Previously, all input state consumers relied on GET /cluster/inputstates, which performs HTTP fan-out to every cluster node and returns full InputStateSummary objects (config, creator, static fields, etc.).

This approach is:

  • Expensive
  • Fragile in larger clusters
  • Prone to node overload and timeouts

This PR is part of an incremental migration to DB-backed input state endpoints, now that input states are persisted in MongoDB (input_runtime_states collection).


What this PR adds

Backend

  • GET /system/inputstates/summary

    • Lightweight endpoint on InputStatesResource
    • Reads directly from MongoDB
    • No fan-out
    • Returns simplified structure:
      { "inputId": ["RUNNING", "FAILED"] }
  • Remove previously made improvements to the InputRegistry and have InputRuntimeStatusProvider use new DB approach.

Frontend

  • useInputStateSummary hook

    • Polls every 5s (previously 2s)
    • Pre-computes hasProblematicInputs boolean
  • InputsDotBadge

    • Now uses useInputStateSummary
    • Removes dependency on heavy fan-out endpoint for nav badge

@kodjo-anipah kodjo-anipah marked this pull request as ready for review March 18, 2026 07:13
@kodjo-anipah kodjo-anipah requested a review from a team March 18, 2026 07:14
@kodjo-anipah kodjo-anipah changed the title Move input state tracking to the db to avoid node wide fetch Move input state tracking to the db to avoid node wide fetch on improved inputs page Mar 18, 2026
@ousmaneo ousmaneo requested a review from a team March 18, 2026 09:01
@laura-b-g
Copy link
Contributor

Frontend Quick Review (Scoped)

Focus: Frontend changes only (4 files, ~80 lines of frontend diff)
Reviewer scope: useInputStateSummary.ts (new), InputsDotBadge.tsx, InputsDotBadge.test.tsx, ApiRoutes.ts


Summary

Replaces the heavy useInputsStates hook (which calls GET /cluster/inputstates — full HTTP fan-out) with a new lightweight useInputStateSummary hook (calls GET /system/inputstates/summary — single MongoDB read) in the InputsDotBadge nav component. Polling interval relaxed from 2s → 5s.

The old useInputsStates hook is not removed — it's still used by 10+ other files (InputsOverview, InputStateBadge, InputStateControl, InputsNotifications, etc.). This PR only migrates InputsDotBadge, which only needs a boolean "are any inputs problematic?" signal.


Findings

No Issues Found

Area Assessment
Hook API design Clean — returns { hasProblematicInputs: boolean; isLoading: boolean }. Minimal surface, single purpose.
Response type alignment Backend returns Map<String, Set<String>>, serializes to { [inputId]: string[] } — matches the StateSummary type.
Polling interval (5s) Appropriate for a nav badge indicator. Lighter load than the previous 2s full fan-out.
Error handling Uses defaultOnError wrapper consistently with other hooks. retry: false is fine since polling retries naturally.
No keepPreviousData needed Static query key means react-query preserves data between refetches by default. No flash risk.
PROBLEMATIC_STATES set FAILED, FAILING, SETUP — matches the old inline check in InputsDotBadge. No behavioral change.
Component simplification InputsDotBadge went from inline state traversal to a simple boolean read. Cleaner.
Tests Good coverage of all component states: loading, clean, problematic, external issues, combined.

Issue Coverage

Linked issue: #25358 — "Improve fragile input state fetching"

Issue goal PR coverage
Add lightweight input state summary endpoint Backend adds GET /system/inputstates/summary
Move consumers to DB-backed endpoints Frontend: InputsDotBadge migrated (this scope)
Remove InputRegistry workaround logic Backend: InputStateCache removed
Decouple input definitions from state Frontend: new hook fetches states independently

Frontend portion addresses the nav badge consumer. Other frontend consumers (InputsOverview, etc.) remain on the old hook — expected for an incremental migration.


🤖 AI-generated review (frontend scope only) — verify findings before acting on them.

Copy link
Contributor

@laura-b-g laura-b-g left a comment

Choose a reason for hiding this comment

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

Frontend-wise the code looks good. I did not test it though, because my setup is messed up. Still working on that.

Copy link
Contributor

@xd4rker xd4rker left a comment

Choose a reason for hiding this comment

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

Backend LGTM.
Tested locally, works as expected.

@kodjo-anipah kodjo-anipah merged commit c9bfd2d into master Mar 20, 2026
24 checks passed
@kodjo-anipah kodjo-anipah deleted the move_input_states_to_db branch March 20, 2026 16:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants