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
vmalert-tool: implement unittest #4789
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we're going in the right direction. But we should try to split responsibility between packages in more clear way. Let's agree on the following:
- main.go is responsible for initial validation of the given params and for initing components like: datasource, remote read, remote write, notifier.
- main.go is responsible for scheduling rules execution via private component
manager
Manager
supposed to operate on the Groups level, where Group is a part ofrule
package- Rules package supposed to expose Group, Alerting and Recording structs. The
Rule
interface can be private, as main.go should use Group to exec rules. - web component is a part of main package and should operating based on the public structs from the
rule
package. Methods like RuleToAPI could be private and belong to main package only. - Unit tests should operate on rules execution via Group, the same way as in p3. It could be needed to add an extra method to a Group struct which would evaluate all the rules on the call. Additionally to
Start
method, which only schedules the evaluation.
This separation supposed to isolate responsibility of components and keep private fields private. It should also provide the same way for rules execution for main.go and for unit tests.
One extra comment is that for unittests it might be better to create a new tool instead of integrating into vmctl. It is right that vmctl was initially meant to become a cli tool for VM. But historically, vmctl is responsible for migration only. Creating a vmalert-tool
could be easier to grasp and argue about for users. Probably, we'll move replay
mode to vmalert-tool
after that.
Let me know wdyt.
@hagen1778 |
8d5f502
to
a76c728
Compare
6c51b86
to
f4bb876
Compare
b7d871d
to
c776bb5
Compare
Codecov ReportAttention:
Additional details and impacted files@@ Coverage Diff @@
## master #4789 +/- ##
==========================================
- Coverage 60.37% 60.21% -0.17%
==========================================
Files 389 397 +8
Lines 73142 74019 +877
==========================================
+ Hits 44163 44572 +409
- Misses 26556 26957 +401
- Partials 2423 2490 +67
☔ View full report in Codecov by Sentry. |
c776bb5
to
466075d
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Almost ready now! Thanks for hard work!
6d44c8f
to
ee2db65
Compare
3188275
to
70077af
Compare
1. split package rule under /app/vmalert, expose needed objects 2. add vmalert-tool with unittest subcmd
70077af
to
4757b6e
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
1. split package rule under /app/vmalert, expose needed objects 2. add vmalert-tool with unittest subcmd #2945
…seTime() to app/vmalert-tool/unittest.durationToTime() The ParseTime() function looks strange, since it converts relative duration to absolute time since Unix Epoch. In most scenarios such a conversion is used by mistake. It is better to do not expose such a function for public use and hide it inside the package where it is needed, e.g. inside app/vmalert-tool/unittest. This is a follow-up for dc28196 Updates #2945 Updates #4789
…seTime() to app/vmalert-tool/unittest.durationToTime() The ParseTime() function looks strange, since it converts relative duration to absolute time since Unix Epoch. In most scenarios such a conversion is used by mistake. It is better to do not expose such a function for public use and hide it inside the package where it is needed, e.g. inside app/vmalert-tool/unittest. This is a follow-up for dc28196 Updates #2945 Updates #4789
1. split package rule under /app/vmalert, expose needed objects 2. add vmalert-tool with unittest subcmd VictoriaMetrics#2945
…seTime() to app/vmalert-tool/unittest.durationToTime() The ParseTime() function looks strange, since it converts relative duration to absolute time since Unix Epoch. In most scenarios such a conversion is used by mistake. It is better to do not expose such a function for public use and hide it inside the package where it is needed, e.g. inside app/vmalert-tool/unittest. This is a follow-up for dc28196 Updates VictoriaMetrics#2945 Updates VictoriaMetrics#4789
FYI, this pull request has been included in v1.95.0 release. |
address #2945
There are two requirements to perform unittest:
vmalert can't implement this like #4734 said.
vmctl used to be considered, but there are unexposed parts in vmalert, so it's not be implemented at that time. Now vmctl is considered only for migration stuff.
update:
After discussion, we are adding a new tool named
vmalert-tool
, it's only used for unittest now.This pull request does two things:
split package
rule
under vmalert, expose needed objects. After this, vmalert should become more functionality, other components can use vmalert library to do rule evaluation.Implement rule evaluation for vmsingle in the future maybe, could simplify the combination of vmsingle+vmalert, mentioned in Add remote_write support to victoria metrics (single) #1645 (comment)
create new
vmalert-tool
to bring unittest feature in vmalert: init unit test #4596.