-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[improve][HIP] HIP-01: Refactoring AbstractCollect (#1930)
Co-authored-by: tomsun28 <[email protected]>
- Loading branch information
1 parent
95a7a13
commit 78ca5ae
Showing
1 changed file
with
54 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
|
||
|
||
# HIP-01: Refactoring AbstractCollect | ||
|
||
|
||
# Motivation | ||
|
||
In the current situation, almost every collector needs to execute the preCheck method (with inconsistent names), and there are also redundant `try-catch` statements; | ||
|
||
I suggest providing another `preCheck` method for `AbstractCollect` to separate the validate logic from the collector's logic, which would make the code structure clearer and also facilitate the writing of unit tests. | ||
|
||
# Goals | ||
|
||
## In Scope | ||
|
||
Add a method `preCheck` to `AbstractCollect`. | ||
|
||
|
||
|
||
|
||
# Detailed Design | ||
|
||
## Design & Implementation Details | ||
|
||
Add a method `preCheck` to the `org.apache.hertzbeat.collector.collect.AbstractCollect` class: | ||
|
||
```java | ||
public abstract class AbstractCollect { | ||
|
||
/** | ||
* @param metrics metric configuration | ||
* @throws Exception when validation failed | ||
*/ | ||
public abstract void preCheck(Metrics metrics) throws Exception; | ||
} | ||
``` | ||
|
||
Before calling the method `org.apache.hertzbeat.collector.collect.AbstractCollect#collect`, call the `preCheck` method and catch the exception. | ||
|
||
Refactoring all `AbstractCollect` to implement the `preCheck` method. | ||
|
||
Supplement the relevant unit tests. | ||
|
||
|
||
|
||
|
||
|
||
# Links | ||
|
||
<!-- | ||
Updated afterwards | ||
--> | ||
* Mailing List discussion thread: https://lists.apache.org/thread/cvvo7xg35fxq7kml5ggdrcdygrx6yvyj | ||
* Mailing List voting thread: https://lists.apache.org/thread/1s7dhrb27qfdx1gsh29dvmo8frjbt619 |