Skip to content

Add include_stats parameter to status endpoint and reduce log verbosity#51

Merged
thiagoralves merged 1 commit into
developmentfrom
devin/1766162887-reduce-status-stats-polling
Dec 19, 2025
Merged

Add include_stats parameter to status endpoint and reduce log verbosity#51
thiagoralves merged 1 commit into
developmentfrom
devin/1766162887-reduce-status-stats-polling

Conversation

@devin-ai-integration

Copy link
Copy Markdown
Contributor

Summary

This PR addresses log flooding from STATUS and STATS commands by:

  1. Adding include_stats parameter to /api/status endpoint - The endpoint now only fetches timing stats when include_stats=true is explicitly passed. Default is false, which completely skips the stats_plc() call and avoids acquiring the stats mutex that could introduce latency to the critical PLC scan cycle.

  2. Reducing command logging verbosity - Removed all log_debug("Received X command") statements for recognized commands (PING, STATUS, STOP, START, STATS, DEBUG) and the generic "Received command" log. Only unrecognized commands are now logged (via existing log_error).

Note: This is a breaking change for clients that expect timing_stats in the status response by default. Per discussion, this is acceptable since the product hasn't been released yet.

Review & Testing Checklist for Human

  • Verify the include_stats query parameter is correctly passed to the data dict by the REST API dispatch layer (check restapi.py if needed)
  • Test /api/status returns only {"status": "..."} without timing_stats when called without parameters
  • Test /api/status?include_stats=true returns both status and timing_stats
  • Confirm runtime logs are significantly less verbose after this change (no more "Received STATUS command" / "Received STATS command" flooding)

Recommended test plan:

  1. Start the runtime and connect openplc-web or openplc-editor
  2. Observe that logs no longer show repeated STATUS/STATS command messages
  3. Use curl or browser to verify: curl -k https://localhost:8443/api/status returns no timing_stats, while curl -k https://localhost:8443/api/status?include_stats=true includes timing_stats

Notes

This is Stage 1 of a 3-stage fix. Stage 2 (openplc-web) and Stage 3 (openplc-editor) will update the clients to use include_stats=true only when the orchestrators/device configuration screen is visible.

Link to Devin run: https://app.devin.ai/sessions/23f46f5fc2d44440a67eda96a6048254
Requested by: Thiago Alves (@thiagoralves)

- Add optional include_stats parameter to /api/status endpoint (default false)
- Only fetch timing stats when include_stats=true, avoiding mutex acquisition
- Remove verbose command logging from unix_socket.c (only log unrecognized commands)
- This reduces log flooding and avoids unnecessary mutex contention on the
  critical PLC scan cycle when stats are not needed

Co-Authored-By: Thiago Alves <thiagoralves@gmail.com>
@devin-ai-integration

Copy link
Copy Markdown
Contributor Author

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment and CI monitoring

@thiagoralves thiagoralves requested a review from Copilot December 19, 2025 17:03

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.

Pull request overview

This PR reduces log flooding from frequent STATUS and STATS commands by making timing statistics optional and removing verbose debug logging. The changes prevent unnecessary mutex acquisition during status polls, which could impact PLC scan cycle performance.

Key changes:

  • Added include_stats query parameter to /api/status endpoint (defaults to false)
  • Removed debug log statements for all recognized commands (PING, STATUS, STOP, START, STATS, DEBUG)

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
webserver/app.py Conditionally fetches timing stats only when include_stats=true parameter is provided
core/src/plc_app/unix_socket.c Removes verbose debug logging for recognized commands and generic command receipt logs

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@thiagoralves thiagoralves merged commit c860270 into development Dec 19, 2025
1 check passed
@thiagoralves thiagoralves deleted the devin/1766162887-reduce-status-stats-polling branch December 28, 2025 01:43
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