Skip to content

Commit

Permalink
Make slack optional
Browse files Browse the repository at this point in the history
Signed-off-by: Kedar Vijay Kulkarni <[email protected]>
  • Loading branch information
Kedar Vijay Kulkarni committed Nov 18, 2021
1 parent 0607a4e commit 8b02c18
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 9 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ This tool allows OpenShift users to run a watcher for Prometheus queries and def
* [x] Slack Notification
* [x] Notify/Do Something(e.g. Pause/Kill benchmark jobs to preserve cluster) when results don't match conditions
* [x] Spawn goroutines to keep running queries and evaluating results to handle scale - e.g. when we have very large number of queries in the yaml file, we can divide and concurrently run queries
* [x] If slack config is not set, it is ignored and no attempts will be made to notify via slack
* [] debug mode
* [] make slack optional
* [] use env vars


Expand Down
2 changes: 1 addition & 1 deletion cmd/analyze/analyze.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ Value: %.4f %s Threshold: %.4f is %t
`, q.Query, v1, opMap[watchItems.Operator], v2, b)
if !b {
log.Printf("\n%[2]s\n Comparison of Value and Threshold is %[1]t. Notifying...\n%[2]s\n", b, strings.Repeat("~", 80))
c <- fmt.Sprintf("\nQuery: %s\nValue: %.4f %s Threshold: %.4f is %t\n", q.Query, v1, opMap[watchItems.Operator], v2, b)
c <- fmt.Sprintf("\nQuery: %s\nValue: %.4f %s Threshold: %.4f is %t for key: %q and val: %q\n", q.Query, v1, opMap[watchItems.Operator], v2, b, watchItems.Key, watchItems.Val)
if terminateBenchmark != "" {
tb <- true // send signal to terminate benchmark channel
}
Expand Down
4 changes: 3 additions & 1 deletion cmd/notify/notifications.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,9 @@ Received following on the channel: %s
%[1]s
`, strings.Repeat("~", 80), msg)
log.Println(msgFmt)
s.SlackNotify("Following query failed:"+msg, thread_ts)
if s.ChannelID != "" && s.UserID != "" && s.SlackToken != "" {
s.SlackNotify("Following query failed:"+msg, thread_ts)
}
default:
fmt.Printf("\r%s Please Wait. No new message received on the channel....", waitChars[rand.Intn(4)])
time.Sleep(time.Millisecond * 500)
Expand Down
13 changes: 7 additions & 6 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,6 @@ func main() {
return
}

if slackConfig.ChannelID == "" || slackConfig.UserID == "" || slackConfig.SlackToken == "" {
log.Printf("Oops something went wrong while trying to fetch Slack Config, check config/slack.yaml")
return
}
// fmt.Println("UserID, Channel ID, slackToken: ", slackConfig)
// queries := []string{
// `sum(kube_pod_status_phase{}) by (phase) > 0`, // pod count by phase
Expand Down Expand Up @@ -105,8 +101,13 @@ func main() {
for _, item := range queryList {
log.Println(item.Query)
}
thread_ts := slackConfig.SlackNotify("New benchmark started, we will monitor it for performance and notify here with the issues.", "")
defer slackConfig.SlackNotify(fmt.Sprintf("Continuous Perf Analysis has ended all iterations. Total time spent: %s", args.Timeout.String()), thread_ts)
var thread_ts string
if slackConfig.ChannelID != "" && slackConfig.UserID != "" && slackConfig.SlackToken != "" {
thread_ts = slackConfig.SlackNotify("New benchmark started, we will monitor it for performance and notify here with the issues.", "")
defer slackConfig.SlackNotify(fmt.Sprintf("Continuous Perf Analysis has ended all iterations. Total time spent: %s", args.Timeout.String()), thread_ts)
} else {
log.Printf("No slack notifications will be sent as Slack Config is not properly setup. One of the fields may be empty. Check config/slack.yaml")
}
go func(c chan string) {
for i := 1; ; i++ {
log.Printf("\n%[2]s\nIteration no. %[1]d\n%[2]s\n", i, strings.Repeat("~", 80))
Expand Down

0 comments on commit 8b02c18

Please sign in to comment.