{"action":"created","comment":{"url":"https://api.github.com/repos/prometheus/prometheus/pulls/comments/181434857","pull_request_review_id":112067991,"id":181434857,"diff_hunk":"@@ -326,3 +349,101 @@ func CheckMetrics() int {\n \n \treturn 0\n }\n+\n+// QueryInstant performs an instant query against prometheus server.\n+func QueryInstant(url *url.URL, query string) int {\n+\tconfig := api.Config{\n+\t\tAddress: url.String(),\n+\t}\n+\n+\t// Create new client.\n+\tc, err := api.NewClient(config)\n+\tif err != nil {\n+\t\tfmt.Fprintln(os.Stderr, \"error creating API client:\", err)\n+\t\treturn 1\n+\t}\n+\n+\t// Run query against client.\n+\tapi := v1.NewAPI(c)\n+\n+\tctx, cancel := context.WithTimeout(context.Background(), 2*time.Minute)\n+\tval, err := api.Query(ctx, query, time.Now())\n+\tcancel()\n+\tif err != nil {\n+\t\tfmt.Fprintln(os.Stderr, \"query error:\", err)\n+\t\treturn 1\n+\t}\n+\n+\tfmt.Println(val.String())\n+\n+\treturn 0\n+}\n+\n+// QueryRange performs a range query against a prometheus server.\n+func QueryRange(url *url.URL, query string, start string, end string) int {\n+\tconfig := api.Config{\n+\t\tAddress: url.String(),\n+\t}\n+\n+\t// Create new client.\n+\tc, err := api.NewClient(config)\n+\tif err != nil {\n+\t\tfmt.Fprintln(os.Stderr, \"error creating API client:\", err)\n+\t\treturn 1\n+\t}\n+\n+\tvar stime, etime time.Time\n+\n+\tif end == \"\" {\n+\t\tetime = time.Now()\n+\t} else {\n+\t\tetime, err = parseTime(end)\n+\t\tif err != nil {\n+\t\t\tfmt.Fprintln(os.Stderr, \"error parsing end time:\", err)\n+\t\t\treturn 1\n+\t\t}\n+\t}\n+\n+\tif start == \"\" {\n+\t\tstime = etime.Add(-5 * time.Minute)\n+\t} else {\n+\t\tstime, err = parseTime(start)\n+\t\tif err != nil {\n+\t\t\tfmt.Fprintln(os.Stderr, \"error parsing start time:\", err)\n+\t\t}\n+\t}\n+\n+\tif !stime.Before(etime) {\n+\t\tfmt.Fprintln(os.Stderr, \"start time is not before end time\")\n+\t}\n+\n+\tresolution := math.Max(math.Floor(etime.Sub(stime).Seconds()/250), 1)\n+\t// Convert seconds to nanoseconds such that time.Duration parses correctly.\n+\tstep := time.Duration(resolution * math.Pow(10, 9))","path":"cmd/promtool/main.go","position":127,"original_position":127,"commit_id":"d9fcb884035fa792498b3f61c109a7771926758c","original_commit_id":"d9fcb884035fa792498b3f61c109a7771926758c","user":{"login":"juliusv","id":538008,"avatar_url":"https://avatars2.githubusercontent.com/u/538008?v=4","gravatar_id":"","url":"https://api.github.com/users/juliusv","html_url":"https://github.com/juliusv","followers_url":"https://api.github.com/users/juliusv/followers","following_url":"https://api.github.com/users/juliusv/following{/other_user}","gists_url":"https://api.github.com/users/juliusv/gists{/gist_id}","starred_url":"https://api.github.com/users/juliusv/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/juliusv/subscriptions","organizations_url":"https://api.github.com/users/juliusv/orgs","repos_url":"https://api.github.com/users/juliusv/repos","events_url":"https://api.github.com/users/juliusv/events{/privacy}","received_events_url":"https://api.github.com/users/juliusv/received_events","type":"User","site_admin":false},"body":"`math.Pow(10, 9)` can just be `1e9`.\r\n\r\nOr better, do `time.Duration(resolution * time.Second)` because that keeps it independent of the integer representation of `time.Duration`.","created_at":"2018-04-13T15:59:50Z","updated_at":"2018-04-13T15:59:50Z","html_url":"https://github.com/prometheus/prometheus/pull/4085#discussion_r181434857","pull_request_url":"https://api.github.com/repos/prometheus/prometheus/pulls/4085","author_association":"OWNER","_links":{"self":{"href":"https://api.github.com/repos/prometheus/prometheus/pulls/comments/181434857"},"html":{"href":"https://github.com/prometheus/prometheus/pull/4085#discussion_r181434857"},"pull_request":{"href":"https://api.github.com/repos/prometheus/prometheus/pulls/4085"}}},"pull_request":{"url":"https://api.github.com/repos/prometheus/prometheus/pulls/4085","id":181524403,"html_url":"https://github.com/prometheus/prometheus/pull/4085","diff_url":"https://github.com/prometheus/prometheus/pull/4085.diff","patch_url":"https://github.com/prometheus/prometheus/pull/4085.patch","issue_url":"https://api.github.com/repos/prometheus/prometheus/issues/4085","number":4085,"state":"open","locked":false,"title":"promtool: add query instant and query range commands","user":{"login":"si74","id":913035,"avatar_url":"https://avatars3.githubusercontent.com/u/913035?v=4","gravatar_id":"","url":"https://api.github.com/users/si74","html_url":"https://github.com/si74","followers_url":"https://api.github.com/users/si74/followers","following_url":"https://api.github.com/users/si74/following{/other_user}","gists_url":"https://api.github.com/users/si74/gists{/gist_id}","starred_url":"https://api.github.com/users/si74/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/si74/subscriptions","organizations_url":"https://api.github.com/users/si74/orgs","repos_url":"https://api.github.com/users/si74/repos","events_url":"https://api.github.com/users/si74/events{/privacy}","received_events_url":"https://api.github.com/users/si74/received_events","type":"User","site_admin":false},"body":"Relating to this issue: https://github.com/prometheus/prometheus/issues/1605","created_at":"2018-04-13T15:36:55Z","updated_at":"2018-04-13T15:59:50Z","closed_at":null,"merged_at":null,"merge_commit_sha":"2ccc4dc4e3c1b8746b9115cfc2e0371f08fcd518","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[],"milestone":null,"commits_url":"https://api.github.com/repos/prometheus/prometheus/pulls/4085/commits","review_comments_url":"https://api.github.com/repos/prometheus/prometheus/pulls/4085/comments","review_comment_url":"https://api.github.com/repos/prometheus/prometheus/pulls/comments{/number}","comments_url":"https://api.github.com/repos/prometheus/prometheus/issues/4085/comments","statuses_url":"https://api.github.com/repos/prometheus/prometheus/statuses/d9fcb884035fa792498b3f61c109a7771926758c","head":{"label":"si74:promtool_add_commands","ref":"promtool_add_commands","sha":"d9fcb884035fa792498b3f61c109a7771926758c","user":{"login":"si74","id":913035,"avatar_url":"https://avatars3.githubusercontent.com/u/913035?v=4","gravatar_id":"","url":"https://api.github.com/users/si74","html_url":"https://github.com/si74","followers_url":"https://api.github.com/users/si74/followers","following_url":"https://api.github.com/users/si74/following{/other_user}","gists_url":"https://api.github.com/users/si74/gists{/gist_id}","starred_url":"https://api.github.com/users/si74/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/si74/subscriptions","organizations_url":"https://api.github.com/users/si74/orgs","repos_url":"https://api.github.com/users/si74/repos","events_url":"https://api.github.com/users/si74/events{/privacy}","received_events_url":"https://api.github.com/users/si74/received_events","type":"User","site_admin":false},"repo":{"id":127658792,"name":"prometheus","full_name":"si74/prometheus","owner":{"login":"si74","id":913035,"avatar_url":"https://avatars3.githubusercontent.com/u/913035?v=4","gravatar_id":"","url":"https://api.github.com/users/si74","html_url":"https://github.com/si74","followers_url":"https://api.github.com/users/si74/followers","following_url":"https://api.github.com/users/si74/following{/other_user}","gists_url":"https://api.github.com/users/si74/gists{/gist_id}","starred_url":"https://api.github.com/users/si74/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/si74/subscriptions","organizations_url":"https://api.github.com/users/si74/orgs","repos_url":"https://api.github.com/users/si74/repos","events_url":"https://api.github.com/users/si74/events{/privacy}","received_events_url":"https://api.github.com/users/si74/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/si74/prometheus","description":"The Prometheus monitoring system and time series database.","fork":true,"url":"https://api.github.com/repos/si74/prometheus","forks_url":"https://api.github.com/repos/si74/prometheus/forks","keys_url":"https://api.github.com/repos/si74/prometheus/keys{/key_id}","collaborators_url":"https://api.github.com/repos/si74/prometheus/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/si74/prometheus/teams","hooks_url":"https://api.github.com/repos/si74/prometheus/hooks","issue_events_url":"https://api.github.com/repos/si74/prometheus/issues/events{/number}","events_url":"https://api.github.com/repos/si74/prometheus/events","assignees_url":"https://api.github.com/repos/si74/prometheus/assignees{/user}","branches_url":"https://api.github.com/repos/si74/prometheus/branches{/branch}","tags_url":"https://api.github.com/repos/si74/prometheus/tags","blobs_url":"https://api.github.com/repos/si74/prometheus/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/si74/prometheus/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/si74/prometheus/git/refs{/sha}","trees_url":"https://api.github.com/repos/si74/prometheus/git/trees{/sha}","statuses_url":"https://api.github.com/repos/si74/prometheus/statuses/{sha}","languages_url":"https://api.github.com/repos/si74/prometheus/languages","stargazers_url":"https://api.github.com/repos/si74/prometheus/stargazers","contributors_url":"https://api.github.com/repos/si74/prometheus/contributors","subscribers_url":"https://api.github.com/repos/si74/prometheus/subscribers","subscription_url":"https://api.github.com/repos/si74/prometheus/subscription","commits_url":"https://api.github.com/repos/si74/prometheus/commits{/sha}","git_commits_url":"https://api.github.com/repos/si74/prometheus/git/commits{/sha}","comments_url":"https://api.github.com/repos/si74/prometheus/comments{/number}","issue_comment_url":"https://api.github.com/repos/si74/prometheus/issues/comments{/number}","contents_url":"https://api.github.com/repos/si74/prometheus/contents/{+path}","compare_url":"https://api.github.com/repos/si74/prometheus/compare/{base}...{head}","merges_url":"https://api.github.com/repos/si74/prometheus/merges","archive_url":"https://api.github.com/repos/si74/prometheus/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/si74/prometheus/downloads","issues_url":"https://api.github.com/repos/si74/prometheus/issues{/number}","pulls_url":"https://api.github.com/repos/si74/prometheus/pulls{/number}","milestones_url":"https://api.github.com/repos/si74/prometheus/milestones{/number}","notifications_url":"https://api.github.com/repos/si74/prometheus/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/si74/prometheus/labels{/name}","releases_url":"https://api.github.com/repos/si74/prometheus/releases{/id}","deployments_url":"https://api.github.com/repos/si74/prometheus/deployments","created_at":"2018-04-01T18:15:39Z","updated_at":"2018-04-01T18:15:43Z","pushed_at":"2018-04-13T15:34:00Z","git_url":"git://github.com/si74/prometheus.git","ssh_url":"git@github.com:si74/prometheus.git","clone_url":"https://github.com/si74/prometheus.git","svn_url":"https://github.com/si74/prometheus","homepage":"https://prometheus.io/","size":34891,"stargazers_count":0,"watchers_count":0,"language":"Go","has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"open_issues_count":0,"license":{"key":"apache-2.0","name":"Apache License 2.0","spdx_id":"Apache-2.0","url":"https://api.github.com/licenses/apache-2.0"},"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"prometheus:master","ref":"master","sha":"e7584ee34560040c30c373fedba040b079dcac8c","user":{"login":"prometheus","id":3380462,"avatar_url":"https://avatars3.githubusercontent.com/u/3380462?v=4","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://avatars3.githubusercontent.com/u/3380462?v=4","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":"2018-04-13T15:27:09Z","pushed_at":"2018-04-13T15:36:56Z","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":"https://prometheus.io/","size":35826,"stargazers_count":15789,"watchers_count":15789,"language":"Go","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":1993,"mirror_url":null,"archived":false,"open_issues_count":254,"license":{"key":"apache-2.0","name":"Apache License 2.0","spdx_id":"Apache-2.0","url":"https://api.github.com/licenses/apache-2.0"},"forks":1993,"open_issues":254,"watchers":15789,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/prometheus/prometheus/pulls/4085"},"html":{"href":"https://github.com/prometheus/prometheus/pull/4085"},"issue":{"href":"https://api.github.com/repos/prometheus/prometheus/issues/4085"},"comments":{"href":"https://api.github.com/repos/prometheus/prometheus/issues/4085/comments"},"review_comments":{"href":"https://api.github.com/repos/prometheus/prometheus/pulls/4085/comments"},"review_comment":{"href":"https://api.github.com/repos/prometheus/prometheus/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/prometheus/prometheus/pulls/4085/commits"},"statuses":{"href":"https://api.github.com/repos/prometheus/prometheus/statuses/d9fcb884035fa792498b3f61c109a7771926758c"}},"author_association":"CONTRIBUTOR"}}
{"actor":{"display_login":"juliusv"}}