Skip to content

Skip daemon RPC calls for servers on maintenance-mode nodes - #2371

Merged
notAreYouScared merged 2 commits into
pelican:mainfrom
LangDuaMC:patch/sleepy-wings
Jun 11, 2026
Merged

Skip daemon RPC calls for servers on maintenance-mode nodes#2371
notAreYouScared merged 2 commits into
pelican:mainfrom
LangDuaMC:patch/sleepy-wings

Conversation

@hUwUtao

@hUwUtao hUwUtao commented Jun 3, 2026

Copy link
Copy Markdown
Contributor

Discussion: Node disruption causes UX delay

Purpose: Practical way to handle Wings node down, yet. Due to the nature of "Maintenance mode" option, runtime consequences must be known by operator, which should make it useful. This option will disengage most of the query process from the dashboard to the node in order to let the Wings instance in a safe state.

What changed:

  • retrieveStatus(): return Missing immediately if node is under maintenance
  • retrieveResources(): return empty if server status is not starting/running, which includes Missing (from maintenance guard) and all stopped states

- retrieveStatus(): return Missing immediately if node is under maintenance
- retrieveResources(): return empty if server status is not starting/running,
  which includes Missing (from maintenance guard) and all stopped states
@coderabbitai

coderabbitai Bot commented Jun 3, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: e84d8da8-d4b5-48b1-a013-f644175eba23

📥 Commits

Reviewing files that changed from the base of the PR and between 0631073 and 95f735a.

📒 Files selected for processing (1)
  • app/Models/Server.php
🚧 Files skipped from review as they are similar to previous changes (1)
  • app/Models/Server.php

📝 Walkthrough

Walkthrough

The Server model now short-circuits daemon queries when a server's node is under maintenance: retrieveStatus() immediately returns ContainerStatus::Missing, and retrieveResources() immediately returns an empty array, both bypassing cached daemon lookups.

Changes

Server state guards

Layer / File(s) Summary
Server status and resource guards
app/Models/Server.php
retrieveStatus() returns ContainerStatus::Missing early when the node is under maintenance. retrieveResources() returns an empty resources array immediately when the node is under maintenance, bypassing cached daemon utilization retrieval.
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.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
Title check ✅ Passed The title 'Skip daemon RPC calls for servers on maintenance-mode nodes' directly and clearly describes the main change: skipping daemon calls when nodes are under maintenance.
Description check ✅ Passed The description is related to the changeset, explaining the purpose (handling Wings node disruption), the specific methods changed, and the rationale for the changes.
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.

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


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.

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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
app/Models/Server.php (1)

477-486: ⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Avoid double daemon getDetails() on cold cache in retrieveResources().

At Line 477, retrieveResources() calls retrieveStatus(), which can already hit daemon getDetails() (Line 466) on a status cache miss; then Line 483 calls getDetails() again for utilization. This doubles RPCs for active servers and can reintroduce the dashboard latency this PR is trying to reduce.

Suggested direction (single daemon fetch path)
 public function retrieveResources(): array
 {
-    if (!$this->retrieveStatus()->isStartingOrRunning()) {
-        return [];
-    }
-
-    return cache()->remember("servers.$this->uuid.resources", now()->addSeconds(15), function () {
-        $details = app(DaemonServerRepository::class)->setServer($this)->getDetails();
-        return Arr::get($details, 'utilization', []);
-    });
+    if ($this->node->isUnderMaintenance()) {
+        return [];
+    }
+
+    return cache()->remember("servers.$this->uuid.resources", now()->addSeconds(15), function () {
+        $details = app(DaemonServerRepository::class)->setServer($this)->getDetails();
+        $status = ContainerStatus::tryFrom(Arr::get($details, 'state')) ?? ContainerStatus::Missing;
+
+        // Keep status cache in sync and avoid a second daemon call in this request path.
+        cache()->put("servers.$this->uuid.status", $status, now()->addSeconds(15));
+
+        return $status->isStartingOrRunning() ? Arr::get($details, 'utilization', []) : [];
+    });
 }
🤖 Prompt for 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.

In `@app/Models/Server.php` around lines 477 - 486, retrieveResources() is causing
two daemon RPCs on a cold cache because retrieveStatus() can already call
DaemonServerRepository::getDetails(), and retrieveResources() calls getDetails()
again; to fix, make retrieveStatus() store the fetched daemon details (e.g., set
a transient property like $this->daemonDetails or return the details alongside
the status) when it calls DaemonServerRepository::getDetails(), then update
retrieveResources() to reuse that stored details if present instead of invoking
DaemonServerRepository::getDetails() again; keep the existing cache key
("servers.$this->uuid.resources"), preserve the phpstan-ignore comment where
needed, and ensure behavior is unchanged when details were not previously
fetched.
🤖 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.

Outside diff comments:
In `@app/Models/Server.php`:
- Around line 477-486: retrieveResources() is causing two daemon RPCs on a cold
cache because retrieveStatus() can already call
DaemonServerRepository::getDetails(), and retrieveResources() calls getDetails()
again; to fix, make retrieveStatus() store the fetched daemon details (e.g., set
a transient property like $this->daemonDetails or return the details alongside
the status) when it calls DaemonServerRepository::getDetails(), then update
retrieveResources() to reuse that stored details if present instead of invoking
DaemonServerRepository::getDetails() again; keep the existing cache key
("servers.$this->uuid.resources"), preserve the phpstan-ignore comment where
needed, and ensure behavior is unchanged when details were not previously
fetched.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 3f9ed00f-21ff-4cc6-a288-17e10a544a57

📥 Commits

Reviewing files that changed from the base of the PR and between 28452e2 and 2ca429c.

📒 Files selected for processing (1)
  • app/Models/Server.php

@Boy132

Boy132 commented Jun 9, 2026

Copy link
Copy Markdown
Member

I don't know if this is desirable. When a node is under maintenance this would restrict what admins can do with servers.

@hUwUtao

hUwUtao commented Jun 9, 2026

Copy link
Copy Markdown
Contributor Author

I don't know if this is desirable. When a node is under maintenance this would restrict what admins can do with servers.

As far as this do, this will only disrupt report of statistics and status.

For actual actions block, it would be introduced in Server::isInConflictState()

@Boy132 Boy132 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

You're right. This is probably fine.

Just one small nitpick.

Comment thread app/Models/Server.php Outdated
*/
public function retrieveResources(): array
{
if (!$this->retrieveStatus()->isStartingOrRunning()) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Resources should still be retrieved when stopping.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

oh sure is

…aintenance check instead of container state check
@hUwUtao
hUwUtao force-pushed the patch/sleepy-wings branch 2 times, most recently from 95f735a to 0631073 Compare June 11, 2026 10:42
@hUwUtao

hUwUtao commented Jun 11, 2026

Copy link
Copy Markdown
Contributor Author

My fault, I rebased main onto this branch, should be fine now.

@notAreYouScared
notAreYouScared merged commit cc2aa38 into pelican:main Jun 11, 2026
30 of 32 checks passed
@github-actions github-actions Bot locked and limited conversation to collaborators Jun 11, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants