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: support printing threshold in alert summary and description (#1827)
Amol Umbark8ab527b1746a
diff --git a/frontend/src/container/CreateAlertRule/defaults.ts b/frontend/src/container/CreateAlertRule/defaults.tsindex c12233bb13..5ce07a03be 100644--- a/frontend/src/container/CreateAlertRule/defaults.ts+++ b/frontend/src/container/CreateAlertRule/defaults.ts@@ -6,6 +6,16 @@ import {defaultMatchType,} from 'types/api/alerts/def';+const defaultAlertDescription =+ 'This alert is fired when the defined metric (current value: {{$value}}) crosses the threshold ({{$threshold}})';+const defaultAlertSummary =+ 'The rule threshold is set to {{$threshold}}, and the observed metric value is {{$value}}';++const defaultAnnotations = {+ description: defaultAlertDescription,+ summary: defaultAlertSummary,+};+export const alertDefaults: AlertDef = {alertType: AlertTypes.METRICS_BASED_ALERT,condition: {@@ -38,9 +48,7 @@ export const alertDefaults: AlertDef = {labels: {severity: 'warning',},- annotations: {- description: 'A new alert',- },+ annotations: defaultAnnotations,evalWindow: defaultEvalWindow,};@@ -85,9 +93,7 @@ export const logAlertDefaults: AlertDef = {severity: 'warning',details: `${window.location.protocol}//${window.location.host}/logs`,},- annotations: {- description: 'A new log-based alert',- },+ annotations: defaultAnnotations,evalWindow: defaultEvalWindow,};@@ -132,9 +138,7 @@ export const traceAlertDefaults: AlertDef = {severity: 'warning',details: `${window.location.protocol}//${window.location.host}/traces`,},- annotations: {- description: 'A new trace-based alert',- },+ annotations: defaultAnnotations,evalWindow: defaultEvalWindow,};@@ -179,8 +183,6 @@ export const exceptionAlertDefaults: AlertDef = {severity: 'warning',details: `${window.location.protocol}//${window.location.host}/exceptions`,},- annotations: {- description: 'A new exceptions-based alert',- },+ annotations: defaultAnnotations,evalWindow: defaultEvalWindow,};diff --git a/pkg/query-service/rules/apiParams.go b/pkg/query-service/rules/apiParams.goindex aad672c99a..53503c6c52 100644--- a/pkg/query-service/rules/apiParams.go+++ b/pkg/query-service/rules/apiParams.go@@ -197,8 +197,8 @@ func testTemplateParsing(rl *PostableRule) (errs []error) {}// Trying to parse templates.- tmplData := AlertTemplateData(make(map[string]string), 0)- defs := "{{$labels := .Labels}}{{$value := .Value}}"+ tmplData := AlertTemplateData(make(map[string]string), 0, 0)+ defs := "{{$labels := .Labels}}{{$value := .Value}}{{$threshold := .Threshold}}"parseTest := func(text string) error {tmpl := NewTemplateExpander(context.TODO(),diff --git a/pkg/query-service/rules/promRule.go b/pkg/query-service/rules/promRule.goindex d4654becd2..bd4ff4d134 100644--- a/pkg/query-service/rules/promRule.go+++ b/pkg/query-service/rules/promRule.go@@ -108,6 +108,14 @@ func (r *PromRule) Condition() *RuleCondition {return r.ruleCondition}+func (r *PromRule) targetVal() float64 {+ if r.ruleCondition == nil || r.ruleCondition.Target == nil {+ return 0+ }++ return *r.ruleCondition.Target+}+func (r *PromRule) Type() RuleType {return RuleTypeProm}@@ -327,10 +335,10 @@ func (r *PromRule) Eval(ctx context.Context, ts time.Time, queriers *Queriers) (l[lbl.Name] = lbl.Value}- tmplData := AlertTemplateData(l, smpl.V)+ tmplData := AlertTemplateData(l, smpl.V, r.targetVal())// Inject some convenience variables that are easier to remember for users// who are not used to Go's templating system.- defs := "{{$labels := .Labels}}{{$value := .Value}}"+ defs := "{{$labels := .Labels}}{{$value := .Value}}{{$threshold := .Threshold}}"expand := func(text string) string {diff --git a/pkg/query-service/rules/templates.go b/pkg/query-service/rules/templates.goindex 955a7b3761..473a5cfa87 100644--- a/pkg/query-service/rules/templates.go+++ b/pkg/query-service/rules/templates.go@@ -21,8 +21,9 @@ import (// related to go templating in rule labels and annotationstype tmplQueryRecord struct {- Labels map[string]string- Value float64+ Labels map[string]string+ Value float64+ Threshold float64}type tmplQueryResults []*tmplQueryRecord@@ -200,13 +201,15 @@ func NewTemplateExpander(}// AlertTemplateData returns the interface to be used in expanding the template.-func AlertTemplateData(labels map[string]string, value float64) interface{} {+func AlertTemplateData(labels map[string]string, value float64, threshold float64) interface{} {return struct {- Labels map[string]string- Value float64+ Labels map[string]string+ Value float64+ Threshold float64}{- Labels: labels,- Value: value,+ Labels: labels,+ Value: value,+ Threshold: threshold,}}diff --git a/pkg/query-service/rules/thresholdRule.go b/pkg/query-service/rules/thresholdRule.goindex c351d96b0f..9da34d2ef3 100644--- a/pkg/query-service/rules/thresholdRule.go+++ b/pkg/query-service/rules/thresholdRule.go@@ -673,10 +673,10 @@ func (r *ThresholdRule) Eval(ctx context.Context, ts time.Time, queriers *Queriel[lbl.Name] = lbl.Value}- tmplData := AlertTemplateData(l, smpl.V)+ tmplData := AlertTemplateData(l, smpl.V, r.targetVal())// Inject some convenience variables that are easier to remember for users// who are not used to Go's templating system.- defs := "{{$labels := .Labels}}{{$value := .Value}}"+ defs := "{{$labels := .Labels}}{{$value := .Value}}{{$threshold := .Threshold}}"// utility function to apply go template on labels and annotsexpand := func(text string) string {