Skip to content

Commit

Permalink
Merge pull request #56 from OpenSLO/agaurav-dev
Browse files Browse the repository at this point in the history
[sumo] add timezone support for alert notifications
  • Loading branch information
agaurav authored May 23, 2022
2 parents 153a924 + 8cb4751 commit b0b8056
Show file tree
Hide file tree
Showing 8 changed files with 20 additions and 2 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ alerts:
notifications: # one or more notification channels
- connectionType: 'Email'
recipients: '[email protected]'
timeZone: 'PST'
triggerFor:
- Warning
- ResolvedWarning
Expand Down
12 changes: 12 additions & 0 deletions libs/monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"bytes"
"sort"
"text/template"
"time"
)

type SLOMonitorConfig struct {
Expand Down Expand Up @@ -125,6 +126,7 @@ func MonitorConfigFromOpenSLO(sloConf SLO) (*SLOMonitorConfig, error) {
for _, alert := range alertTmplParams {

sortedNotifs := make([]Notification, len(alert.Notifications))

copy(sortedNotifs, alert.Notifications)
sort.Slice(sortedNotifs, func(i, j int) bool {
return GiveStructCompare(sortedNotifs[i], sortedNotifs[j])
Expand Down Expand Up @@ -175,3 +177,13 @@ func ConvertToBurnRateTmplParams(alerts []BurnRate, target, timesliceTarget floa

return tmplAlertsParams
}

func giveLocalTimeZone() string {
loc, err := time.LoadLocation("Local")

if err != nil {
log.Fatal(err)
}

return loc.String()
}
2 changes: 1 addition & 1 deletion libs/overview.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func giveWhereClause(dashVars []string) string {

var clauses []string
for _, v := range dashVars {
clauses = append(clauses, fmt.Sprintf("(\"{{%s}}\"=\"*\" or %s=\"{{%s}}\")", v, v, v))
clauses = append(clauses, fmt.Sprintf(`( %s matches "{{%s}}" )`, v, v))
}

wherePart := "| where " + strings.Join(clauses, " and ")
Expand Down
2 changes: 1 addition & 1 deletion libs/templates/terra/monitor.tf.gotf
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ QUERY
{{end}}
]
subject = "SLO breach alert: {{$.Service}} - {{$.Name}}"
time_zone = "PST"
time_zone = {{if ne $n.TimeZone "" }}"{{$n.TimeZone}}"{{else}}"PST"{{end}}
message_body = "{{`{{Description}} \n Result : {{ResultsJson}}\n Alert: {{AlertResponseURL}}`}}"
{{else}}
connection_id = "{{$n.ConnectionID}}"
Expand Down
1 change: 1 addition & 0 deletions samples/logs/drift-calculation.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ alerts:
- connectionType: 'Email'
recipients:
- '[email protected]'
timeZone: 'PST'
triggerFor:
- Warning
- ResolvedWarning
1 change: 1 addition & 0 deletions samples/logs/ingest-lag-timeslice-budgeting.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ alerts:
- connectionType: 'Email'
recipients:
- '[email protected]'
timeZone: 'PST'
triggerFor:
- Warning
- ResolvedWarning
2 changes: 2 additions & 0 deletions samples/logs/trend-calculation.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ alerts:
- connectionType: 'Email'
recipients:
- '[email protected]'
timeZone: 'PST'
triggerFor:
- Warning
- ResolvedWarning
Expand All @@ -51,6 +52,7 @@ alerts:
- connectionType: 'Email'
recipients:
- '[email protected]'
timeZone: 'PST'
triggerFor:
- Warning
- ResolvedWarning
1 change: 1 addition & 0 deletions samples/tracing/checkout-latency.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ alerts:
- connectionType: 'Email'
recipients:
- '[email protected]'
timeZone: 'PST'
triggerFor:
- Warning
- ResolvedWarning

0 comments on commit b0b8056

Please sign in to comment.