Skip to content

feat(monitor): improve power monitor with dynamic collection based on interval #2016

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: reboot
Choose a base branch
from

Conversation

sthaha
Copy link
Collaborator

@sthaha sthaha commented Apr 17, 2025

This refactor enhances the monitor as follows:

  • Replace mutex-based synchronization with atomic operations for thread safety
  • Implement dynamic collection scheduling with configurable intervals
  • Add option to disable automatic collection (interval=0) for on-demand only mode
  • Pass previous snapshot explicitly to calculateNodePower
  • Simplify zone name handling by removing unnecessary synchronization
  • Use a context for clean cancellation of collection goroutines
  • Ensure freshness checks always return recent data

Copy link

codecov bot commented Apr 17, 2025

Codecov Report

Attention: Patch coverage is 86.72566% with 15 lines in your changes missing coverage. Please review.

Project coverage is 92.19%. Comparing base (1341ea9) to head (9472e01).

Files with missing lines Patch % Lines
internal/monitor/monitor.go 85.18% 9 Missing and 3 partials ⚠️
internal/device/fake_cpu_power_meter.go 50.00% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           reboot    #2016      +/-   ##
==========================================
+ Coverage   91.50%   92.19%   +0.69%     
==========================================
  Files          17       17              
  Lines        1000     1050      +50     
==========================================
+ Hits          915      968      +53     
+ Misses         66       64       -2     
+ Partials       19       18       -1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@sthaha sthaha force-pushed the feat-monitor-with-interval branch from 2163787 to afff6fd Compare April 17, 2025 02:18
This commit modifies the start up behavior. It refactors the service lifecycle
management, replacing the Start and Stop methods with
* Init: used to initiliaze a service and can assume it isn't called from
  go routines
* Run: Runs the service and blocks until context is cancelled or an
  error is encountered
* `Shutdown`:  methods is the cleanup and indicates that you can't call
  `Run` after `Shutdown`.

This change aims to separate initialization which is run serially and allows
services to initialize without worrying about thread-safety.
I.E. Its okay for an Init() to call another Init().

Thus this change separates initialization, runtime, and cleanup phases for better
clarity and control.

Tests are updated keep up with the change.

Signed-off-by: Sunil Thaha <[email protected]>
@sthaha sthaha force-pushed the feat-monitor-with-interval branch from afff6fd to 19e677e Compare April 19, 2025 05:57
…anagement

This commit replaces sync.RWMutex with atomic.Pointer for thread-safe snapshot
access in PowerMonitor.

* Move zone initialization to initZones method and defer snapshot creation.
* Update calculateNodePower to accept previous node data, decoupling it from snapshot locking.
* update tests to reflect new logic.

Signed-off-by: Sunil Thaha <[email protected]>
@sthaha sthaha force-pushed the feat-monitor-with-interval branch 3 times, most recently from 753f1a9 to 7eadf46 Compare April 20, 2025 11:42
sthaha added 2 commits April 20, 2025 09:06
This refactor enhances the power monitoring system with the following improvements:

- Implement dynamic collection scheduling with configurable intervals
- Add option to disable automatic collection (interval=0) for on-demand only mode
- Use a context for clean cancellation of collection goroutines

Signed-off-by: Sunil Thaha <[email protected]>
@sthaha sthaha force-pushed the feat-monitor-with-interval branch from 7eadf46 to 629fb42 Compare April 20, 2025 13:07
@sthaha sthaha force-pushed the feat-monitor-with-interval branch from 105ea67 to 9472e01 Compare April 20, 2025 14:15
@sthaha sthaha changed the title refactor(monitor): improve power monitor with atomic snapshots and dynamic collection feat(monitor): improve power monitor with dynamic collection based on interval Apr 20, 2025
@sthaha sthaha added the feat A new feature or enhancement label Apr 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feat A new feature or enhancement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant