Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pkg/contextlinks/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,4 @@ type URLShareableOptions struct {
SelectColumns []v3.AttributeKey `json:"selectColumns"`
}

var PredefinedAlertLabels = []string{ruletypes.LabelThresholdName}
var PredefinedAlertLabels = []string{ruletypes.LabelThresholdName, ruletypes.LabelSeverityName, ruletypes.LabelLastSeen}
3 changes: 2 additions & 1 deletion pkg/query-service/app/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"encoding/json"
"errors"
"fmt"
"github.com/SigNoz/signoz/pkg/types/thirdpartyapitypes"
"math"
"net/http"
"sort"
Expand All @@ -15,6 +14,8 @@ import (
"text/template"
"time"

"github.com/SigNoz/signoz/pkg/types/thirdpartyapitypes"

"github.com/SigNoz/govaluate"
"github.com/SigNoz/signoz/pkg/query-service/app/integrations/messagingQueues/kafka"
queues2 "github.com/SigNoz/signoz/pkg/query-service/app/integrations/messagingQueues/queues"
Expand Down
4 changes: 2 additions & 2 deletions pkg/query-service/rules/threshold_rule.go
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,7 @@ func (r *ThresholdRule) buildAndRunQuery(ctx context.Context, orgID valuer.UUID,
r.logger.InfoContext(ctx, "no data found for rule condition", "rule_id", r.ID())
lbls := labels.NewBuilder(labels.Labels{})
if !r.lastTimestampWithDatapoints.IsZero() {
lbls.Set("lastSeen", r.lastTimestampWithDatapoints.Format(constants.AlertTimeFormat))
lbls.Set(ruletypes.LabelLastSeen, r.lastTimestampWithDatapoints.Format(constants.AlertTimeFormat))
}
resultVector = append(resultVector, ruletypes.Sample{
Metric: lbls.Labels(),
Expand Down Expand Up @@ -544,7 +544,7 @@ func (r *ThresholdRule) buildAndRunQueryV5(ctx context.Context, orgID valuer.UUI
r.logger.InfoContext(ctx, "no data found for rule condition", "rule_id", r.ID())
lbls := labels.NewBuilder(labels.Labels{})
if !r.lastTimestampWithDatapoints.IsZero() {
lbls.Set("lastSeen", r.lastTimestampWithDatapoints.Format(constants.AlertTimeFormat))
lbls.Set(ruletypes.LabelLastSeen, r.lastTimestampWithDatapoints.Format(constants.AlertTimeFormat))
}
resultVector = append(resultVector, ruletypes.Sample{
Metric: lbls.Labels(),
Expand Down
13 changes: 10 additions & 3 deletions pkg/types/ruletypes/constants.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
package ruletypes

const CriticalThresholdName = "CRITICAL"
const LabelThresholdName = "threshold.name"
const LabelRuleId = "ruleId"
const (
CriticalThresholdName = "critical"
ErrorThresholdName = "error"
WarningThresholdName = "warning"
InfoThresholdName = "info"
LabelThresholdName = "threshold.name"
LabelSeverityName = "severity"
LabelLastSeen = "lastSeen"
LabelRuleId = "ruleId"
)
4 changes: 4 additions & 0 deletions pkg/types/ruletypes/threshold.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"encoding/json"
"math"
"sort"
"strings"

"github.com/SigNoz/signoz/pkg/errors"
"github.com/SigNoz/signoz/pkg/query-service/converter"
Expand Down Expand Up @@ -198,7 +199,10 @@ func (b BasicRuleThreshold) shouldAlert(series v3.Series, ruleUnit string) (Samp

target := b.target(ruleUnit)

// TODO(srikanthccv): is it better to move the logic to notifier instead of
// adding two labels?
lbls = append(lbls, labels.Label{Name: LabelThresholdName, Value: b.Name})
lbls = append(lbls, labels.Label{Name: LabelSeverityName, Value: strings.ToLower(b.Name)})

series.Points = removeGroupinSetPoints(series)

Expand Down
37 changes: 23 additions & 14 deletions pkg/types/ruletypes/threshold_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package ruletypes

import (
"strings"
"testing"

"github.com/stretchr/testify/assert"
Expand All @@ -21,7 +22,7 @@ func TestBasicRuleThresholdShouldAlert_UnitConversion(t *testing.T) {
{
name: "milliseconds to seconds conversion - should alert",
threshold: BasicRuleThreshold{
Name: "test",
Name: CriticalThresholdName,
TargetValue: &target, // 100ms
TargetUnit: "ms",
MatchType: AtleastOnce,
Expand All @@ -39,7 +40,7 @@ func TestBasicRuleThresholdShouldAlert_UnitConversion(t *testing.T) {
{
name: "milliseconds to seconds conversion - should not alert",
threshold: BasicRuleThreshold{
Name: "test",
Name: WarningThresholdName,
TargetValue: &target, // 100ms
TargetUnit: "ms",
MatchType: AtleastOnce,
Expand All @@ -57,7 +58,7 @@ func TestBasicRuleThresholdShouldAlert_UnitConversion(t *testing.T) {
{
name: "seconds to milliseconds conversion - should alert",
threshold: BasicRuleThreshold{
Name: "test",
Name: CriticalThresholdName,
TargetValue: &target, // 100s
TargetUnit: "s",
MatchType: AtleastOnce,
Expand All @@ -76,7 +77,7 @@ func TestBasicRuleThresholdShouldAlert_UnitConversion(t *testing.T) {
{
name: "bytes to kibibytes conversion - should alert",
threshold: BasicRuleThreshold{
Name: "test",
Name: InfoThresholdName,
TargetValue: &target, // 100 bytes
TargetUnit: "bytes",
MatchType: AtleastOnce,
Expand All @@ -94,7 +95,7 @@ func TestBasicRuleThresholdShouldAlert_UnitConversion(t *testing.T) {
{
name: "kibibytes to mebibytes conversion - should alert",
threshold: BasicRuleThreshold{
Name: "test",
Name: ErrorThresholdName,
TargetValue: &target, // 100KiB
TargetUnit: "kbytes",
MatchType: AtleastOnce,
Expand All @@ -113,7 +114,7 @@ func TestBasicRuleThresholdShouldAlert_UnitConversion(t *testing.T) {
{
name: "milliseconds to seconds with ValueIsBelow - should alert",
threshold: BasicRuleThreshold{
Name: "test",
Name: WarningThresholdName,
TargetValue: &target, // 100ms
TargetUnit: "ms",
MatchType: AtleastOnce,
Expand All @@ -131,7 +132,7 @@ func TestBasicRuleThresholdShouldAlert_UnitConversion(t *testing.T) {
{
name: "milliseconds to seconds with OnAverage - should alert",
threshold: BasicRuleThreshold{
Name: "test",
Name: CriticalThresholdName,
TargetValue: &target, // 100ms
TargetUnit: "ms",
MatchType: OnAverage,
Expand All @@ -151,7 +152,7 @@ func TestBasicRuleThresholdShouldAlert_UnitConversion(t *testing.T) {
{
name: "decimal megabytes to gigabytes with InTotal - should alert",
threshold: BasicRuleThreshold{
Name: "test",
Name: WarningThresholdName,
TargetValue: &target, // 100MB
TargetUnit: "decmbytes",
MatchType: InTotal,
Expand All @@ -171,7 +172,7 @@ func TestBasicRuleThresholdShouldAlert_UnitConversion(t *testing.T) {
{
name: "milliseconds to seconds with AllTheTimes - should alert",
threshold: BasicRuleThreshold{
Name: "test",
Name: InfoThresholdName,
TargetValue: &target, // 100ms
TargetUnit: "ms",
MatchType: AllTheTimes,
Expand All @@ -191,7 +192,7 @@ func TestBasicRuleThresholdShouldAlert_UnitConversion(t *testing.T) {
{
name: "kilobytes to megabytes with Last - should not alert",
threshold: BasicRuleThreshold{
Name: "test",
Name: ErrorThresholdName,
TargetValue: &target, // 100kB
TargetUnit: "deckbytes",
MatchType: Last,
Expand All @@ -211,7 +212,7 @@ func TestBasicRuleThresholdShouldAlert_UnitConversion(t *testing.T) {
{
name: "bytes per second to kilobytes per second - should alert",
threshold: BasicRuleThreshold{
Name: "test",
Name: CriticalThresholdName,
TargetValue: &target, // 100 bytes/s
TargetUnit: "Bps",
MatchType: AtleastOnce,
Expand All @@ -230,7 +231,7 @@ func TestBasicRuleThresholdShouldAlert_UnitConversion(t *testing.T) {
{
name: "same unit - no conversion needed - should alert",
threshold: BasicRuleThreshold{
Name: "test",
Name: InfoThresholdName,
TargetValue: &target, // 100ms
TargetUnit: "ms",
MatchType: AtleastOnce,
Expand All @@ -249,7 +250,7 @@ func TestBasicRuleThresholdShouldAlert_UnitConversion(t *testing.T) {
{
name: "empty unit - no conversion - should alert",
threshold: BasicRuleThreshold{
Name: "test",
Name: ErrorThresholdName,
TargetValue: &target, // 100 (unitless)
TargetUnit: "",
MatchType: AtleastOnce,
Expand Down Expand Up @@ -280,12 +281,20 @@ func TestBasicRuleThresholdShouldAlert_UnitConversion(t *testing.T) {

hasThresholdLabel := false
for _, label := range sample.Metric {
if label.Name == LabelThresholdName && label.Value == "test" {
if label.Name == LabelThresholdName && label.Value == tt.threshold.Name {
hasThresholdLabel = true
break
}
}
assert.True(t, hasThresholdLabel)
hasSeverityLabel := false
for _, label := range sample.Metric {
if label.Name == LabelSeverityName && label.Value == strings.ToLower(tt.threshold.Name) {
hasSeverityLabel = true
break
}
}
assert.True(t, hasSeverityLabel)
assert.Equal(t, *tt.threshold.TargetValue, sample.Target)
assert.Equal(t, tt.threshold.TargetUnit, sample.TargetUnit)
}
Expand Down
Loading