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.
Add a method preCheck
to AbstractCollect
.
Add a method preCheck
to the org.apache.hertzbeat.collector.collect.AbstractCollect
class:
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.