{"action":"created","comment":{"url":"https://api.github.com/repos/sourcegraph/appdash/pulls/comments/60011319","id":60011319,"diff_hunk":"@@ -145,6 +173,85 @@ func (in *InfluxDBStore) Trace(id ID) (*Trace, error) {\n \treturn trace, nil\n }\n \n+func mustJSONFloat64(x interface{}) float64 {\n+\tn := x.(json.Number)\n+\tv, err := n.Float64()\n+\tif err != nil {\n+\t\tpanic(err)\n+\t}\n+\treturn v\n+}\n+\n+func mustJSONInt64(x interface{}) int64 {\n+\tn := x.(json.Number)\n+\tv, err := n.Int64()\n+\tif err != nil {\n+\t\tpanic(err)\n+\t}\n+\treturn v\n+}\n+\n+// Aggregate implements the Aggregator interface.\n+func (in *InfluxDBStore) Aggregate(start, end time.Duration) ([]*AggregatedResult, error) {\n+\t// Find the mean (average), minimum, maximum, std. deviation, and count of\n+\t// all spans.\n+\tq := `SELECT MEAN(\"duration\"),MIN(\"duration\"),MAX(\"duration\"),STDDEV(\"duration\"),COUNT(\"duration\") from spans`\n+\tq += fmt.Sprintf(\n+\t\t\" WHERE time >= '%s' AND time <= '%s'\",\n+\t\ttime.Now().Add(start).UTC().Format(time.RFC3339Nano),\n+\t\ttime.Now().Add(end).UTC().Format(time.RFC3339Nano),\n+\t)\n+\tq += ` GROUP BY \"name\"`\n+\tresult, err := in.executeOneQuery(q)\n+\tif err != nil {\n+\t\treturn nil, err\n+\t}\n+\n+\t// Populate the results.\n+\tresults := make([]*AggregatedResult, len(result.Series))\n+\tfor i, row := range result.Series {\n+\t\tv := row.Values[0]\n+\t\tmean, min, max, stddev, count := v[1], v[2], v[3], v[4], v[5]\n+\t\tresults[i] = &AggregatedResult{\n+\t\t\tRootSpanName: row.Tags[\"name\"],\n+\t\t\tAverage:      time.Duration(mustJSONFloat64(mean) * float64(time.Second)),","path":"influxdb_store.go","position":null,"original_position":93,"commit_id":"4e8ef32598a32f465e56a82c61204f9dddb89058","original_commit_id":"958b511fee594fe145aa3f8cb4a585b690f13312","user":{"login":"chris-ramon","id":1000404,"avatar_url":"https://avatars.githubusercontent.com/u/1000404?v=3","gravatar_id":"","url":"https://api.github.com/users/chris-ramon","html_url":"https://github.com/chris-ramon","followers_url":"https://api.github.com/users/chris-ramon/followers","following_url":"https://api.github.com/users/chris-ramon/following{/other_user}","gists_url":"https://api.github.com/users/chris-ramon/gists{/gist_id}","starred_url":"https://api.github.com/users/chris-ramon/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/chris-ramon/subscriptions","organizations_url":"https://api.github.com/users/chris-ramon/orgs","repos_url":"https://api.github.com/users/chris-ramon/repos","events_url":"https://api.github.com/users/chris-ramon/events{/privacy}","received_events_url":"https://api.github.com/users/chris-ramon/received_events","type":"User","site_admin":false},"body":"Could we replace `float64(time.Second)` with a variable instead? declared & assigned around line 209, to avoid repetitive equal calculations.","created_at":"2016-04-18T06:46:34Z","updated_at":"2016-04-18T06:46:34Z","html_url":"https://github.com/sourcegraph/appdash/pull/136#discussion_r60011319","pull_request_url":"https://api.github.com/repos/sourcegraph/appdash/pulls/136","_links":{"self":{"href":"https://api.github.com/repos/sourcegraph/appdash/pulls/comments/60011319"},"html":{"href":"https://github.com/sourcegraph/appdash/pull/136#discussion_r60011319"},"pull_request":{"href":"https://api.github.com/repos/sourcegraph/appdash/pulls/136"}}},"pull_request":{"url":"https://api.github.com/repos/sourcegraph/appdash/pulls/136","id":66724655,"html_url":"https://github.com/sourcegraph/appdash/pull/136","diff_url":"https://github.com/sourcegraph/appdash/pull/136.diff","patch_url":"https://github.com/sourcegraph/appdash/pull/136.patch","issue_url":"https://api.github.com/repos/sourcegraph/appdash/issues/136","number":136,"state":"open","locked":false,"title":"Aggregation support for InfluxDBStore.","user":{"login":"slimsag","id":3173176,"avatar_url":"https://avatars.githubusercontent.com/u/3173176?v=3","gravatar_id":"","url":"https://api.github.com/users/slimsag","html_url":"https://github.com/slimsag","followers_url":"https://api.github.com/users/slimsag/followers","following_url":"https://api.github.com/users/slimsag/following{/other_user}","gists_url":"https://api.github.com/users/slimsag/gists{/gist_id}","starred_url":"https://api.github.com/users/slimsag/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/slimsag/subscriptions","organizations_url":"https://api.github.com/users/slimsag/orgs","repos_url":"https://api.github.com/users/slimsag/repos","events_url":"https://api.github.com/users/slimsag/events{/privacy}","received_events_url":"https://api.github.com/users/slimsag/received_events","type":"User","site_admin":false},"body":"#### Details\r\n\r\n- [x] Adds aggregation support to: `/dashboard` & `/aggregate` endpoints.\r\n- [x] Adds re-usable functions:\r\n  - `appdash.AggregateEvent.SlowestRawQuery() string`\r\n  - `appdash.Trace.TimespanEvent() (TimespanEvent, error)`\r\n- [x] Extends interface: \r\n  - `appdash.Traces() ([]*Trace, error)` ---> `Traces(opts TracesOpts) ([]*Trace, error)`\r\n    - So we are be able to pass aggregation information (Eg. start/end time) through `TracesOpts`.\r\n- [x] Removes `AggregateStore` in favor of `InfluxDBStore`.\r\n\r\nCloses #137","created_at":"2016-04-16T02:09:59Z","updated_at":"2016-04-18T06:46:34Z","closed_at":null,"merged_at":null,"merge_commit_sha":"9bac2b97f092965e341185a485a6ce31aa363a2d","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/sourcegraph/appdash/pulls/136/commits","review_comments_url":"https://api.github.com/repos/sourcegraph/appdash/pulls/136/comments","review_comment_url":"https://api.github.com/repos/sourcegraph/appdash/pulls/comments{/number}","comments_url":"https://api.github.com/repos/sourcegraph/appdash/issues/136/comments","statuses_url":"https://api.github.com/repos/sourcegraph/appdash/statuses/4e8ef32598a32f465e56a82c61204f9dddb89058","head":{"label":"sourcegraph:influxdb-aggregate-feature","ref":"influxdb-aggregate-feature","sha":"4e8ef32598a32f465e56a82c61204f9dddb89058","user":{"login":"sourcegraph","id":3979584,"avatar_url":"https://avatars.githubusercontent.com/u/3979584?v=3","gravatar_id":"","url":"https://api.github.com/users/sourcegraph","html_url":"https://github.com/sourcegraph","followers_url":"https://api.github.com/users/sourcegraph/followers","following_url":"https://api.github.com/users/sourcegraph/following{/other_user}","gists_url":"https://api.github.com/users/sourcegraph/gists{/gist_id}","starred_url":"https://api.github.com/users/sourcegraph/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sourcegraph/subscriptions","organizations_url":"https://api.github.com/users/sourcegraph/orgs","repos_url":"https://api.github.com/users/sourcegraph/repos","events_url":"https://api.github.com/users/sourcegraph/events{/privacy}","received_events_url":"https://api.github.com/users/sourcegraph/received_events","type":"Organization","site_admin":false},"repo":{"id":26996090,"name":"appdash","full_name":"sourcegraph/appdash","owner":{"login":"sourcegraph","id":3979584,"avatar_url":"https://avatars.githubusercontent.com/u/3979584?v=3","gravatar_id":"","url":"https://api.github.com/users/sourcegraph","html_url":"https://github.com/sourcegraph","followers_url":"https://api.github.com/users/sourcegraph/followers","following_url":"https://api.github.com/users/sourcegraph/following{/other_user}","gists_url":"https://api.github.com/users/sourcegraph/gists{/gist_id}","starred_url":"https://api.github.com/users/sourcegraph/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sourcegraph/subscriptions","organizations_url":"https://api.github.com/users/sourcegraph/orgs","repos_url":"https://api.github.com/users/sourcegraph/repos","events_url":"https://api.github.com/users/sourcegraph/events{/privacy}","received_events_url":"https://api.github.com/users/sourcegraph/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/sourcegraph/appdash","description":"Application tracing system for Go, based on Google's Dapper.","fork":false,"url":"https://api.github.com/repos/sourcegraph/appdash","forks_url":"https://api.github.com/repos/sourcegraph/appdash/forks","keys_url":"https://api.github.com/repos/sourcegraph/appdash/keys{/key_id}","collaborators_url":"https://api.github.com/repos/sourcegraph/appdash/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/sourcegraph/appdash/teams","hooks_url":"https://api.github.com/repos/sourcegraph/appdash/hooks","issue_events_url":"https://api.github.com/repos/sourcegraph/appdash/issues/events{/number}","events_url":"https://api.github.com/repos/sourcegraph/appdash/events","assignees_url":"https://api.github.com/repos/sourcegraph/appdash/assignees{/user}","branches_url":"https://api.github.com/repos/sourcegraph/appdash/branches{/branch}","tags_url":"https://api.github.com/repos/sourcegraph/appdash/tags","blobs_url":"https://api.github.com/repos/sourcegraph/appdash/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/sourcegraph/appdash/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/sourcegraph/appdash/git/refs{/sha}","trees_url":"https://api.github.com/repos/sourcegraph/appdash/git/trees{/sha}","statuses_url":"https://api.github.com/repos/sourcegraph/appdash/statuses/{sha}","languages_url":"https://api.github.com/repos/sourcegraph/appdash/languages","stargazers_url":"https://api.github.com/repos/sourcegraph/appdash/stargazers","contributors_url":"https://api.github.com/repos/sourcegraph/appdash/contributors","subscribers_url":"https://api.github.com/repos/sourcegraph/appdash/subscribers","subscription_url":"https://api.github.com/repos/sourcegraph/appdash/subscription","commits_url":"https://api.github.com/repos/sourcegraph/appdash/commits{/sha}","git_commits_url":"https://api.github.com/repos/sourcegraph/appdash/git/commits{/sha}","comments_url":"https://api.github.com/repos/sourcegraph/appdash/comments{/number}","issue_comment_url":"https://api.github.com/repos/sourcegraph/appdash/issues/comments{/number}","contents_url":"https://api.github.com/repos/sourcegraph/appdash/contents/{+path}","compare_url":"https://api.github.com/repos/sourcegraph/appdash/compare/{base}...{head}","merges_url":"https://api.github.com/repos/sourcegraph/appdash/merges","archive_url":"https://api.github.com/repos/sourcegraph/appdash/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/sourcegraph/appdash/downloads","issues_url":"https://api.github.com/repos/sourcegraph/appdash/issues{/number}","pulls_url":"https://api.github.com/repos/sourcegraph/appdash/pulls{/number}","milestones_url":"https://api.github.com/repos/sourcegraph/appdash/milestones{/number}","notifications_url":"https://api.github.com/repos/sourcegraph/appdash/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/sourcegraph/appdash/labels{/name}","releases_url":"https://api.github.com/repos/sourcegraph/appdash/releases{/id}","deployments_url":"https://api.github.com/repos/sourcegraph/appdash/deployments","created_at":"2014-11-22T10:47:38Z","updated_at":"2016-04-17T12:17:54Z","pushed_at":"2016-04-18T05:48:41Z","git_url":"git://github.com/sourcegraph/appdash.git","ssh_url":"git@github.com:sourcegraph/appdash.git","clone_url":"https://github.com/sourcegraph/appdash.git","svn_url":"https://github.com/sourcegraph/appdash","homepage":"","size":695,"stargazers_count":429,"watchers_count":429,"language":"Go","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":30,"mirror_url":null,"open_issues_count":13,"forks":30,"open_issues":13,"watchers":429,"default_branch":"master"}},"base":{"label":"sourcegraph:master","ref":"master","sha":"9796bce60c769f4123f0a7e23efdf6070a332f79","user":{"login":"sourcegraph","id":3979584,"avatar_url":"https://avatars.githubusercontent.com/u/3979584?v=3","gravatar_id":"","url":"https://api.github.com/users/sourcegraph","html_url":"https://github.com/sourcegraph","followers_url":"https://api.github.com/users/sourcegraph/followers","following_url":"https://api.github.com/users/sourcegraph/following{/other_user}","gists_url":"https://api.github.com/users/sourcegraph/gists{/gist_id}","starred_url":"https://api.github.com/users/sourcegraph/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sourcegraph/subscriptions","organizations_url":"https://api.github.com/users/sourcegraph/orgs","repos_url":"https://api.github.com/users/sourcegraph/repos","events_url":"https://api.github.com/users/sourcegraph/events{/privacy}","received_events_url":"https://api.github.com/users/sourcegraph/received_events","type":"Organization","site_admin":false},"repo":{"id":26996090,"name":"appdash","full_name":"sourcegraph/appdash","owner":{"login":"sourcegraph","id":3979584,"avatar_url":"https://avatars.githubusercontent.com/u/3979584?v=3","gravatar_id":"","url":"https://api.github.com/users/sourcegraph","html_url":"https://github.com/sourcegraph","followers_url":"https://api.github.com/users/sourcegraph/followers","following_url":"https://api.github.com/users/sourcegraph/following{/other_user}","gists_url":"https://api.github.com/users/sourcegraph/gists{/gist_id}","starred_url":"https://api.github.com/users/sourcegraph/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sourcegraph/subscriptions","organizations_url":"https://api.github.com/users/sourcegraph/orgs","repos_url":"https://api.github.com/users/sourcegraph/repos","events_url":"https://api.github.com/users/sourcegraph/events{/privacy}","received_events_url":"https://api.github.com/users/sourcegraph/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/sourcegraph/appdash","description":"Application tracing system for Go, based on Google's Dapper.","fork":false,"url":"https://api.github.com/repos/sourcegraph/appdash","forks_url":"https://api.github.com/repos/sourcegraph/appdash/forks","keys_url":"https://api.github.com/repos/sourcegraph/appdash/keys{/key_id}","collaborators_url":"https://api.github.com/repos/sourcegraph/appdash/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/sourcegraph/appdash/teams","hooks_url":"https://api.github.com/repos/sourcegraph/appdash/hooks","issue_events_url":"https://api.github.com/repos/sourcegraph/appdash/issues/events{/number}","events_url":"https://api.github.com/repos/sourcegraph/appdash/events","assignees_url":"https://api.github.com/repos/sourcegraph/appdash/assignees{/user}","branches_url":"https://api.github.com/repos/sourcegraph/appdash/branches{/branch}","tags_url":"https://api.github.com/repos/sourcegraph/appdash/tags","blobs_url":"https://api.github.com/repos/sourcegraph/appdash/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/sourcegraph/appdash/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/sourcegraph/appdash/git/refs{/sha}","trees_url":"https://api.github.com/repos/sourcegraph/appdash/git/trees{/sha}","statuses_url":"https://api.github.com/repos/sourcegraph/appdash/statuses/{sha}","languages_url":"https://api.github.com/repos/sourcegraph/appdash/languages","stargazers_url":"https://api.github.com/repos/sourcegraph/appdash/stargazers","contributors_url":"https://api.github.com/repos/sourcegraph/appdash/contributors","subscribers_url":"https://api.github.com/repos/sourcegraph/appdash/subscribers","subscription_url":"https://api.github.com/repos/sourcegraph/appdash/subscription","commits_url":"https://api.github.com/repos/sourcegraph/appdash/commits{/sha}","git_commits_url":"https://api.github.com/repos/sourcegraph/appdash/git/commits{/sha}","comments_url":"https://api.github.com/repos/sourcegraph/appdash/comments{/number}","issue_comment_url":"https://api.github.com/repos/sourcegraph/appdash/issues/comments{/number}","contents_url":"https://api.github.com/repos/sourcegraph/appdash/contents/{+path}","compare_url":"https://api.github.com/repos/sourcegraph/appdash/compare/{base}...{head}","merges_url":"https://api.github.com/repos/sourcegraph/appdash/merges","archive_url":"https://api.github.com/repos/sourcegraph/appdash/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/sourcegraph/appdash/downloads","issues_url":"https://api.github.com/repos/sourcegraph/appdash/issues{/number}","pulls_url":"https://api.github.com/repos/sourcegraph/appdash/pulls{/number}","milestones_url":"https://api.github.com/repos/sourcegraph/appdash/milestones{/number}","notifications_url":"https://api.github.com/repos/sourcegraph/appdash/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/sourcegraph/appdash/labels{/name}","releases_url":"https://api.github.com/repos/sourcegraph/appdash/releases{/id}","deployments_url":"https://api.github.com/repos/sourcegraph/appdash/deployments","created_at":"2014-11-22T10:47:38Z","updated_at":"2016-04-17T12:17:54Z","pushed_at":"2016-04-18T05:48:41Z","git_url":"git://github.com/sourcegraph/appdash.git","ssh_url":"git@github.com:sourcegraph/appdash.git","clone_url":"https://github.com/sourcegraph/appdash.git","svn_url":"https://github.com/sourcegraph/appdash","homepage":"","size":695,"stargazers_count":429,"watchers_count":429,"language":"Go","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":30,"mirror_url":null,"open_issues_count":13,"forks":30,"open_issues":13,"watchers":429,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/sourcegraph/appdash/pulls/136"},"html":{"href":"https://github.com/sourcegraph/appdash/pull/136"},"issue":{"href":"https://api.github.com/repos/sourcegraph/appdash/issues/136"},"comments":{"href":"https://api.github.com/repos/sourcegraph/appdash/issues/136/comments"},"review_comments":{"href":"https://api.github.com/repos/sourcegraph/appdash/pulls/136/comments"},"review_comment":{"href":"https://api.github.com/repos/sourcegraph/appdash/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/sourcegraph/appdash/pulls/136/commits"},"statuses":{"href":"https://api.github.com/repos/sourcegraph/appdash/statuses/4e8ef32598a32f465e56a82c61204f9dddb89058"}}}}