{"action":"created","comment":{"url":"https://api.github.com/repos/grafana/metrictank/pulls/comments/157174380","pull_request_review_id":83769647,"id":157174380,"diff_hunk":"@@ -465,6 +467,228 @@ func (m *MemoryIdx) TagDetails(orgId int, key, filter string, from int64) (map[s\n \treturn res, nil\n }\n \n+// AutoCompleteTags is used to generate a list of possible values that could\n+// complete a given prefix. It also accepts additional conditions to further\n+// narrow down the result set.\n+//\n+// tagPrefix:   the string to be completed\n+// expressions: tagdb expressions in the same format as graphite uses\n+// from:        only tags will be returned that have at least one metric\n+//              with a LastUpdate above from\n+// limit:       the maximum number of results to return, the results will\n+//              always be sorted alphabetically for consistency between\n+//              consecutive queries and the limit is applied after sorting\n+//\n+func (m *MemoryIdx) AutoCompleteTags(orgId int, tagPrefix string, expressions []string, from int64, limit uint) ([]string, error) {\n+\tres := make([]string, 0)\n+\n+\t// only if expressions are specified we need to build a tag query.\n+\t// otherwise, the generation of the result set is much simpler\n+\tif len(expressions) > 0 {\n+\t\t// incorporate the tag prefix into the tag query expressions\n+\t\tif len(tagPrefix) > 0 {\n+\t\t\texpressions = append(expressions, fmt.Sprintf(\"__tag^=%s\", tagPrefix))\n+\t\t}\n+\n+\t\tquery, err := NewTagQuery(expressions, from)\n+\t\tif err != nil {\n+\t\t\treturn nil, err\n+\t\t}\n+\n+\t\t// only acquire lock after we're sure the query is valid\n+\t\tm.RLock()\n+\t\tdefer m.RUnlock()\n+\n+\t\ttags, ok := m.tags[orgId]\n+\t\tif !ok {\n+\t\t\treturn nil, nil\n+\t\t}\n+\n+\t\tresMap := query.RunGetTags(tags, m.DefById)\n+\t\tfor tag := range resMap {\n+\t\t\tres = append(res, tag)\n+\t\t}\n+\n+\t\tsort.Strings(res)\n+\t\tif uint(len(res)) > limit {\n+\t\t\tres = res[:limit]\n+\t\t}\n+\t} else {\n+\t\tm.RLock()\n+\t\tdefer m.RUnlock()\n+\n+\t\ttags, ok := m.tags[orgId]\n+\t\tif !ok {\n+\t\t\treturn nil, nil\n+\t\t}\n+\n+\t\ttagsSorted := make([]string, 0, len(tags))\n+\t\tfor tag := range tags {\n+\t\t\tif len(tagPrefix) > 0 && (len(tagPrefix) > len(tag) || tag[:len(tagPrefix)] != tagPrefix) {","path":"idx/memory/memory.go","position":82,"original_position":82,"commit_id":"9d217cd83c383b8046976e88be2a0f6c43946d2f","original_commit_id":"3c6a14a602b0c36b63af7ff201100cb79c9ed435","user":{"login":"Dieterbe","id":20774,"avatar_url":"https://avatars2.githubusercontent.com/u/20774?v=4","gravatar_id":"","url":"https://api.github.com/users/Dieterbe","html_url":"https://github.com/Dieterbe","followers_url":"https://api.github.com/users/Dieterbe/followers","following_url":"https://api.github.com/users/Dieterbe/following{/other_user}","gists_url":"https://api.github.com/users/Dieterbe/gists{/gist_id}","starred_url":"https://api.github.com/users/Dieterbe/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Dieterbe/subscriptions","organizations_url":"https://api.github.com/users/Dieterbe/orgs","repos_url":"https://api.github.com/users/Dieterbe/repos","events_url":"https://api.github.com/users/Dieterbe/events{/privacy}","received_events_url":"https://api.github.com/users/Dieterbe/received_events","type":"User","site_admin":false},"body":"I think we can replace this entire condition with  `if !strings.HasPrefix(tag, tagPrefix) {`\r\ntagPrefix being \"\" doesn't need anything special, it just works.","created_at":"2017-12-15T11:01:00Z","updated_at":"2017-12-15T11:11:45Z","html_url":"https://github.com/grafana/metrictank/pull/779#discussion_r157174380","pull_request_url":"https://api.github.com/repos/grafana/metrictank/pulls/779","author_association":"CONTRIBUTOR","_links":{"self":{"href":"https://api.github.com/repos/grafana/metrictank/pulls/comments/157174380"},"html":{"href":"https://github.com/grafana/metrictank/pull/779#discussion_r157174380"},"pull_request":{"href":"https://api.github.com/repos/grafana/metrictank/pulls/779"}}},"pull_request":{"url":"https://api.github.com/repos/grafana/metrictank/pulls/779","id":157046276,"html_url":"https://github.com/grafana/metrictank/pull/779","diff_url":"https://github.com/grafana/metrictank/pull/779.diff","patch_url":"https://github.com/grafana/metrictank/pull/779.patch","issue_url":"https://api.github.com/repos/grafana/metrictank/issues/779","number":779,"state":"open","locked":false,"title":"Autocomplete for tag keys and tag values","user":{"login":"replay","id":195371,"avatar_url":"https://avatars3.githubusercontent.com/u/195371?v=4","gravatar_id":"","url":"https://api.github.com/users/replay","html_url":"https://github.com/replay","followers_url":"https://api.github.com/users/replay/followers","following_url":"https://api.github.com/users/replay/following{/other_user}","gists_url":"https://api.github.com/users/replay/gists{/gist_id}","starred_url":"https://api.github.com/users/replay/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/replay/subscriptions","organizations_url":"https://api.github.com/users/replay/orgs","repos_url":"https://api.github.com/users/replay/repos","events_url":"https://api.github.com/users/replay/events{/privacy}","received_events_url":"https://api.github.com/users/replay/received_events","type":"User","site_admin":false},"body":"This implements the autocomplete endpoints for tags and tag values.\r\n\r\nIn order to do this more efficiently the whole query execution has been changed from the previous \"evaluate everything one-by-one and then consolidate\" to something that's more like multi-threaded map/reduce, which can also be aborted in the case of tag autocomplete queries once a sufficient number of results has been collected. \r\n\r\nEspecially in the case of tag autocomplete this brings some pretty significant speed improvements.\r\nThis benchmark queries for the tag prefix `di` with expressions `\"metric=~.*_time$\", \"direction!=~re\", \"host=~host9[0-9]0\"` on an index with 1.68 million entries:\r\n\r\n```\r\n# Before abortable multi-threaded map/reduce\r\nBenchmarkTagQueryKeysByPrefixExpressions-8   \t      50\t 200014598 ns/op\t36032354 B/op\t  602109 allocs/op\r\n# After\r\nBenchmarkTagQueryKeysByPrefixExpressions-8   \t   10000\t    923016 ns/op\t  262924 B/op\t    1960 allocs/op\r\n```","created_at":"2017-12-07T16:48:29Z","updated_at":"2017-12-15T11:11:45Z","closed_at":null,"merged_at":null,"merge_commit_sha":"23cd4d73c266e6ab7db0c4c04dd88aa2b497349d","assignee":null,"assignees":[],"requested_reviewers":[{"login":"woodsaj","id":8415072,"avatar_url":"https://avatars3.githubusercontent.com/u/8415072?v=4","gravatar_id":"","url":"https://api.github.com/users/woodsaj","html_url":"https://github.com/woodsaj","followers_url":"https://api.github.com/users/woodsaj/followers","following_url":"https://api.github.com/users/woodsaj/following{/other_user}","gists_url":"https://api.github.com/users/woodsaj/gists{/gist_id}","starred_url":"https://api.github.com/users/woodsaj/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/woodsaj/subscriptions","organizations_url":"https://api.github.com/users/woodsaj/orgs","repos_url":"https://api.github.com/users/woodsaj/repos","events_url":"https://api.github.com/users/woodsaj/events{/privacy}","received_events_url":"https://api.github.com/users/woodsaj/received_events","type":"User","site_admin":false}],"milestone":null,"commits_url":"https://api.github.com/repos/grafana/metrictank/pulls/779/commits","review_comments_url":"https://api.github.com/repos/grafana/metrictank/pulls/779/comments","review_comment_url":"https://api.github.com/repos/grafana/metrictank/pulls/comments{/number}","comments_url":"https://api.github.com/repos/grafana/metrictank/issues/779/comments","statuses_url":"https://api.github.com/repos/grafana/metrictank/statuses/9d217cd83c383b8046976e88be2a0f6c43946d2f","head":{"label":"grafana:autocomplete","ref":"autocomplete","sha":"9d217cd83c383b8046976e88be2a0f6c43946d2f","user":{"login":"grafana","id":7195757,"avatar_url":"https://avatars0.githubusercontent.com/u/7195757?v=4","gravatar_id":"","url":"https://api.github.com/users/grafana","html_url":"https://github.com/grafana","followers_url":"https://api.github.com/users/grafana/followers","following_url":"https://api.github.com/users/grafana/following{/other_user}","gists_url":"https://api.github.com/users/grafana/gists{/gist_id}","starred_url":"https://api.github.com/users/grafana/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/grafana/subscriptions","organizations_url":"https://api.github.com/users/grafana/orgs","repos_url":"https://api.github.com/users/grafana/repos","events_url":"https://api.github.com/users/grafana/events{/privacy}","received_events_url":"https://api.github.com/users/grafana/received_events","type":"Organization","site_admin":false},"repo":{"id":30401116,"name":"metrictank","full_name":"grafana/metrictank","owner":{"login":"grafana","id":7195757,"avatar_url":"https://avatars0.githubusercontent.com/u/7195757?v=4","gravatar_id":"","url":"https://api.github.com/users/grafana","html_url":"https://github.com/grafana","followers_url":"https://api.github.com/users/grafana/followers","following_url":"https://api.github.com/users/grafana/following{/other_user}","gists_url":"https://api.github.com/users/grafana/gists{/gist_id}","starred_url":"https://api.github.com/users/grafana/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/grafana/subscriptions","organizations_url":"https://api.github.com/users/grafana/orgs","repos_url":"https://api.github.com/users/grafana/repos","events_url":"https://api.github.com/users/grafana/events{/privacy}","received_events_url":"https://api.github.com/users/grafana/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/grafana/metrictank","description":"Cassandra-backed, metrics2.0 based, multi-tenant timeseries database for Graphite and friends","fork":false,"url":"https://api.github.com/repos/grafana/metrictank","forks_url":"https://api.github.com/repos/grafana/metrictank/forks","keys_url":"https://api.github.com/repos/grafana/metrictank/keys{/key_id}","collaborators_url":"https://api.github.com/repos/grafana/metrictank/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/grafana/metrictank/teams","hooks_url":"https://api.github.com/repos/grafana/metrictank/hooks","issue_events_url":"https://api.github.com/repos/grafana/metrictank/issues/events{/number}","events_url":"https://api.github.com/repos/grafana/metrictank/events","assignees_url":"https://api.github.com/repos/grafana/metrictank/assignees{/user}","branches_url":"https://api.github.com/repos/grafana/metrictank/branches{/branch}","tags_url":"https://api.github.com/repos/grafana/metrictank/tags","blobs_url":"https://api.github.com/repos/grafana/metrictank/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/grafana/metrictank/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/grafana/metrictank/git/refs{/sha}","trees_url":"https://api.github.com/repos/grafana/metrictank/git/trees{/sha}","statuses_url":"https://api.github.com/repos/grafana/metrictank/statuses/{sha}","languages_url":"https://api.github.com/repos/grafana/metrictank/languages","stargazers_url":"https://api.github.com/repos/grafana/metrictank/stargazers","contributors_url":"https://api.github.com/repos/grafana/metrictank/contributors","subscribers_url":"https://api.github.com/repos/grafana/metrictank/subscribers","subscription_url":"https://api.github.com/repos/grafana/metrictank/subscription","commits_url":"https://api.github.com/repos/grafana/metrictank/commits{/sha}","git_commits_url":"https://api.github.com/repos/grafana/metrictank/git/commits{/sha}","comments_url":"https://api.github.com/repos/grafana/metrictank/comments{/number}","issue_comment_url":"https://api.github.com/repos/grafana/metrictank/issues/comments{/number}","contents_url":"https://api.github.com/repos/grafana/metrictank/contents/{+path}","compare_url":"https://api.github.com/repos/grafana/metrictank/compare/{base}...{head}","merges_url":"https://api.github.com/repos/grafana/metrictank/merges","archive_url":"https://api.github.com/repos/grafana/metrictank/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/grafana/metrictank/downloads","issues_url":"https://api.github.com/repos/grafana/metrictank/issues{/number}","pulls_url":"https://api.github.com/repos/grafana/metrictank/pulls{/number}","milestones_url":"https://api.github.com/repos/grafana/metrictank/milestones{/number}","notifications_url":"https://api.github.com/repos/grafana/metrictank/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/grafana/metrictank/labels{/name}","releases_url":"https://api.github.com/repos/grafana/metrictank/releases{/id}","deployments_url":"https://api.github.com/repos/grafana/metrictank/deployments","created_at":"2015-02-06T07:44:12Z","updated_at":"2017-12-06T17:01:16Z","pushed_at":"2017-12-15T11:09:38Z","git_url":"git://github.com/grafana/metrictank.git","ssh_url":"git@github.com:grafana/metrictank.git","clone_url":"https://github.com/grafana/metrictank.git","svn_url":"https://github.com/grafana/metrictank","homepage":"","size":15935,"stargazers_count":150,"watchers_count":150,"language":"Go","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":21,"mirror_url":null,"archived":false,"open_issues_count":114,"license":{"key":"agpl-3.0","name":"GNU Affero General Public License v3.0","spdx_id":"AGPL-3.0","url":"https://api.github.com/licenses/agpl-3.0"},"forks":21,"open_issues":114,"watchers":150,"default_branch":"master"}},"base":{"label":"grafana:master","ref":"master","sha":"e83343094ef1939ae1798beadbe5c6492c4fd188","user":{"login":"grafana","id":7195757,"avatar_url":"https://avatars0.githubusercontent.com/u/7195757?v=4","gravatar_id":"","url":"https://api.github.com/users/grafana","html_url":"https://github.com/grafana","followers_url":"https://api.github.com/users/grafana/followers","following_url":"https://api.github.com/users/grafana/following{/other_user}","gists_url":"https://api.github.com/users/grafana/gists{/gist_id}","starred_url":"https://api.github.com/users/grafana/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/grafana/subscriptions","organizations_url":"https://api.github.com/users/grafana/orgs","repos_url":"https://api.github.com/users/grafana/repos","events_url":"https://api.github.com/users/grafana/events{/privacy}","received_events_url":"https://api.github.com/users/grafana/received_events","type":"Organization","site_admin":false},"repo":{"id":30401116,"name":"metrictank","full_name":"grafana/metrictank","owner":{"login":"grafana","id":7195757,"avatar_url":"https://avatars0.githubusercontent.com/u/7195757?v=4","gravatar_id":"","url":"https://api.github.com/users/grafana","html_url":"https://github.com/grafana","followers_url":"https://api.github.com/users/grafana/followers","following_url":"https://api.github.com/users/grafana/following{/other_user}","gists_url":"https://api.github.com/users/grafana/gists{/gist_id}","starred_url":"https://api.github.com/users/grafana/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/grafana/subscriptions","organizations_url":"https://api.github.com/users/grafana/orgs","repos_url":"https://api.github.com/users/grafana/repos","events_url":"https://api.github.com/users/grafana/events{/privacy}","received_events_url":"https://api.github.com/users/grafana/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/grafana/metrictank","description":"Cassandra-backed, metrics2.0 based, multi-tenant timeseries database for Graphite and friends","fork":false,"url":"https://api.github.com/repos/grafana/metrictank","forks_url":"https://api.github.com/repos/grafana/metrictank/forks","keys_url":"https://api.github.com/repos/grafana/metrictank/keys{/key_id}","collaborators_url":"https://api.github.com/repos/grafana/metrictank/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/grafana/metrictank/teams","hooks_url":"https://api.github.com/repos/grafana/metrictank/hooks","issue_events_url":"https://api.github.com/repos/grafana/metrictank/issues/events{/number}","events_url":"https://api.github.com/repos/grafana/metrictank/events","assignees_url":"https://api.github.com/repos/grafana/metrictank/assignees{/user}","branches_url":"https://api.github.com/repos/grafana/metrictank/branches{/branch}","tags_url":"https://api.github.com/repos/grafana/metrictank/tags","blobs_url":"https://api.github.com/repos/grafana/metrictank/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/grafana/metrictank/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/grafana/metrictank/git/refs{/sha}","trees_url":"https://api.github.com/repos/grafana/metrictank/git/trees{/sha}","statuses_url":"https://api.github.com/repos/grafana/metrictank/statuses/{sha}","languages_url":"https://api.github.com/repos/grafana/metrictank/languages","stargazers_url":"https://api.github.com/repos/grafana/metrictank/stargazers","contributors_url":"https://api.github.com/repos/grafana/metrictank/contributors","subscribers_url":"https://api.github.com/repos/grafana/metrictank/subscribers","subscription_url":"https://api.github.com/repos/grafana/metrictank/subscription","commits_url":"https://api.github.com/repos/grafana/metrictank/commits{/sha}","git_commits_url":"https://api.github.com/repos/grafana/metrictank/git/commits{/sha}","comments_url":"https://api.github.com/repos/grafana/metrictank/comments{/number}","issue_comment_url":"https://api.github.com/repos/grafana/metrictank/issues/comments{/number}","contents_url":"https://api.github.com/repos/grafana/metrictank/contents/{+path}","compare_url":"https://api.github.com/repos/grafana/metrictank/compare/{base}...{head}","merges_url":"https://api.github.com/repos/grafana/metrictank/merges","archive_url":"https://api.github.com/repos/grafana/metrictank/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/grafana/metrictank/downloads","issues_url":"https://api.github.com/repos/grafana/metrictank/issues{/number}","pulls_url":"https://api.github.com/repos/grafana/metrictank/pulls{/number}","milestones_url":"https://api.github.com/repos/grafana/metrictank/milestones{/number}","notifications_url":"https://api.github.com/repos/grafana/metrictank/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/grafana/metrictank/labels{/name}","releases_url":"https://api.github.com/repos/grafana/metrictank/releases{/id}","deployments_url":"https://api.github.com/repos/grafana/metrictank/deployments","created_at":"2015-02-06T07:44:12Z","updated_at":"2017-12-06T17:01:16Z","pushed_at":"2017-12-15T11:09:38Z","git_url":"git://github.com/grafana/metrictank.git","ssh_url":"git@github.com:grafana/metrictank.git","clone_url":"https://github.com/grafana/metrictank.git","svn_url":"https://github.com/grafana/metrictank","homepage":"","size":15935,"stargazers_count":150,"watchers_count":150,"language":"Go","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":21,"mirror_url":null,"archived":false,"open_issues_count":114,"license":{"key":"agpl-3.0","name":"GNU Affero General Public License v3.0","spdx_id":"AGPL-3.0","url":"https://api.github.com/licenses/agpl-3.0"},"forks":21,"open_issues":114,"watchers":150,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/grafana/metrictank/pulls/779"},"html":{"href":"https://github.com/grafana/metrictank/pull/779"},"issue":{"href":"https://api.github.com/repos/grafana/metrictank/issues/779"},"comments":{"href":"https://api.github.com/repos/grafana/metrictank/issues/779/comments"},"review_comments":{"href":"https://api.github.com/repos/grafana/metrictank/pulls/779/comments"},"review_comment":{"href":"https://api.github.com/repos/grafana/metrictank/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/grafana/metrictank/pulls/779/commits"},"statuses":{"href":"https://api.github.com/repos/grafana/metrictank/statuses/9d217cd83c383b8046976e88be2a0f6c43946d2f"}},"author_association":"CONTRIBUTOR"}}
{"actor":{"display_login":"Dieterbe"}}