Skip to content

refactor(monitor): replace RWMutex with atomic.Pointer for snapshot management #2022

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 3 commits into
base: reboot
Choose a base branch
from

Conversation

sthaha
Copy link
Collaborator

@sthaha sthaha commented Apr 19, 2025

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.

sthaha added 2 commits April 19, 2025 01:41
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]>
…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]>
Copy link

codecov bot commented Apr 19, 2025

Codecov Report

Attention: Patch coverage is 92.30769% with 6 lines in your changes missing coverage. Please review.

Project coverage is 93.51%. Comparing base (1341ea9) to head (11a01a6).

Files with missing lines Patch % Lines
internal/device/fake_cpu_power_meter.go 50.00% 3 Missing ⚠️
internal/monitor/monitor.go 94.11% 2 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           reboot    #2022      +/-   ##
==========================================
+ Coverage   91.50%   93.51%   +2.01%     
==========================================
  Files          17       17              
  Lines        1000     1018      +18     
==========================================
+ Hits          915      952      +37     
+ Misses         66       52      -14     
+ Partials       19       14       -5     

☔ 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 refactor-monitor-snapshot branch from cc1a4ca to 005cd50 Compare April 20, 2025 11:40
@sthaha sthaha force-pushed the refactor-monitor-snapshot branch from 005cd50 to 11a01a6 Compare April 20, 2025 13:06
@sthaha sthaha added the refactor Code refactoring without changing functionality label Apr 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
refactor Code refactoring without changing functionality
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant