MCPcopy Index your code
hub / github.com/rilldata/rill / parseAlert

Method parseAlert

runtime/parser/parse_alert.go:75–385  ·  view source on GitHub ↗

parseAlert parses an alert definition and adds the resulting resource to p.Resources.

(node *Node)

Source from the content-addressed store, hash-verified

73
74// parseAlert parses an alert definition and adds the resulting resource to p.Resources.
75func (p *Parser) parseAlert(node *Node) error {
76 // Parse YAML
77 tmp := &AlertYAML{}
78 err := p.decodeNodeYAML(node, true, tmp)
79 if err != nil {
80 return err
81 }
82
83 // Validate SQL or connector isn't set
84 if node.SQL != "" {
85 return fmt.Errorf("alerts cannot have SQL")
86 }
87 if !node.ConnectorInferred && node.Connector != "" {
88 return fmt.Errorf("alerts cannot have a connector")
89 }
90
91 // Display name backwards compatibility
92 if tmp.Title != "" && tmp.DisplayName == "" {
93 tmp.DisplayName = tmp.Title
94 }
95
96 // Parse refresh schedule
97 schedule, err := p.parseScheduleYAML(tmp.Refresh, false)
98 if err != nil {
99 return err
100 }
101
102 // Parse watermark
103 watermarkInherit := false
104 if tmp.Watermark != "" {
105 switch strings.ToLower(tmp.Watermark) {
106 case "inherit":
107 watermarkInherit = true
108 case "trigger_time":
109 // Do nothing
110 default:
111 return fmt.Errorf(`invalid value %q for property "watermark"`, tmp.Watermark)
112 }
113 }
114
115 // Validate the interval duration as a standard ISO8601 duration (without Rill extensions) with only one component
116 if tmp.Intervals.Duration != "" {
117 err := duration.ValidateISO8601(tmp.Intervals.Duration, true, true)
118 if err != nil {
119 return fmt.Errorf(`invalid value %q for property "intervals.duration"`, tmp.Intervals.Duration)
120 }
121 }
122
123 // Parse timeout
124 var timeout time.Duration
125 if tmp.Timeout != "" {
126 timeout, err = parseDuration(tmp.Timeout)
127 if err != nil {
128 return err
129 }
130 }
131
132 // Data and query

Callers 1

parseNodeMethod · 0.95

Calls 11

decodeNodeYAMLMethod · 0.95
parseScheduleYAMLMethod · 0.95
parseDataYAMLMethod · 0.95
insertResourceMethod · 0.95
ValidateISO8601Function · 0.92
ToSliceAnyFunction · 0.92
EncodePropsFunction · 0.92
parseDurationFunction · 0.85
ToDisplayNameFunction · 0.85
ErrorfMethod · 0.65
ValidMethod · 0.45

Tested by

no test coverage detected