Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

List open incidents #1764

Merged
merged 14 commits into from
Jun 8, 2016
31 changes: 28 additions & 3 deletions cmd/bosun/conf/conf.go
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,31 @@ func (ns *Notifications) Get(c *Conf, tags opentsdb.TagSet) map[string]*Notifica
return nots
}

func GetNotificationChains(c *Conf, n map[string]*Notification) ([][]string) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this needs a comments about exactly what it returns. I'm kinda confused on the myself. A list of lists of chains for a single alert? With no duplicates. Maybe writing it out will help.

chains := [][]string{}
for _, root := range n {
chain := []string{}
seen := make(map[string]bool)
var walkChain func(next *Notification)
walkChain = func(next *Notification) {
if (next == nil) {
chains = append(chains, chain)
return
}
if (seen[next.Name]) {
chain = append(chain, fmt.Sprintf("...%v", next.Name))
chains = append(chains, chain)
return
}
chain = append(chain, next.Name)
seen[next.Name] = true
walkChain(next.Next)
}
walkChain(root)
}
return chains
}

// parseNotifications parses the comma-separated string v for notifications and
// returns them.
func (c *Conf) parseNotifications(v string) (map[string]*Notification, error) {
Expand Down Expand Up @@ -340,9 +365,9 @@ type Notification struct {
body string
}

func (n *Notification) MarshalJSON() ([]byte, error) {
return nil, fmt.Errorf("conf: cannot json marshal notifications")
}
// func (n *Notification) MarshalJSON() ([]byte, error) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

delete rather than comment.

// return nil, fmt.Errorf("conf: cannot json marshal notifications")
// }

type Vars map[string]string

Expand Down
112 changes: 0 additions & 112 deletions cmd/bosun/sched/filter.go

This file was deleted.

28 changes: 22 additions & 6 deletions cmd/bosun/sched/sched.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ import (
"github.com/MiniProfiler/go/miniprofiler"
"github.com/boltdb/bolt"
"github.com/bradfitz/slice"
"github.com/kylebrandt/boolq"
"github.com/kylebrandt/boolq/parse"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we alias this reference please. We have way too many things called parse. Better yet, maybe it should just be boolq.Parse and nobody else needs to know about the internal parse package.

"github.com/tatsushid/go-fastping"
)

Expand Down Expand Up @@ -372,16 +374,19 @@ func (s *Schedule) MarshalGroups(T miniprofiler.Timer, filter string) (*StateGro
}
t.FailingAlerts, t.UnclosedErrors = s.getErrorCounts()
T.Step("Setup", func(miniprofiler.Timer) {
matches, err2 := makeFilter(filter)
if err2 != nil {
err = err2
return
}
status2, err2 := s.GetOpenStates()
if err2 != nil {
err = err2
return
}
var parsedExpr *parse.Tree
if filter != "" {
parsedExpr, err2 = parse.Parse(filter)
if err2 != nil {
err = err2
return
}
}
for k, v := range status2 {
a := s.Conf.Alerts[k.Name()]
if a == nil {
Expand All @@ -391,7 +396,18 @@ func (s *Schedule) MarshalGroups(T miniprofiler.Timer, filter string) (*StateGro
}
continue
}
if matches(s.Conf, a, v) {
if parsedExpr == nil {
Copy link
Contributor

@captncraig captncraig Jun 7, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel like the logic here is a bit odd. I would like to see the status[k] = v bit only once, and continue if it doesn't match the filter.
Something like if filter and !filter.Matches(is) { continue} status[k] = v. If that makes any sense.

status[k] = v
continue
}
is := MakeIncidentSummary(s.Conf, silenced, v)
match := false
match, err2 = boolq.AskParsedExpr(*parsedExpr, is)
if err2 != nil {
err = err2
return
}
if match {
status[k] = v
}
}
Expand Down
Loading