mirror of
https://git.mirrors.martin98.com/https://github.com/SigNoz/signoz
synced 2025-08-15 19:05:57 +08:00
feat: add last option to alert condition match type (#5929)
This commit is contained in:
parent
e203276678
commit
4edc6dbeae
@ -53,6 +53,7 @@
|
|||||||
"option_atleastonce": "at least once",
|
"option_atleastonce": "at least once",
|
||||||
"option_onaverage": "on average",
|
"option_onaverage": "on average",
|
||||||
"option_intotal": "in total",
|
"option_intotal": "in total",
|
||||||
|
"option_last": "last",
|
||||||
"option_above": "above",
|
"option_above": "above",
|
||||||
"option_below": "below",
|
"option_below": "below",
|
||||||
"option_equal": "is equal to",
|
"option_equal": "is equal to",
|
||||||
|
@ -40,6 +40,7 @@
|
|||||||
"option_atleastonce": "at least once",
|
"option_atleastonce": "at least once",
|
||||||
"option_onaverage": "on average",
|
"option_onaverage": "on average",
|
||||||
"option_intotal": "in total",
|
"option_intotal": "in total",
|
||||||
|
"option_last": "last",
|
||||||
"option_above": "above",
|
"option_above": "above",
|
||||||
"option_below": "below",
|
"option_below": "below",
|
||||||
"option_equal": "is equal to",
|
"option_equal": "is equal to",
|
||||||
|
@ -53,6 +53,7 @@
|
|||||||
"option_atleastonce": "at least once",
|
"option_atleastonce": "at least once",
|
||||||
"option_onaverage": "on average",
|
"option_onaverage": "on average",
|
||||||
"option_intotal": "in total",
|
"option_intotal": "in total",
|
||||||
|
"option_last": "last",
|
||||||
"option_above": "above",
|
"option_above": "above",
|
||||||
"option_below": "below",
|
"option_below": "below",
|
||||||
"option_equal": "is equal to",
|
"option_equal": "is equal to",
|
||||||
|
@ -40,6 +40,7 @@
|
|||||||
"option_atleastonce": "at least once",
|
"option_atleastonce": "at least once",
|
||||||
"option_onaverage": "on average",
|
"option_onaverage": "on average",
|
||||||
"option_intotal": "in total",
|
"option_intotal": "in total",
|
||||||
|
"option_last": "last",
|
||||||
"option_above": "above",
|
"option_above": "above",
|
||||||
"option_below": "below",
|
"option_below": "below",
|
||||||
"option_equal": "is equal to",
|
"option_equal": "is equal to",
|
||||||
|
@ -103,6 +103,7 @@ function RuleOptions({
|
|||||||
<Select.Option value="2">{t('option_allthetimes')}</Select.Option>
|
<Select.Option value="2">{t('option_allthetimes')}</Select.Option>
|
||||||
<Select.Option value="3">{t('option_onaverage')}</Select.Option>
|
<Select.Option value="3">{t('option_onaverage')}</Select.Option>
|
||||||
<Select.Option value="4">{t('option_intotal')}</Select.Option>
|
<Select.Option value="4">{t('option_intotal')}</Select.Option>
|
||||||
|
<Select.Option value="5">{t('option_last')}</Select.Option>
|
||||||
</InlineSelect>
|
</InlineSelect>
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -112,6 +112,7 @@ const (
|
|||||||
AllTheTimes MatchType = "2"
|
AllTheTimes MatchType = "2"
|
||||||
OnAverage MatchType = "3"
|
OnAverage MatchType = "3"
|
||||||
InTotal MatchType = "4"
|
InTotal MatchType = "4"
|
||||||
|
Last MatchType = "5"
|
||||||
)
|
)
|
||||||
|
|
||||||
type RuleCondition struct {
|
type RuleCondition struct {
|
||||||
|
@ -483,6 +483,27 @@ func (r *BaseRule) shouldAlert(series v3.Series) (Sample, bool) {
|
|||||||
shouldAlert = true
|
shouldAlert = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
case Last:
|
||||||
|
// If the last sample matches the condition, the rule is firing.
|
||||||
|
shouldAlert = false
|
||||||
|
alertSmpl = Sample{Point: Point{V: series.Points[len(series.Points)-1].Value}, Metric: lblsNormalized, MetricOrig: lbls}
|
||||||
|
if r.compareOp() == ValueIsAbove {
|
||||||
|
if series.Points[len(series.Points)-1].Value > r.targetVal() {
|
||||||
|
shouldAlert = true
|
||||||
|
}
|
||||||
|
} else if r.compareOp() == ValueIsBelow {
|
||||||
|
if series.Points[len(series.Points)-1].Value < r.targetVal() {
|
||||||
|
shouldAlert = true
|
||||||
|
}
|
||||||
|
} else if r.compareOp() == ValueIsEq {
|
||||||
|
if series.Points[len(series.Points)-1].Value == r.targetVal() {
|
||||||
|
shouldAlert = true
|
||||||
|
}
|
||||||
|
} else if r.compareOp() == ValueIsNotEq {
|
||||||
|
if series.Points[len(series.Points)-1].Value != r.targetVal() {
|
||||||
|
shouldAlert = true
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return alertSmpl, shouldAlert
|
return alertSmpl, shouldAlert
|
||||||
}
|
}
|
||||||
|
@ -677,6 +677,111 @@ func TestThresholdRuleShouldAlert(t *testing.T) {
|
|||||||
matchType: "4", // InTotal
|
matchType: "4", // InTotal
|
||||||
target: 20.0,
|
target: 20.0,
|
||||||
},
|
},
|
||||||
|
// Test cases for Last
|
||||||
|
// greater than last
|
||||||
|
{
|
||||||
|
values: v3.Series{
|
||||||
|
Points: []v3.Point{
|
||||||
|
{Value: 10.0},
|
||||||
|
{Value: 10.0},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
expectAlert: true,
|
||||||
|
compareOp: "1", // Greater Than
|
||||||
|
matchType: "5", // Last
|
||||||
|
target: 5.0,
|
||||||
|
expectedAlertSample: v3.Point{Value: 10.0},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
values: v3.Series{
|
||||||
|
Points: []v3.Point{
|
||||||
|
{Value: 10.0},
|
||||||
|
{Value: 10.0},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
expectAlert: false,
|
||||||
|
compareOp: "1", // Greater Than
|
||||||
|
matchType: "5", // Last
|
||||||
|
target: 20.0,
|
||||||
|
},
|
||||||
|
// less than last
|
||||||
|
{
|
||||||
|
values: v3.Series{
|
||||||
|
Points: []v3.Point{
|
||||||
|
{Value: 10.0},
|
||||||
|
{Value: 10.0},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
expectAlert: true,
|
||||||
|
compareOp: "2", // Less Than
|
||||||
|
matchType: "5", // Last
|
||||||
|
target: 15.0,
|
||||||
|
expectedAlertSample: v3.Point{Value: 10.0},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
values: v3.Series{
|
||||||
|
Points: []v3.Point{
|
||||||
|
{Value: 10.0},
|
||||||
|
{Value: 10.0},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
expectAlert: false,
|
||||||
|
compareOp: "2", // Less Than
|
||||||
|
matchType: "5", // Last
|
||||||
|
target: 5.0,
|
||||||
|
},
|
||||||
|
// equals last
|
||||||
|
{
|
||||||
|
values: v3.Series{
|
||||||
|
Points: []v3.Point{
|
||||||
|
{Value: 10.0},
|
||||||
|
{Value: 10.0},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
expectAlert: true,
|
||||||
|
compareOp: "3", // Equals
|
||||||
|
matchType: "5", // Last
|
||||||
|
target: 10.0,
|
||||||
|
expectedAlertSample: v3.Point{Value: 10.0},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
values: v3.Series{
|
||||||
|
Points: []v3.Point{
|
||||||
|
{Value: 10.0},
|
||||||
|
{Value: 10.0},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
expectAlert: false,
|
||||||
|
compareOp: "3", // Equals
|
||||||
|
matchType: "5", // Last
|
||||||
|
target: 5.0,
|
||||||
|
},
|
||||||
|
// not equals last
|
||||||
|
{
|
||||||
|
values: v3.Series{
|
||||||
|
Points: []v3.Point{
|
||||||
|
{Value: 10.0},
|
||||||
|
{Value: 10.0},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
expectAlert: true,
|
||||||
|
compareOp: "4", // Not Equals
|
||||||
|
matchType: "5", // Last
|
||||||
|
target: 5.0,
|
||||||
|
expectedAlertSample: v3.Point{Value: 10.0},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
values: v3.Series{
|
||||||
|
Points: []v3.Point{
|
||||||
|
{Value: 10.0},
|
||||||
|
{Value: 10.0},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
expectAlert: false,
|
||||||
|
compareOp: "4", // Not Equals
|
||||||
|
matchType: "5", // Last
|
||||||
|
target: 10.0,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
fm := featureManager.StartManager()
|
fm := featureManager.StartManager()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user