feat: add runtime statistics tracking and integration tests for PluginStats#237
Merged
lijingrs merged 1 commit intomofa-org:feature/mofa-rsfrom Feb 23, 2026
Conversation
Contributor
Author
|
@BH3GEI let me know |
lijingrs
approved these changes
Feb 23, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
📋 Summary
Add per-plugin runtime statistics to the Rhai plugin runtime. Introduces a thread-safe
PluginStatsstruct to track total calls, failed calls, and cumulative latency, along with accessors and JSON snapshot support.This enables monitoring plugin usage, debugging failures, and measuring performance in a production-ready way.
🔗 Related Issues
Closes #235
Related to #173
🧠 Context
Currently, Rhai plugins do not expose any runtime statistics, making it difficult to measure plugin performance, detect errors, or optimize execution.
This PR solves the problem by:
AtomicU64countersstats()accessor🛠️ Changes
PluginStatsstruct with counters,record(),avg_latency_ms(), andto_map()PluginStatstoRhaiPluginandpub useit fromrhai_runtime/mod.rsstats()accessor onRhaiPluginreturningArc<PluginStats>crates/mofa-plugins/src/rhai_runtime/plugin.rsfor counter increments, average latency, zero-call guardcrates/mofa-plugins/tests/rhai_integration_tests.rsdriving plugin invocations and asserting stats🧪 How you Tested
PluginStatscounters increment correctly and average latency calculations📸 Screenshots / Logs (if applicable)
N/A – metrics are exposed via JSON snapshot in tests
If breaking: N/A
🧹 Checklist
Code Quality
cargo fmtruncargo clippypasses without warningsTesting
cargo testpasses locally without any errorDocumentation
PR Hygiene
main🚀 Deployment Notes (if applicable)
No migrations or config changes; rollout is safe.
🧩 Additional Notes for Reviewers
PluginStatsusesAtomicU64for thread-safety