{"action":"created","comment":{"url":"https://api.github.com/repos/bosun-monitor/bosun/pulls/comments/26731300","id":26731300,"diff_hunk":"@@ -200,58 +186,135 @@ func (s *Schedule) RunHistory(r *RunHistory) {\n \ts.Save()\n }\n \n-// CheckUnknown checks for unknown alerts.\n-func (s *Schedule) CheckUnknown() {\n-\tfor range time.Tick(s.Conf.CheckFrequency / 4) {\n-\t\tlog.Println(\"checkUnknown\")\n-\t\tr := s.NewRunHistory(time.Now(), nil)\n-\t\ts.Lock()\n-\t\tfor ak, st := range s.status {\n-\t\t\tif st.Forgotten {\n-\t\t\t\tcontinue\n-\t\t\t}\n-\t\t\ta := s.Conf.Alerts[ak.Name()]\n-\t\t\tt := a.Unknown\n-\t\t\tif t == 0 {\n-\t\t\t\tt = s.Conf.CheckFrequency * 2\n-\t\t\t}\n-\t\t\tif t == 0 {\n-\t\t\t\tcontinue\n-\t\t\t}\n-\t\t\tif time.Since(st.Touched) < t {\n-\t\t\t\tcontinue\n-\t\t\t}\n-\t\t\tr.Events[ak] = &Event{Status: StUnknown}\n+func (r *RunHistory) GetUnknownAndUnevaluatedAlertKeys(alert string) (unknown, uneval []expr.AlertKey) {\n+\tunknown = []expr.AlertKey{}\n+\tuneval = []expr.AlertKey{}\n+\tfor ak, ev := range r.Events {\n+\t\tif ak.Name() != alert {\n+\t\t\tcontinue\n+\t\t}\n+\t\tif ev.Status == StUnknown {\n+\t\t\tunknown = append(unknown, ak)\n+\t\t} else if ev.Unevaluated {\n+\t\t\tuneval = append(uneval, ak)\n+\t\t}\n+\t}\n+\treturn unknown, uneval\n+}\n+\n+// Check evaluates all critical and warning alert rules. An error is returned if\n+// the check could not be performed.\n+func (s *Schedule) Check(T miniprofiler.Timer, now time.Time) (time.Duration, error) {\n+\tselect {\n+\tcase s.checkRunning <- true:\n+\t\t// Good, we've got the lock.\n+\tdefault:\n+\t\treturn 0, fmt.Errorf(\"check already running\")\n+\t}\n+\tr := s.NewRunHistory(now, cache.New(0))\n+\tstart := time.Now()\n+\tfor _, ak := range s.findUnknownAlerts(now) {\n+\t\tr.Events[ak] = &Event{Status: StUnknown}\n+\t}\n+\tfor _, a := range s.Conf.Alerts {\n+\t\ts.CheckAlert(T, r, a)\n+\t}\n+\td := time.Since(start)\n+\ts.RunHistory(r)\n+\t<-s.checkRunning\n+\treturn d, nil\n+}\n+\n+var bosunStartupTime = time.Now()\n+\n+func (s *Schedule) findUnknownAlerts(now time.Time) []expr.AlertKey {\n+\tkeys := []expr.AlertKey{}\n+\tif time.Now().Sub(bosunStartupTime) < 1*time.Minute {\n+\t\treturn keys\n+\t}\n+\ts.Lock()\n+\tfor ak, st := range s.status {\n+\t\tif st.Forgotten {\n+\t\t\tcontinue\n+\t\t}\n+\t\ta := s.Conf.Alerts[ak.Name()]\n+\t\tt := a.Unknown\n+\t\tif t == 0 {\n+\t\t\tt = s.Conf.CheckFrequency * 2\n \t\t}\n-\t\ts.Unlock()\n-\t\ts.RunHistory(r)\n+\t\tif now.Sub(st.Touched) < t {\n+\t\t\tcontinue\n+\t\t}\n+\t\tkeys = append(keys, ak)\n \t}\n+\ts.Unlock()\n+\treturn keys\n }\n \n func (s *Schedule) CheckAlert(T miniprofiler.Timer, r *RunHistory, a *conf.Alert) {\n \tlog.Printf(\"check alert %v start\", a.Name)\n \tstart := time.Now()\n-\tvar warns expr.AlertKeys\n-\tcrits, err := s.CheckExpr(T, r, a, a.Crit, StCritical, nil)\n+\tvar warns, crits expr.AlertKeys\n+\td, err := s.executeExpr(T, r, a, a.Depends)\n+\tvar deps expr.ResultSlice\n \tif err == nil {","path":"cmd/bosun/sched/check.go","position":152,"original_position":152,"commit_id":"789005c998443201c7214feb27f3356d4c914b63","original_commit_id":"789005c998443201c7214feb27f3356d4c914b63","user":{"login":"mjibson","id":41181,"avatar_url":"https://avatars.githubusercontent.com/u/41181?v=3","gravatar_id":"","url":"https://api.github.com/users/mjibson","html_url":"https://github.com/mjibson","followers_url":"https://api.github.com/users/mjibson/followers","following_url":"https://api.github.com/users/mjibson/following{/other_user}","gists_url":"https://api.github.com/users/mjibson/gists{/gist_id}","starred_url":"https://api.github.com/users/mjibson/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mjibson/subscriptions","organizations_url":"https://api.github.com/users/mjibson/orgs","repos_url":"https://api.github.com/users/mjibson/repos","events_url":"https://api.github.com/users/mjibson/events{/privacy}","received_events_url":"https://api.github.com/users/mjibson/received_events","type":"User","site_admin":false},"body":"What about if err != nil?","created_at":"2015-03-19T05:54:33Z","updated_at":"2015-03-19T05:54:33Z","html_url":"https://github.com/bosun-monitor/bosun/pull/772#discussion_r26731300","pull_request_url":"https://api.github.com/repos/bosun-monitor/bosun/pulls/772","_links":{"self":{"href":"https://api.github.com/repos/bosun-monitor/bosun/pulls/comments/26731300"},"html":{"href":"https://github.com/bosun-monitor/bosun/pull/772#discussion_r26731300"},"pull_request":{"href":"https://api.github.com/repos/bosun-monitor/bosun/pulls/772"}}},"pull_request":{"url":"https://api.github.com/repos/bosun-monitor/bosun/pulls/772","id":30789791,"html_url":"https://github.com/bosun-monitor/bosun/pull/772","diff_url":"https://github.com/bosun-monitor/bosun/pull/772.diff","patch_url":"https://github.com/bosun-monitor/bosun/pull/772.patch","issue_url":"https://api.github.com/repos/bosun-monitor/bosun/issues/772","number":772,"state":"open","locked":false,"title":"Dependencies v2","user":{"login":"captncraig","id":192540,"avatar_url":"https://avatars.githubusercontent.com/u/192540?v=3","gravatar_id":"","url":"https://api.github.com/users/captncraig","html_url":"https://github.com/captncraig","followers_url":"https://api.github.com/users/captncraig/followers","following_url":"https://api.github.com/users/captncraig/following{/other_user}","gists_url":"https://api.github.com/users/captncraig/gists{/gist_id}","starred_url":"https://api.github.com/users/captncraig/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/captncraig/subscriptions","organizations_url":"https://api.github.com/users/captncraig/orgs","repos_url":"https://api.github.com/users/captncraig/repos","events_url":"https://api.github.com/users/captncraig/events{/privacy}","received_events_url":"https://api.github.com/users/captncraig/received_events","type":"User","site_admin":false},"body":"The other one was only getting buggier and buggier.\r\n\r\nThis version is based off of newer code and should be a tad simpler, and have more tests.","created_at":"2015-03-09T19:04:53Z","updated_at":"2015-03-19T05:54:33Z","closed_at":null,"merged_at":null,"merge_commit_sha":"32139a78e76ef72d48deba290dc6f3f7dcfb1e21","assignee":{"login":"kylebrandt","id":1692624,"avatar_url":"https://avatars.githubusercontent.com/u/1692624?v=3","gravatar_id":"","url":"https://api.github.com/users/kylebrandt","html_url":"https://github.com/kylebrandt","followers_url":"https://api.github.com/users/kylebrandt/followers","following_url":"https://api.github.com/users/kylebrandt/following{/other_user}","gists_url":"https://api.github.com/users/kylebrandt/gists{/gist_id}","starred_url":"https://api.github.com/users/kylebrandt/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kylebrandt/subscriptions","organizations_url":"https://api.github.com/users/kylebrandt/orgs","repos_url":"https://api.github.com/users/kylebrandt/repos","events_url":"https://api.github.com/users/kylebrandt/events{/privacy}","received_events_url":"https://api.github.com/users/kylebrandt/received_events","type":"User","site_admin":false},"milestone":null,"commits_url":"https://api.github.com/repos/bosun-monitor/bosun/pulls/772/commits","review_comments_url":"https://api.github.com/repos/bosun-monitor/bosun/pulls/772/comments","review_comment_url":"https://api.github.com/repos/bosun-monitor/bosun/pulls/comments{/number}","comments_url":"https://api.github.com/repos/bosun-monitor/bosun/issues/772/comments","statuses_url":"https://api.github.com/repos/bosun-monitor/bosun/statuses/789005c998443201c7214feb27f3356d4c914b63","head":{"label":"bosun-monitor:dependencies","ref":"dependencies","sha":"789005c998443201c7214feb27f3356d4c914b63","user":{"login":"bosun-monitor","id":9555242,"avatar_url":"https://avatars.githubusercontent.com/u/9555242?v=3","gravatar_id":"","url":"https://api.github.com/users/bosun-monitor","html_url":"https://github.com/bosun-monitor","followers_url":"https://api.github.com/users/bosun-monitor/followers","following_url":"https://api.github.com/users/bosun-monitor/following{/other_user}","gists_url":"https://api.github.com/users/bosun-monitor/gists{/gist_id}","starred_url":"https://api.github.com/users/bosun-monitor/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bosun-monitor/subscriptions","organizations_url":"https://api.github.com/users/bosun-monitor/orgs","repos_url":"https://api.github.com/users/bosun-monitor/repos","events_url":"https://api.github.com/users/bosun-monitor/events{/privacy}","received_events_url":"https://api.github.com/users/bosun-monitor/received_events","type":"Organization","site_admin":false},"repo":{"id":14410778,"name":"bosun","full_name":"bosun-monitor/bosun","owner":{"login":"bosun-monitor","id":9555242,"avatar_url":"https://avatars.githubusercontent.com/u/9555242?v=3","gravatar_id":"","url":"https://api.github.com/users/bosun-monitor","html_url":"https://github.com/bosun-monitor","followers_url":"https://api.github.com/users/bosun-monitor/followers","following_url":"https://api.github.com/users/bosun-monitor/following{/other_user}","gists_url":"https://api.github.com/users/bosun-monitor/gists{/gist_id}","starred_url":"https://api.github.com/users/bosun-monitor/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bosun-monitor/subscriptions","organizations_url":"https://api.github.com/users/bosun-monitor/orgs","repos_url":"https://api.github.com/users/bosun-monitor/repos","events_url":"https://api.github.com/users/bosun-monitor/events{/privacy}","received_events_url":"https://api.github.com/users/bosun-monitor/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/bosun-monitor/bosun","description":"Time Series Alerting Framework","fork":false,"url":"https://api.github.com/repos/bosun-monitor/bosun","forks_url":"https://api.github.com/repos/bosun-monitor/bosun/forks","keys_url":"https://api.github.com/repos/bosun-monitor/bosun/keys{/key_id}","collaborators_url":"https://api.github.com/repos/bosun-monitor/bosun/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/bosun-monitor/bosun/teams","hooks_url":"https://api.github.com/repos/bosun-monitor/bosun/hooks","issue_events_url":"https://api.github.com/repos/bosun-monitor/bosun/issues/events{/number}","events_url":"https://api.github.com/repos/bosun-monitor/bosun/events","assignees_url":"https://api.github.com/repos/bosun-monitor/bosun/assignees{/user}","branches_url":"https://api.github.com/repos/bosun-monitor/bosun/branches{/branch}","tags_url":"https://api.github.com/repos/bosun-monitor/bosun/tags","blobs_url":"https://api.github.com/repos/bosun-monitor/bosun/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/bosun-monitor/bosun/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/bosun-monitor/bosun/git/refs{/sha}","trees_url":"https://api.github.com/repos/bosun-monitor/bosun/git/trees{/sha}","statuses_url":"https://api.github.com/repos/bosun-monitor/bosun/statuses/{sha}","languages_url":"https://api.github.com/repos/bosun-monitor/bosun/languages","stargazers_url":"https://api.github.com/repos/bosun-monitor/bosun/stargazers","contributors_url":"https://api.github.com/repos/bosun-monitor/bosun/contributors","subscribers_url":"https://api.github.com/repos/bosun-monitor/bosun/subscribers","subscription_url":"https://api.github.com/repos/bosun-monitor/bosun/subscription","commits_url":"https://api.github.com/repos/bosun-monitor/bosun/commits{/sha}","git_commits_url":"https://api.github.com/repos/bosun-monitor/bosun/git/commits{/sha}","comments_url":"https://api.github.com/repos/bosun-monitor/bosun/comments{/number}","issue_comment_url":"https://api.github.com/repos/bosun-monitor/bosun/issues/comments{/number}","contents_url":"https://api.github.com/repos/bosun-monitor/bosun/contents/{+path}","compare_url":"https://api.github.com/repos/bosun-monitor/bosun/compare/{base}...{head}","merges_url":"https://api.github.com/repos/bosun-monitor/bosun/merges","archive_url":"https://api.github.com/repos/bosun-monitor/bosun/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/bosun-monitor/bosun/downloads","issues_url":"https://api.github.com/repos/bosun-monitor/bosun/issues{/number}","pulls_url":"https://api.github.com/repos/bosun-monitor/bosun/pulls{/number}","milestones_url":"https://api.github.com/repos/bosun-monitor/bosun/milestones{/number}","notifications_url":"https://api.github.com/repos/bosun-monitor/bosun/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/bosun-monitor/bosun/labels{/name}","releases_url":"https://api.github.com/repos/bosun-monitor/bosun/releases{/id}","created_at":"2013-11-15T00:12:27Z","updated_at":"2015-03-18T18:20:04Z","pushed_at":"2015-03-19T02:57:04Z","git_url":"git://github.com/bosun-monitor/bosun.git","ssh_url":"git@github.com:bosun-monitor/bosun.git","clone_url":"https://github.com/bosun-monitor/bosun.git","svn_url":"https://github.com/bosun-monitor/bosun","homepage":"http://bosun.org","size":24403,"stargazers_count":834,"watchers_count":834,"language":"Go","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":86,"mirror_url":null,"open_issues_count":146,"forks":86,"open_issues":146,"watchers":834,"default_branch":"master"}},"base":{"label":"bosun-monitor:master","ref":"master","sha":"67e75de4d831607755e0d8fd08e8238a04c73490","user":{"login":"bosun-monitor","id":9555242,"avatar_url":"https://avatars.githubusercontent.com/u/9555242?v=3","gravatar_id":"","url":"https://api.github.com/users/bosun-monitor","html_url":"https://github.com/bosun-monitor","followers_url":"https://api.github.com/users/bosun-monitor/followers","following_url":"https://api.github.com/users/bosun-monitor/following{/other_user}","gists_url":"https://api.github.com/users/bosun-monitor/gists{/gist_id}","starred_url":"https://api.github.com/users/bosun-monitor/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bosun-monitor/subscriptions","organizations_url":"https://api.github.com/users/bosun-monitor/orgs","repos_url":"https://api.github.com/users/bosun-monitor/repos","events_url":"https://api.github.com/users/bosun-monitor/events{/privacy}","received_events_url":"https://api.github.com/users/bosun-monitor/received_events","type":"Organization","site_admin":false},"repo":{"id":14410778,"name":"bosun","full_name":"bosun-monitor/bosun","owner":{"login":"bosun-monitor","id":9555242,"avatar_url":"https://avatars.githubusercontent.com/u/9555242?v=3","gravatar_id":"","url":"https://api.github.com/users/bosun-monitor","html_url":"https://github.com/bosun-monitor","followers_url":"https://api.github.com/users/bosun-monitor/followers","following_url":"https://api.github.com/users/bosun-monitor/following{/other_user}","gists_url":"https://api.github.com/users/bosun-monitor/gists{/gist_id}","starred_url":"https://api.github.com/users/bosun-monitor/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bosun-monitor/subscriptions","organizations_url":"https://api.github.com/users/bosun-monitor/orgs","repos_url":"https://api.github.com/users/bosun-monitor/repos","events_url":"https://api.github.com/users/bosun-monitor/events{/privacy}","received_events_url":"https://api.github.com/users/bosun-monitor/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/bosun-monitor/bosun","description":"Time Series Alerting Framework","fork":false,"url":"https://api.github.com/repos/bosun-monitor/bosun","forks_url":"https://api.github.com/repos/bosun-monitor/bosun/forks","keys_url":"https://api.github.com/repos/bosun-monitor/bosun/keys{/key_id}","collaborators_url":"https://api.github.com/repos/bosun-monitor/bosun/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/bosun-monitor/bosun/teams","hooks_url":"https://api.github.com/repos/bosun-monitor/bosun/hooks","issue_events_url":"https://api.github.com/repos/bosun-monitor/bosun/issues/events{/number}","events_url":"https://api.github.com/repos/bosun-monitor/bosun/events","assignees_url":"https://api.github.com/repos/bosun-monitor/bosun/assignees{/user}","branches_url":"https://api.github.com/repos/bosun-monitor/bosun/branches{/branch}","tags_url":"https://api.github.com/repos/bosun-monitor/bosun/tags","blobs_url":"https://api.github.com/repos/bosun-monitor/bosun/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/bosun-monitor/bosun/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/bosun-monitor/bosun/git/refs{/sha}","trees_url":"https://api.github.com/repos/bosun-monitor/bosun/git/trees{/sha}","statuses_url":"https://api.github.com/repos/bosun-monitor/bosun/statuses/{sha}","languages_url":"https://api.github.com/repos/bosun-monitor/bosun/languages","stargazers_url":"https://api.github.com/repos/bosun-monitor/bosun/stargazers","contributors_url":"https://api.github.com/repos/bosun-monitor/bosun/contributors","subscribers_url":"https://api.github.com/repos/bosun-monitor/bosun/subscribers","subscription_url":"https://api.github.com/repos/bosun-monitor/bosun/subscription","commits_url":"https://api.github.com/repos/bosun-monitor/bosun/commits{/sha}","git_commits_url":"https://api.github.com/repos/bosun-monitor/bosun/git/commits{/sha}","comments_url":"https://api.github.com/repos/bosun-monitor/bosun/comments{/number}","issue_comment_url":"https://api.github.com/repos/bosun-monitor/bosun/issues/comments{/number}","contents_url":"https://api.github.com/repos/bosun-monitor/bosun/contents/{+path}","compare_url":"https://api.github.com/repos/bosun-monitor/bosun/compare/{base}...{head}","merges_url":"https://api.github.com/repos/bosun-monitor/bosun/merges","archive_url":"https://api.github.com/repos/bosun-monitor/bosun/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/bosun-monitor/bosun/downloads","issues_url":"https://api.github.com/repos/bosun-monitor/bosun/issues{/number}","pulls_url":"https://api.github.com/repos/bosun-monitor/bosun/pulls{/number}","milestones_url":"https://api.github.com/repos/bosun-monitor/bosun/milestones{/number}","notifications_url":"https://api.github.com/repos/bosun-monitor/bosun/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/bosun-monitor/bosun/labels{/name}","releases_url":"https://api.github.com/repos/bosun-monitor/bosun/releases{/id}","created_at":"2013-11-15T00:12:27Z","updated_at":"2015-03-18T18:20:04Z","pushed_at":"2015-03-19T02:57:04Z","git_url":"git://github.com/bosun-monitor/bosun.git","ssh_url":"git@github.com:bosun-monitor/bosun.git","clone_url":"https://github.com/bosun-monitor/bosun.git","svn_url":"https://github.com/bosun-monitor/bosun","homepage":"http://bosun.org","size":24403,"stargazers_count":834,"watchers_count":834,"language":"Go","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":86,"mirror_url":null,"open_issues_count":146,"forks":86,"open_issues":146,"watchers":834,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/bosun-monitor/bosun/pulls/772"},"html":{"href":"https://github.com/bosun-monitor/bosun/pull/772"},"issue":{"href":"https://api.github.com/repos/bosun-monitor/bosun/issues/772"},"comments":{"href":"https://api.github.com/repos/bosun-monitor/bosun/issues/772/comments"},"review_comments":{"href":"https://api.github.com/repos/bosun-monitor/bosun/pulls/772/comments"},"review_comment":{"href":"https://api.github.com/repos/bosun-monitor/bosun/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/bosun-monitor/bosun/pulls/772/commits"},"statuses":{"href":"https://api.github.com/repos/bosun-monitor/bosun/statuses/789005c998443201c7214feb27f3356d4c914b63"}}}}