{"action":"created","comment":{"url":"https://api.github.com/repos/prometheus/prometheus/pulls/comments/51944591","id":51944591,"diff_hunk":"@@ -127,6 +130,59 @@ func (api *API) options(r *http.Request) (interface{}, *apiError) {\n \treturn nil, nil\n }\n \n+// TODO(jsanford): FIXME: This is a sample implementation.\n+func (api *API) queryRule(r *http.Request) (interface{}, *apiError) {\n+\tvar ts model.Time\n+\tif t := r.FormValue(\"time\"); t != \"\" {\n+\t\tvar err error\n+\t\tts, err = parseTime(t)\n+\t\tif err != nil {\n+\t\t\treturn nil, &apiError{errorBadData, err}\n+\t\t}\n+\t} else {\n+\t\tts = api.now()\n+\t}\n+\n+\tst, err := promql.ParseStmts(string(r.FormValue(\"query\")))\n+\tif err != nil {\n+\t\treturn nil, &apiError{errorBadData, err}\n+\t}\n+\n+\trls, err := rules.NewRules(st)\n+\tif err != nil {\n+\t\treturn nil, &apiError{errorBadData, err}\n+\t}\n+\n+\tvar v []interface{}\n+\tfor _, r := range rls {\n+\t\tvector, err := r.Eval(ts, api.QueryEngine)\n+\t\tif err != nil {\n+\t\t\tswitch err.(type) {\n+\t\t\tcase promql.ErrQueryCanceled:\n+\t\t\t\treturn nil, &apiError{errorCanceled, err}\n+\t\t\tcase promql.ErrQueryTimeout:\n+\t\t\t\treturn nil, &apiError{errorTimeout, err}\n+\t\t\t}\n+\t\t\treturn nil, &apiError{errorExec, err}\n+\t\t}\n+\n+\t\t// TODO(jsanford): Do we want to return this at all?  Probably not.","path":"web/api/v1/api.go","position":null,"original_position":64,"commit_id":"4eec1baed95dc02b14b43656b8ef967a85b6effb","original_commit_id":"03538744bb702a7fb4dead8900412075bede34fd","user":{"login":"matthiasr","id":131590,"avatar_url":"https://avatars.githubusercontent.com/u/131590?v=3","gravatar_id":"","url":"https://api.github.com/users/matthiasr","html_url":"https://github.com/matthiasr","followers_url":"https://api.github.com/users/matthiasr/followers","following_url":"https://api.github.com/users/matthiasr/following{/other_user}","gists_url":"https://api.github.com/users/matthiasr/gists{/gist_id}","starred_url":"https://api.github.com/users/matthiasr/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/matthiasr/subscriptions","organizations_url":"https://api.github.com/users/matthiasr/orgs","repos_url":"https://api.github.com/users/matthiasr/repos","events_url":"https://api.github.com/users/matthiasr/events{/privacy}","received_events_url":"https://api.github.com/users/matthiasr/received_events","type":"User","site_admin":false},"body":"Given this endpoint this can be done on the client side. Evaluating a whole\nweek should not be default behavior, it would take minutes and be very\nexpensive for wide-reaching rules on a big server. Overriding the defaults\ndepending on the use case is easily done, but the minimal amount of work is\na safer default.\n","created_at":"2016-02-04T21:58:49Z","updated_at":"2016-02-04T21:58:49Z","html_url":"https://github.com/prometheus/prometheus/pull/1369#discussion_r51944591","pull_request_url":"https://api.github.com/repos/prometheus/prometheus/pulls/1369","_links":{"self":{"href":"https://api.github.com/repos/prometheus/prometheus/pulls/comments/51944591"},"html":{"href":"https://github.com/prometheus/prometheus/pull/1369#discussion_r51944591"},"pull_request":{"href":"https://api.github.com/repos/prometheus/prometheus/pulls/1369"}}},"pull_request":{"url":"https://api.github.com/repos/prometheus/prometheus/pulls/1369","id":58231578,"html_url":"https://github.com/prometheus/prometheus/pull/1369","diff_url":"https://github.com/prometheus/prometheus/pull/1369.diff","patch_url":"https://github.com/prometheus/prometheus/pull/1369.patch","issue_url":"https://api.github.com/repos/prometheus/prometheus/issues/1369","number":1369,"state":"open","locked":false,"title":"API endpoint to evaluate arbitrary ALERT rules","user":{"login":"jamessanford","id":1072753,"avatar_url":"https://avatars.githubusercontent.com/u/1072753?v=3","gravatar_id":"","url":"https://api.github.com/users/jamessanford","html_url":"https://github.com/jamessanford","followers_url":"https://api.github.com/users/jamessanford/followers","following_url":"https://api.github.com/users/jamessanford/following{/other_user}","gists_url":"https://api.github.com/users/jamessanford/gists{/gist_id}","starred_url":"https://api.github.com/users/jamessanford/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jamessanford/subscriptions","organizations_url":"https://api.github.com/users/jamessanford/orgs","repos_url":"https://api.github.com/users/jamessanford/repos","events_url":"https://api.github.com/users/jamessanford/events{/privacy}","received_events_url":"https://api.github.com/users/jamessanford/received_events","type":"User","site_admin":false},"body":"The `api.go` changes in this PR should **not** be merged, it's just a (working) example.\r\n\r\nThis adds the ability to paste an entire ALERT rule definition into Prometheus, have it evaluate the rule, and show the full resulting alerts -- and templated data -- that would fire.\r\n\r\nThis serves as a rapid way of developing new alert rules with live data, and perhaps brings things in the direction of being able to write tests for alerts.\r\n\r\nA little bit of refactoring was necessary, see the individual commits.\r\n\r\nI'm looking for comments for how the `/query_rule` endpoint should work.  I plan to add a tab in the UI with a large textarea and an \"Evaluate\" button.","created_at":"2016-02-04T02:03:04Z","updated_at":"2016-02-04T21:58:49Z","closed_at":null,"merged_at":null,"merge_commit_sha":"719bf30884bf3ed994ce79b19e5bb09b2ee56f2a","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/prometheus/prometheus/pulls/1369/commits","review_comments_url":"https://api.github.com/repos/prometheus/prometheus/pulls/1369/comments","review_comment_url":"https://api.github.com/repos/prometheus/prometheus/pulls/comments{/number}","comments_url":"https://api.github.com/repos/prometheus/prometheus/issues/1369/comments","statuses_url":"https://api.github.com/repos/prometheus/prometheus/statuses/4eec1baed95dc02b14b43656b8ef967a85b6effb","head":{"label":"jamessanford:jamessanford/query_rule_api","ref":"jamessanford/query_rule_api","sha":"4eec1baed95dc02b14b43656b8ef967a85b6effb","user":{"login":"jamessanford","id":1072753,"avatar_url":"https://avatars.githubusercontent.com/u/1072753?v=3","gravatar_id":"","url":"https://api.github.com/users/jamessanford","html_url":"https://github.com/jamessanford","followers_url":"https://api.github.com/users/jamessanford/followers","following_url":"https://api.github.com/users/jamessanford/following{/other_user}","gists_url":"https://api.github.com/users/jamessanford/gists{/gist_id}","starred_url":"https://api.github.com/users/jamessanford/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jamessanford/subscriptions","organizations_url":"https://api.github.com/users/jamessanford/orgs","repos_url":"https://api.github.com/users/jamessanford/repos","events_url":"https://api.github.com/users/jamessanford/events{/privacy}","received_events_url":"https://api.github.com/users/jamessanford/received_events","type":"User","site_admin":false},"repo":{"id":51044547,"name":"prometheus","full_name":"jamessanford/prometheus","owner":{"login":"jamessanford","id":1072753,"avatar_url":"https://avatars.githubusercontent.com/u/1072753?v=3","gravatar_id":"","url":"https://api.github.com/users/jamessanford","html_url":"https://github.com/jamessanford","followers_url":"https://api.github.com/users/jamessanford/followers","following_url":"https://api.github.com/users/jamessanford/following{/other_user}","gists_url":"https://api.github.com/users/jamessanford/gists{/gist_id}","starred_url":"https://api.github.com/users/jamessanford/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jamessanford/subscriptions","organizations_url":"https://api.github.com/users/jamessanford/orgs","repos_url":"https://api.github.com/users/jamessanford/repos","events_url":"https://api.github.com/users/jamessanford/events{/privacy}","received_events_url":"https://api.github.com/users/jamessanford/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/jamessanford/prometheus","description":"The Prometheus monitoring system and time series database.","fork":true,"url":"https://api.github.com/repos/jamessanford/prometheus","forks_url":"https://api.github.com/repos/jamessanford/prometheus/forks","keys_url":"https://api.github.com/repos/jamessanford/prometheus/keys{/key_id}","collaborators_url":"https://api.github.com/repos/jamessanford/prometheus/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/jamessanford/prometheus/teams","hooks_url":"https://api.github.com/repos/jamessanford/prometheus/hooks","issue_events_url":"https://api.github.com/repos/jamessanford/prometheus/issues/events{/number}","events_url":"https://api.github.com/repos/jamessanford/prometheus/events","assignees_url":"https://api.github.com/repos/jamessanford/prometheus/assignees{/user}","branches_url":"https://api.github.com/repos/jamessanford/prometheus/branches{/branch}","tags_url":"https://api.github.com/repos/jamessanford/prometheus/tags","blobs_url":"https://api.github.com/repos/jamessanford/prometheus/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/jamessanford/prometheus/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/jamessanford/prometheus/git/refs{/sha}","trees_url":"https://api.github.com/repos/jamessanford/prometheus/git/trees{/sha}","statuses_url":"https://api.github.com/repos/jamessanford/prometheus/statuses/{sha}","languages_url":"https://api.github.com/repos/jamessanford/prometheus/languages","stargazers_url":"https://api.github.com/repos/jamessanford/prometheus/stargazers","contributors_url":"https://api.github.com/repos/jamessanford/prometheus/contributors","subscribers_url":"https://api.github.com/repos/jamessanford/prometheus/subscribers","subscription_url":"https://api.github.com/repos/jamessanford/prometheus/subscription","commits_url":"https://api.github.com/repos/jamessanford/prometheus/commits{/sha}","git_commits_url":"https://api.github.com/repos/jamessanford/prometheus/git/commits{/sha}","comments_url":"https://api.github.com/repos/jamessanford/prometheus/comments{/number}","issue_comment_url":"https://api.github.com/repos/jamessanford/prometheus/issues/comments{/number}","contents_url":"https://api.github.com/repos/jamessanford/prometheus/contents/{+path}","compare_url":"https://api.github.com/repos/jamessanford/prometheus/compare/{base}...{head}","merges_url":"https://api.github.com/repos/jamessanford/prometheus/merges","archive_url":"https://api.github.com/repos/jamessanford/prometheus/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/jamessanford/prometheus/downloads","issues_url":"https://api.github.com/repos/jamessanford/prometheus/issues{/number}","pulls_url":"https://api.github.com/repos/jamessanford/prometheus/pulls{/number}","milestones_url":"https://api.github.com/repos/jamessanford/prometheus/milestones{/number}","notifications_url":"https://api.github.com/repos/jamessanford/prometheus/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/jamessanford/prometheus/labels{/name}","releases_url":"https://api.github.com/repos/jamessanford/prometheus/releases{/id}","deployments_url":"https://api.github.com/repos/jamessanford/prometheus/deployments","created_at":"2016-02-04T01:44:20Z","updated_at":"2016-02-04T01:44:22Z","pushed_at":"2016-02-04T21:39:54Z","git_url":"git://github.com/jamessanford/prometheus.git","ssh_url":"git@github.com:jamessanford/prometheus.git","clone_url":"https://github.com/jamessanford/prometheus.git","svn_url":"https://github.com/jamessanford/prometheus","homepage":"http://prometheus.io/","size":9735,"stargazers_count":0,"watchers_count":0,"language":"Go","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"prometheus:master","ref":"master","sha":"1756c0811c20760095e87391863b8322bba82546","user":{"login":"prometheus","id":3380462,"avatar_url":"https://avatars.githubusercontent.com/u/3380462?v=3","gravatar_id":"","url":"https://api.github.com/users/prometheus","html_url":"https://github.com/prometheus","followers_url":"https://api.github.com/users/prometheus/followers","following_url":"https://api.github.com/users/prometheus/following{/other_user}","gists_url":"https://api.github.com/users/prometheus/gists{/gist_id}","starred_url":"https://api.github.com/users/prometheus/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/prometheus/subscriptions","organizations_url":"https://api.github.com/users/prometheus/orgs","repos_url":"https://api.github.com/users/prometheus/repos","events_url":"https://api.github.com/users/prometheus/events{/privacy}","received_events_url":"https://api.github.com/users/prometheus/received_events","type":"Organization","site_admin":false},"repo":{"id":6838921,"name":"prometheus","full_name":"prometheus/prometheus","owner":{"login":"prometheus","id":3380462,"avatar_url":"https://avatars.githubusercontent.com/u/3380462?v=3","gravatar_id":"","url":"https://api.github.com/users/prometheus","html_url":"https://github.com/prometheus","followers_url":"https://api.github.com/users/prometheus/followers","following_url":"https://api.github.com/users/prometheus/following{/other_user}","gists_url":"https://api.github.com/users/prometheus/gists{/gist_id}","starred_url":"https://api.github.com/users/prometheus/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/prometheus/subscriptions","organizations_url":"https://api.github.com/users/prometheus/orgs","repos_url":"https://api.github.com/users/prometheus/repos","events_url":"https://api.github.com/users/prometheus/events{/privacy}","received_events_url":"https://api.github.com/users/prometheus/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/prometheus/prometheus","description":"The Prometheus monitoring system and time series database.","fork":false,"url":"https://api.github.com/repos/prometheus/prometheus","forks_url":"https://api.github.com/repos/prometheus/prometheus/forks","keys_url":"https://api.github.com/repos/prometheus/prometheus/keys{/key_id}","collaborators_url":"https://api.github.com/repos/prometheus/prometheus/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/prometheus/prometheus/teams","hooks_url":"https://api.github.com/repos/prometheus/prometheus/hooks","issue_events_url":"https://api.github.com/repos/prometheus/prometheus/issues/events{/number}","events_url":"https://api.github.com/repos/prometheus/prometheus/events","assignees_url":"https://api.github.com/repos/prometheus/prometheus/assignees{/user}","branches_url":"https://api.github.com/repos/prometheus/prometheus/branches{/branch}","tags_url":"https://api.github.com/repos/prometheus/prometheus/tags","blobs_url":"https://api.github.com/repos/prometheus/prometheus/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/prometheus/prometheus/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/prometheus/prometheus/git/refs{/sha}","trees_url":"https://api.github.com/repos/prometheus/prometheus/git/trees{/sha}","statuses_url":"https://api.github.com/repos/prometheus/prometheus/statuses/{sha}","languages_url":"https://api.github.com/repos/prometheus/prometheus/languages","stargazers_url":"https://api.github.com/repos/prometheus/prometheus/stargazers","contributors_url":"https://api.github.com/repos/prometheus/prometheus/contributors","subscribers_url":"https://api.github.com/repos/prometheus/prometheus/subscribers","subscription_url":"https://api.github.com/repos/prometheus/prometheus/subscription","commits_url":"https://api.github.com/repos/prometheus/prometheus/commits{/sha}","git_commits_url":"https://api.github.com/repos/prometheus/prometheus/git/commits{/sha}","comments_url":"https://api.github.com/repos/prometheus/prometheus/comments{/number}","issue_comment_url":"https://api.github.com/repos/prometheus/prometheus/issues/comments{/number}","contents_url":"https://api.github.com/repos/prometheus/prometheus/contents/{+path}","compare_url":"https://api.github.com/repos/prometheus/prometheus/compare/{base}...{head}","merges_url":"https://api.github.com/repos/prometheus/prometheus/merges","archive_url":"https://api.github.com/repos/prometheus/prometheus/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/prometheus/prometheus/downloads","issues_url":"https://api.github.com/repos/prometheus/prometheus/issues{/number}","pulls_url":"https://api.github.com/repos/prometheus/prometheus/pulls{/number}","milestones_url":"https://api.github.com/repos/prometheus/prometheus/milestones{/number}","notifications_url":"https://api.github.com/repos/prometheus/prometheus/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/prometheus/prometheus/labels{/name}","releases_url":"https://api.github.com/repos/prometheus/prometheus/releases{/id}","deployments_url":"https://api.github.com/repos/prometheus/prometheus/deployments","created_at":"2012-11-24T11:14:12Z","updated_at":"2016-02-04T21:39:42Z","pushed_at":"2016-02-04T21:39:55Z","git_url":"git://github.com/prometheus/prometheus.git","ssh_url":"git@github.com:prometheus/prometheus.git","clone_url":"https://github.com/prometheus/prometheus.git","svn_url":"https://github.com/prometheus/prometheus","homepage":"http://prometheus.io/","size":10978,"stargazers_count":3837,"watchers_count":3837,"language":"Go","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":296,"mirror_url":null,"open_issues_count":117,"forks":296,"open_issues":117,"watchers":3837,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/prometheus/prometheus/pulls/1369"},"html":{"href":"https://github.com/prometheus/prometheus/pull/1369"},"issue":{"href":"https://api.github.com/repos/prometheus/prometheus/issues/1369"},"comments":{"href":"https://api.github.com/repos/prometheus/prometheus/issues/1369/comments"},"review_comments":{"href":"https://api.github.com/repos/prometheus/prometheus/pulls/1369/comments"},"review_comment":{"href":"https://api.github.com/repos/prometheus/prometheus/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/prometheus/prometheus/pulls/1369/commits"},"statuses":{"href":"https://api.github.com/repos/prometheus/prometheus/statuses/4eec1baed95dc02b14b43656b8ef967a85b6effb"}}}}