Skip to content
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

[improvement] Refactor Auditor to simplify the readability #3637

Merged
merged 26 commits into from
Feb 16, 2023

Conversation

wenbingshen
Copy link
Member

@wenbingshen wenbingshen commented Nov 14, 2022

Motivation

Fix #3636

See explanation in #3636

Changes

  1. Auditor class: Only reserved to do some necessary initialization work, scheduling of various detection tasks
  2. Separate monitoring metrics into AuditorStats
  3. Separate the auditBookies task to the AuditorBookieCheckTask
  4. Separate the checkAllLedgers task into the AuditorCheckAllLedgersTask
  5. Separate placementPolicyCheck task into AuditorPlacementPolicyCheckTask
  6. Separate replicasCheck to AuditorReplicasCheckTask

@wenbingshen
Copy link
Member Author

rerun failure checks

@eolivelli eolivelli requested review from dlg99, hangc0276, jiazhai, merlimat and shoothzj and removed request for dlg99 November 14, 2022 10:59
Copy link
Contributor

@eolivelli eolivelli left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1
thanks for this improvement, it will help a lot new contributions

@wenbingshen
Copy link
Member Author

ping @zymap @hangc0276 @shoothzj @dlg99 If you have time, can you help take a look. Thanks.

@wenbingshen
Copy link
Member Author

rerun failure checks

@wenbingshen
Copy link
Member Author

@hangc0276 I have addressed all your comments. PTAL.

Copy link
Contributor

@dlg99 dlg99 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

First of all, thank you for taking on this task.
I recognize it is not simple, given all the iterations of this code and "small changes" snuck there over the years.

Looking at this version I feel it fails a bit short of original plan of refactoring.
It does split the code into smaller components but it leaves the components interconnected - tasks that have to access Auditor's internals etc. Typically this is a design smell that will backfire in the future when changing the code or it will become a burden when you start writing unit tests and mocks for the tasks
Second point is the unit tests. I think that new tasks deserve some unit tests.

This is a fantastic job so far and I applaud you for doing it.
I hope my comment makes sense and it can be made even better.

@wenbingshen
Copy link
Member Author

wenbingshen commented Nov 23, 2022

I hope my comment makes sense and it can be made even better.

@dlg99 Thanks for all your comments. The comments make a lot of sense, I'll try to perfect the whole PR.

@wenbingshen
Copy link
Member Author

It does split the code into smaller components but it leaves the components interconnected - tasks that have to access Auditor's internals etc. Typically this is a design smell that will backfire in the future when changing the code or it will become a burden when you start writing unit tests and mocks for the tasks
Second point is the unit tests. I think that new tasks deserve some unit tests.

@dlg99

  1. I updated the code to avoid circular dependency between Auditor and CheckTask.
  2. I added unit tests corresponding to different tasks.
  3. Now these tasks can run independently without Auditor.
  4. These tasks all have basic unit tests, indicating that they can run independently without Auditor. Since there are too many items that can be used for testing, if we want other unit tests to cover more options, I hope to use another PR. The previous unit tests are sufficient to prove that the changes in this PR maintain compatibility.

If tests not fail, PTAL. Thanks!

Copy link
Contributor

@dlg99 dlg99 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thank you!

One test failed, I am re-running the test suite, we'll see if that's a flake.

@wenbingshen
Copy link
Member Author

wenbingshen commented Dec 1, 2022

I have another bugfix for Auditor. I want to commit after this PR so that I can avoid rebase master and resolve code conflicts. Can you help me to see this PR? Thank you very much. @hangc0276 @dlg99 @eolivelli

@codecov-commenter
Copy link

codecov-commenter commented Feb 7, 2023

Codecov Report

Merging #3637 (2cd8a1e) into master (d6d9212) will increase coverage by 9.93%.
The diff coverage is 70.82%.

@@             Coverage Diff              @@
##             master    #3637      +/-   ##
============================================
+ Coverage     58.23%   68.17%   +9.93%     
- Complexity     5612     6712    +1100     
============================================
  Files           467      473       +6     
  Lines         40822    40943     +121     
  Branches       5234     5234              
============================================
+ Hits          23774    27913    +4139     
+ Misses        14933    10768    -4165     
- Partials       2115     2262     +147     
Flag Coverage Δ
bookie 39.68% <0.00%> (?)
client 44.28% <20.88%> (+0.04%) ⬆️
remaining 29.61% <70.82%> (+0.11%) ⬆️
replication 41.41% <24.51%> (+0.01%) ⬆️
tls 21.08% <0.00%> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
...ava/org/apache/bookkeeper/replication/Auditor.java 74.26% <ø> (+4.57%) ⬆️
...keeper/replication/AuditorCheckAllLedgersTask.java 56.46% <56.46%> (ø)
...r/replication/AuditorPlacementPolicyCheckTask.java 64.63% <64.63%> (ø)
...okkeeper/replication/AuditorReplicasCheckTask.java 73.78% <73.78%> (ø)
...bookkeeper/replication/AuditorBookieCheckTask.java 75.67% <75.67%> (ø)
...rg/apache/bookkeeper/replication/AuditorStats.java 82.14% <82.14%> (ø)
...org/apache/bookkeeper/replication/AuditorTask.java 88.09% <88.09%> (ø)
...rg/apache/bookkeeper/proto/ReadLacProcessorV3.java 73.33% <0.00%> (-5.00%) ⬇️
.../main/java/org/apache/bookkeeper/util/ZkUtils.java 82.47% <0.00%> (-4.13%) ⬇️
...apache/bookkeeper/client/ReadOnlyLedgerHandle.java 83.21% <0.00%> (-2.10%) ⬇️
... and 119 more

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

Copy link
Member

@horizonzy horizonzy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

Copy link
Contributor

@hangc0276 hangc0276 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall LGTM.

@hangc0276 hangc0276 merged commit c217385 into apache:master Feb 16, 2023
@wenbingshen wenbingshen deleted the wenbing/refactorAuditorClass branch February 16, 2023 05:28
Ghatage pushed a commit to sijie/bookkeeper that referenced this pull request Jul 12, 2024
### Motivation

Fix apache#3636 

See explanation in apache#3636 

### Changes

1. Auditor class: Only reserved to do some necessary initialization work, scheduling of various detection tasks
2. Separate monitoring metrics into `AuditorStats`
3. Separate the auditBookies task to the `AuditorBookieCheckTask`
4. Separate the checkAllLedgers task into the `AuditorCheckAllLedgersTask`
5. Separate placementPolicyCheck task into `AuditorPlacementPolicyCheckTask`
6. Separate replicasCheck to `AuditorReplicasCheckTask`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[improvement] Refactor Auditor to simplify the readability
6 participants