Skip to content

Revert diagnostics changes#2169

Closed
bergware wants to merge 4 commits into
unraid:masterfrom
bergware:master
Closed

Revert diagnostics changes#2169
bergware wants to merge 4 commits into
unraid:masterfrom
bergware:master

Conversation

@bergware

@bergware bergware commented Apr 24, 2025

Copy link
Copy Markdown
Contributor

Summary by CodeRabbit

  • Bug Fixes

    • Improved reliability of diagnostics message delivery by changing how messages are sent to the diagnostics endpoint.
    • IP masking for network diagnostics is now correctly skipped when viewing all data.
  • Other Improvements

    • Enhanced internal handling of diagnostic commands for better compatibility.

@coderabbitai

coderabbitai Bot commented Apr 24, 2025

Copy link
Copy Markdown
Contributor

Walkthrough

The script in the diagnostics plugin has been updated to alter how diagnostic messages are sent and how commands are executed. The write() function now uses a persistent cURL handle to POST messages to a local diagnostics endpoint via a Unix socket, replacing the previous use of the publish() function. The run() function no longer sets the locale explicitly in its execution command and now includes a global declaration for certain variables. Additionally, IP masking for diagnostic output is now conditional based on a flag.

Changes

File(s) Change Summary
emhttp/plugins/dynamix/scripts/diagnostics Replaced publish.php with Wrappers.php; rewrote write() to use cURL POST over Unix socket; updated run() to remove locale setting and add global declarations; made IP masking conditional on a flag.

Sequence Diagram(s)

sequenceDiagram
    participant Script
    participant DiagnosticsEndpoint

    Script->>DiagnosticsEndpoint: POST /pub/diagnostics?buffer_length=1 (via Unix socket) [for each message]
Loading

Possibly related PRs

  • fix: diagnostics improvements #2163: Directly modifies the same write() and run() functions but implements the opposite communication method, reverting from cURL POST back to publish() calls.

Poem

🐇
In the warren, scripts now hop,
Curling messages, they never stop.
Through sockets deep, diagnostics flow,
No more publish—off they go!
With globals declared and masking neat,
This rabbit’s code is quite the feat.


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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@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: 0

🧹 Nitpick comments (1)
emhttp/plugins/dynamix/scripts/diagnostics (1)

47-60: Improved diagnostics messaging with direct socket communication

The write() function has been fundamentally changed to use a persistent cURL handle to POST messages directly to a local diagnostics endpoint via a Unix socket instead of using the publish() function. This likely provides more reliable and direct communication.

However, there's no error handling for potential cURL failures, which could occur if the nginx server isn't running or accessible.

Consider adding basic error handling:

function write(...$messages){
  $com = curl_init();
  curl_setopt_array($com,[
    CURLOPT_URL => 'http://localhost/pub/diagnostics?buffer_length=1',
    CURLOPT_UNIX_SOCKET_PATH => '/var/run/nginx.socket',
    CURLOPT_POST => 1,
    CURLOPT_RETURNTRANSFER => true
  ]);
  foreach ($messages as $message) {
    curl_setopt($com, CURLOPT_POSTFIELDS, $message);
-   curl_exec($com);
+   if (!curl_exec($com) && $cli) {
+     echo "Warning: Failed to send diagnostic message.\n";
+   }
  }
  curl_close($com);
}
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 664daff and d5e0406.

📒 Files selected for processing (1)
  • emhttp/plugins/dynamix/scripts/diagnostics (3 hunks)
🔇 Additional comments (5)
emhttp/plugins/dynamix/scripts/diagnostics (5)

29-29: Switched from publish.php to Wrappers.php dependency

This change aligns with the modifications to the write() function that now uses direct curl calls instead of the previous publish() function.


62-63: Updated function comment for run()

The comment indicates the run function now includes error logging, though the implementation doesn't show explicit error logging changes.


64-64: Added global variable declarations

The function now declares $cli and $diag as global variables, making the function more maintainable by explicitly showing its dependencies.


471-471: Made IP masking conditional based on the all flag

IP masking for system/ifconfig.txt is now conditional on $all being false. This is consistent with the purpose of having a comprehensive diagnostic mode that includes all information when requested.


68-69:

Details

❓ Verification inconclusive

Simplified command execution by removing locale setting

The explicit locale setting (LC_ALL=en_US.UTF-8) has been removed from the exec command, which simplifies the code. However, this could potentially lead to locale-dependent output formatting which might affect parsing in some environments.

The trailing space in the string concatenation has also been removed, which is a good cleanup.

Verify if any command outputs are sensitive to locale settings:


🏁 Script executed:

#!/bin/bash
# Check if any commands rely on specific locale formatting
grep -r "LC_ALL" /usr/local/emhttp/ --include="*.php" | grep -v "diagnostics"

Length of output: 127


🏁 Script executed:

#!/bin/bash
# Search for explicit locale settings across the repository
grep -R "LC_ALL" -n .

Length of output: 858


🏁 Script executed:

#!/bin/bash
# Display beginning of diagnostics script to inspect commands and locale usage
sed -n '1,200p' emhttp/plugins/dynamix/scripts/diagnostics

Length of output: 7906


🏁 Script executed:

#!/bin/bash
# Check for any usage of date commands in diagnostics script
grep -R -n "date " emhttp/plugins/dynamix/scripts/diagnostics

Length of output: 379


Review locale handling in diagnostics script

The PHP calls to setlocale(LC_ALL, 'en_US.UTF-8') in local_prepend.php only affect PHP’s internal functions and do not set the shell environment for exec(). By removing the LC_ALL=en_US.UTF-8 prefix, all commands invoked via:

  • File: emhttp/plugins/dynamix/scripts/diagnostics
    Location: run() function (around lines 65–75)
    Snippet:
    function run($cmd, &$save=null, $timeout=30) {
      // … 
      exec("timeout -s9 $timeout $cmd", $save);
      return implode("\n",$save);
    }

will now inherit the system’s default locale, which may vary between installations. If any output parsing (e.g. of df, smartctl, date stamps, decimal separators, month names) depends on a consistent locale, you should:

  • Verify that unRAID’s default locale is uniformly set to en_US.UTF-8 (or C) in all environments
  • Or explicitly prefix the command in run() with LC_ALL=C (or your desired locale) to ensure consistent, locale-independent output

Please confirm which approach is appropriate for your target deployments.

@limetech limetech closed this Apr 24, 2025
@limetech

Copy link
Copy Markdown
Contributor

Superseded by #2170

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