Skip to content

feat(runs): add ActionRepo.CountActiveActionsByPhase - #8259

Open
Icewind52 wants to merge 4 commits into
flyteorg:mainfrom
Icewind52:feat/runs-count-active-actions
Open

Icewind52 wants to merge 4 commits into
flyteorg:mainfrom
Icewind52:feat/runs-count-active-actions

Conversation

@Icewind52

@Icewind52 Icewind52 commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

Tracking issue

Related to #8235

Why are the changes needed?

The flyte.active_runs and flyte.active_actions gauges in #8235 need a count of live actions from the database. This adds the repo method the runs sampler will call. The sampler itself is a follow-up PR.

What changes were proposed in this pull request?

Adds ActionRepo. CountActiveActionsByPhase , as suggested in the issue, with two adjustments:

  1. Map key. The query groups by (phase, is_root), but a map[int32]int64 keyed by phase alone would let the root and child rows for the same phase overwrite each other. The method returns map[PhaseKey]int64 with PhaseKey{Phase, IsRoot} instead.
  2. Non-terminal filter. The query filters with WHERE phase = ANY(<non-terminal phases>) so it reads only live actions.

Note: FAILED and TIMED_OUT count as terminal, so an action waiting between retries isn't counted until it moves back to a live phase.

How was this patch tested?

  • TestCountActiveActionsByPhase (embedded Postgres): an empty table, plus live and finished runs with children in every phase. It checks that only non-terminal actions are counted and that roots and children are split.

Mock now regenerated. Adding a method to ActionRepo means runs/repository/mocks/mocks.go needs regenerating, but make mocks currently fails, both locally and in CI:

internal error: package "context" without types was imported from "github.com/eko/gocache/lib/v4/cache"

This started with #7949 (Go 1.26.5 → 1.27.2 in gen.Dockerfile, mockery still v3.7.0). The first failing check-mocks run is 37968610418, and it still fails today (40579043741). The job stays green because the timed macro in the Makefile ignores mockery's exit code, so nothing is written and git diff finds no changes. make mocks exits 0 locally too.

This is what I observed, not sure if this is a real regression.

Labels

  • added

Check all the applicable boxes

  • I updated the documentation accordingly.
  • All new and existing tests passed.
  • All commits are signed-off.

Signed-off-by: William Tang <williamtang83@hotmail.com>
@Icewind52
Icewind52 force-pushed the feat/runs-count-active-actions branch from 7a2717e to 9d61e90 Compare October 28, 2026 01:29
Signed-off-by: William Tang <williamtang83@hotmail.com>
@Icewind52
Icewind52 force-pushed the feat/runs-count-active-actions branch from 4c5b32a to 44c274a Compare October 28, 2026 06:14
Replace the loop that derived nonTerminalPhases with an explicit
activePhases list covering every phase not in terminalPhases.

Make TestCountActionsByPhase easier to read: label each expected count with
its seeded action and assert the active run and action totals.

Signed-off-by: William Tang <williamtang83@hotmail.com>
Comment thread runs/repository/interfaces/action.go Resolved
@pingsutw

Copy link
Copy Markdown
Member

LGTM, just one nit

Signed-off-by: William Tang <williamtang83@hotmail.com>
Copilot AI balanced review requested due to automatic review settings October 31, 2026 01:44
@Icewind52 Icewind52 changed the title feat(runs): add ActionRepo.CountActionsByPhase feat(runs): add ActionRepo.CountActiveActionsByPhase Oct 31, 2026

Copilot AI 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.

🟢 Approval recommended

No active review issues were identified for the live-action counting changes.

No open issues 🎉

1 file not reviewed
  • runs/repository/mocks/mocks.go: Generated file
What changed in this PR

Adds repository support for counting live actions, preparing for the flyte.active_runs and flyte.active_actions gauges tracked in #8235. The sampler remains a follow-up change.

Changes:

  • Adds CountActiveActionsByPhase, returning counts keyed by phase and root/child status.
  • Filters the aggregate query to non-terminal phases.
  • Updates the mock and adds database tests for empty results, terminal exclusion, and root/child separation.
File Description
runs/​repository/​mocks/​mocks.go Adds mock support for the new count method.
runs/​repository/​interfaces/​action.go Defines the count method and composite PhaseKey.
runs/​repository/​impl/​action.go Defines active phases and implements the aggregate query.
runs/​repository/​impl/​action_test.go Tests filtering, grouped counts, and gauge totals.

Review effort: Balanced

@0yukali0 0yukali0 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.

+1, LGTM.

The new test is also ideal.
It uses both active and non-active actions to verify that the function returns the correct counts grouped by phase and is_root.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants