Skip to content

SigNoz is an open-source, OpenTelemetry-native observability platform for your team and their AI agents. Get logs, metrics, and traces in one tool with features like APM, distributed tracing, log management, infra monitoring, etc. Combined with SigNoz MCP and a native AI teammate (in SigNoz Cloud) it helps you build more resilient apps.

fix: test notification always sends a new notification (#9807)

Abhishek Kumar Singhb38ffce7f2b1
diff --git a/.mockery.yml b/.mockery.yml
new file mode 100644
index 0000000000..164fd52a54
--- /dev/null
+++ b/.mockery.yml
@@ -0,0 +1,10 @@
+# Link to template variables: https://pkg.go.dev/github.com/vektra/mockery/v3/config#TemplateData
+template: testify
+packages:
+ github.com/SigNoz/signoz/pkg/alertmanager:
+ config:
+ all: true
+ dir: '{{.InterfaceDir}}/mocks'
+ filename: "mocks.go"
+ structname: 'Mock{{.InterfaceName}}'
+ pkgname: '{{.SrcPackageName}}mock'
diff --git a/ee/query-service/rules/anomaly.go b/ee/query-service/rules/anomaly.go
index 6420374b33..9ff1872546 100644
--- a/ee/query-service/rules/anomaly.go
+++ b/ee/query-service/rules/anomaly.go
@@ -247,7 +247,8 @@ func (r *AnomalyRule) buildAndRunQuery(ctx context.Context, orgID valuer.UUID, t
}
}
results, err := r.Threshold.Eval(*series, r.Unit(), ruletypes.EvalData{
- ActiveAlerts: r.ActiveAlertsLabelFP(),
+ ActiveAlerts: r.ActiveAlertsLabelFP(),
+ SendUnmatched: r.ShouldSendUnmatched(),
})
if err != nil {
return nil, err
@@ -299,7 +300,8 @@ func (r *AnomalyRule) buildAndRunQueryV5(ctx context.Context, orgID valuer.UUID,
}
}
results, err := r.Threshold.Eval(*series, r.Unit(), ruletypes.EvalData{
- ActiveAlerts: r.ActiveAlertsLabelFP(),
+ ActiveAlerts: r.ActiveAlertsLabelFP(),
+ SendUnmatched: r.ShouldSendUnmatched(),
})
if err != nil {
return nil, err
diff --git a/ee/query-service/rules/manager_test.go b/ee/query-service/rules/manager_test.go
new file mode 100644
index 0000000000..1d365393ed
--- /dev/null
+++ b/ee/query-service/rules/manager_test.go
@@ -0,0 +1,283 @@
+package rules
+
+import (
+ "context"
+ "encoding/json"
+ "math"
+ "strconv"
+ "testing"
+ "time"
+
+ "github.com/SigNoz/signoz/pkg/alertmanager"
+ alertmanagermock "github.com/SigNoz/signoz/pkg/alertmanager/mocks"
+ "github.com/SigNoz/signoz/pkg/instrumentation/instrumentationtest"
+ "github.com/SigNoz/signoz/pkg/prometheus"
+ "github.com/SigNoz/signoz/pkg/prometheus/prometheustest"
+ "github.com/SigNoz/signoz/pkg/query-service/rules"
+ "github.com/SigNoz/signoz/pkg/sqlstore"
+ "github.com/SigNoz/signoz/pkg/sqlstore/sqlstoretest"
+ "github.com/SigNoz/signoz/pkg/telemetrystore"
+ "github.com/SigNoz/signoz/pkg/telemetrystore/telemetrystoretest"
+ "github.com/SigNoz/signoz/pkg/types/alertmanagertypes"
+ "github.com/SigNoz/signoz/pkg/types/metrictypes"
+ "github.com/SigNoz/signoz/pkg/valuer"
+ "github.com/stretchr/testify/assert"
+ "github.com/stretchr/testify/mock"
+ "github.com/stretchr/testify/require"
+
+ cmock "github.com/srikanthccv/ClickHouse-go-mock"
+)
+
+func TestManager_TestNotification_SendUnmatched_ThresholdRule(t *testing.T) {
+ target := 10.0
+ recovery := 5.0
+
+ for _, tc := range rules.TcTestNotiSendUnmatchedThresholdRule {
+ t.Run(tc.Name, func(t *testing.T) {
+ rule := rules.ThresholdRuleAtLeastOnceValueAbove(target, &recovery)
+
+ // Marshal rule to JSON as TestNotification expects
+ ruleBytes, err := json.Marshal(rule)
+ require.NoError(t, err)
+
+ orgID := valuer.GenerateUUID()
+
+ // for saving temp alerts that are triggered via TestNotification
+ triggeredTestAlerts := []map[*alertmanagertypes.PostableAlert][]string{}
+
+ // Create manager using test factory with hooks
+ mgr := rules.NewTestManager(t, &rules.TestManagerOptions{
+ AlertmanagerHook: func(am alertmanager.Alertmanager) {
+ fAlert := am.(*alertmanagermock.MockAlertmanager)
+ // mock set notification config
+ fAlert.On("SetNotificationConfig", mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(nil)
+ // for saving temp alerts that are triggered via TestNotification
+ if tc.ExpectAlerts > 0 {
+ fAlert.On("TestAlert", mock.Anything, mock.Anything, mock.Anything, mock.Anything).Run(func(args mock.Arguments) {
+ triggeredTestAlerts = append(triggeredTestAlerts, args.Get(3).(map[*alertmanagertypes.PostableAlert][]string))
+ }).Return(nil).Times(tc.ExpectAlerts)
+ }
+ },
+ ManagerOptionsHook: func(opts *rules.ManagerOptions) {
+ opts.PrepareTestRuleFunc = TestNotification
+ },
+ SqlStoreHook: func(store sqlstore.SQLStore) {
+ mockStore := store.(*sqlstoretest.Provider)
+ // Mock the organizations query that SendAlerts makes
+ // Bun generates: SELECT id FROM organizations LIMIT 1 (or SELECT "id" FROM "organizations" LIMIT 1)
+ orgRows := mockStore.Mock().NewRows([]string{"id"}).AddRow(orgID.StringValue())
+ // Match bun's generated query pattern - bun may quote identifiers
+ mockStore.Mock().ExpectQuery("SELECT (.+) FROM (.+)organizations(.+) LIMIT (.+)").WillReturnRows(orgRows)
+ },
+ TelemetryStoreHook: func(store telemetrystore.TelemetryStore) {
+ telemetryStore := store.(*telemetrystoretest.Provider)
+ // Set up mock data for telemetry store
+ cols := make([]cmock.ColumnType, 0)
+ cols = append(cols, cmock.ColumnType{Name: "value", Type: "Float64"})
+ cols = append(cols, cmock.ColumnType{Name: "attr", Type: "String"})
+ cols = append(cols, cmock.ColumnType{Name: "ts", Type: "DateTime"})
+
+ alertDataRows := cmock.NewRows(cols, tc.Values)
+
+ mock := telemetryStore.Mock()
+
+ // Generate query arguments for the metric query
+ evalTime := time.Now().UTC()
+ evalWindow := 5 * time.Minute
+ evalDelay := time.Duration(0)
+ queryArgs := rules.GenerateMetricQueryCHArgs(
+ evalTime,
+ evalWindow,
+ evalDelay,
+ "probe_success",
+ metrictypes.Unspecified,
+ )
+
+ mock.ExpectQuery("*WITH __temporal_aggregation_cte*").
+ WithArgs(queryArgs...).
+ WillReturnRows(alertDataRows)
+ },
+ })
+
+ count, apiErr := mgr.TestNotification(context.Background(), orgID, string(ruleBytes))
+ if apiErr != nil {
+ t.Logf("TestNotification error: %v, type: %s", apiErr.Err, apiErr.Typ)
+ }
+ require.Nil(t, apiErr)
+ assert.Equal(t, tc.ExpectAlerts, count)
+
+ if tc.ExpectAlerts > 0 {
+ // check if the alert has been triggered
+ require.Len(t, triggeredTestAlerts, 1)
+ var gotAlerts []*alertmanagertypes.PostableAlert
+ for a := range triggeredTestAlerts[0] {
+ gotAlerts = append(gotAlerts, a)
+ }
+ require.Len(t, gotAlerts, tc.ExpectAlerts)
+ // check if the alert has triggered with correct threshold value
+ if tc.ExpectValue != 0 {
+ assert.Equal(t, strconv.FormatFloat(tc.ExpectValue, 'f', -1, 64), gotAlerts[0].Annotations["value"])
+ }
+ } else {
+ // check if no alerts have been triggered
+ assert.Empty(t, triggeredTestAlerts)
+ }
+ })
+ }
+}
+
+func TestManager_TestNotification_SendUnmatched_PromRule(t *testing.T) {
+ target := 10.0
+
+ for _, tc := range rules.TcTestNotificationSendUnmatchedPromRule {
+ t.Run(tc.Name, func(t *testing.T) {
+ // Capture base time once per test case to ensure consistent timestamps
+ baseTime := time.Now().UTC()
+
+ rule := rules.BuildPromAtLeastOnceValueAbove(target, nil)
+
+ // Marshal rule to JSON as TestNotification expects
+ ruleBytes, err := json.Marshal(rule)
+ require.NoError(t, err)
+
+ orgID := valuer.GenerateUUID()
+
+ // for saving temp alerts that are triggered via TestNotification
+ triggeredTestAlerts := []map[*alertmanagertypes.PostableAlert][]string{}
+
+ // Variable to store promProvider for cleanup
+ var promProvider *prometheustest.Provider
+
+ // Create manager using test factory with hooks
+ mgr := rules.NewTestManager(t, &rules.TestManagerOptions{
+ AlertmanagerHook: func(am alertmanager.Alertmanager) {
+ mockAM := am.(*alertmanagermock.MockAlertmanager)
+ // mock set notification config
+ mockAM.On("SetNotificationConfig", mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(nil)
+ // for saving temp alerts that are triggered via TestNotification
+ if tc.ExpectAlerts > 0 {
+ mockAM.On("TestAlert", mock.Anything, mock.Anything, mock.Anything, mock.Anything).Run(func(args mock.Arguments) {
+ triggeredTestAlerts = append(triggeredTestAlerts, args.Get(3).(map[*alertmanagertypes.PostableAlert][]string))
+ }).Return(nil).Times(tc.ExpectAlerts)
+ }
+ },
+ SqlStoreHook: func(store sqlstore.SQLStore) {
+ mockStore := store.(*sqlstoretest.Provider)
+ // Mock the organizations query that SendAlerts makes
+ orgRows := mockStore.Mock().NewRows([]string{"id"}).AddRow(orgID.StringValue())
+ mockStore.Mock().ExpectQuery("SELECT (.+) FROM (.+)organizations(.+) LIMIT (.+)").WillReturnRows(orgRows)
+ },
+ TelemetryStoreHook: func(store telemetrystore.TelemetryStore) {
+ mockStore := store.(*telemetrystoretest.Provider)
+
+ // Set up Prometheus-specific mock data
+ // Fingerprint columns for Prometheus queries
+ fingerprintCols := []cmock.ColumnType{
+ {Name: "fingerprint", Type: "UInt64"},
+ {Name: "any(labels)", Type: "String"},
+ }
+
+ // Samples columns for Prometheus queries
+ samplesCols := []cmock.ColumnType{
+ {Name: "metric_name", Type: "String"},
+ {Name: "fingerprint", Type: "UInt64"},
+ {Name: "unix_milli", Type: "Int64"},
+ {Name: "value", Type: "Float64"},
+ {Name: "flags", Type: "UInt32"},
+ }
+
+ // Calculate query time range similar to Prometheus rule tests
+ // TestNotification uses time.Now().UTC() for evaluation
+ // We calculate the query window based on current time to match what the actual evaluation will use
+ evalTime := baseTime
+ evalWindowMs := int64(5 * 60 * 1000) // 5 minutes in ms
+ evalTimeMs := evalTime.UnixMilli()
+ queryStart := ((evalTimeMs-2*evalWindowMs)/60000)*60000 + 1 // truncate to minute + 1ms
+ queryEnd := (evalTimeMs / 60000) * 60000 // truncate to minute
+
+ // Create fingerprint data
+ fingerprint := uint64(12345)
+ labelsJSON := `{"__name__":"test_metric"}`
+ fingerprintData := [][]interface{}{
+ {fingerprint, labelsJSON},
+ }
+ fingerprintRows := cmock.NewRows(fingerprintCols, fingerprintData)
+
+ // Create samples data from test case values, calculating timestamps relative to baseTime
+ validSamplesData := make([][]interface{}, 0)
+ for _, v := range tc.Values {
+ // Skip NaN and Inf values in the samples data
+ if math.IsNaN(v.Value) || math.IsInf(v.Value, 0) {
+ continue
+ }
+ // Calculate timestamp relative to baseTime
+ sampleTimestamp := baseTime.Add(v.Offset).UnixMilli()
+ validSamplesData = append(validSamplesData, []interface{}{
+ "test_metric",
+ fingerprint,
+ sampleTimestamp,
+ v.Value,
+ uint32(0), // flags - 0 means normal value
+ })
+ }
+ samplesRows := cmock.NewRows(samplesCols, validSamplesData)
+
+ mock := mockStore.Mock()
+
+ // Mock the fingerprint query (for Prometheus label matching)
+ mock.ExpectQuery("SELECT fingerprint, any").
+ WithArgs("test_metric", "__name__", "test_metric").
+ WillReturnRows(fingerprintRows)
+
+ // Mock the samples query (for Prometheus metric data)
+ mock.ExpectQuery("SELECT metric_name, fingerprint, unix_milli").
+ WithArgs(
+ "test_metric",
+ "test_metric",
+ "__name__",
+ "test_metric",
+ queryStart,
+ queryEnd,
+ ).
+ WillReturnRows(samplesRows)
+
+ // Create Prometheus provider for this test
+ promProvider = prometheustest.New(context.Background(), instrumentationtest.New().ToProviderSettings(), prometheus.Config{}, store)
+ },
+ ManagerOptionsHook: func(opts *rules.ManagerOptions) {
+ // Set Prometheus provider for PromQL queries
+ if promProvider != nil {
+ opts.Prometheus = promProvider
+ }
+ opts.PrepareTestRuleFunc = TestNotification
+ },
+ })
+
+ count, apiErr := mgr.TestNotification(context.Background(), orgID, string(ruleBytes))
+ if apiErr != nil {
+ t.Logf("TestNotification error: %v, type: %s", apiErr.Err, apiErr.Typ)
+ }
+ require.Nil(t, apiErr)
+ assert.Equal(t, tc.ExpectAlerts, count)
+
+ if tc.ExpectAlerts > 0 {
+ // check if the alert has been triggered
+ require.Len(t, triggeredTestAlerts, 1)
+ var gotAlerts []*alertmanagertypes.PostableAlert
+ for a := range triggeredTestAlerts[0] {
+ gotAlerts = append(gotAlerts, a)
+ }
+ require.Len(t, gotAlerts, tc.ExpectAlerts)
+ // check if the alert has triggered with correct threshold value
+ if tc.ExpectValue != 0 && !math.IsNaN(tc.ExpectValue) && !math.IsInf(tc.ExpectValue, 0) {
+ assert.Equal(t, strconv.FormatFloat(tc.ExpectValue, 'f', -1, 64), gotAlerts[0].Annotations["value"])
+ }
+ } else {
+ // check if no alerts have been triggered
+ assert.Empty(t, triggeredTestAlerts)
+ }
+
+ promProvider.Close()
+ })
+ }
+}
diff --git a/go.mod b/go.mod
index 3dc3c226df..51ddc9375a 100644
--- a/go.mod
+++ b/go.mod
@@ -54,7 +54,7 @@ require (
github.com/smartystreets/goconvey v1.8.1
github.com/soheilhy/cmux v0.1.5
github.com/spf13/cobra v1.10.1
- github.com/srikanthccv/ClickHouse-go-mock v0.12.0
+ github.com/srikanthccv/ClickHouse-go-mock v0.13.0
github.com/stretchr/testify v1.11.1
github.com/swaggest/jsonschema-go v0.3.78
github.com/swaggest/rest v0.2.75
diff --git a/go.sum b/go.sum
index 81ace875fa..a5ea82fd16 100644
--- a/go.sum
+++ b/go.sum
@@ -964,8 +964,8 @@ github.com/spf13/pflag v1.0.10/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3A
github.com/spf13/viper v1.13.0/go.mod h1:Icm2xNL3/8uyh/wFuB1jI7TiTNKp8632Nwegu+zgdYw=
github.com/spf13/viper v1.20.1 h1:ZMi+z/lvLyPSCoNtFCpqjy0S4kPbirhpTMwl8BkW9X4=
github.com/spf13/viper v1.20.1/go.mod h1:P9Mdzt1zoHIG8m2eZQinpiBjo6kCmZSKBClNNqjJvu4=
-github.com/srikanthccv/ClickHouse-go-mock v0.12.0 h1:KUzaWTwuqMc2uf5FylM/oAcTFdE2DdZjvISm9V0/NAA=
-github.com/srikanthccv/ClickHouse-go-mock v0.12.0/go.mod h1:1oUmLtXEXOyS0EEWVKlKEfLfv9y02agCMAvD3tVnhlo=
+github.com/srikanthccv/ClickHouse-go-mock v0.13.0 h1:/b7DQphGkh29ocNtLh4DGmQxQYA0CfHz65Wy2zAH2GM=
+github.com/srikanthccv/ClickHouse-go-mock v0.13.0/go.mod h1:LiiyBUdXNwB/1DE9rgK/8q9qjVYsTzg6WXQ/3mU3TeY=
github.com/stoewer/go-strcase v1.3.0 h1:g0eASXYtp+yvN9fK8sH94oCIk0fau9uV1/ZdJ0AVEzs=
github.com/stoewer/go-strcase v1.3.0/go.mod h1:fAH5hQ5pehh+j3nZfvwdk2RgEgQjAoM8wodgtPmh1xo=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
diff --git a/pkg/alertmanager/mocks/mocks.go b/pkg/alertmanager/mocks/mocks.go
new file mode 100644
index 0000000000..3a207d18b7
--- /dev/null
+++ b/pkg/alertmanager/mocks/mocks.go
@@ -0,0 +1,1836 @@
+// Code generated by mockery; DO NOT EDIT.
+// github.com/vektra/mockery
+// template: testify
+
+package alertmanagermock
+
+import (
+ "context"
+
+ "github.com/SigNoz/signoz/pkg/types/alertmanagertypes"
+ "github.com/SigNoz/signoz/pkg/valuer"
+ "github.com/prometheus/alertmanager/config"
+ mock "github.com/stretchr/testify/mock"
+)
+
+// NewMockAlertmanager creates a new instance of MockAlertmanager. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations.
+// The first argument is typically a *testing.T value.
+func NewMockAlertmanager(t interface {
+ mock.TestingT
+ Cleanup(func())
+}) *MockAlertmanager {
+ mock := &MockAlertmanager{}
+ mock.Mock.Test(t)
+
+ t.Cleanup(func() { mock.AssertExpectations(t) })
+
+ return mock
+}
+
+// MockAlertmanager is an autogenerated mock type for the Alertmanager type
+type MockAlertmanager struct {
+ mock.Mock
+}
+
+type MockAlertmanager_Expecter struct {
+ mock *mock.Mock
+}
+
+func (_m *MockAlertmanager) EXPECT() *MockAlertmanager_Expecter {
+ return &MockAlertmanager_Expecter{mock: &_m.Mock}
+}
+
+// Collect provides a mock function for the type MockAlertmanager
+func (_mock *MockAlertmanager) Collect(context1 context.Context, uUID valuer.UUID) (map[string]any, error) {
+ ret := _mock.Called(context1, uUID)
+
+ if len(ret) == 0 {
+ panic("no return value specified for Collect")
+ }
+
+ var r0 map[string]any
+ var r1 error
+ if returnFunc, ok := ret.Get(0).(func(context.Context, valuer.UUID) (map[string]any, error)); ok {
+ return returnFunc(context1, uUID)
+ }
+ if returnFunc, ok := ret.Get(0).(func(context.Context, valuer.UUID) map[string]any); ok {
+ r0 = returnFunc(context1, uUID)
+ } else {
+ if ret.Get(0) != nil {
+ r0 = ret.Get(0).(map[string]any)
+ }
+ }
+ if returnFunc, ok := ret.Get(1).(func(context.Context, valuer.UUID) error); ok {
+ r1 = returnFunc(context1, uUID)
+ } else {
+ r1 = ret.Error(1)
+ }
+ return r0, r1
+}
+
+// MockAlertmanager_Collect_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Collect'
+type MockAlertmanager_Collect_Call struct {
+ *mock.Call
+}
+
+// Collect is a helper method to define mock.On call
+// - context1 context.Context
+// - uUID valuer.UUID
+func (_e *MockAlertmanager_Expecter) Collect(context1 interface{}, uUID interface{}) *MockAlertmanager_Collect_Call {
+ return &MockAlertmanager_Collect_Call{Call: _e.mock.On("Collect", context1, uUID)}
+}
+
+func (_c *MockAlertmanager_Collect_Call) Run(run func(context1 context.Context, uUID valuer.UUID)) *MockAlertmanager_Collect_Call {
+ _c.Call.Run(func(args mock.Arguments) {
+ var arg0 context.Context
+ if args[0] != nil {
+ arg0 = args[0].(context.Context)
+ }
+ var arg1 valuer.UUID
+ if args[1] != nil {
+ arg1 = args[1].(valuer.UUID)
+ }
+ run(
+ arg0,
+ arg1,
+ )
+ })
+ return _c
+}
+
+func (_c *MockAlertmanager_Collect_Call) Return(stringToV map[string]any, err error) *MockAlertmanager_Collect_Call {
+ _c.Call.Return(stringToV, err)
+ return _c
+}
+
+func (_c *MockAlertmanager_Collect_Call) RunAndReturn(run func(context1 context.Context, uUID valuer.UUID) (map[string]any, error)) *MockAlertmanager_Collect_Call {
+ _c.Call.Return(run)
+ return _c
+}
+
+// CreateChannel provides a mock function for the type MockAlertmanager
+func (_mock *MockAlertmanager) CreateChannel(context1 context.Context, s string, v alertmanagertypes.Receiver) error {
+ ret := _mock.Called(context1, s, v)
+
+ if len(ret) == 0 {
+ panic("no return value specified for CreateChannel")
+ }
+
+ var r0 error
+ if returnFunc, ok := ret.Get(0).(func(context.Context, string, alertmanagertypes.Receiver) error); ok {
+ r0 = returnFunc(context1, s, v)
+ } else {
+ r0 = ret.Error(0)
+ }
+ return r0
+}
+
+// MockAlertmanager_CreateChannel_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'CreateChannel'
+type MockAlertmanager_CreateChannel_Call struct {
+ *mock.Call
+}
+
+// CreateChannel is a helper method to define mock.On call
+// - context1 context.Context
+// - s string
+// - v alertmanagertypes.Receiver
+func (_e *MockAlertmanager_Expecter) CreateChannel(context1 interface{}, s interface{}, v interface{}) *MockAlertmanager_CreateChannel_Call {
+ return &MockAlertmanager_CreateChannel_Call{Call: _e.mock.On("CreateChannel", context1, s, v)}
+}
+
+func (_c *MockAlertmanager_CreateChannel_Call) Run(run func(context1 context.Context, s string, v alertmanagertypes.Receiver)) *MockAlertmanager_CreateChannel_Call {
+ _c.Call.Run(func(args mock.Arguments) {
+ var arg0 context.Context
+ if args[0] != nil {
+ arg0 = args[0].(context.Context)
+ }
+ var arg1 string
+ if args[1] != nil {
+ arg1 = args[1].(string)
+ }
+ var arg2 alertmanagertypes.Receiver
+ if args[2] != nil {
+ arg2 = args[2].(alertmanagertypes.Receiver)
+ }
+ run(
+ arg0,
+ arg1,
+ arg2,
+ )
+ })
+ return _c
+}
+
+func (_c *MockAlertmanager_CreateChannel_Call) Return(err error) *MockAlertmanager_CreateChannel_Call {
+ _c.Call.Return(err)
+ return _c
+}
+
+func (_c *MockAlertmanager_CreateChannel_Call) RunAndReturn(run func(context1 context.Context, s string, v alertmanagertypes.Receiver) error) *MockAlertmanager_CreateChannel_Call {
+ _c.Call.Return(run)
+ return _c
+}
+
+// CreateInhibitRules provides a mock function for the type MockAlertmanager
+func (_mock *MockAlertmanager) CreateInhibitRules(ctx context.Context, orgID valuer.UUID, rules []config.InhibitRule) error {
+ ret := _mock.Called(ctx, orgID, rules)
+
+ if len(ret) == 0 {
+ panic("no return value specified for CreateInhibitRules")
+ }
+
+ var r0 error
+ if returnFunc, ok := ret.Get(0).(func(context.Context, valuer.UUID, []config.InhibitRule) error); ok {
+ r0 = returnFunc(ctx, orgID, rules)
+ } else {
+ r0 = ret.Error(0)
+ }
+ return r0
+}
+
+// MockAlertmanager_CreateInhibitRules_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'CreateInhibitRules'
+type MockAlertmanager_CreateInhibitRules_Call struct {
+ *mock.Call
+}
+
+// CreateInhibitRules is a helper method to define mock.On call
+// - ctx context.Context
+// - orgID valuer.UUID
+// - rules []config.InhibitRule
+func (_e *MockAlertmanager_Expecter) CreateInhibitRules(ctx interface{}, orgID interface{}, rules interface{}) *MockAlertmanager_CreateInhibitRules_Call {
+ return &MockAlertmanager_CreateInhibitRules_Call{Call: _e.mock.On("CreateInhibitRules", ctx, orgID, rules)}
+}
+
+func (_c *MockAlertmanager_CreateInhibitRules_Call) Run(run func(ctx context.Context, orgID valuer.UUID, rules []config.InhibitRule)) *MockAlertmanager_CreateInhibitRules_Call {
+ _c.Call.Run(func(args mock.Arguments) {
+ var arg0 context.Context
+ if args[0] != nil {
+ arg0 = args[0].(context.Context)
+ }
+ var arg1 valuer.UUID
+ if args[1] != nil {
+ arg1 = args[1].(valuer.UUID)
+ }
+ var arg2 []config.InhibitRule
+ if args[2] != nil {
+ arg2 = args[2].([]config.InhibitRule)
+ }
+ run(
+ arg0,
+ arg1,
+ arg2,
+ )
+ })
+ return _c
+}
+
+func (_c *MockAlertmanager_CreateInhibitRules_Call) Return(err error) *MockAlertmanager_CreateInhibitRules_Call {
+ _c.Call.Return(err)
+ return _c
+}
+
+func (_c *MockAlertmanager_CreateInhibitRules_Call) RunAndReturn(run func(ctx context.Context, orgID valuer.UUID, rules []config.InhibitRule) error) *MockAlertmanager_CreateInhibitRules_Call {
+ _c.Call.Return(run)
+ return _c
+}
+
+// CreateRoutePolicies provides a mock function for the type MockAlertmanager
+func (_mock *MockAlertmanager) CreateRoutePolicies(ctx context.Context, routeRequests []*alertmanagertypes.PostableRoutePolicy) ([]*alertmanagertypes.GettableRoutePolicy, error) {
+ ret := _mock.Called(ctx, routeRequests)
+
+ if len(ret) == 0 {
+ panic("no return value specified for CreateRoutePolicies")
+ }
+
+ var r0 []*alertmanagertypes.GettableRoutePolicy
+ var r1 error
+ if returnFunc, ok := ret.Get(0).(func(context.Context, []*alertmanagertypes.PostableRoutePolicy) ([]*alertmanagertypes.GettableRoutePolicy, error)); ok {
+ return returnFunc(ctx, routeRequests)
+ }
+ if returnFunc, ok := ret.Get(0).(func(context.Context, []*alertmanagertypes.PostableRoutePolicy) []*alertmanagertypes.GettableRoutePolicy); ok {
+ r0 = returnFunc(ctx, routeRequests)
+ } else {
+ if ret.Get(0) != nil {
+ r0 = ret.Get(0).([]*alertmanagertypes.GettableRoutePolicy)
+ }
+ }
+ if returnFunc, ok := ret.Get(1).(func(context.Context, []*alertmanagertypes.PostableRoutePolicy) error); ok {
+ r1 = returnFunc(ctx, routeRequests)
+ } else {
+ r1 = ret.Error(1)
+ }
+ return r0, r1
+}
+
+// MockAlertmanager_CreateRoutePolicies_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'CreateRoutePolicies'
+type MockAlertmanager_CreateRoutePolicies_Call struct {
+ *mock.Call
+}
+
+// CreateRoutePolicies is a helper method to define mock.On call
+// - ctx context.Context
+// - routeRequests []*alertmanagertypes.PostableRoutePolicy
+func (_e *MockAlertmanager_Expecter) CreateRoutePolicies(ctx interface{}, routeRequests interface{}) *MockAlertmanager_CreateRoutePolicies_Call {
+ return &MockAlertmanager_CreateRoutePolicies_Call{Call: _e.mock.On("CreateRoutePolicies", ctx, routeRequests)}
+}
+
+func (_c *MockAlertmanager_CreateRoutePolicies_Call) Run(run func(ctx context.Context, routeRequests []*alertmanagertypes.PostableRoutePolicy)) *MockAlertmanager_CreateRoutePolicies_Call {
+ _c.Call.Run(func(args mock.Arguments) {
+ var arg0 context.Context
+ if args[0] != nil {
+ arg0 = args[0].(context.Context)
+ }
+ var arg1 []*alertmanagertypes.PostableRoutePolicy
+ if args[1] != nil {
+ arg1 = args[1].([]*alertmanagertypes.PostableRoutePolicy)
+ }
+ run(
+ arg0,
+ arg1,
+ )
+ })
+ return _c
+}
+
+func (_c *MockAlertmanager_CreateRoutePolicies_Call) Return(gettableRoutePolicys []*alertmanagertypes.GettableRoutePolicy, err error) *MockAlertmanager_CreateRoutePolicies_Call {
+ _c.Call.Return(gettableRoutePolicys, err)
+ return _c
+}
+
+func (_c *MockAlertmanager_CreateRoutePolicies_Call) RunAndReturn(run func(ctx context.Context, routeRequests []*alertmanagertypes.PostableRoutePolicy) ([]*alertmanagertypes.GettableRoutePolicy, error)) *MockAlertmanager_CreateRoutePolicies_Call {
+ _c.Call.Return(run)
+ return _c
+}
+
+// CreateRoutePolicy provides a mock function for the type MockAlertmanager
+func (_mock *MockAlertmanager) CreateRoutePolicy(ctx context.Context, route *alertmanagertypes.PostableRoutePolicy) (*alertmanagertypes.GettableRoutePolicy, error) {
+ ret := _mock.Called(ctx, route)
+
+ if len(ret) == 0 {
+ panic("no return value specified for CreateRoutePolicy")
+ }
+
+ var r0 *alertmanagertypes.GettableRoutePolicy
+ var r1 error
+ if returnFunc, ok := ret.Get(0).(func(context.Context, *alertmanagertypes.PostableRoutePolicy) (*alertmanagertypes.GettableRoutePolicy, error)); ok {
+ return returnFunc(ctx, route)
+ }
+ if returnFunc, ok := ret.Get(0).(func(context.Context, *alertmanagertypes.PostableRoutePolicy) *alertmanagertypes.GettableRoutePolicy); ok {
+ r0 = returnFunc(ctx, route)
+ } else {
+ if ret.Get(0) != nil {
+ r0 = ret.Get(0).(*alertmanagertypes.GettableRoutePolicy)
+ }
+ }
+ if returnFunc, ok := ret.Get(1).(func(context.Context, *alertmanagertypes.PostableRoutePolicy) error); ok {
+ r1 = returnFunc(ctx, route)
+ } else {
+ r1 = ret.Error(1)
+ }
+ return r0, r1
+}
+
+// MockAlertmanager_CreateRoutePolicy_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'CreateRoutePolicy'
+type MockAlertmanager_CreateRoutePolicy_Call struct {
+ *mock.Call
+}
+
+// CreateRoutePolicy is a helper method to define mock.On call
+// - ctx context.Context
+// - route *alertmanagertypes.PostableRoutePolicy
+func (_e *MockAlertmanager_Expecter) CreateRoutePolicy(ctx interface{}, route interface{}) *MockAlertmanager_CreateRoutePolicy_Call {
+ return &MockAlertmanager_CreateRoutePolicy_Call{Call: _e.mock.On("CreateRoutePolicy", ctx, route)}
+}
+
+func (_c *MockAlertmanager_CreateRoutePolicy_Call) Run(run func(ctx context.Context, route *alertmanagertypes.PostableRoutePolicy)) *MockAlertmanager_CreateRoutePolicy_Call {
+ _c.Call.Run(func(args mock.Arguments) {
+ var arg0 context.Context
+ if args[0] != nil {
+ arg0 = args[0].(context.Context)
+ }
+ var arg1 *alertmanagertypes.PostableRoutePolicy
+ if args[1] != nil {
+ arg1 = args[1].(*alertmanagertypes.PostableRoutePolicy)
+ }
+ run(
+ arg0,
+ arg1,
+ )
+ })
+ return _c
+}
+
+func (_c *MockAlertmanager_CreateRoutePolicy_Call) Return(gettableRoutePolicy *alertmanagertypes.GettableRoutePolicy, err error) *MockAlertmanager_CreateRoutePolicy_Call {
+ _c.Call.Return(gettableRoutePolicy, err)
+ return _c
+}
+
+func (_c *MockAlertmanager_CreateRoutePolicy_Call) RunAndReturn(run func(ctx context.Context, route *alertmanagertypes.PostableRoutePolicy) (*alertmanagertypes.GettableRoutePolicy, error)) *MockAlertmanager_CreateRoutePolicy_Call {
+ _c.Call.Return(run)
+ return _c
+}
+
+// DeleteAllInhibitRulesByRuleId provides a mock function for the type MockAlertmanager
+func (_mock *MockAlertmanager) DeleteAllInhibitRulesByRuleId(ctx context.Context, orgID valuer.UUID, ruleId string) error {
+ ret := _mock.Called(ctx, orgID, ruleId)
+
+ if len(ret) == 0 {
+ panic("no return value specified for DeleteAllInhibitRulesByRuleId")
+ }
+
+ var r0 error
+ if returnFunc, ok := ret.Get(0).(func(context.Context, valuer.UUID, string) error); ok {
+ r0 = returnFunc(ctx, orgID, ruleId)
+ } else {
+ r0 = ret.Error(0)
+ }
+ return r0
+}
+
+// MockAlertmanager_DeleteAllInhibitRulesByRuleId_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'DeleteAllInhibitRulesByRuleId'
+type MockAlertmanager_DeleteAllInhibitRulesByRuleId_Call struct {
+ *mock.Call
+}
+
+// DeleteAllInhibitRulesByRuleId is a helper method to define mock.On call
+// - ctx context.Context
+// - orgID valuer.UUID
+// - ruleId string
+func (_e *MockAlertmanager_Expecter) DeleteAllInhibitRulesByRuleId(ctx interface{}, orgID interface{}, ruleId interface{}) *MockAlertmanager_DeleteAllInhibitRulesByRuleId_Call {
+ return &MockAlertmanager_DeleteAllInhibitRulesByRuleId_Call{Call: _e.mock.On("DeleteAllInhibitRulesByRuleId", ctx, orgID, ruleId)}
+}
+
+func (_c *MockAlertmanager_DeleteAllInhibitRulesByRuleId_Call) Run(run func(ctx context.Context, orgID valuer.UUID, ruleId string)) *MockAlertmanager_DeleteAllInhibitRulesByRuleId_Call {
+ _c.Call.Run(func(args mock.Arguments) {
+ var arg0 context.Context
+ if args[0] != nil {
+ arg0 = args[0].(context.Context)
+ }
+ var arg1 valuer.UUID
+ if args[1] != nil {
+ arg1 = args[1].(valuer.UUID)
+ }
+ var arg2 string
+ if args[2] != nil {
+ arg2 = args[2].(string)
+ }
+ run(
+ arg0,
+ arg1,
+ arg2,
+ )
+ })
+ return _c
+}
+
+func (_c *MockAlertmanager_DeleteAllInhibitRulesByRuleId_Call) Return(err error) *MockAlertmanager_DeleteAllInhibitRulesByRuleId_Call {
+ _c.Call.Return(err)
+ return _c
+}
+
+func (_c *MockAlertmanager_DeleteAllInhibitRulesByRuleId_Call) RunAndReturn(run func(ctx context.Context, orgID valuer.UUID, ruleId string) error) *MockAlertmanager_DeleteAllInhibitRulesByRuleId_Call {
+ _c.Call.Return(run)
+ return _c
+}
+
+// DeleteAllRoutePoliciesByRuleId provides a mock function for the type MockAlertmanager
+func (_mock *MockAlertmanager) DeleteAllRoutePoliciesByRuleId(ctx context.Context, ruleId string) error {
+ ret := _mock.Called(ctx, ruleId)
+
+ if len(ret) == 0 {
+ panic("no return value specified for DeleteAllRoutePoliciesByRuleId")
+ }
+
+ var r0 error
+ if returnFunc, ok := ret.Get(0).(func(context.Context, string) error); ok {
+ r0 = returnFunc(ctx, ruleId)
+ } else {
+ r0 = ret.Error(0)
+ }
+ return r0
+}
+
+// MockAlertmanager_DeleteAllRoutePoliciesByRuleId_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'DeleteAllRoutePoliciesByRuleId'
+type MockAlertmanager_DeleteAllRoutePoliciesByRuleId_Call struct {
+ *mock.Call
+}
+
+// DeleteAllRoutePoliciesByRuleId is a helper method to define mock.On call
+// - ctx context.Context
+// - ruleId string
+func (_e *MockAlertmanager_Expecter) DeleteAllRoutePoliciesByRuleId(ctx interface{}, ruleId interface{}) *MockAlertmanager_DeleteAllRoutePoliciesByRuleId_Call {
+ return &MockAlertmanager_DeleteAllRoutePoliciesByRuleId_Call{Call: _e.mock.On("DeleteAllRoutePoliciesByRuleId", ctx, ruleId)}
+}
+
+func (_c *MockAlertmanager_DeleteAllRoutePoliciesByRuleId_Call) Run(run func(ctx context.Context, ruleId string)) *MockAlertmanager_DeleteAllRoutePoliciesByRuleId_Call {
+ _c.Call.Run(func(args mock.Arguments) {
+ var arg0 context.Context
+ if args[0] != nil {
+ arg0 = args[0].(context.Context)
+ }
+ var arg1 string
+ if args[1] != nil {
+ arg1 = args[1].(string)
+ }
+ run(
+ arg0,
+ arg1,
+ )
+ })
+ return _c
+}
+
+func (_c *MockAlertmanager_DeleteAllRoutePoliciesByRuleId_Call) Return(err error) *MockAlertmanager_DeleteAllRoutePoliciesByRuleId_Call {
+ _c.Call.Return(err)
+ return _c
+}
+
+func (_c *MockAlertmanager_DeleteAllRoutePoliciesByRuleId_Call) RunAndReturn(run func(ctx context.Context, ruleId string) error) *MockAlertmanager_DeleteAllRoutePoliciesByRuleId_Call {
+ _c.Call.Return(run)
+ return _c
+}
+
+// DeleteChannelByID provides a mock function for the type MockAlertmanager
+func (_mock *MockAlertmanager) DeleteChannelByID(context1 context.Context, s string, uUID valuer.UUID) error {
+ ret := _mock.Called(context1, s, uUID)
+
+ if len(ret) == 0 {
+ panic("no return value specified for DeleteChannelByID")
+ }
+
+ var r0 error
+ if returnFunc, ok := ret.Get(0).(func(context.Context, string, valuer.UUID) error); ok {
+ r0 = returnFunc(context1, s, uUID)
+ } else {
+ r0 = ret.Error(0)
+ }
+ return r0
+}
+
+// MockAlertmanager_DeleteChannelByID_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'DeleteChannelByID'
+type MockAlertmanager_DeleteChannelByID_Call struct {
+ *mock.Call
+}
+
+// DeleteChannelByID is a helper method to define mock.On call
+// - context1 context.Context
+// - s string
+// - uUID valuer.UUID
+func (_e *MockAlertmanager_Expecter) DeleteChannelByID(context1 interface{}, s interface{}, uUID interface{}) *MockAlertmanager_DeleteChannelByID_Call {
+ return &MockAlertmanager_DeleteChannelByID_Call{Call: _e.mock.On("DeleteChannelByID", context1, s, uUID)}
+}
+
+func (_c *MockAlertmanager_DeleteChannelByID_Call) Run(run func(context1 context.Context, s string, uUID valuer.UUID)) *MockAlertmanager_DeleteChannelByID_Call {
+ _c.Call.Run(func(args mock.Arguments) {
+ var arg0 context.Context
+ if args[0] != nil {
+ arg0 = args[0].(context.Context)
+ }
+ var arg1 string
+ if args[1] != nil {
+ arg1 = args[1].(string)
+ }
+ var arg2 valuer.UUID
+ if args[2] != nil {
+ arg2 = args[2].(valuer.UUID)
+ }
+ run(
+ arg0,
+ arg1,
+ arg2,
+ )
+ })
+ return _c
+}
+
+func (_c *MockAlertmanager_DeleteChannelByID_Call) Return(err error) *MockAlertmanager_DeleteChannelByID_Call {
+ _c.Call.Return(err)
+ return _c
+}
+
+func (_c *MockAlertmanager_DeleteChannelByID_Call) RunAndReturn(run func(context1 context.Context, s string, uUID valuer.UUID) error) *MockAlertmanager_DeleteChannelByID_Call {
+ _c.Call.Return(run)
+ return _c
+}
+
+// DeleteNotificationConfig provides a mock function for the type MockAlertmanager
+func (_mock *MockAlertmanager) DeleteNotificationConfig(ctx context.Context, orgID valuer.UUID, ruleId string) error {
+ ret := _mock.Called(ctx, orgID, ruleId)
+
+ if len(ret) == 0 {
+ panic("no return value specified for DeleteNotificationConfig")
+ }
+
+ var r0 error
+ if returnFunc, ok := ret.Get(0).(func(context.Context, valuer.UUID, string) error); ok {
+ r0 = returnFunc(ctx, orgID, ruleId)
+ } else {
+ r0 = ret.Error(0)
+ }
+ return r0
+}
+
+// MockAlertmanager_DeleteNotificationConfig_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'DeleteNotificationConfig'
+type MockAlertmanager_DeleteNotificationConfig_Call struct {
+ *mock.Call
+}
+
+// DeleteNotificationConfig is a helper method to define mock.On call
+// - ctx context.Context
+// - orgID valuer.UUID
+// - ruleId string
+func (_e *MockAlertmanager_Expecter) DeleteNotificationConfig(ctx interface{}, orgID interface{}, ruleId interface{}) *MockAlertmanager_DeleteNotificationConfig_Call {
+ return &MockAlertmanager_DeleteNotificationConfig_Call{Call: _e.mock.On("DeleteNotificationConfig", ctx, orgID, ruleId)}
+}
+
+func (_c *MockAlertmanager_DeleteNotificationConfig_Call) Run(run func(ctx context.Context, orgID valuer.UUID, ruleId string)) *MockAlertmanager_DeleteNotificationConfig_Call {
+ _c.Call.Run(func(args mock.Arguments) {
+ var arg0 context.Context
+ if args[0] != nil {
+ arg0 = args[0].(context.Context)
+ }
+ var arg1 valuer.UUID
+ if args[1] != nil {
+ arg1 = args[1].(valuer.UUID)
+ }
+ var arg2 string
+ if args[2] != nil {
+ arg2 = args[2].(string)
+ }
+ run(
+ arg0,
+ arg1,
+ arg2,
+ )
+ })
+ return _c
+}
+
+func (_c *MockAlertmanager_DeleteNotificationConfig_Call) Return(err error) *MockAlertmanager_DeleteNotificationConfig_Call {
+ _c.Call.Return(err)
+ return _c
+}
+
+func (_c *MockAlertmanager_DeleteNotificationConfig_Call) RunAndReturn(run func(ctx context.Context, orgID valuer.UUID, ruleId string) error) *MockAlertmanager_DeleteNotificationConfig_Call {
+ _c.Call.Return(run)
+ return _c
+}
+
+// DeleteRoutePolicyByID provides a mock function for the type MockAlertmanager
+func (_mock *MockAlertmanager) DeleteRoutePolicyByID(ctx context.Context, routeID string) error {
+ ret := _mock.Called(ctx, routeID)
+
+ if len(ret) == 0 {
+ panic("no return value specified for DeleteRoutePolicyByID")
+ }
+
+ var r0 error
+ if returnFunc, ok := ret.Get(0).(func(context.Context, string) error); ok {
+ r0 = returnFunc(ctx, routeID)
+ } else {
+ r0 = ret.Error(0)
+ }
+ return r0
+}
+
+// MockAlertmanager_DeleteRoutePolicyByID_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'DeleteRoutePolicyByID'
+type MockAlertmanager_DeleteRoutePolicyByID_Call struct {
+ *mock.Call
+}
+
+// DeleteRoutePolicyByID is a helper method to define mock.On call
+// - ctx context.Context
+// - routeID string
+func (_e *MockAlertmanager_Expecter) DeleteRoutePolicyByID(ctx interface{}, routeID interface{}) *MockAlertmanager_DeleteRoutePolicyByID_Call {
+ return &MockAlertmanager_DeleteRoutePolicyByID_Call{Call: _e.mock.On("DeleteRoutePolicyByID", ctx, routeID)}
+}
+
+func (_c *MockAlertmanager_DeleteRoutePolicyByID_Call) Run(run func(ctx context.Context, routeID string)) *MockAlertmanager_DeleteRoutePolicyByID_Call {
+ _c.Call.Run(func(args mock.Arguments) {
+ var arg0 context.Context
+ if args[0] != nil {
+ arg0 = args[0].(context.Context)
+ }
+ var arg1 string
+ if args[1] != nil {
+ arg1 = args[1].(string)
+ }
+ run(
+ arg0,
+ arg1,
+ )
+ })
+ return _c
+}
+
+func (_c *MockAlertmanager_DeleteRoutePolicyByID_Call) Return(err error) *MockAlertmanager_DeleteRoutePolicyByID_Call {
+ _c.Call.Return(err)
+ return _c
+}
+
+func (_c *MockAlertmanager_DeleteRoutePolicyByID_Call) RunAndReturn(run func(ctx context.Context, routeID string) error) *MockAlertmanager_DeleteRoutePolicyByID_Call {
+ _c.Call.Return(run)
+ return _c
+}
+
+// GetAlerts provides a mock function for the type MockAlertmanager
+func (_mock *MockAlertmanager) GetAlerts(context1 context.Context, s string, gettableAlertsParams alertmanagertypes.GettableAlertsParams) (alertmanagertypes.DeprecatedGettableAlerts, error) {
+ ret := _mock.Called(context1, s, gettableAlertsParams)
+
+ if len(ret) == 0 {
+ panic("no return value specified for GetAlerts")
+ }
+
+ var r0 alertmanagertypes.DeprecatedGettableAlerts
+ var r1 error
+ if returnFunc, ok := ret.Get(0).(func(context.Context, string, alertmanagertypes.GettableAlertsParams) (alertmanagertypes.DeprecatedGettableAlerts, error)); ok {
+ return returnFunc(context1, s, gettableAlertsParams)
+ }
+ if returnFunc, ok := ret.Get(0).(func(context.Context, string, alertmanagertypes.GettableAlertsParams) alertmanagertypes.DeprecatedGettableAlerts); ok {
+ r0 = returnFunc(context1, s, gettableAlertsParams)
+ } else {
+ if ret.Get(0) != nil {
+ r0 = ret.Get(0).(alertmanagertypes.DeprecatedGettableAlerts)
+ }
+ }
+ if returnFunc, ok := ret.Get(1).(func(context.Context, string, alertmanagertypes.GettableAlertsParams) error); ok {
+ r1 = returnFunc(context1, s, gettableAlertsParams)
+ } else {
+ r1 = ret.Error(1)
+ }
+ return r0, r1
+}
+
+// MockAlertmanager_GetAlerts_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetAlerts'
+type MockAlertmanager_GetAlerts_Call struct {
+ *mock.Call
+}
+
+// GetAlerts is a helper method to define mock.On call
+// - context1 context.Context
+// - s string
+// - gettableAlertsParams alertmanagertypes.GettableAlertsParams
+func (_e *MockAlertmanager_Expecter) GetAlerts(context1 interface{}, s interface{}, gettableAlertsParams interface{}) *MockAlertmanager_GetAlerts_Call {
+ return &MockAlertmanager_GetAlerts_Call{Call: _e.mock.On("GetAlerts", context1, s, gettableAlertsParams)}
+}
+
+func (_c *MockAlertmanager_GetAlerts_Call) Run(run func(context1 context.Context, s string, gettableAlertsParams alertmanagertypes.GettableAlertsParams)) *MockAlertmanager_GetAlerts_Call {
+ _c.Call.Run(func(args mock.Arguments) {
+ var arg0 context.Context
+ if args[0] != nil {
+ arg0 = args[0].(context.Context)
+ }
+ var arg1 string
+ if args[1] != nil {
+ arg1 = args[1].(string)
+ }
+ var arg2 alertmanagertypes.GettableAlertsParams
+ if args[2] != nil {
+ arg2 = args[2].(alertmanagertypes.GettableAlertsParams)
+ }
+ run(
+ arg0,
+ arg1,
+ arg2,
+ )
+ })
+ return _c
+}
+
+func (_c *MockAlertmanager_GetAlerts_Call) Return(v alertmanagertypes.DeprecatedGettableAlerts, err error) *MockAlertmanager_GetAlerts_Call {
+ _c.Call.Return(v, err)
+ return _c
+}
+
+func (_c *MockAlertmanager_GetAlerts_Call) RunAndReturn(run func(context1 context.Context, s string, gettableAlertsParams alertmanagertypes.GettableAlertsParams) (alertmanagertypes.DeprecatedGettableAlerts, error)) *MockAlertmanager_GetAlerts_Call {
+ _c.Call.Return(run)
+ return _c
+}
+
+// GetAllRoutePolicies provides a mock function for the type MockAlertmanager
+func (_mock *MockAlertmanager) GetAllRoutePolicies(ctx context.Context) ([]*alertmanagertypes.GettableRoutePolicy, error) {
+ ret := _mock.Called(ctx)
+
+ if len(ret) == 0 {
+ panic("no return value specified for GetAllRoutePolicies")
+ }
+
+ var r0 []*alertmanagertypes.GettableRoutePolicy
+ var r1 error
+ if returnFunc, ok := ret.Get(0).(func(context.Context) ([]*alertmanagertypes.GettableRoutePolicy, error)); ok {
+ return returnFunc(ctx)
+ }
+ if returnFunc, ok := ret.Get(0).(func(context.Context) []*alertmanagertypes.GettableRoutePolicy); ok {
+ r0 = returnFunc(ctx)
+ } else {
+ if ret.Get(0) != nil {
+ r0 = ret.Get(0).([]*alertmanagertypes.GettableRoutePolicy)
+ }
+ }
+ if returnFunc, ok := ret.Get(1).(func(context.Context) error); ok {
+ r1 = returnFunc(ctx)
+ } else {
+ r1 = ret.Error(1)
+ }
+ return r0, r1
+}
+
+// MockAlertmanager_GetAllRoutePolicies_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetAllRoutePolicies'
+type MockAlertmanager_GetAllRoutePolicies_Call struct {
+ *mock.Call
+}
+
+// GetAllRoutePolicies is a helper method to define mock.On call
+// - ctx context.Context
+func (_e *MockAlertmanager_Expecter) GetAllRoutePolicies(ctx interface{}) *MockAlertmanager_GetAllRoutePolicies_Call {
+ return &MockAlertmanager_GetAllRoutePolicies_Call{Call: _e.mock.On("GetAllRoutePolicies", ctx)}
+}
+
+func (_c *MockAlertmanager_GetAllRoutePolicies_Call) Run(run func(ctx context.Context)) *MockAlertmanager_GetAllRoutePolicies_Call {
+ _c.Call.Run(func(args mock.Arguments) {
+ var arg0 context.Context
+ if args[0] != nil {
+ arg0 = args[0].(context.Context)
+ }
+ run(
+ arg0,
+ )
+ })
+ return _c
+}
+
+func (_c *MockAlertmanager_GetAllRoutePolicies_Call) Return(gettableRoutePolicys []*alertmanagertypes.GettableRoutePolicy, err error) *MockAlertmanager_GetAllRoutePolicies_Call {
+ _c.Call.Return(gettableRoutePolicys, err)
+ return _c
+}
+
+func (_c *MockAlertmanager_GetAllRoutePolicies_Call) RunAndReturn(run func(ctx context.Context) ([]*alertmanagertypes.GettableRoutePolicy, error)) *MockAlertmanager_GetAllRoutePolicies_Call {
+ _c.Call.Return(run)
+ return _c
+}
+
+// GetChannelByID provides a mock function for the type MockAlertmanager
+func (_mock *MockAlertmanager) GetChannelByID(context1 context.Context, s string, uUID valuer.UUID) (*alertmanagertypes.Channel, error) {
+ ret := _mock.Called(context1, s, uUID)
+
+ if len(ret) == 0 {
+ panic("no return value specified for GetChannelByID")
+ }
+
+ var r0 *alertmanagertypes.Channel
+ var r1 error
+ if returnFunc, ok := ret.Get(0).(func(context.Context, string, valuer.UUID) (*alertmanagertypes.Channel, error)); ok {
+ return returnFunc(context1, s, uUID)
+ }
+ if returnFunc, ok := ret.Get(0).(func(context.Context, string, valuer.UUID) *alertmanagertypes.Channel); ok {
+ r0 = returnFunc(context1, s, uUID)
+ } else {
+ if ret.Get(0) != nil {
+ r0 = ret.Get(0).(*alertmanagertypes.Channel)
+ }
+ }
+ if returnFunc, ok := ret.Get(1).(func(context.Context, string, valuer.UUID) error); ok {
+ r1 = returnFunc(context1, s, uUID)
+ } else {
+ r1 = ret.Error(1)
+ }
+ return r0, r1
+}
+
+// MockAlertmanager_GetChannelByID_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetChannelByID'
+type MockAlertmanager_GetChannelByID_Call struct {
+ *mock.Call
+}
+
+// GetChannelByID is a helper method to define mock.On call
+// - context1 context.Context
+// - s string
+// - uUID valuer.UUID
+func (_e *MockAlertmanager_Expecter) GetChannelByID(context1 interface{}, s interface{}, uUID interface{}) *MockAlertmanager_GetChannelByID_Call {
+ return &MockAlertmanager_GetChannelByID_Call{Call: _e.mock.On("GetChannelByID", context1, s, uUID)}
+}
+
+func (_c *MockAlertmanager_GetChannelByID_Call) Run(run func(context1 context.Context, s string, uUID valuer.UUID)) *MockAlertmanager_GetChannelByID_Call {
+ _c.Call.Run(func(args mock.Arguments) {
+ var arg0 context.Context
+ if args[0] != nil {
+ arg0 = args[0].(context.Context)
+ }
+ var arg1 string
+ if args[1] != nil {
+ arg1 = args[1].(string)
+ }
+ var arg2 valuer.UUID
+ if args[2] != nil {
+ arg2 = args[2].(valuer.UUID)
+ }
+ run(
+ arg0,
+ arg1,
+ arg2,
+ )
+ })
+ return _c
+}
+
+func (_c *MockAlertmanager_GetChannelByID_Call) Return(channel *alertmanagertypes.Channel, err error) *MockAlertmanager_GetChannelByID_Call {
+ _c.Call.Return(channel, err)
+ return _c
+}
+
+func (_c *MockAlertmanager_GetChannelByID_Call) RunAndReturn(run func(context1 context.Context, s string, uUID valuer.UUID) (*alertmanagertypes.Channel, error)) *MockAlertmanager_GetChannelByID_Call {
+ _c.Call.Return(run)
+ return _c
+}
+
+// GetConfig provides a mock function for the type MockAlertmanager
+func (_mock *MockAlertmanager) GetConfig(context1 context.Context, s string) (*alertmanagertypes.Config, error) {
+ ret := _mock.Called(context1, s)
+
+ if len(ret) == 0 {
+ panic("no return value specified for GetConfig")
+ }
+
+ var r0 *alertmanagertypes.Config
+ var r1 error
+ if returnFunc, ok := ret.Get(0).(func(context.Context, string) (*alertmanagertypes.Config, error)); ok {
+ return returnFunc(context1, s)
+ }
+ if returnFunc, ok := ret.Get(0).(func(context.Context, string) *alertmanagertypes.Config); ok {
+ r0 = returnFunc(context1, s)
+ } else {
+ if ret.Get(0) != nil {
+ r0 = ret.Get(0).(*alertmanagertypes.Config)
+ }
+ }
+ if returnFunc, ok := ret.Get(1).(func(context.Context, string) error); ok {
+ r1 = returnFunc(context1, s)
+ } else {
+ r1 = ret.Error(1)
+ }
+ return r0, r1
+}
+
+// MockAlertmanager_GetConfig_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetConfig'
+type MockAlertmanager_GetConfig_Call struct {
+ *mock.Call
+}
+
+// GetConfig is a helper method to define mock.On call
+// - context1 context.Context
+// - s string
+func (_e *MockAlertmanager_Expecter) GetConfig(context1 interface{}, s interface{}) *MockAlertmanager_GetConfig_Call {
+ return &MockAlertmanager_GetConfig_Call{Call: _e.mock.On("GetConfig", context1, s)}
+}
+
+func (_c *MockAlertmanager_GetConfig_Call) Run(run func(context1 context.Context, s string)) *MockAlertmanager_GetConfig_Call {
+ _c.Call.Run(func(args mock.Arguments) {
+ var arg0 context.Context
+ if args[0] != nil {
+ arg0 = args[0].(context.Context)
+ }
+ var arg1 string
+ if args[1] != nil {
+ arg1 = args[1].(string)
+ }
+ run(
+ arg0,
+ arg1,
+ )
+ })
+ return _c
+}
+
+func (_c *MockAlertmanager_GetConfig_Call) Return(config1 *alertmanagertypes.Config, err error) *MockAlertmanager_GetConfig_Call {
+ _c.Call.Return(config1, err)
+ return _c
+}
+
+func (_c *MockAlertmanager_GetConfig_Call) RunAndReturn(run func(context1 context.Context, s string) (*alertmanagertypes.Config, error)) *MockAlertmanager_GetConfig_Call {
+ _c.Call.Return(run)
+ return _c
+}
+
+// GetRoutePolicyByID provides a mock function for the type MockAlertmanager
+func (_mock *MockAlertmanager) GetRoutePolicyByID(ctx context.Context, routeID string) (*alertmanagertypes.GettableRoutePolicy, error) {
+ ret := _mock.Called(ctx, routeID)
+
+ if len(ret) == 0 {
+ panic("no return value specified for GetRoutePolicyByID")
+ }
+
+ var r0 *alertmanagertypes.GettableRoutePolicy
+ var r1 error
+ if returnFunc, ok := ret.Get(0).(func(context.Context, string) (*alertmanagertypes.GettableRoutePolicy, error)); ok {
+ return returnFunc(ctx, routeID)
+ }
+ if returnFunc, ok := ret.Get(0).(func(context.Context, string) *alertmanagertypes.GettableRoutePolicy); ok {
+ r0 = returnFunc(ctx, routeID)
+ } else {
+ if ret.Get(0) != nil {
+ r0 = ret.Get(0).(*alertmanagertypes.GettableRoutePolicy)
+ }
+ }
+ if returnFunc, ok := ret.Get(1).(func(context.Context, string) error); ok {
+ r1 = returnFunc(ctx, routeID)
+ } else {
+ r1 = ret.Error(1)
+ }
+ return r0, r1
+}
+
+// MockAlertmanager_GetRoutePolicyByID_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetRoutePolicyByID'
+type MockAlertmanager_GetRoutePolicyByID_Call struct {
+ *mock.Call
+}
+
+// GetRoutePolicyByID is a helper method to define mock.On call
+// - ctx context.Context
+// - routeID string
+func (_e *MockAlertmanager_Expecter) GetRoutePolicyByID(ctx interface{}, routeID interface{}) *MockAlertmanager_GetRoutePolicyByID_Call {
+ return &MockAlertmanager_GetRoutePolicyByID_Call{Call: _e.mock.On("GetRoutePolicyByID", ctx, routeID)}
+}
+
+func (_c *MockAlertmanager_GetRoutePolicyByID_Call) Run(run func(ctx context.Context, routeID string)) *MockAlertmanager_GetRoutePolicyByID_Call {
+ _c.Call.Run(func(args mock.Arguments) {
+ var arg0 context.Context
+ if args[0] != nil {
+ arg0 = args[0].(context.Context)
+ }
+ var arg1 string
+ if args[1] != nil {
+ arg1 = args[1].(string)
+ }
+ run(
+ arg0,
+ arg1,
+ )
+ })
+ return _c
+}
+
+func (_c *MockAlertmanager_GetRoutePolicyByID_Call) Return(gettableRoutePolicy *alertmanagertypes.GettableRoutePolicy, err error) *MockAlertmanager_GetRoutePolicyByID_Call {
+ _c.Call.Return(gettableRoutePolicy, err)
+ return _c
+}
+
+func (_c *MockAlertmanager_GetRoutePolicyByID_Call) RunAndReturn(run func(ctx context.Context, routeID string) (*alertmanagertypes.GettableRoutePolicy, error)) *MockAlertmanager_GetRoutePolicyByID_Call {
+ _c.Call.Return(run)
+ return _c
+}
+
+// ListAllChannels provides a mock function for the type MockAlertmanager
+func (_mock *MockAlertmanager) ListAllChannels(context1 context.Context) ([]*alertmanagertypes.Channel, error) {
+ ret := _mock.Called(context1)
+
+ if len(ret) == 0 {
+ panic("no return value specified for ListAllChannels")
+ }
+
+ var r0 []*alertmanagertypes.Channel
+ var r1 error
+ if returnFunc, ok := ret.Get(0).(func(context.Context) ([]*alertmanagertypes.Channel, error)); ok {
+ return returnFunc(context1)
+ }
+ if returnFunc, ok := ret.Get(0).(func(context.Context) []*alertmanagertypes.Channel); ok {
+ r0 = returnFunc(context1)
+ } else {
+ if ret.Get(0) != nil {
+ r0 = ret.Get(0).([]*alertmanagertypes.Channel)
+ }
+ }
+ if returnFunc, ok := ret.Get(1).(func(context.Context) error); ok {
+ r1 = returnFunc(context1)
+ } else {
+ r1 = ret.Error(1)
+ }
+ return r0, r1
+}
+
+// MockAlertmanager_ListAllChannels_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'ListAllChannels'
+type MockAlertmanager_ListAllChannels_Call struct {
+ *mock.Call
+}
+
+// ListAllChannels is a helper method to define mock.On call
+// - context1 context.Context
+func (_e *MockAlertmanager_Expecter) ListAllChannels(context1 interface{}) *MockAlertmanager_ListAllChannels_Call {
+ return &MockAlertmanager_ListAllChannels_Call{Call: _e.mock.On("ListAllChannels", context1)}
+}
+
+func (_c *MockAlertmanager_ListAllChannels_Call) Run(run func(context1 context.Context)) *MockAlertmanager_ListAllChannels_Call {
+ _c.Call.Run(func(args mock.Arguments) {
+ var arg0 context.Context
+ if args[0] != nil {
+ arg0 = args[0].(context.Context)
+ }
+ run(
+ arg0,
+ )
+ })
+ return _c
+}
+
+func (_c *MockAlertmanager_ListAllChannels_Call) Return(channels []*alertmanagertypes.Channel, err error) *MockAlertmanager_ListAllChannels_Call {
+ _c.Call.Return(channels, err)
+ return _c
+}
+
+func (_c *MockAlertmanager_ListAllChannels_Call) RunAndReturn(run func(context1 context.Context) ([]*alertmanagertypes.Channel, error)) *MockAlertmanager_ListAllChannels_Call {
+ _c.Call.Return(run)
+ return _c
+}
+
+// ListChannels provides a mock function for the type MockAlertmanager
+func (_mock *MockAlertmanager) ListChannels(context1 context.Context, s string) ([]*alertmanagertypes.Channel, error) {
+ ret := _mock.Called(context1, s)
+
+ if len(ret) == 0 {
+ panic("no return value specified for ListChannels")
+ }
+
+ var r0 []*alertmanagertypes.Channel
+ var r1 error
+ if returnFunc, ok := ret.Get(0).(func(context.Context, string) ([]*alertmanagertypes.Channel, error)); ok {
+ return returnFunc(context1, s)
+ }
+ if returnFunc, ok := ret.Get(0).(func(context.Context, string) []*alertmanagertypes.Channel); ok {
+ r0 = returnFunc(context1, s)
+ } else {
+ if ret.Get(0) != nil {
+ r0 = ret.Get(0).([]*alertmanagertypes.Channel)
+ }
+ }
+ if returnFunc, ok := ret.Get(1).(func(context.Context, string) error); ok {
+ r1 = returnFunc(context1, s)
+ } else {
+ r1 = ret.Error(1)
+ }
+ return r0, r1
+}
+
+// MockAlertmanager_ListChannels_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'ListChannels'
+type MockAlertmanager_ListChannels_Call struct {
+ *mock.Call
+}
+
+// ListChannels is a helper method to define mock.On call
+// - context1 context.Context
+// - s string
+func (_e *MockAlertmanager_Expecter) ListChannels(context1 interface{}, s interface{}) *MockAlertmanager_ListChannels_Call {
+ return &MockAlertmanager_ListChannels_Call{Call: _e.mock.On("ListChannels", context1, s)}
+}
+
+func (_c *MockAlertmanager_ListChannels_Call) Run(run func(context1 context.Context, s string)) *MockAlertmanager_ListChannels_Call {
+ _c.Call.Run(func(args mock.Arguments) {
+ var arg0 context.Context
+ if args[0] != nil {
+ arg0 = args[0].(context.Context)
+ }
+ var arg1 string
+ if args[1] != nil {
+ arg1 = args[1].(string)
+ }
+ run(
+ arg0,
+ arg1,
+ )
+ })
+ return _c
+}
+
+func (_c *MockAlertmanager_ListChannels_Call) Return(channels []*alertmanagertypes.Channel, err error) *MockAlertmanager_ListChannels_Call {
+ _c.Call.Return(channels, err)
+ return _c
+}
+
+func (_c *MockAlertmanager_ListChannels_Call) RunAndReturn(run func(context1 context.Context, s string) ([]*alertmanagertypes.Channel, error)) *MockAlertmanager_ListChannels_Call {
+ _c.Call.Return(run)
+ return _c
+}
+
+// PutAlerts provides a mock function for the type MockAlertmanager
+func (_mock *MockAlertmanager) PutAlerts(context1 context.Context, s string, v alertmanagertypes.PostableAlerts) error {
+ ret := _mock.Called(context1, s, v)
+
+ if len(ret) == 0 {
+ panic("no return value specified for PutAlerts")
+ }
+
+ var r0 error
+ if returnFunc, ok := ret.Get(0).(func(context.Context, string, alertmanagertypes.PostableAlerts) error); ok {
+ r0 = returnFunc(context1, s, v)
+ } else {
+ r0 = ret.Error(0)
+ }
+ return r0
+}
+
+// MockAlertmanager_PutAlerts_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'PutAlerts'
+type MockAlertmanager_PutAlerts_Call struct {
+ *mock.Call
+}
+
+// PutAlerts is a helper method to define mock.On call
+// - context1 context.Context
+// - s string
+// - v alertmanagertypes.PostableAlerts
+func (_e *MockAlertmanager_Expecter) PutAlerts(context1 interface{}, s interface{}, v interface{}) *MockAlertmanager_PutAlerts_Call {
+ return &MockAlertmanager_PutAlerts_Call{Call: _e.mock.On("PutAlerts", context1, s, v)}
+}
+
+func (_c *MockAlertmanager_PutAlerts_Call) Run(run func(context1 context.Context, s string, v alertmanagertypes.PostableAlerts)) *MockAlertmanager_PutAlerts_Call {
+ _c.Call.Run(func(args mock.Arguments) {
+ var arg0 context.Context
+ if args[0] != nil {
+ arg0 = args[0].(context.Context)
+ }
+ var arg1 string
+ if args[1] != nil {
+ arg1 = args[1].(string)
+ }
+ var arg2 alertmanagertypes.PostableAlerts
+ if args[2] != nil {
+ arg2 = args[2].(alertmanagertypes.PostableAlerts)
+ }
+ run(
+ arg0,
+ arg1,
+ arg2,
+ )
+ })
+ return _c
+}
+
+func (_c *MockAlertmanager_PutAlerts_Call) Return(err error) *MockAlertmanager_PutAlerts_Call {
+ _c.Call.Return(err)
+ return _c
+}
+
+func (_c *MockAlertmanager_PutAlerts_Call) RunAndReturn(run func(context1 context.Context, s string, v alertmanagertypes.PostableAlerts) error) *MockAlertmanager_PutAlerts_Call {
+ _c.Call.Return(run)
+ return _c
+}
+
+// SetConfig provides a mock function for the type MockAlertmanager
+func (_mock *MockAlertmanager) SetConfig(context1 context.Context, config1 *alertmanagertypes.Config) error {
+ ret := _mock.Called(context1, config1)
+
+ if len(ret) == 0 {
+ panic("no return value specified for SetConfig")
+ }
+
+ var r0 error
+ if returnFunc, ok := ret.Get(0).(func(context.Context, *alertmanagertypes.Config) error); ok {
+ r0 = returnFunc(context1, config1)
+ } else {
+ r0 = ret.Error(0)
+ }
+ return r0
+}
+
+// MockAlertmanager_SetConfig_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'SetConfig'
+type MockAlertmanager_SetConfig_Call struct {
+ *mock.Call
+}
+
+// SetConfig is a helper method to define mock.On call
+// - context1 context.Context
+// - config1 *alertmanagertypes.Config
+func (_e *MockAlertmanager_Expecter) SetConfig(context1 interface{}, config1 interface{}) *MockAlertmanager_SetConfig_Call {
+ return &MockAlertmanager_SetConfig_Call{Call: _e.mock.On("SetConfig", context1, config1)}
+}
+
+func (_c *MockAlertmanager_SetConfig_Call) Run(run func(context1 context.Context, config1 *alertmanagertypes.Config)) *MockAlertmanager_SetConfig_Call {
+ _c.Call.Run(func(args mock.Arguments) {
+ var arg0 context.Context
+ if args[0] != nil {
+ arg0 = args[0].(context.Context)
+ }
+ var arg1 *alertmanagertypes.Config
+ if args[1] != nil {
+ arg1 = args[1].(*alertmanagertypes.Config)
+ }
+ run(
+ arg0,
+ arg1,
+ )
+ })
+ return _c
+}
+
+func (_c *MockAlertmanager_SetConfig_Call) Return(err error) *MockAlertmanager_SetConfig_Call {
+ _c.Call.Return(err)
+ return _c
+}
+
+func (_c *MockAlertmanager_SetConfig_Call) RunAndReturn(run func(context1 context.Context, config1 *alertmanagertypes.Config) error) *MockAlertmanager_SetConfig_Call {
+ _c.Call.Return(run)
+ return _c
+}
+
+// SetDefaultConfig provides a mock function for the type MockAlertmanager
+func (_mock *MockAlertmanager) SetDefaultConfig(context1 context.Context, s string) error {
+ ret := _mock.Called(context1, s)
+
+ if len(ret) == 0 {
+ panic("no return value specified for SetDefaultConfig")
+ }
+
+ var r0 error
+ if returnFunc, ok := ret.Get(0).(func(context.Context, string) error); ok {
+ r0 = returnFunc(context1, s)
+ } else {
+ r0 = ret.Error(0)
+ }
+ return r0
+}
+
+// MockAlertmanager_SetDefaultConfig_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'SetDefaultConfig'
+type MockAlertmanager_SetDefaultConfig_Call struct {
+ *mock.Call
+}
+
+// SetDefaultConfig is a helper method to define mock.On call
+// - context1 context.Context
+// - s string
+func (_e *MockAlertmanager_Expecter) SetDefaultConfig(context1 interface{}, s interface{}) *MockAlertmanager_SetDefaultConfig_Call {
+ return &MockAlertmanager_SetDefaultConfig_Call{Call: _e.mock.On("SetDefaultConfig", context1, s)}
+}
+
+func (_c *MockAlertmanager_SetDefaultConfig_Call) Run(run func(context1 context.Context, s string)) *MockAlertmanager_SetDefaultConfig_Call {
+ _c.Call.Run(func(args mock.Arguments) {
+ var arg0 context.Context
+ if args[0] != nil {
+ arg0 = args[0].(context.Context)
+ }
+ var arg1 string
+ if args[1] != nil {
+ arg1 = args[1].(string)
+ }
+ run(
+ arg0,
+ arg1,
+ )
+ })
+ return _c
+}
+
+func (_c *MockAlertmanager_SetDefaultConfig_Call) Return(err error) *MockAlertmanager_SetDefaultConfig_Call {
+ _c.Call.Return(err)
+ return _c
+}
+
+func (_c *MockAlertmanager_SetDefaultConfig_Call) RunAndReturn(run func(context1 context.Context, s string) error) *MockAlertmanager_SetDefaultConfig_Call {
+ _c.Call.Return(run)
+ return _c
+}
+
+// SetNotificationConfig provides a mock function for the type MockAlertmanager
+func (_mock *MockAlertmanager) SetNotificationConfig(ctx context.Context, orgID valuer.UUID, ruleId string, config1 *alertmanagertypes.NotificationConfig) error {
+ ret := _mock.Called(ctx, orgID, ruleId, config1)
+
+ if len(ret) == 0 {
+ panic("no return value specified for SetNotificationConfig")
+ }
+
+ var r0 error
+ if returnFunc, ok := ret.Get(0).(func(context.Context, valuer.UUID, string, *alertmanagertypes.NotificationConfig) error); ok {
+ r0 = returnFunc(ctx, orgID, ruleId, config1)
+ } else {
+ r0 = ret.Error(0)
+ }
+ return r0
+}
+
+// MockAlertmanager_SetNotificationConfig_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'SetNotificationConfig'
+type MockAlertmanager_SetNotificationConfig_Call struct {
+ *mock.Call
+}
+
+// SetNotificationConfig is a helper method to define mock.On call
+// - ctx context.Context
+// - orgID valuer.UUID
+// - ruleId string
+// - config1 *alertmanagertypes.NotificationConfig
+func (_e *MockAlertmanager_Expecter) SetNotificationConfig(ctx interface{}, orgID interface{}, ruleId interface{}, config1 interface{}) *MockAlertmanager_SetNotificationConfig_Call {
+ return &MockAlertmanager_SetNotificationConfig_Call{Call: _e.mock.On("SetNotificationConfig", ctx, orgID, ruleId, config1)}
+}
+
+func (_c *MockAlertmanager_SetNotificationConfig_Call) Run(run func(ctx context.Context, orgID valuer.UUID, ruleId string, config1 *alertmanagertypes.NotificationConfig)) *MockAlertmanager_SetNotificationConfig_Call {
+ _c.Call.Run(func(args mock.Arguments) {
+ var arg0 context.Context
+ if args[0] != nil {
+ arg0 = args[0].(context.Context)
+ }
+ var arg1 valuer.UUID
+ if args[1] != nil {
+ arg1 = args[1].(valuer.UUID)
+ }
+ var arg2 string
+ if args[2] != nil {
+ arg2 = args[2].(string)
+ }
+ var arg3 *alertmanagertypes.NotificationConfig
+ if args[3] != nil {
+ arg3 = args[3].(*alertmanagertypes.NotificationConfig)
+ }
+ run(
+ arg0,
+ arg1,
+ arg2,
+ arg3,
+ )
+ })
+ return _c
+}
+
+func (_c *MockAlertmanager_SetNotificationConfig_Call) Return(err error) *MockAlertmanager_SetNotificationConfig_Call {
+ _c.Call.Return(err)
+ return _c
+}
+
+func (_c *MockAlertmanager_SetNotificationConfig_Call) RunAndReturn(run func(ctx context.Context, orgID valuer.UUID, ruleId string, config1 *alertmanagertypes.NotificationConfig) error) *MockAlertmanager_SetNotificationConfig_Call {
+ _c.Call.Return(run)
+ return _c
+}
+
+// Start provides a mock function for the type MockAlertmanager
+func (_mock *MockAlertmanager) Start(context1 context.Context) error {
+ ret := _mock.Called(context1)
+
+ if len(ret) == 0 {
+ panic("no return value specified for Start")
+ }
+
+ var r0 error
+ if returnFunc, ok := ret.Get(0).(func(context.Context) error); ok {
+ r0 = returnFunc(context1)
+ } else {
+ r0 = ret.Error(0)
+ }
+ return r0
+}
+
+// MockAlertmanager_Start_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Start'
+type MockAlertmanager_Start_Call struct {
+ *mock.Call
+}
+
+// Start is a helper method to define mock.On call
+// - context1 context.Context
+func (_e *MockAlertmanager_Expecter) Start(context1 interface{}) *MockAlertmanager_Start_Call {
+ return &MockAlertmanager_Start_Call{Call: _e.mock.On("Start", context1)}
+}
+
+func (_c *MockAlertmanager_Start_Call) Run(run func(context1 context.Context)) *MockAlertmanager_Start_Call {
+ _c.Call.Run(func(args mock.Arguments) {
+ var arg0 context.Context
+ if args[0] != nil {
+ arg0 = args[0].(context.Context)
+ }
+ run(
+ arg0,
+ )
+ })
+ return _c
+}
+
+func (_c *MockAlertmanager_Start_Call) Return(err error) *MockAlertmanager_Start_Call {
+ _c.Call.Return(err)
+ return _c
+}
+
+func (_c *MockAlertmanager_Start_Call) RunAndReturn(run func(context1 context.Context) error) *MockAlertmanager_Start_Call {
+ _c.Call.Return(run)
+ return _c
+}
+
+// Stop provides a mock function for the type MockAlertmanager
+func (_mock *MockAlertmanager) Stop(context1 context.Context) error {
+ ret := _mock.Called(context1)
+
+ if len(ret) == 0 {
+ panic("no return value specified for Stop")
+ }
+
+ var r0 error
+ if returnFunc, ok := ret.Get(0).(func(context.Context) error); ok {
+ r0 = returnFunc(context1)
+ } else {
+ r0 = ret.Error(0)
+ }
+ return r0
+}
+
+// MockAlertmanager_Stop_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Stop'
+type MockAlertmanager_Stop_Call struct {
+ *mock.Call
+}
+
+// Stop is a helper method to define mock.On call
+// - context1 context.Context
+func (_e *MockAlertmanager_Expecter) Stop(context1 interface{}) *MockAlertmanager_Stop_Call {
+ return &MockAlertmanager_Stop_Call{Call: _e.mock.On("Stop", context1)}
+}
+
+func (_c *MockAlertmanager_Stop_Call) Run(run func(context1 context.Context)) *MockAlertmanager_Stop_Call {
+ _c.Call.Run(func(args mock.Arguments) {
+ var arg0 context.Context
+ if args[0] != nil {
+ arg0 = args[0].(context.Context)
+ }
+ run(
+ arg0,
+ )
+ })
+ return _c
+}
+
+func (_c *MockAlertmanager_Stop_Call) Return(err error) *MockAlertmanager_Stop_Call {
+ _c.Call.Return(err)
+ return _c
+}
+
+func (_c *MockAlertmanager_Stop_Call) RunAndReturn(run func(context1 context.Context) error) *MockAlertmanager_Stop_Call {
+ _c.Call.Return(run)
+ return _c
+}
+
+// TestAlert provides a mock function for the type MockAlertmanager
+func (_mock *MockAlertmanager) TestAlert(ctx context.Context, orgID string, ruleID string, receiversMap map[*alertmanagertypes.PostableAlert][]string) error {
+ ret := _mock.Called(ctx, orgID, ruleID, receiversMap)
+
+ if len(ret) == 0 {
+ panic("no return value specified for TestAlert")
+ }
+
+ var r0 error
+ if returnFunc, ok := ret.Get(0).(func(context.Context, string, string, map[*alertmanagertypes.PostableAlert][]string) error); ok {
+ r0 = returnFunc(ctx, orgID, ruleID, receiversMap)
+ } else {
+ r0 = ret.Error(0)
+ }
+ return r0
+}
+
+// MockAlertmanager_TestAlert_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'TestAlert'
+type MockAlertmanager_TestAlert_Call struct {
+ *mock.Call
+}
+
+// TestAlert is a helper method to define mock.On call
+// - ctx context.Context
+// - orgID string
+// - ruleID string
+// - receiversMap map[*alertmanagertypes.PostableAlert][]string
+func (_e *MockAlertmanager_Expecter) TestAlert(ctx interface{}, orgID interface{}, ruleID interface{}, receiversMap interface{}) *MockAlertmanager_TestAlert_Call {
+ return &MockAlertmanager_TestAlert_Call{Call: _e.mock.On("TestAlert", ctx, orgID, ruleID, receiversMap)}
+}
+
+func (_c *MockAlertmanager_TestAlert_Call) Run(run func(ctx context.Context, orgID string, ruleID string, receiversMap map[*alertmanagertypes.PostableAlert][]string)) *MockAlertmanager_TestAlert_Call {
+ _c.Call.Run(func(args mock.Arguments) {
+ var arg0 context.Context
+ if args[0] != nil {
+ arg0 = args[0].(context.Context)
+ }
+ var arg1 string
+ if args[1] != nil {
+ arg1 = args[1].(string)
+ }
+ var arg2 string
+ if args[2] != nil {
+ arg2 = args[2].(string)
+ }
+ var arg3 map[*alertmanagertypes.PostableAlert][]string
+ if args[3] != nil {
+ arg3 = args[3].(map[*alertmanagertypes.PostableAlert][]string)
+ }
+ run(
+ arg0,
+ arg1,
+ arg2,
+ arg3,
+ )
+ })
+ return _c
+}
+
+func (_c *MockAlertmanager_TestAlert_Call) Return(err error) *MockAlertmanager_TestAlert_Call {
+ _c.Call.Return(err)
+ return _c
+}
+
+func (_c *MockAlertmanager_TestAlert_Call) RunAndReturn(run func(ctx context.Context, orgID string, ruleID string, receiversMap map[*alertmanagertypes.PostableAlert][]string) error) *MockAlertmanager_TestAlert_Call {
+ _c.Call.Return(run)
+ return _c
+}
+
+// TestReceiver provides a mock function for the type MockAlertmanager
+func (_mock *MockAlertmanager) TestReceiver(context1 context.Context, s string, v alertmanagertypes.Receiver) error {
+ ret := _mock.Called(context1, s, v)
+
+ if len(ret) == 0 {
+ panic("no return value specified for TestReceiver")
+ }
+
+ var r0 error
+ if returnFunc, ok := ret.Get(0).(func(context.Context, string, alertmanagertypes.Receiver) error); ok {
+ r0 = returnFunc(context1, s, v)
+ } else {
+ r0 = ret.Error(0)
+ }
+ return r0
+}
+
+// MockAlertmanager_TestReceiver_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'TestReceiver'
+type MockAlertmanager_TestReceiver_Call struct {
+ *mock.Call
+}
+
+// TestReceiver is a helper method to define mock.On call
+// - context1 context.Context
+// - s string
+// - v alertmanagertypes.Receiver
+func (_e *MockAlertmanager_Expecter) TestReceiver(context1 interface{}, s interface{}, v interface{}) *MockAlertmanager_TestReceiver_Call {
+ return &MockAlertmanager_TestReceiver_Call{Call: _e.mock.On("TestReceiver", context1, s, v)}
+}
+
+func (_c *MockAlertmanager_TestReceiver_Call) Run(run func(context1 context.Context, s string, v alertmanagertypes.Receiver)) *MockAlertmanager_TestReceiver_Call {
+ _c.Call.Run(func(args mock.Arguments) {
+ var arg0 context.Context
+ if args[0] != nil {
+ arg0 = args[0].(context.Context)
+ }
+ var arg1 string
+ if args[1] != nil {
+ arg1 = args[1].(string)
+ }
+ var arg2 alertmanagertypes.Receiver
+ if args[2] != nil {
+ arg2 = args[2].(alertmanagertypes.Receiver)
+ }
+ run(
+ arg0,
+ arg1,
+ arg2,
+ )
+ })
+ return _c
+}
+
+func (_c *MockAlertmanager_TestReceiver_Call) Return(err error) *MockAlertmanager_TestReceiver_Call {
+ _c.Call.Return(err)
+ return _c
+}
+
+func (_c *MockAlertmanager_TestReceiver_Call) RunAndReturn(run func(context1 context.Context, s string, v alertmanagertypes.Receiver) error) *MockAlertmanager_TestReceiver_Call {
+ _c.Call.Return(run)
+ return _c
+}
+
+// UpdateAllRoutePoliciesByRuleId provides a mock function for the type MockAlertmanager
+func (_mock *MockAlertmanager) UpdateAllRoutePoliciesByRuleId(ctx context.Context, ruleId string, routes []*alertmanagertypes.PostableRoutePolicy) error {
+ ret := _mock.Called(ctx, ruleId, routes)
+
+ if len(ret) == 0 {
+ panic("no return value specified for UpdateAllRoutePoliciesByRuleId")
+ }
+
+ var r0 error
+ if returnFunc, ok := ret.Get(0).(func(context.Context, string, []*alertmanagertypes.PostableRoutePolicy) error); ok {
+ r0 = returnFunc(ctx, ruleId, routes)
+ } else {
+ r0 = ret.Error(0)
+ }
+ return r0
+}
+
+// MockAlertmanager_UpdateAllRoutePoliciesByRuleId_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'UpdateAllRoutePoliciesByRuleId'
+type MockAlertmanager_UpdateAllRoutePoliciesByRuleId_Call struct {
+ *mock.Call
+}
+
+// UpdateAllRoutePoliciesByRuleId is a helper method to define mock.On call
+// - ctx context.Context
+// - ruleId string
+// - routes []*alertmanagertypes.PostableRoutePolicy
+func (_e *MockAlertmanager_Expecter) UpdateAllRoutePoliciesByRuleId(ctx interface{}, ruleId interface{}, routes interface{}) *MockAlertmanager_UpdateAllRoutePoliciesByRuleId_Call {
+ return &MockAlertmanager_UpdateAllRoutePoliciesByRuleId_Call{Call: _e.mock.On("UpdateAllRoutePoliciesByRuleId", ctx, ruleId, routes)}
+}
+
+func (_c *MockAlertmanager_UpdateAllRoutePoliciesByRuleId_Call) Run(run func(ctx context.Context, ruleId string, routes []*alertmanagertypes.PostableRoutePolicy)) *MockAlertmanager_UpdateAllRoutePoliciesByRuleId_Call {
+ _c.Call.Run(func(args mock.Arguments) {
+ var arg0 context.Context
+ if args[0] != nil {
+ arg0 = args[0].(context.Context)
+ }
+ var arg1 string
+ if args[1] != nil {
+ arg1 = args[1].(string)
+ }
+ var arg2 []*alertmanagertypes.PostableRoutePolicy
+ if args[2] != nil {
+ arg2 = args[2].([]*alertmanagertypes.PostableRoutePolicy)
+ }
+ run(
+ arg0,
+ arg1,
+ arg2,
+ )
+ })
+ return _c
+}
+
+func (_c *MockAlertmanager_UpdateAllRoutePoliciesByRuleId_Call) Return(err error) *MockAlertmanager_UpdateAllRoutePoliciesByRuleId_Call {
+ _c.Call.Return(err)
+ return _c
+}
+
+func (_c *MockAlertmanager_UpdateAllRoutePoliciesByRuleId_Call) RunAndReturn(run func(ctx context.Context, ruleId string, routes []*alertmanagertypes.PostableRoutePolicy) error) *MockAlertmanager_UpdateAllRoutePoliciesByRuleId_Call {
+ _c.Call.Return(run)
+ return _c
+}
+
+// UpdateChannelByReceiverAndID provides a mock function for the type MockAlertmanager
+func (_mock *MockAlertmanager) UpdateChannelByReceiverAndID(context1 context.Context, s string, v alertmanagertypes.Receiver, uUID valuer.UUID) error {
+ ret := _mock.Called(context1, s, v, uUID)
+
+ if len(ret) == 0 {
+ panic("no return value specified for UpdateChannelByReceiverAndID")
+ }
+
+ var r0 error
+ if returnFunc, ok := ret.Get(0).(func(context.Context, string, alertmanagertypes.Receiver, valuer.UUID) error); ok {
+ r0 = returnFunc(context1, s, v, uUID)
+ } else {
+ r0 = ret.Error(0)
+ }
+ return r0
+}
+
+// MockAlertmanager_UpdateChannelByReceiverAndID_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'UpdateChannelByReceiverAndID'
+type MockAlertmanager_UpdateChannelByReceiverAndID_Call struct {
+ *mock.Call
+}
+
+// UpdateChannelByReceiverAndID is a helper method to define mock.On call
+// - context1 context.Context
+// - s string
+// - v alertmanagertypes.Receiver
+// - uUID valuer.UUID
+func (_e *MockAlertmanager_Expecter) UpdateChannelByReceiverAndID(context1 interface{}, s interface{}, v interface{}, uUID interface{}) *MockAlertmanager_UpdateChannelByReceiverAndID_Call {
+ return &MockAlertmanager_UpdateChannelByReceiverAndID_Call{Call: _e.mock.On("UpdateChannelByReceiverAndID", context1, s, v, uUID)}
+}
+
+func (_c *MockAlertmanager_UpdateChannelByReceiverAndID_Call) Run(run func(context1 context.Context, s string, v alertmanagertypes.Receiver, uUID valuer.UUID)) *MockAlertmanager_UpdateChannelByReceiverAndID_Call {
+ _c.Call.Run(func(args mock.Arguments) {
+ var arg0 context.Context
+ if args[0] != nil {
+ arg0 = args[0].(context.Context)
+ }
+ var arg1 string
+ if args[1] != nil {
+ arg1 = args[1].(string)
+ }
+ var arg2 alertmanagertypes.Receiver
+ if args[2] != nil {
+ arg2 = args[2].(alertmanagertypes.Receiver)
+ }
+ var arg3 valuer.UUID
+ if args[3] != nil {
+ arg3 = args[3].(valuer.UUID)
+ }
+ run(
+ arg0,
+ arg1,
+ arg2,
+ arg3,
+ )
+ })
+ return _c
+}
+
+func (_c *MockAlertmanager_UpdateChannelByReceiverAndID_Call) Return(err error) *MockAlertmanager_UpdateChannelByReceiverAndID_Call {
+ _c.Call.Return(err)
+ return _c
+}
+
+func (_c *MockAlertmanager_UpdateChannelByReceiverAndID_Call) RunAndReturn(run func(context1 context.Context, s string, v alertmanagertypes.Receiver, uUID valuer.UUID) error) *MockAlertmanager_UpdateChannelByReceiverAndID_Call {
+ _c.Call.Return(run)
+ return _c
+}
+
+// UpdateRoutePolicyByID provides a mock function for the type MockAlertmanager
+func (_mock *MockAlertmanager) UpdateRoutePolicyByID(ctx context.Context, routeID string, route *alertmanagertypes.PostableRoutePolicy) (*alertmanagertypes.GettableRoutePolicy, error) {
+ ret := _mock.Called(ctx, routeID, route)
+
+ if len(ret) == 0 {
+ panic("no return value specified for UpdateRoutePolicyByID")
+ }
+
+ var r0 *alertmanagertypes.GettableRoutePolicy
+ var r1 error
+ if returnFunc, ok := ret.Get(0).(func(context.Context, string, *alertmanagertypes.PostableRoutePolicy) (*alertmanagertypes.GettableRoutePolicy, error)); ok {
+ return returnFunc(ctx, routeID, route)
+ }
+ if returnFunc, ok := ret.Get(0).(func(context.Context, string, *alertmanagertypes.PostableRoutePolicy) *alertmanagertypes.GettableRoutePolicy); ok {
+ r0 = returnFunc(ctx, routeID, route)
+ } else {
+ if ret.Get(0) != nil {
+ r0 = ret.Get(0).(*alertmanagertypes.GettableRoutePolicy)
+ }
+ }
+ if returnFunc, ok := ret.Get(1).(func(context.Context, string, *alertmanagertypes.PostableRoutePolicy) error); ok {
+ r1 = returnFunc(ctx, routeID, route)
+ } else {
+ r1 = ret.Error(1)
+ }
+ return r0, r1
+}
+
+// MockAlertmanager_UpdateRoutePolicyByID_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'UpdateRoutePolicyByID'
+type MockAlertmanager_UpdateRoutePolicyByID_Call struct {
+ *mock.Call
+}
+
+// UpdateRoutePolicyByID is a helper method to define mock.On call
+// - ctx context.Context
+// - routeID string
+// - route *alertmanagertypes.PostableRoutePolicy
+func (_e *MockAlertmanager_Expecter) UpdateRoutePolicyByID(ctx interface{}, routeID interface{}, route interface{}) *MockAlertmanager_UpdateRoutePolicyByID_Call {
+ return &MockAlertmanager_UpdateRoutePolicyByID_Call{Call: _e.mock.On("UpdateRoutePolicyByID", ctx, routeID, route)}
+}
+
+func (_c *MockAlertmanager_UpdateRoutePolicyByID_Call) Run(run func(ctx context.Context, routeID string, route *alertmanagertypes.PostableRoutePolicy)) *MockAlertmanager_UpdateRoutePolicyByID_Call {
+ _c.Call.Run(func(args mock.Arguments) {
+ var arg0 context.Context
+ if args[0] != nil {
+ arg0 = args[0].(context.Context)
+ }
+ var arg1 string
+ if args[1] != nil {
+ arg1 = args[1].(string)
+ }
+ var arg2 *alertmanagertypes.PostableRoutePolicy
+ if args[2] != nil {
+ arg2 = args[2].(*alertmanagertypes.PostableRoutePolicy)
+ }
+ run(
+ arg0,
+ arg1,
+ arg2,
+ )
+ })
+ return _c
+}
+
+func (_c *MockAlertmanager_UpdateRoutePolicyByID_Call) Return(gettableRoutePolicy *alertmanagertypes.GettableRoutePolicy, err error) *MockAlertmanager_UpdateRoutePolicyByID_Call {
+ _c.Call.Return(gettableRoutePolicy, err)
+ return _c
+}
+
+func (_c *MockAlertmanager_UpdateRoutePolicyByID_Call) RunAndReturn(run func(ctx context.Context, routeID string, route *alertmanagertypes.PostableRoutePolicy) (*alertmanagertypes.GettableRoutePolicy, error)) *MockAlertmanager_UpdateRoutePolicyByID_Call {
+ _c.Call.Return(run)
+ return _c
+}
diff --git a/pkg/query-service/rules/base_rule.go b/pkg/query-service/rules/base_rule.go
index 80d896d787..7594b7fc7b 100644
--- a/pkg/query-service/rules/base_rule.go
+++ b/pkg/query-service/rules/base_rule.go
@@ -191,6 +191,13 @@ func (r *BaseRule) currentAlerts() []*ruletypes.Alert {
return alerts
}
+// ShouldSendUnmatched returns true if the rule should send unmatched samples
+// during alert evaluation, even if they don't match the rule condition.
+// This is useful in testing the rule.
+func (r *BaseRule) ShouldSendUnmatched() bool {
+ return r.sendUnmatched
+}
+
// ActiveAlertsLabelFP returns a map of active alert labels fingerprint and
// the fingerprint is computed using the QueryResultLables.Hash() method.
// We use the QueryResultLables instead of labels as these labels are raw labels
diff --git a/pkg/query-service/rules/manager_test.go b/pkg/query-service/rules/manager_test.go
new file mode 100644
index 0000000000..681c67dde8
--- /dev/null
+++ b/pkg/query-service/rules/manager_test.go
@@ -0,0 +1,278 @@
+package rules
+
+import (
+ "context"
+ "encoding/json"
+ "math"
+ "strconv"
+ "testing"
+ "time"
+
+ "github.com/SigNoz/signoz/pkg/alertmanager"
+ alertmanagermock "github.com/SigNoz/signoz/pkg/alertmanager/mocks"
+ "github.com/SigNoz/signoz/pkg/instrumentation/instrumentationtest"
+ "github.com/SigNoz/signoz/pkg/prometheus"
+ "github.com/SigNoz/signoz/pkg/prometheus/prometheustest"
+ "github.com/SigNoz/signoz/pkg/sqlstore"
+ "github.com/SigNoz/signoz/pkg/sqlstore/sqlstoretest"
+ "github.com/SigNoz/signoz/pkg/telemetrystore"
+ "github.com/SigNoz/signoz/pkg/telemetrystore/telemetrystoretest"
+ "github.com/SigNoz/signoz/pkg/types/alertmanagertypes"
+ "github.com/SigNoz/signoz/pkg/types/metrictypes"
+ "github.com/SigNoz/signoz/pkg/valuer"
+ "github.com/stretchr/testify/assert"
+ "github.com/stretchr/testify/mock"
+ "github.com/stretchr/testify/require"
+
+ cmock "github.com/srikanthccv/ClickHouse-go-mock"
+)
+
+func TestManager_TestNotification_SendUnmatched_ThresholdRule(t *testing.T) {
+ target := 10.0
+ recovery := 5.0
+
+ for _, tc := range TcTestNotiSendUnmatchedThresholdRule {
+ t.Run(tc.Name, func(t *testing.T) {
+ rule := ThresholdRuleAtLeastOnceValueAbove(target, &recovery)
+
+ // Marshal rule to JSON as TestNotification expects
+ ruleBytes, err := json.Marshal(rule)
+ require.NoError(t, err)
+
+ orgID := valuer.GenerateUUID()
+
+ // for saving temp alerts that are triggered via TestNotification
+ triggeredTestAlerts := []map[*alertmanagertypes.PostableAlert][]string{}
+
+ // Create manager using test factory with hooks
+ mgr := NewTestManager(t, &TestManagerOptions{
+ AlertmanagerHook: func(am alertmanager.Alertmanager) {
+ mockAM := am.(*alertmanagermock.MockAlertmanager)
+ // mock set notification config
+ mockAM.On("SetNotificationConfig", mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(nil)
+ // for saving temp alerts that are triggered via TestNotification
+ if tc.ExpectAlerts > 0 {
+ mockAM.On("TestAlert", mock.Anything, mock.Anything, mock.Anything, mock.Anything).Run(func(args mock.Arguments) {
+ triggeredTestAlerts = append(triggeredTestAlerts, args.Get(3).(map[*alertmanagertypes.PostableAlert][]string))
+ }).Return(nil).Times(tc.ExpectAlerts)
+ }
+ },
+ SqlStoreHook: func(store sqlstore.SQLStore) {
+ mockStore := store.(*sqlstoretest.Provider)
+ // Mock the organizations query that SendAlerts makes
+ // Bun generates: SELECT id FROM organizations LIMIT 1 (or SELECT "id" FROM "organizations" LIMIT 1)
+ orgRows := mockStore.Mock().NewRows([]string{"id"}).AddRow(orgID.StringValue())
+ // Match bun's generated query pattern - bun may quote identifiers
+ mockStore.Mock().ExpectQuery("SELECT (.+) FROM (.+)organizations(.+) LIMIT (.+)").WillReturnRows(orgRows)
+ },
+ TelemetryStoreHook: func(store telemetrystore.TelemetryStore) {
+ mockStore := store.(*telemetrystoretest.Provider)
+ // Set up mock data for telemetry store
+ cols := make([]cmock.ColumnType, 0)
+ cols = append(cols, cmock.ColumnType{Name: "value", Type: "Float64"})
+ cols = append(cols, cmock.ColumnType{Name: "attr", Type: "String"})
+ cols = append(cols, cmock.ColumnType{Name: "ts", Type: "DateTime"})
+
+ alertDataRows := cmock.NewRows(cols, tc.Values)
+
+ mock := mockStore.Mock()
+
+ // Generate query arguments for the metric query
+ evalTime := time.Now().UTC()
+ evalWindow := 5 * time.Minute
+ evalDelay := time.Duration(0)
+ queryArgs := GenerateMetricQueryCHArgs(
+ evalTime,
+ evalWindow,
+ evalDelay,
+ "probe_success",
+ metrictypes.Unspecified,
+ )
+
+ mock.ExpectQuery("*WITH __temporal_aggregation_cte*").
+ WithArgs(queryArgs...).
+ WillReturnRows(alertDataRows)
+ },
+ })
+
+ count, apiErr := mgr.TestNotification(context.Background(), orgID, string(ruleBytes))
+ if apiErr != nil {
+ t.Logf("TestNotification error: %v, type: %s", apiErr.Err, apiErr.Typ)
+ }
+ require.Nil(t, apiErr)
+ assert.Equal(t, tc.ExpectAlerts, count)
+
+ if tc.ExpectAlerts > 0 {
+ // check if the alert has been triggered
+ require.Len(t, triggeredTestAlerts, 1)
+ var gotAlerts []*alertmanagertypes.PostableAlert
+ for a := range triggeredTestAlerts[0] {
+ gotAlerts = append(gotAlerts, a)
+ }
+ require.Len(t, gotAlerts, tc.ExpectAlerts)
+ // check if the alert has triggered with correct threshold value
+ if tc.ExpectValue != 0 {
+ assert.Equal(t, strconv.FormatFloat(tc.ExpectValue, 'f', -1, 64), gotAlerts[0].Annotations["value"])
+ }
+ } else {
+ // check if no alerts have been triggered
+ assert.Empty(t, triggeredTestAlerts)
+ }
+ })
+ }
+}
+
+func TestManager_TestNotification_SendUnmatched_PromRule(t *testing.T) {
+ target := 10.0
+
+ for _, tc := range TcTestNotificationSendUnmatchedPromRule {
+ t.Run(tc.Name, func(t *testing.T) {
+ // Capture base time once per test case to ensure consistent timestamps
+ baseTime := time.Now().UTC()
+
+ rule := BuildPromAtLeastOnceValueAbove(target, nil)
+
+ // Marshal rule to JSON as TestNotification expects
+ ruleBytes, err := json.Marshal(rule)
+ require.NoError(t, err)
+
+ orgID := valuer.GenerateUUID()
+
+ // for saving temp alerts that are triggered via TestNotification
+ triggeredTestAlerts := []map[*alertmanagertypes.PostableAlert][]string{}
+
+ // Variable to store promProvider for cleanup
+ var promProvider *prometheustest.Provider
+
+ // Create manager using test factory with hooks
+ mgr := NewTestManager(t, &TestManagerOptions{
+ AlertmanagerHook: func(am alertmanager.Alertmanager) {
+ mockAM := am.(*alertmanagermock.MockAlertmanager)
+ // mock set notification config
+ mockAM.On("SetNotificationConfig", mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(nil)
+ // for saving temp alerts that are triggered via TestNotification
+ if tc.ExpectAlerts > 0 {
+ mockAM.On("TestAlert", mock.Anything, mock.Anything, mock.Anything, mock.Anything).Run(func(args mock.Arguments) {
+ triggeredTestAlerts = append(triggeredTestAlerts, args.Get(3).(map[*alertmanagertypes.PostableAlert][]string))
+ }).Return(nil).Times(tc.ExpectAlerts)
+ }
+ },
+ SqlStoreHook: func(store sqlstore.SQLStore) {
+ mockStore := store.(*sqlstoretest.Provider)
+ // Mock the organizations query that SendAlerts makes
+ orgRows := mockStore.Mock().NewRows([]string{"id"}).AddRow(orgID.StringValue())
+ mockStore.Mock().ExpectQuery("SELECT (.+) FROM (.+)organizations(.+) LIMIT (.+)").WillReturnRows(orgRows)
+ },
+ TelemetryStoreHook: func(store telemetrystore.TelemetryStore) {
+ mockStore := store.(*telemetrystoretest.Provider)
+
+ // Set up Prometheus-specific mock data
+ // Fingerprint columns for Prometheus queries
+ fingerprintCols := []cmock.ColumnType{
+ {Name: "fingerprint", Type: "UInt64"},
+ {Name: "any(labels)", Type: "String"},
+ }
+
+ // Samples columns for Prometheus queries
+ samplesCols := []cmock.ColumnType{
+ {Name: "metric_name", Type: "String"},
+ {Name: "fingerprint", Type: "UInt64"},
+ {Name: "unix_milli", Type: "Int64"},
+ {Name: "value", Type: "Float64"},
+ {Name: "flags", Type: "UInt32"},
+ }
+
+ // Calculate query time range similar to Prometheus rule tests
+ // TestNotification uses time.Now().UTC() for evaluation
+ // We calculate the query window based on current time to match what the actual evaluation will use
+ evalTime := baseTime
+ evalWindowMs := int64(5 * 60 * 1000) // 5 minutes in ms
+ evalTimeMs := evalTime.UnixMilli()
+ queryStart := ((evalTimeMs-2*evalWindowMs)/60000)*60000 + 1 // truncate to minute + 1ms
+ queryEnd := (evalTimeMs / 60000) * 60000 // truncate to minute
+
+ // Create fingerprint data
+ fingerprint := uint64(12345)
+ labelsJSON := `{"__name__":"test_metric"}`
+ fingerprintData := [][]interface{}{
+ {fingerprint, labelsJSON},
+ }
+ fingerprintRows := cmock.NewRows(fingerprintCols, fingerprintData)
+
+ // Create samples data from test case values, calculating timestamps relative to baseTime
+ validSamplesData := make([][]interface{}, 0)
+ for _, v := range tc.Values {
+ // Skip NaN and Inf values in the samples data
+ if math.IsNaN(v.Value) || math.IsInf(v.Value, 0) {
+ continue
+ }
+ // Calculate timestamp relative to baseTime
+ sampleTimestamp := baseTime.Add(v.Offset).UnixMilli()
+ validSamplesData = append(validSamplesData, []interface{}{
+ "test_metric",
+ fingerprint,
+ sampleTimestamp,
+ v.Value,
+ uint32(0), // flags - 0 means normal value
+ })
+ }
+ samplesRows := cmock.NewRows(samplesCols, validSamplesData)
+
+ mock := mockStore.Mock()
+
+ // Mock the fingerprint query (for Prometheus label matching)
+ mock.ExpectQuery("SELECT fingerprint, any").
+ WithArgs("test_metric", "__name__", "test_metric").
+ WillReturnRows(fingerprintRows)
+
+ // Mock the samples query (for Prometheus metric data)
+ mock.ExpectQuery("SELECT metric_name, fingerprint, unix_milli").
+ WithArgs(
+ "test_metric",
+ "test_metric",
+ "__name__",
+ "test_metric",
+ queryStart,
+ queryEnd,
+ ).
+ WillReturnRows(samplesRows)
+
+ // Create Prometheus provider for this test
+ promProvider = prometheustest.New(context.Background(), instrumentationtest.New().ToProviderSettings(), prometheus.Config{}, store)
+ },
+ ManagerOptionsHook: func(opts *ManagerOptions) {
+ // Set Prometheus provider for PromQL queries
+ if promProvider != nil {
+ opts.Prometheus = promProvider
+ }
+ },
+ })
+
+ count, apiErr := mgr.TestNotification(context.Background(), orgID, string(ruleBytes))
+ if apiErr != nil {
+ t.Logf("TestNotification error: %v, type: %s", apiErr.Err, apiErr.Typ)
+ }
+ require.Nil(t, apiErr)
+ assert.Equal(t, tc.ExpectAlerts, count)
+
+ if tc.ExpectAlerts > 0 {
+ // check if the alert has been triggered
+ require.Len(t, triggeredTestAlerts, 1)
+ var gotAlerts []*alertmanagertypes.PostableAlert
+ for a := range triggeredTestAlerts[0] {
+ gotAlerts = append(gotAlerts, a)
+ }
+ require.Len(t, gotAlerts, tc.ExpectAlerts)
+ // check if the alert has triggered with correct threshold value
+ if tc.ExpectValue != 0 && !math.IsNaN(tc.ExpectValue) && !math.IsInf(tc.ExpectValue, 0) {
+ assert.Equal(t, strconv.FormatFloat(tc.ExpectValue, 'f', -1, 64), gotAlerts[0].Annotations["value"])
+ }
+ } else {
+ // check if no alerts have been triggered
+ assert.Empty(t, triggeredTestAlerts)
+ }
+
+ promProvider.Close()
+ })
+ }
+}
diff --git a/pkg/query-service/rules/manager_test_data.go b/pkg/query-service/rules/manager_test_data.go
new file mode 100644
index 0000000000..fca4f46575
--- /dev/null
+++ b/pkg/query-service/rules/manager_test_data.go
@@ -0,0 +1,228 @@
+package rules
+
+import (
+ "math"
+ "time"
+
+ v3 "github.com/SigNoz/signoz/pkg/query-service/model/v3"
+ "github.com/SigNoz/signoz/pkg/types/metrictypes"
+ qbtypes "github.com/SigNoz/signoz/pkg/types/querybuildertypes/querybuildertypesv5"
+ ruletypes "github.com/SigNoz/signoz/pkg/types/ruletypes"
+ "github.com/SigNoz/signoz/pkg/types/telemetrytypes"
+)
+
+// ThresholdRuleTestCase defines test case structure for threshold rule test notifications
+type ThresholdRuleTestCase struct {
+ Name string
+ Values [][]interface{}
+ ExpectAlerts int
+ ExpectValue float64
+}
+
+// PromRuleTestValue represents a single value point in a PromQL rule test case
+type PromRuleTestValue struct {
+ Offset time.Duration // offset from baseTime (negative = in the past)
+ Value float64
+}
+
+// PromRuleTestCase defines test case structure for PromQL rule test notifications
+type PromRuleTestCase struct {
+ Name string
+ Values []PromRuleTestValue
+ ExpectAlerts int
+ ExpectValue float64
+}
+
+// ThresholdRuleAtLeastOnceValueAbove creates a PostableRule for threshold rule test notifications
+func ThresholdRuleAtLeastOnceValueAbove(target float64, recovery *float64) ruletypes.PostableRule {
+ return ruletypes.PostableRule{
+ AlertName: "test-alert",
+ AlertType: ruletypes.AlertTypeMetric,
+ RuleType: ruletypes.RuleTypeThreshold,
+ Evaluation: &ruletypes.EvaluationEnvelope{Kind: ruletypes.RollingEvaluation, Spec: ruletypes.RollingWindow{
+ EvalWindow: ruletypes.Duration(5 * time.Minute),
+ Frequency: ruletypes.Duration(1 * time.Minute),
+ }},
+ Labels: map[string]string{
+ "service.name": "frontend",
+ },
+ Annotations: map[string]string{
+ "value": "{{$value}}",
+ },
+ Version: "v5",
+ RuleCondition: &ruletypes.RuleCondition{
+ MatchType: ruletypes.AtleastOnce,
+ CompareOp: ruletypes.ValueIsAbove,
+ Target: &target,
+ CompositeQuery: &v3.CompositeQuery{
+ QueryType: v3.QueryTypeBuilder,
+ Queries: []qbtypes.QueryEnvelope{
+ {
+ Type: qbtypes.QueryTypeBuilder,
+ Spec: qbtypes.QueryBuilderQuery[qbtypes.MetricAggregation]{
+ Name: "A",
+ StepInterval: qbtypes.Step{Duration: 60 * time.Second},
+ Signal: telemetrytypes.SignalMetrics,
+
+ Aggregations: []qbtypes.MetricAggregation{
+ {
+ MetricName: "probe_success",
+ TimeAggregation: metrictypes.TimeAggregationAvg,
+ SpaceAggregation: metrictypes.SpaceAggregationAvg,
+ },
+ },
+ },
+ },
+ },
+ },
+ Thresholds: &ruletypes.RuleThresholdData{
+ Kind: ruletypes.BasicThresholdKind,
+ Spec: ruletypes.BasicRuleThresholds{
+ {
+ Name: "primary",
+ TargetValue: &target,
+ RecoveryTarget: recovery,
+ MatchType: ruletypes.AtleastOnce,
+ CompareOp: ruletypes.ValueIsAbove,
+ },
+ },
+ },
+ },
+ NotificationSettings: &ruletypes.NotificationSettings{},
+ }
+}
+
+// BuildPromAtLeastOnceValueAbove creates a PostableRule for PromQL rule test notifications
+func BuildPromAtLeastOnceValueAbove(target float64, recovery *float64) ruletypes.PostableRule {
+ return ruletypes.PostableRule{
+ AlertName: "test-prom-alert",
+ AlertType: ruletypes.AlertTypeMetric,
+ RuleType: ruletypes.RuleTypeProm,
+ Evaluation: &ruletypes.EvaluationEnvelope{Kind: ruletypes.RollingEvaluation, Spec: ruletypes.RollingWindow{
+ EvalWindow: ruletypes.Duration(5 * time.Minute),
+ Frequency: ruletypes.Duration(1 * time.Minute),
+ }},
+ Labels: map[string]string{
+ "service.name": "frontend",
+ },
+ Annotations: map[string]string{
+ "value": "{{$value}}",
+ },
+ Version: "v5",
+ RuleCondition: &ruletypes.RuleCondition{
+ MatchType: ruletypes.AtleastOnce,
+ SelectedQuery: "A",
+ CompareOp: ruletypes.ValueIsAbove,
+ Target: &target,
+ CompositeQuery: &v3.CompositeQuery{
+ QueryType: v3.QueryTypePromQL,
+ PanelType: v3.PanelTypeGraph,
+ Queries: []qbtypes.QueryEnvelope{
+ {
+ Type: qbtypes.QueryTypePromQL,
+ Spec: qbtypes.PromQuery{
+ Name: "A",
+ Query: "{\"test_metric\"}",
+ Disabled: false,
+ Stats: false,
+ },
+ },
+ },
+ },
+ Thresholds: &ruletypes.RuleThresholdData{
+ Kind: ruletypes.BasicThresholdKind,
+ Spec: ruletypes.BasicRuleThresholds{
+ {
+ Name: "primary",
+ TargetValue: &target,
+ RecoveryTarget: recovery,
+ MatchType: ruletypes.AtleastOnce,
+ CompareOp: ruletypes.ValueIsAbove,
+ Channels: []string{"slack"},
+ },
+ },
+ },
+ },
+ NotificationSettings: &ruletypes.NotificationSettings{},
+ }
+}
+
+var (
+ // TcTestNotiSendUnmatchedThresholdRule contains test cases for threshold rule test notifications
+ TcTestNotiSendUnmatchedThresholdRule = []ThresholdRuleTestCase{
+ {
+ Name: "return first valid point in case of test notification",
+ Values: [][]interface{}{
+ {float64(3), "attr", time.Now()},
+ {float64(4), "attr", time.Now().Add(1 * time.Minute)},
+ },
+ ExpectAlerts: 1,
+ ExpectValue: 3,
+ },
+ {
+ Name: "No data in DB so no alerts fired",
+ Values: [][]interface{}{},
+ ExpectAlerts: 0,
+ },
+ {
+ Name: "return first valid point in case of test notification skips NaN and Inf",
+ Values: [][]interface{}{
+ {math.NaN(), "attr", time.Now()},
+ {math.Inf(1), "attr", time.Now().Add(1 * time.Minute)},
+ {float64(7), "attr", time.Now().Add(2 * time.Minute)},
+ },
+ ExpectAlerts: 1,
+ ExpectValue: 7,
+ },
+ {
+ Name: "If found matching alert with given target value, return the alerting value rather than first valid point",
+ Values: [][]interface{}{
+ {float64(1), "attr", time.Now()},
+ {float64(2), "attr", time.Now().Add(1 * time.Minute)},
+ {float64(3), "attr", time.Now().Add(2 * time.Minute)},
+ {float64(12), "attr", time.Now().Add(3 * time.Minute)},
+ },
+ ExpectAlerts: 1,
+ ExpectValue: 12,
+ },
+ }
+
+ // TcTestNotificationSendUnmatchedPromRule contains test cases for PromQL rule test notifications
+ TcTestNotificationSendUnmatchedPromRule = []PromRuleTestCase{
+ {
+ Name: "return first valid point in case of test notification",
+ Values: []PromRuleTestValue{
+ {Offset: -4 * time.Minute, Value: 3},
+ {Offset: -3 * time.Minute, Value: 4},
+ },
+ ExpectAlerts: 1,
+ ExpectValue: 3,
+ },
+ {
+ Name: "No data in DB so no alerts fired",
+ Values: []PromRuleTestValue{},
+ ExpectAlerts: 0,
+ },
+ {
+ Name: "return first valid point in case of test notification skips NaN and Inf",
+ Values: []PromRuleTestValue{
+ {Offset: -4 * time.Minute, Value: math.NaN()},
+ {Offset: -3 * time.Minute, Value: math.Inf(1)},
+ {Offset: -2 * time.Minute, Value: 7},
+ },
+ ExpectAlerts: 1,
+ ExpectValue: 7,
+ },
+ {
+ Name: "If found matching alert with given target value, return the alerting value rather than first valid point",
+ Values: []PromRuleTestValue{
+ {Offset: -4 * time.Minute, Value: 1},
+ {Offset: -3 * time.Minute, Value: 2},
+ {Offset: -2 * time.Minute, Value: 3},
+ {Offset: -1 * time.Minute, Value: 12},
+ },
+ ExpectAlerts: 1,
+ ExpectValue: 12,
+ },
+ }
+)
diff --git a/pkg/query-service/rules/managertestfactory.go b/pkg/query-service/rules/managertestfactory.go
new file mode 100644
index 0000000000..90d1b08fba
--- /dev/null
+++ b/pkg/query-service/rules/managertestfactory.go
@@ -0,0 +1,145 @@
+package rules
+
+import (
+ "context"
+ "testing"
+ "time"
+
+ "github.com/DATA-DOG/go-sqlmock"
+ "github.com/SigNoz/signoz/pkg/alertmanager"
+ alertmanagermock "github.com/SigNoz/signoz/pkg/alertmanager/mocks"
+ "github.com/SigNoz/signoz/pkg/cache"
+ "github.com/SigNoz/signoz/pkg/cache/cachetest"
+ "github.com/SigNoz/signoz/pkg/flagger"
+ "github.com/SigNoz/signoz/pkg/instrumentation/instrumentationtest"
+ "github.com/SigNoz/signoz/pkg/prometheus"
+ "github.com/SigNoz/signoz/pkg/prometheus/prometheustest"
+ "github.com/SigNoz/signoz/pkg/querier"
+ "github.com/SigNoz/signoz/pkg/querier/signozquerier"
+ "github.com/SigNoz/signoz/pkg/query-service/app/clickhouseReader"
+ "github.com/SigNoz/signoz/pkg/sqlstore"
+ "github.com/SigNoz/signoz/pkg/sqlstore/sqlstoretest"
+ "github.com/SigNoz/signoz/pkg/telemetrystore"
+ "github.com/SigNoz/signoz/pkg/telemetrystore/telemetrystoretest"
+ "github.com/stretchr/testify/require"
+ "go.uber.org/zap"
+)
+
+type queryMatcherAny struct {
+}
+
+func (m *queryMatcherAny) Match(x string, y string) error {
+ return nil
+}
+
+// TestManagerOptions provides options for customizing the test manager creation.
+type TestManagerOptions struct {
+ // AlertmanagerHook is a function that will be called with the Alertmanager mock
+ // after it's created but before it's used. This allows customizing the mock behavior.
+ AlertmanagerHook func(alertmanager.Alertmanager)
+
+ // SqlStoreHook is a function that will be called with the SQLStore mock
+ // after it's created but before it's used. This allows customizing the mock behavior.
+ SqlStoreHook func(sqlstore.SQLStore)
+
+ // TelemetryStoreHook is a function that will be called with the TelemetryStore mock
+ // after it's created but before it's used. This allows customizing the mock behavior.
+ TelemetryStoreHook func(telemetrystore.TelemetryStore)
+
+ // ManagerOptionsHook is a function that will be called with the ManagerOptions
+ // before the manager is created. This allows customizing the manager options (e.g., setting Prometheus).
+ ManagerOptionsHook func(*ManagerOptions)
+}
+
+// NewTestManager creates a Manager instance for testing purposes.
+// It sets up all the necessary mocks and dependencies required for testing.
+// Options can be provided to customize the manager behavior. If nil, default options are used.
+func NewTestManager(t *testing.T, testOpts *TestManagerOptions) *Manager {
+ // mocking the alertmanager + capturing the triggered test alerts
+ fAlert := alertmanagermock.NewMockAlertmanager(t)
+
+ // Call the Alertmanager hook if provided
+ if testOpts != nil && testOpts.AlertmanagerHook != nil {
+ testOpts.AlertmanagerHook(fAlert)
+ }
+
+ cacheObj, err := cachetest.New(cache.Config{
+ Provider: "memory",
+ Memory: cache.Memory{
+ NumCounters: 1000,
+ MaxCost: 1 << 20,
+ },
+ })
+ require.NoError(t, err)
+
+ // Create SQLStore mock
+ sqlStore := sqlstoretest.New(sqlstore.Config{Provider: "sqlite"}, sqlmock.QueryMatcherRegexp)
+
+ // Call the SqlStore hook if provided
+ if testOpts != nil && testOpts.SqlStoreHook != nil {
+ testOpts.SqlStoreHook(sqlStore)
+ }
+
+ // Create TelemetryStore mock
+ telemetryStore := telemetrystoretest.New(telemetrystore.Config{}, &queryMatcherAny{})
+
+ // Call the TelemetryStore hook if provided
+ if testOpts != nil && testOpts.TelemetryStoreHook != nil {
+ testOpts.TelemetryStoreHook(telemetryStore)
+ }
+
+ // Create reader with mocked telemetry store
+ readerCache, err := cachetest.New(cache.Config{
+ Provider: "memory",
+ Memory: cache.Memory{
+ NumCounters: 10 * 1000,
+ MaxCost: 1 << 26,
+ },
+ })
+ require.NoError(t, err)
+
+ options := clickhouseReader.NewOptions("", "", "archiveNamespace")
+ providerSettings := instrumentationtest.New().ToProviderSettings()
+ prometheus := prometheustest.New(context.Background(), providerSettings, prometheus.Config{}, telemetryStore)
+ reader := clickhouseReader.NewReader(
+ nil,
+ telemetryStore,
+ prometheus,
+ "",
+ time.Duration(time.Second),
+ nil,
+ readerCache,
+ options,
+ )
+
+ flagger, err := flagger.New(context.Background(), instrumentationtest.New().ToProviderSettings(), flagger.Config{}, flagger.MustNewRegistry())
+ if err != nil {
+ t.Fatalf("failed to create flagger: %v", err)
+ }
+
+ // Create mock querierV5 with test values
+ providerFactory := signozquerier.NewFactory(telemetryStore, prometheus, readerCache, flagger)
+ mockQuerier, err := providerFactory.New(context.Background(), providerSettings, querier.Config{})
+ require.NoError(t, err)
+
+ mgrOpts := &ManagerOptions{
+ Logger: zap.NewNop(),
+ SLogger: instrumentationtest.New().Logger(),
+ Cache: cacheObj,
+ Alertmanager: fAlert,
+ Querier: mockQuerier,
+ TelemetryStore: telemetryStore,
+ Reader: reader,
+ SqlStore: sqlStore, // SQLStore needed for SendAlerts to query organizations
+ }
+
+ // Call the ManagerOptions hook if provided to allow customization
+ if testOpts != nil && testOpts.ManagerOptionsHook != nil {
+ testOpts.ManagerOptionsHook(mgrOpts)
+ }
+
+ mgr, err := NewManager(mgrOpts)
+ require.NoError(t, err)
+
+ return mgr
+}
diff --git a/pkg/query-service/rules/prom_rule.go b/pkg/query-service/rules/prom_rule.go
index d7c5ca952f..e45d61acba 100644
--- a/pkg/query-service/rules/prom_rule.go
+++ b/pkg/query-service/rules/prom_rule.go
@@ -138,7 +138,8 @@ func (r *PromRule) buildAndRunQuery(ctx context.Context, ts time.Time) (ruletype
var resultVector ruletypes.Vector
for _, series := range res {
resultSeries, err := r.Threshold.Eval(toCommonSeries(series), r.Unit(), ruletypes.EvalData{
- ActiveAlerts: r.ActiveAlertsLabelFP(),
+ ActiveAlerts: r.ActiveAlertsLabelFP(),
+ SendUnmatched: r.ShouldSendUnmatched(),
})
if err != nil {
return nil, err
diff --git a/pkg/query-service/rules/threshold_rule.go b/pkg/query-service/rules/threshold_rule.go
index 2d81f98328..437f06e8ce 100644
--- a/pkg/query-service/rules/threshold_rule.go
+++ b/pkg/query-service/rules/threshold_rule.go
@@ -489,7 +489,8 @@ func (r *ThresholdRule) buildAndRunQuery(ctx context.Context, orgID valuer.UUID,
}
}
resultSeries, err := r.Threshold.Eval(*series, r.Unit(), ruletypes.EvalData{
- ActiveAlerts: r.ActiveAlertsLabelFP(),
+ ActiveAlerts: r.ActiveAlertsLabelFP(),
+ SendUnmatched: r.ShouldSendUnmatched(),
})
if err != nil {
return nil, err
@@ -568,7 +569,8 @@ func (r *ThresholdRule) buildAndRunQueryV5(ctx context.Context, orgID valuer.UUI
}
}
resultSeries, err := r.Threshold.Eval(*series, r.Unit(), ruletypes.EvalData{
- ActiveAlerts: r.ActiveAlertsLabelFP(),
+ ActiveAlerts: r.ActiveAlertsLabelFP(),
+ SendUnmatched: r.ShouldSendUnmatched(),
})
if err != nil {
return nil, err
diff --git a/pkg/query-service/rules/threshold_rule_test.go b/pkg/query-service/rules/threshold_rule_test.go
index f3e9804680..76f1e55d6a 100644
--- a/pkg/query-service/rules/threshold_rule_test.go
+++ b/pkg/query-service/rules/threshold_rule_test.go
@@ -2,6 +2,7 @@ package rules
import (
"context"
+ "math"
"strings"
"testing"
"time"
@@ -608,13 +609,6 @@ func TestThresholdRuleClickHouseTmpl(t *testing.T) {
}
}
-type queryMatcherAny struct {
-}
-
-func (m *queryMatcherAny) Match(x string, y string) error {
- return nil
-}
-
func TestThresholdRuleUnitCombinations(t *testing.T) {
postableRule := ruletypes.PostableRule{
AlertName: "Units test",
@@ -1519,6 +1513,283 @@ func TestThresholdRuleEval_MatchPlusCompareOps(t *testing.T) {
}
+// TestThresholdRuleEval_SendUnmatchedBypassesRecovery tests the case where the sendUnmatched is true and the recovery target is met.
+// In this case, the rule should return the first sample as sendUnmatched is supposed to be used in tests and in case of tests
+// recovery target is expected to be present. This test make sure this behavior is working as expected.
+func TestThresholdRuleEval_SendUnmatchedBypassesRecovery(t *testing.T) {
+ target := 10.0
+ recovery := 4.0
+
+ postableRule := ruletypes.PostableRule{
+ AlertName: "Send unmatched bypass recovery",
+ AlertType: ruletypes.AlertTypeMetric,
+ RuleType: ruletypes.RuleTypeThreshold,
+ Evaluation: &ruletypes.EvaluationEnvelope{Kind: ruletypes.RollingEvaluation, Spec: ruletypes.RollingWindow{
+ EvalWindow: ruletypes.Duration(5 * time.Minute),
+ Frequency: ruletypes.Duration(1 * time.Minute),
+ }},
+ RuleCondition: &ruletypes.RuleCondition{
+ CompositeQuery: &v3.CompositeQuery{
+ QueryType: v3.QueryTypeBuilder,
+ BuilderQueries: map[string]*v3.BuilderQuery{
+ "A": {
+ QueryName: "A",
+ StepInterval: 60,
+ AggregateAttribute: v3.AttributeKey{
+ Key: "probe_success",
+ },
+ AggregateOperator: v3.AggregateOperatorNoOp,
+ DataSource: v3.DataSourceMetrics,
+ Expression: "A",
+ },
+ },
+ },
+ },
+ }
+
+ postableRule.RuleCondition.Thresholds = &ruletypes.RuleThresholdData{
+ Kind: ruletypes.BasicThresholdKind,
+ Spec: ruletypes.BasicRuleThresholds{
+ {
+ Name: "primary",
+ TargetValue: &target,
+ RecoveryTarget: &recovery,
+ MatchType: ruletypes.AtleastOnce,
+ CompareOp: ruletypes.ValueIsAbove,
+ },
+ },
+ }
+
+ logger := instrumentationtest.New().Logger()
+ rule, err := NewThresholdRule("69", valuer.GenerateUUID(), &postableRule, nil, nil, logger, WithEvalDelay(2*time.Minute))
+ require.NoError(t, err)
+
+ now := time.Now()
+ series := v3.Series{
+ Points: []v3.Point{
+ {Timestamp: now.UnixMilli(), Value: 3},
+ {Timestamp: now.Add(time.Minute).UnixMilli(), Value: 4},
+ {Timestamp: now.Add(2 * time.Minute).UnixMilli(), Value: 5},
+ },
+ Labels: map[string]string{
+ "service.name": "frontend",
+ },
+ LabelsArray: []map[string]string{
+ {
+ "service.name": "frontend",
+ },
+ },
+ }
+
+ alertLabels := ruletypes.PrepareSampleLabelsForRule(series.Labels, "primary")
+ activeAlerts := map[uint64]struct{}{alertLabels.Hash(): {}}
+
+ resultVectors, err := rule.Threshold.Eval(series, rule.Unit(), ruletypes.EvalData{
+ ActiveAlerts: activeAlerts,
+ SendUnmatched: true,
+ })
+ require.NoError(t, err)
+ require.Len(t, resultVectors, 1, "expected unmatched sample to be returned")
+
+ smpl := resultVectors[0]
+ assert.Equal(t, float64(3), smpl.V)
+ assert.False(t, smpl.IsRecovering, "unmatched path should not mark sample as recovering")
+ assert.Equal(t, float64(4), *smpl.RecoveryTarget, "unmatched path should set recovery target")
+ assert.InDelta(t, target, smpl.Target, 0.01)
+ assert.Equal(t, "primary", smpl.Metric.Get(ruletypes.LabelThresholdName))
+}
+
+func intPtr(v int) *int {
+ return &v
+}
+
+// TestThresholdRuleEval_SendUnmatchedVariants tests the different variants of sendUnmatched behavior.
+// It tests the case where sendUnmatched is true, false.
+func TestThresholdRuleEval_SendUnmatchedVariants(t *testing.T) {
+ target := 10.0
+ recovery := 5.0
+ postableRule := ruletypes.PostableRule{
+ AlertName: "Send unmatched variants",
+ AlertType: ruletypes.AlertTypeMetric,
+ RuleType: ruletypes.RuleTypeThreshold,
+ Evaluation: &ruletypes.EvaluationEnvelope{Kind: ruletypes.RollingEvaluation, Spec: ruletypes.RollingWindow{
+ EvalWindow: ruletypes.Duration(5 * time.Minute),
+ Frequency: ruletypes.Duration(1 * time.Minute),
+ }},
+ RuleCondition: &ruletypes.RuleCondition{
+ CompositeQuery: &v3.CompositeQuery{
+ QueryType: v3.QueryTypeBuilder,
+ BuilderQueries: map[string]*v3.BuilderQuery{
+ "A": {
+ QueryName: "A",
+ StepInterval: 60,
+ AggregateAttribute: v3.AttributeKey{
+ Key: "probe_success",
+ },
+ AggregateOperator: v3.AggregateOperatorNoOp,
+ DataSource: v3.DataSourceMetrics,
+ Expression: "A",
+ },
+ },
+ },
+ },
+ }
+
+ now := time.Now()
+
+ tests := []recoveryTestCase{
+ {
+ description: "sendUnmatched returns first valid point",
+ values: v3.Series{
+ Points: []v3.Point{
+ {Timestamp: now.UnixMilli(), Value: 3},
+ {Timestamp: now.Add(time.Minute).UnixMilli(), Value: 4},
+ },
+ Labels: map[string]string{
+ "service.name": "frontend",
+ },
+ LabelsArray: []map[string]string{
+ {
+ "service.name": "frontend",
+ },
+ },
+ },
+ compareOp: string(ruletypes.ValueIsAbove),
+ matchType: string(ruletypes.AtleastOnce),
+ target: target,
+ recoveryTarget: &recovery,
+ thresholdName: "primary",
+ // Since sendUnmatched is true, the rule should return the first valid point
+ // even if it doesn't match the rule condition with current target value of 10.0
+ sendUnmatched: true,
+ expectSamples: intPtr(1),
+ expectedSampleValue: 3,
+ },
+ {
+ description: "sendUnmatched false suppresses unmatched",
+ values: v3.Series{
+ Points: []v3.Point{
+ {Timestamp: now.UnixMilli(), Value: 3},
+ {Timestamp: now.Add(time.Minute).UnixMilli(), Value: 4},
+ },
+ Labels: map[string]string{
+ "service.name": "frontend",
+ },
+ LabelsArray: []map[string]string{
+ {
+ "service.name": "frontend",
+ },
+ },
+ },
+ compareOp: string(ruletypes.ValueIsAbove),
+ matchType: string(ruletypes.AtleastOnce),
+ target: target,
+ recoveryTarget: &recovery,
+ thresholdName: "primary",
+ // Since sendUnmatched is false, the rule should not return any samples
+ sendUnmatched: false,
+ expectSamples: intPtr(0),
+ },
+ {
+ description: "sendUnmatched skips NaN and uses next point",
+ values: v3.Series{
+ Points: []v3.Point{
+ {Timestamp: now.UnixMilli(), Value: math.NaN()},
+ {Timestamp: now.Add(time.Minute).UnixMilli(), Value: math.Inf(1)},
+ {Timestamp: now.Add(2 * time.Minute).UnixMilli(), Value: 7},
+ },
+ Labels: map[string]string{
+ "service.name": "frontend",
+ },
+ LabelsArray: []map[string]string{
+ {
+ "service.name": "frontend",
+ },
+ },
+ },
+ compareOp: string(ruletypes.ValueIsAbove),
+ matchType: string(ruletypes.AtleastOnce),
+ target: target,
+ recoveryTarget: &recovery,
+ thresholdName: "primary",
+ // Since sendUnmatched is true, the rule should return the first valid point
+ // even if it doesn't match the rule condition with current target value of 10.0
+ sendUnmatched: true,
+ expectSamples: intPtr(1),
+ expectedSampleValue: 7,
+ },
+ }
+
+ for _, tc := range tests {
+ runEvalTests(t, postableRule, []recoveryTestCase{tc})
+ }
+}
+
+// TestThresholdRuleEval_RecoveryNotMetSendUnmatchedFalse tests the case where the recovery target is not met and sendUnmatched is false.
+// In this case, the rule should not return any samples as no alert is active plus the recovery target is not met.
+func TestThresholdRuleEval_RecoveryNotMetSendUnmatchedFalse(t *testing.T) {
+ target := 10.0
+ recovery := 5.0
+
+ now := time.Now()
+ postableRule := ruletypes.PostableRule{
+ AlertName: "Recovery not met sendUnmatched false",
+ AlertType: ruletypes.AlertTypeMetric,
+ RuleType: ruletypes.RuleTypeThreshold,
+ Evaluation: &ruletypes.EvaluationEnvelope{Kind: ruletypes.RollingEvaluation, Spec: ruletypes.RollingWindow{
+ EvalWindow: ruletypes.Duration(5 * time.Minute),
+ Frequency: ruletypes.Duration(1 * time.Minute),
+ }},
+ RuleCondition: &ruletypes.RuleCondition{
+ CompositeQuery: &v3.CompositeQuery{
+ QueryType: v3.QueryTypeBuilder,
+ BuilderQueries: map[string]*v3.BuilderQuery{
+ "A": {
+ QueryName: "A",
+ StepInterval: 60,
+ AggregateAttribute: v3.AttributeKey{
+ Key: "probe_success",
+ },
+ AggregateOperator: v3.AggregateOperatorNoOp,
+ DataSource: v3.DataSourceMetrics,
+ Expression: "A",
+ },
+ },
+ },
+ },
+ }
+
+ tc := recoveryTestCase{
+ description: "recovery target present but not met, sendUnmatched false",
+ values: v3.Series{
+ Points: []v3.Point{
+ {Timestamp: now.UnixMilli(), Value: 3},
+ {Timestamp: now.Add(time.Minute).UnixMilli(), Value: 4},
+ },
+ Labels: map[string]string{
+ "service.name": "frontend",
+ },
+ LabelsArray: []map[string]string{
+ {
+ "service.name": "frontend",
+ },
+ },
+ },
+ compareOp: string(ruletypes.ValueIsAbove),
+ matchType: string(ruletypes.AtleastOnce),
+ target: target,
+ recoveryTarget: &recovery,
+ thresholdName: "primary",
+ sendUnmatched: false,
+ expectSamples: intPtr(0),
+ activeAlerts: nil, // will auto-calc
+ expectedTarget: target,
+ expectedRecoveryTarget: recovery,
+ }
+
+ runEvalTests(t, postableRule, []recoveryTestCase{tc})
+}
+
func runEvalTests(t *testing.T, postableRule ruletypes.PostableRule, testCases []recoveryTestCase) {
logger := instrumentationtest.New().Logger()
for _, c := range testCases {
@@ -1577,12 +1848,21 @@ func runEvalTests(t *testing.T, postableRule ruletypes.PostableRule, testCases [
}
evalData := ruletypes.EvalData{
- ActiveAlerts: activeAlerts,
+ ActiveAlerts: activeAlerts,
+ SendUnmatched: c.sendUnmatched,
}
resultVectors, err := rule.Threshold.Eval(values, rule.Unit(), evalData)
assert.NoError(t, err)
+ if c.expectSamples != nil {
+ assert.Equal(t, *c.expectSamples, len(resultVectors), "sample count mismatch")
+ if *c.expectSamples > 0 {
+ assert.InDelta(t, c.expectedSampleValue, resultVectors[0].V, 0.01, "sample value mismatch")
+ }
+ return
+ }
+
// Verify results
if c.expectAlert || c.expectRecovery {
// Either a new alert fires or recovery happens - both return result vectors
diff --git a/pkg/query-service/rules/threshold_rule_test_data.go b/pkg/query-service/rules/threshold_rule_test_data.go
index 9552191759..aea41045d0 100644
--- a/pkg/query-service/rules/threshold_rule_test_data.go
+++ b/pkg/query-service/rules/threshold_rule_test_data.go
@@ -27,6 +27,10 @@ type recoveryTestCase struct {
expectedTarget float64
expectedRecoveryTarget float64
thresholdName string // for hash calculation
+ // Optional fields for SendUnmatched scenarios
+ sendUnmatched bool // whether to set EvalData.SendUnmatched
+ expectSamples *int // if set, assert exact sample count
+ expectedSampleValue float64 // used when expectSamples is set
}
// thresholdExpectation defines expected behavior for a single threshold in multi-threshold tests
diff --git a/pkg/query-service/rules/utils.go b/pkg/query-service/rules/utils.go
new file mode 100644
index 0000000000..83013fdab0
--- /dev/null
+++ b/pkg/query-service/rules/utils.go
@@ -0,0 +1,79 @@
+package rules
+
+import (
+ "time"
+
+ "github.com/SigNoz/signoz/pkg/types/metrictypes"
+)
+
+// GenerateMetricQueryCHArgs generates query arguments for metric queries used in tests.
+// It calculates the time range, builds time series CTE args, temporal aggregation args,
+// and spatial aggregation args to match the actual query builder behavior.
+func GenerateMetricQueryCHArgs(
+ evalTime time.Time,
+ evalWindow time.Duration,
+ evalDelay time.Duration,
+ metricName string,
+ temporality metrictypes.Temporality,
+) []interface{} {
+ // Calculate time range
+ startTime := evalTime.Add(-evalWindow)
+ endTime := evalTime
+
+ startMs := startTime.UnixMilli()
+ endMs := endTime.UnixMilli()
+
+ // Apply eval delay if present
+ if evalDelay > 0 {
+ startMs = startMs - int64(evalDelay.Milliseconds())
+ endMs = endMs - int64(evalDelay.Milliseconds())
+ }
+
+ // Round to nearest minute
+ startMs = startMs - (startMs % (60 * 1000))
+ endMs = endMs - (endMs % (60 * 1000))
+
+ start := uint64(startMs)
+ end := uint64(endMs)
+
+ // Step1: Build time series CTE args
+
+ // Adjust start time to nearest hour
+ oneHourInMilliseconds := uint64(time.Hour.Milliseconds())
+ // start time for filtering signoz_metrics.time_series_v4 with start time
+ timeSeriesCTEStartTime := start - (start % oneHourInMilliseconds)
+
+ queryArgs := []interface{}{
+ metricName,
+ timeSeriesCTEStartTime,
+ end,
+ }
+
+ // Add temporality if specified
+ if temporality == metrictypes.Unknown {
+ temporality = metrictypes.Unspecified
+ }
+ if temporality != metrictypes.Unknown {
+ queryArgs = append(queryArgs, temporality.StringValue())
+ }
+
+ // Add normalized flag
+ queryArgs = append(queryArgs, false)
+
+ // Step2: Add temporal aggregation args
+ // build args for filtering signoz_metrics.distributed_samples_v4 table
+ temporalAggArgs := []interface{}{
+ metricName,
+ start,
+ end,
+ }
+ queryArgs = append(queryArgs, temporalAggArgs...)
+
+ // Add spatial aggregation args
+ spatialAggArgs := []interface{}{
+ 0, // isNaN check
+ }
+ queryArgs = append(queryArgs, spatialAggArgs...)
+
+ return queryArgs
+}
diff --git a/pkg/types/ruletypes/threshold.go b/pkg/types/ruletypes/threshold.go
index 4342ae9644..97e690b535 100644
--- a/pkg/types/ruletypes/threshold.go
+++ b/pkg/types/ruletypes/threshold.go
@@ -63,6 +63,11 @@ type EvalData struct {
// used to check if a sample is part of an active alert
// when evaluating the recovery threshold.
ActiveAlerts map[uint64]struct{}
+
+ // SendUnmatched is a flag to return samples
+ // even if they don't match the rule condition.
+ // This is useful in testing the rule.
+ SendUnmatched bool
}
// HasActiveAlert checks if the given sample figerprint is active
@@ -131,6 +136,24 @@ func (r BasicRuleThresholds) Eval(series v3.Series, unit string, evalData EvalDa
smpl.TargetUnit = threshold.TargetUnit
resultVector = append(resultVector, smpl)
continue
+ } else if evalData.SendUnmatched {
+ // Sanitise the series points to remove any NaN or Inf values
+ series.Points = removeGroupinSetPoints(series)
+ if len(series.Points) == 0 {
+ continue
+ }
+ // prepare the sample with the first point of the series
+ smpl := Sample{
+ Point: Point{T: series.Points[0].Timestamp, V: series.Points[0].Value},
+ Metric: PrepareSampleLabelsForRule(series.Labels, threshold.Name),
+ Target: *threshold.TargetValue,
+ TargetUnit: threshold.TargetUnit,
+ }
+ if threshold.RecoveryTarget != nil {
+ smpl.RecoveryTarget = threshold.RecoveryTarget
+ }
+ resultVector = append(resultVector, smpl)
+ continue
}
// Prepare alert hash from series labels and threshold name if recovery target option was provided