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.
TypeScript apmapplication-monitoringdistributed-tracinggogood-first-issuejaegerloglogsmetricsmonitoringnextjsobservabilityopen-sourceopentelemetryprometheusreactreactjsself-hostedtracingtypescript
feat: add ability to customize alert frequency (#4697)
Srikanth Chekuri83f68f13db3d
diff --git a/frontend/public/locales/en-GB/alerts.json b/frontend/public/locales/en-GB/alerts.jsonindex fb360e579b..4dffb641d3 100644--- a/frontend/public/locales/en-GB/alerts.json+++ b/frontend/public/locales/en-GB/alerts.json@@ -112,6 +112,7 @@"exceptions_based_alert_desc": "Send a notification when a condition occurs in the exceptions data.","field_unit": "Threshold unit","text_alert_on_absent": "Send a notification if data is missing for",+ "text_alert_frequency": "Run alert every","text_for": "minutes","selected_query_placeholder": "Select query"}diff --git a/frontend/public/locales/en/alerts.json b/frontend/public/locales/en/alerts.jsonindex 0349568c70..33714d4429 100644--- a/frontend/public/locales/en/alerts.json+++ b/frontend/public/locales/en/alerts.json@@ -112,6 +112,7 @@"exceptions_based_alert_desc": "Send a notification when a condition occurs in the exceptions data.","field_unit": "Threshold unit","text_alert_on_absent": "Send a notification if data is missing for",+ "text_alert_frequency": "Run alert every","text_for": "minutes","selected_query_placeholder": "Select query"}diff --git a/frontend/src/container/FormAlertRules/RuleOptions.tsx b/frontend/src/container/FormAlertRules/RuleOptions.tsxindex 88e7c83979..d62b39f30f 100644--- a/frontend/src/container/FormAlertRules/RuleOptions.tsx+++ b/frontend/src/container/FormAlertRules/RuleOptions.tsx@@ -1,5 +1,6 @@import {Checkbox,+ Collapse,Form,InputNumber,InputNumberProps,@@ -24,7 +25,12 @@ import {import { EQueryType } from 'types/common/dashboard';import { popupContainer } from 'utils/selectPopupContainer';-import { FormContainer, InlineSelect, StepHeading } from './styles';+import {+ FormContainer,+ InlineSelect,+ StepHeading,+ VerticalLine,+} from './styles';function RuleOptions({alertDef,@@ -238,42 +244,72 @@ function RuleOptions({/></Form.Item></Space>- <Space direction="horizontal" align="center">- <Form.Item noStyle name={['condition', 'alertOnAbsent']}>- <Checkbox- checked={alertDef?.condition?.alertOnAbsent}- onChange={(e): void => {- setAlertDef({- ...alertDef,- condition: {- ...alertDef.condition,- alertOnAbsent: e.target.checked,- },- });- }}- />- </Form.Item>- <Typography.Text>{t('text_alert_on_absent')}</Typography.Text>+ <Collapse>+ <Collapse.Panel header={t('More options')} key="1">+ <Space direction="vertical" size="large">+ <VerticalLine>+ <Space direction="horizontal" align="center">+ <Typography.Text>{t('text_alert_frequency')}</Typography.Text>+ <Form.Item noStyle name={['condition', 'frequency']}>+ <InputNumber+ defaultValue={1}+ min={1}+ value={alertDef?.frequency}+ onChange={(value): void => {+ setAlertDef({+ ...alertDef,+ frequency: Number(value) || 0,+ });+ }}+ type="number"+ onWheel={(e): void => e.currentTarget.blur()}+ />+ </Form.Item>+ <Typography.Text>{t('text_for')}</Typography.Text>+ </Space>+ </VerticalLine>- <Form.Item noStyle name={['condition', 'absentFor']}>- <InputNumber- min={1}- value={alertDef?.condition?.absentFor}- onChange={(value): void => {- setAlertDef({- ...alertDef,- condition: {- ...alertDef.condition,- absentFor: Number(value) || 0,- },- });- }}- type="number"- onWheel={(e): void => e.currentTarget.blur()}- />- </Form.Item>- <Typography.Text>{t('text_for')}</Typography.Text>- </Space>+ <VerticalLine>+ <Space direction="horizontal" align="center">+ <Form.Item noStyle name={['condition', 'alertOnAbsent']}>+ <Checkbox+ checked={alertDef?.condition?.alertOnAbsent}+ onChange={(e): void => {+ setAlertDef({+ ...alertDef,+ condition: {+ ...alertDef.condition,+ alertOnAbsent: e.target.checked,+ },+ });+ }}+ />+ </Form.Item>+ <Typography.Text>{t('text_alert_on_absent')}</Typography.Text>++ <Form.Item noStyle name={['condition', 'absentFor']}>+ <InputNumber+ min={1}+ value={alertDef?.condition?.absentFor}+ onChange={(value): void => {+ setAlertDef({+ ...alertDef,+ condition: {+ ...alertDef.condition,+ absentFor: Number(value) || 0,+ },+ });+ }}+ type="number"+ onWheel={(e): void => e.currentTarget.blur()}+ />+ </Form.Item>+ <Typography.Text>{t('text_for')}</Typography.Text>+ </Space>+ </VerticalLine>+ </Space>+ </Collapse.Panel>+ </Collapse></Space></FormContainer></>diff --git a/frontend/src/container/FormAlertRules/styles.ts b/frontend/src/container/FormAlertRules/styles.tsindex 9fcaf4c59c..11205c0ab4 100644--- a/frontend/src/container/FormAlertRules/styles.ts+++ b/frontend/src/container/FormAlertRules/styles.ts@@ -67,6 +67,13 @@ export const SeveritySelect = styled(Select)`width: 25% !important;`;+export const VerticalLine = styled.div`+ border-left: 2px solid #e8e8e8; /* Adjust color and thickness as desired */+ padding-left: 20px; /* Adjust spacing to content as needed */+ margin-left: 20px; /* Adjust margin as desired */+ height: 100%; /* Adjust based on your layout needs */+`;+export const InputSmall = styled(Input)`width: 40% !important;`;diff --git a/frontend/src/pages/AlertList/index.tsx b/frontend/src/pages/AlertList/index.tsxindex 336c399a2f..33f3ada0f9 100644--- a/frontend/src/pages/AlertList/index.tsx+++ b/frontend/src/pages/AlertList/index.tsx@@ -12,6 +12,11 @@ function AllAlertList(): JSX.Element {children: <TriggeredAlerts />,},// {+ // label: 'Planned Downtime',+ // key: 'Planned Downtime',+ // // children: <PlannedDowntime />,+ // },+ // {// label: 'Map Alert Channels',// key = 'Map Alert Channels',// children: <MapAlertChannels />,diff --git a/frontend/src/types/api/alerts/def.ts b/frontend/src/types/api/alerts/def.tsindex af3a4bc912..96fa86654f 100644--- a/frontend/src/types/api/alerts/def.ts+++ b/frontend/src/types/api/alerts/def.ts@@ -14,6 +14,7 @@ export interface AlertDef {alertType?: string;alert?: string;ruleType?: string;+ frequency?: number | undefined;condition: RuleCondition;labels?: Labels;annotations?: Labels;diff --git a/pkg/query-service/rules/manager.go b/pkg/query-service/rules/manager.goindex 530bb30d14..95181eade6 100644--- a/pkg/query-service/rules/manager.go+++ b/pkg/query-service/rules/manager.go@@ -525,7 +525,7 @@ func (m *Manager) prepareTask(acquireLock bool, r *PostableRule, taskName stringrules = append(rules, tr)// create ch rule task for evalution- task = newTask(TaskTypeCh, taskName, taskNamesuffix, time.Duration(r.Frequency), rules, m.opts, m.prepareNotifyFunc())+ task = newTask(TaskTypeCh, taskName, taskNamesuffix, time.Duration(r.Frequency*Duration(time.Minute)), rules, m.opts, m.prepareNotifyFunc())// add rule to memorym.rules[ruleId] = tr@@ -547,7 +547,7 @@ func (m *Manager) prepareTask(acquireLock bool, r *PostableRule, taskName stringrules = append(rules, pr)// create promql rule task for evalution- task = newTask(TaskTypeProm, taskName, taskNamesuffix, time.Duration(r.Frequency), rules, m.opts, m.prepareNotifyFunc())+ task = newTask(TaskTypeProm, taskName, taskNamesuffix, time.Duration(r.Frequency*Duration(time.Minute)), rules, m.opts, m.prepareNotifyFunc())// add rule to memorym.rules[ruleId] = prdiff --git a/pkg/query-service/rules/thresholdRule.go b/pkg/query-service/rules/thresholdRule.goindex 0fdb3745ca..f358d80393 100644--- a/pkg/query-service/rules/thresholdRule.go+++ b/pkg/query-service/rules/thresholdRule.go@@ -713,7 +713,7 @@ func (r *ThresholdRule) runChQuery(ctx context.Context, db clickhouse.Conn, querzap.S().Debugf("ruleid:", r.ID(), "\t resultmap(potential alerts):", len(resultMap))// if the data is missing for `For` duration then we should send alert- if r.ruleCondition.AlertOnAbsent && r.lastTimestampWithDatapoints.Add(r.Condition().AbsentFor).Before(time.Now()) {+ if r.ruleCondition.AlertOnAbsent && r.lastTimestampWithDatapoints.Add(r.Condition().AbsentFor*time.Minute).Before(time.Now()) {zap.S().Debugf("ruleid:", r.ID(), "\t msg: no data found for rule condition")lbls := labels.NewBuilder(labels.Labels{})if !r.lastTimestampWithDatapoints.IsZero() {