{"action":"created","comment":{"url":"https://api.github.com/repos/istio/istio/pulls/comments/176533147","pull_request_review_id":106251645,"id":176533147,"diff_hunk":"@@ -0,0 +1,208 @@\n+// Copyright 2017 Istio Authors.\n+//\n+// Licensed under the Apache License, Version 2.0 (the \"License\");\n+// you may not use this file except in compliance with the License.\n+// You may obtain a copy of the License at\n+//\n+//     http://www.apache.org/licenses/LICENSE-2.0\n+//\n+// Unless required by applicable law or agreed to in writing, software\n+// distributed under the License is distributed on an \"AS IS\" BASIS,\n+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n+// See the License for the specific language governing permissions and\n+// limitations under the License.\n+\n+package registry\n+\n+import (\n+\t\"fmt\"\n+\n+\t\"encoding/base64\"\n+\t\"io/ioutil\"\n+\t\"regexp\"\n+\t\"strings\"\n+\n+\t\"github.com/gogo/protobuf/proto\"\n+\t\"github.com/gogo/protobuf/protoc-gen-gogo/descriptor\"\n+\t\"github.com/hashicorp/go-multierror\"\n+\n+\tadapter \"istio.io/api/mixer/adapter/model/v1beta1\"\n+\ttmpl \"istio.io/api/mixer/adapter/model/v1beta1\"\n+\t\"istio.io/istio/pkg/log\"\n+)\n+\n+// TemplateMetadata contains info about a template\n+type TemplateMetadata struct {\n+\tName          string\n+\tFileDescSet   *descriptor.FileDescriptorSet\n+\tFileDescProto *descriptor.FileDescriptorProto\n+}\n+\n+// AdapterMetadata contains info about an adapter\n+type AdapterMetadata struct {\n+\tInfo               *adapter.Info\n+\tSupportedTemplates []string\n+}\n+\n+// Registry to find metadata about templates and adapters\n+type Registry interface {\n+\tGetAdapter(name string) (adapter *AdapterMetadata, found bool)\n+\tGetTemplate(name string) (template *TemplateMetadata, found bool)\n+}\n+\n+// registry to ingest templates and adapters. It is single threaded.\n+type registry struct {\n+\tadapters  map[string]*AdapterMetadata\n+\ttemplates map[string]*TemplateMetadata\n+}\n+\n+// New creates a `Registry` from given adapter infos.\n+// Note: For adding built-in templates that are not associated with any adapters, supply the `Info` object with\n+// only `templates`, leaving other fields to default empty.\n+func New(infos []adapter.Info) (Registry, error) {\n+\tr := &registry{make(map[string]*AdapterMetadata), make(map[string]*TemplateMetadata)}\n+\tvar resultErr error = nil\n+\tlog.Debugf(\"registering %#v\", infos)\n+\n+\tfor _, info := range infos {\n+\t\tif old, ok := r.GetAdapter(info.Name); ok {\n+\t\t\t// duplicate entry found\n+\t\t\tresultErr = multierror.Append(resultErr,\n+\t\t\t\tfmt.Errorf(\"duplicate registration for adapter '%s' : new = %v old = %v\", info.Name, info, old))\n+\t\t\tcontinue\n+\t\t}\n+\n+\t\ttmplNames, err := r.ingestTemplates(info.Templates)\n+\t\tif err != nil {\n+\t\t\tresultErr = multierror.Append(resultErr, err)\n+\t\t\tcontinue\n+\t\t}\n+\n+\t\t// empty adapter name means just the template needs to be ingested.\n+\t\tif len(info.Name) != 0 {\n+\t\t\tr.adapters[info.Name] = &AdapterMetadata{Info: &info, SupportedTemplates: tmplNames}\n+\t\t}\n+\t}\n+\n+\tif resultErr != nil {\n+\t\tlog.Error(resultErr.Error())\n+\t}\n+\n+\treturn r, resultErr\n+}\n+\n+// GetAdapterInfo returns a AdapterMetadata for a adapter with the given name.\n+func (r *registry) GetAdapter(name string) (b *AdapterMetadata, found bool) {\n+\tif bi, found := r.adapters[name]; found {\n+\t\treturn bi, true\n+\t}\n+\treturn nil, false\n+}\n+\n+// GetTemplate returns a TemplateMetadata for a template with the given name.\n+func (r *registry) GetTemplate(name string) (b *TemplateMetadata, found bool) {\n+\tif bi, found := r.templates[name]; found {\n+\t\treturn bi, true\n+\t}\n+\n+\treturn nil, false\n+}\n+\n+func (r *registry) ingestTemplates(tmpls []string) ([]string, error) {\n+\tvar resultErr error = nil\n+\ttemplates := make([]*TemplateMetadata, 0)","path":"mixer/pkg/config/registry/registry.go","position":113,"original_position":113,"commit_id":"9116ec73cf59e516ca5392e00b6b5e7a188aa807","original_commit_id":"9116ec73cf59e516ca5392e00b6b5e7a188aa807","user":{"login":"geeknoid","id":22780957,"avatar_url":"https://avatars3.githubusercontent.com/u/22780957?v=4","gravatar_id":"","url":"https://api.github.com/users/geeknoid","html_url":"https://github.com/geeknoid","followers_url":"https://api.github.com/users/geeknoid/followers","following_url":"https://api.github.com/users/geeknoid/following{/other_user}","gists_url":"https://api.github.com/users/geeknoid/gists{/gist_id}","starred_url":"https://api.github.com/users/geeknoid/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/geeknoid/subscriptions","organizations_url":"https://api.github.com/users/geeknoid/orgs","repos_url":"https://api.github.com/users/geeknoid/repos","events_url":"https://api.github.com/users/geeknoid/events{/privacy}","received_events_url":"https://api.github.com/users/geeknoid/received_events","type":"User","site_admin":false},"body":"Preallocate to known size","created_at":"2018-03-22T18:46:33Z","updated_at":"2018-03-22T18:50:32Z","html_url":"https://github.com/istio/istio/pull/4455#discussion_r176533147","pull_request_url":"https://api.github.com/repos/istio/istio/pulls/4455","author_association":"CONTRIBUTOR","_links":{"self":{"href":"https://api.github.com/repos/istio/istio/pulls/comments/176533147"},"html":{"href":"https://github.com/istio/istio/pull/4455#discussion_r176533147"},"pull_request":{"href":"https://api.github.com/repos/istio/istio/pulls/4455"}}},"pull_request":{"url":"https://api.github.com/repos/istio/istio/pulls/4455","id":176682883,"html_url":"https://github.com/istio/istio/pull/4455","diff_url":"https://github.com/istio/istio/pull/4455.diff","patch_url":"https://github.com/istio/istio/pull/4455.patch","issue_url":"https://api.github.com/repos/istio/istio/issues/4455","number":4455,"state":"open","locked":false,"title":"Add registry to consume templates and adapters.","user":{"login":"guptasu","id":11448595,"avatar_url":"https://avatars3.githubusercontent.com/u/11448595?v=4","gravatar_id":"","url":"https://api.github.com/users/guptasu","html_url":"https://github.com/guptasu","followers_url":"https://api.github.com/users/guptasu/followers","following_url":"https://api.github.com/users/guptasu/following{/other_user}","gists_url":"https://api.github.com/users/guptasu/gists{/gist_id}","starred_url":"https://api.github.com/users/guptasu/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/guptasu/subscriptions","organizations_url":"https://api.github.com/users/guptasu/orgs","repos_url":"https://api.github.com/users/guptasu/repos","events_url":"https://api.github.com/users/guptasu/events{/privacy}","received_events_url":"https://api.github.com/users/guptasu/received_events","type":"User","site_admin":false},"body":"Creates a single registry for ingestion of adapter info and base64 encoded template descriptors. PR also contains provision for ingesting template descriptors that are not tied to any adapters (example: all the core built-in templates).\r\n\r\nThis PR provides the wiring needed for next work of taking descriptor and yaml config to generate bytes.\r\n\r\n**NOTE:** This PR depend on [new Info proto pr](https://github.com/istio/api/pull/426) \r\n\r\n100% codecoverage woohoo!!\r\n\r\n","created_at":"2018-03-22T06:00:09Z","updated_at":"2018-03-22T18:50:32Z","closed_at":null,"merged_at":null,"merge_commit_sha":"bff775430e41dcd0c62db3d50f5bd843be9ff527","assignee":null,"assignees":[],"requested_reviewers":[{"login":"mandarjog","id":800375,"avatar_url":"https://avatars2.githubusercontent.com/u/800375?v=4","gravatar_id":"","url":"https://api.github.com/users/mandarjog","html_url":"https://github.com/mandarjog","followers_url":"https://api.github.com/users/mandarjog/followers","following_url":"https://api.github.com/users/mandarjog/following{/other_user}","gists_url":"https://api.github.com/users/mandarjog/gists{/gist_id}","starred_url":"https://api.github.com/users/mandarjog/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mandarjog/subscriptions","organizations_url":"https://api.github.com/users/mandarjog/orgs","repos_url":"https://api.github.com/users/mandarjog/repos","events_url":"https://api.github.com/users/mandarjog/events{/privacy}","received_events_url":"https://api.github.com/users/mandarjog/received_events","type":"User","site_admin":false},{"login":"douglas-reid","id":21148125,"avatar_url":"https://avatars3.githubusercontent.com/u/21148125?v=4","gravatar_id":"","url":"https://api.github.com/users/douglas-reid","html_url":"https://github.com/douglas-reid","followers_url":"https://api.github.com/users/douglas-reid/followers","following_url":"https://api.github.com/users/douglas-reid/following{/other_user}","gists_url":"https://api.github.com/users/douglas-reid/gists{/gist_id}","starred_url":"https://api.github.com/users/douglas-reid/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/douglas-reid/subscriptions","organizations_url":"https://api.github.com/users/douglas-reid/orgs","repos_url":"https://api.github.com/users/douglas-reid/repos","events_url":"https://api.github.com/users/douglas-reid/events{/privacy}","received_events_url":"https://api.github.com/users/douglas-reid/received_events","type":"User","site_admin":false}],"requested_teams":[],"labels":[{"id":491318011,"url":"https://api.github.com/repos/istio/istio/labels/cla:%20yes","name":"cla: yes","color":"bfdadc","default":false}],"milestone":null,"commits_url":"https://api.github.com/repos/istio/istio/pulls/4455/commits","review_comments_url":"https://api.github.com/repos/istio/istio/pulls/4455/comments","review_comment_url":"https://api.github.com/repos/istio/istio/pulls/comments{/number}","comments_url":"https://api.github.com/repos/istio/istio/issues/4455/comments","statuses_url":"https://api.github.com/repos/istio/istio/statuses/9116ec73cf59e516ca5392e00b6b5e7a188aa807","head":{"label":"guptasu:ingestinfo","ref":"ingestinfo","sha":"9116ec73cf59e516ca5392e00b6b5e7a188aa807","user":{"login":"guptasu","id":11448595,"avatar_url":"https://avatars3.githubusercontent.com/u/11448595?v=4","gravatar_id":"","url":"https://api.github.com/users/guptasu","html_url":"https://github.com/guptasu","followers_url":"https://api.github.com/users/guptasu/followers","following_url":"https://api.github.com/users/guptasu/following{/other_user}","gists_url":"https://api.github.com/users/guptasu/gists{/gist_id}","starred_url":"https://api.github.com/users/guptasu/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/guptasu/subscriptions","organizations_url":"https://api.github.com/users/guptasu/orgs","repos_url":"https://api.github.com/users/guptasu/repos","events_url":"https://api.github.com/users/guptasu/events{/privacy}","received_events_url":"https://api.github.com/users/guptasu/received_events","type":"User","site_admin":false},"repo":{"id":102579018,"name":"istio","full_name":"guptasu/istio","owner":{"login":"guptasu","id":11448595,"avatar_url":"https://avatars3.githubusercontent.com/u/11448595?v=4","gravatar_id":"","url":"https://api.github.com/users/guptasu","html_url":"https://github.com/guptasu","followers_url":"https://api.github.com/users/guptasu/followers","following_url":"https://api.github.com/users/guptasu/following{/other_user}","gists_url":"https://api.github.com/users/guptasu/gists{/gist_id}","starred_url":"https://api.github.com/users/guptasu/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/guptasu/subscriptions","organizations_url":"https://api.github.com/users/guptasu/orgs","repos_url":"https://api.github.com/users/guptasu/repos","events_url":"https://api.github.com/users/guptasu/events{/privacy}","received_events_url":"https://api.github.com/users/guptasu/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/guptasu/istio","description":"Sample code, build and tests and governance material for the Istio project.","fork":true,"url":"https://api.github.com/repos/guptasu/istio","forks_url":"https://api.github.com/repos/guptasu/istio/forks","keys_url":"https://api.github.com/repos/guptasu/istio/keys{/key_id}","collaborators_url":"https://api.github.com/repos/guptasu/istio/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/guptasu/istio/teams","hooks_url":"https://api.github.com/repos/guptasu/istio/hooks","issue_events_url":"https://api.github.com/repos/guptasu/istio/issues/events{/number}","events_url":"https://api.github.com/repos/guptasu/istio/events","assignees_url":"https://api.github.com/repos/guptasu/istio/assignees{/user}","branches_url":"https://api.github.com/repos/guptasu/istio/branches{/branch}","tags_url":"https://api.github.com/repos/guptasu/istio/tags","blobs_url":"https://api.github.com/repos/guptasu/istio/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/guptasu/istio/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/guptasu/istio/git/refs{/sha}","trees_url":"https://api.github.com/repos/guptasu/istio/git/trees{/sha}","statuses_url":"https://api.github.com/repos/guptasu/istio/statuses/{sha}","languages_url":"https://api.github.com/repos/guptasu/istio/languages","stargazers_url":"https://api.github.com/repos/guptasu/istio/stargazers","contributors_url":"https://api.github.com/repos/guptasu/istio/contributors","subscribers_url":"https://api.github.com/repos/guptasu/istio/subscribers","subscription_url":"https://api.github.com/repos/guptasu/istio/subscription","commits_url":"https://api.github.com/repos/guptasu/istio/commits{/sha}","git_commits_url":"https://api.github.com/repos/guptasu/istio/git/commits{/sha}","comments_url":"https://api.github.com/repos/guptasu/istio/comments{/number}","issue_comment_url":"https://api.github.com/repos/guptasu/istio/issues/comments{/number}","contents_url":"https://api.github.com/repos/guptasu/istio/contents/{+path}","compare_url":"https://api.github.com/repos/guptasu/istio/compare/{base}...{head}","merges_url":"https://api.github.com/repos/guptasu/istio/merges","archive_url":"https://api.github.com/repos/guptasu/istio/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/guptasu/istio/downloads","issues_url":"https://api.github.com/repos/guptasu/istio/issues{/number}","pulls_url":"https://api.github.com/repos/guptasu/istio/pulls{/number}","milestones_url":"https://api.github.com/repos/guptasu/istio/milestones{/number}","notifications_url":"https://api.github.com/repos/guptasu/istio/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/guptasu/istio/labels{/name}","releases_url":"https://api.github.com/repos/guptasu/istio/releases{/id}","deployments_url":"https://api.github.com/repos/guptasu/istio/deployments","created_at":"2017-09-06T07:45:27Z","updated_at":"2017-09-06T07:45:31Z","pushed_at":"2018-03-22T06:03:35Z","git_url":"git://github.com/guptasu/istio.git","ssh_url":"git@github.com:guptasu/istio.git","clone_url":"https://github.com/guptasu/istio.git","svn_url":"https://github.com/guptasu/istio","homepage":"https://istio.io","size":100465,"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":null,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"istio:master","ref":"master","sha":"98b1e4aacdaafb9155fcc2413e4c9b47cc7e78da","user":{"login":"istio","id":23534644,"avatar_url":"https://avatars1.githubusercontent.com/u/23534644?v=4","gravatar_id":"","url":"https://api.github.com/users/istio","html_url":"https://github.com/istio","followers_url":"https://api.github.com/users/istio/followers","following_url":"https://api.github.com/users/istio/following{/other_user}","gists_url":"https://api.github.com/users/istio/gists{/gist_id}","starred_url":"https://api.github.com/users/istio/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/istio/subscriptions","organizations_url":"https://api.github.com/users/istio/orgs","repos_url":"https://api.github.com/users/istio/repos","events_url":"https://api.github.com/users/istio/events{/privacy}","received_events_url":"https://api.github.com/users/istio/received_events","type":"Organization","site_admin":false},"repo":{"id":74175805,"name":"istio","full_name":"istio/istio","owner":{"login":"istio","id":23534644,"avatar_url":"https://avatars1.githubusercontent.com/u/23534644?v=4","gravatar_id":"","url":"https://api.github.com/users/istio","html_url":"https://github.com/istio","followers_url":"https://api.github.com/users/istio/followers","following_url":"https://api.github.com/users/istio/following{/other_user}","gists_url":"https://api.github.com/users/istio/gists{/gist_id}","starred_url":"https://api.github.com/users/istio/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/istio/subscriptions","organizations_url":"https://api.github.com/users/istio/orgs","repos_url":"https://api.github.com/users/istio/repos","events_url":"https://api.github.com/users/istio/events{/privacy}","received_events_url":"https://api.github.com/users/istio/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/istio/istio","description":"An open platform to connect, manage, and secure microservices.","fork":false,"url":"https://api.github.com/repos/istio/istio","forks_url":"https://api.github.com/repos/istio/istio/forks","keys_url":"https://api.github.com/repos/istio/istio/keys{/key_id}","collaborators_url":"https://api.github.com/repos/istio/istio/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/istio/istio/teams","hooks_url":"https://api.github.com/repos/istio/istio/hooks","issue_events_url":"https://api.github.com/repos/istio/istio/issues/events{/number}","events_url":"https://api.github.com/repos/istio/istio/events","assignees_url":"https://api.github.com/repos/istio/istio/assignees{/user}","branches_url":"https://api.github.com/repos/istio/istio/branches{/branch}","tags_url":"https://api.github.com/repos/istio/istio/tags","blobs_url":"https://api.github.com/repos/istio/istio/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/istio/istio/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/istio/istio/git/refs{/sha}","trees_url":"https://api.github.com/repos/istio/istio/git/trees{/sha}","statuses_url":"https://api.github.com/repos/istio/istio/statuses/{sha}","languages_url":"https://api.github.com/repos/istio/istio/languages","stargazers_url":"https://api.github.com/repos/istio/istio/stargazers","contributors_url":"https://api.github.com/repos/istio/istio/contributors","subscribers_url":"https://api.github.com/repos/istio/istio/subscribers","subscription_url":"https://api.github.com/repos/istio/istio/subscription","commits_url":"https://api.github.com/repos/istio/istio/commits{/sha}","git_commits_url":"https://api.github.com/repos/istio/istio/git/commits{/sha}","comments_url":"https://api.github.com/repos/istio/istio/comments{/number}","issue_comment_url":"https://api.github.com/repos/istio/istio/issues/comments{/number}","contents_url":"https://api.github.com/repos/istio/istio/contents/{+path}","compare_url":"https://api.github.com/repos/istio/istio/compare/{base}...{head}","merges_url":"https://api.github.com/repos/istio/istio/merges","archive_url":"https://api.github.com/repos/istio/istio/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/istio/istio/downloads","issues_url":"https://api.github.com/repos/istio/istio/issues{/number}","pulls_url":"https://api.github.com/repos/istio/istio/pulls{/number}","milestones_url":"https://api.github.com/repos/istio/istio/milestones{/number}","notifications_url":"https://api.github.com/repos/istio/istio/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/istio/istio/labels{/name}","releases_url":"https://api.github.com/repos/istio/istio/releases{/id}","deployments_url":"https://api.github.com/repos/istio/istio/deployments","created_at":"2016-11-18T23:57:21Z","updated_at":"2018-03-22T18:44:12Z","pushed_at":"2018-03-22T18:48:35Z","git_url":"git://github.com/istio/istio.git","ssh_url":"git@github.com:istio/istio.git","clone_url":"https://github.com/istio/istio.git","svn_url":"https://github.com/istio/istio","homepage":"https://istio.io","size":18187,"stargazers_count":6717,"watchers_count":6717,"language":"Go","has_issues":true,"has_projects":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":870,"mirror_url":null,"archived":false,"open_issues_count":771,"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":870,"open_issues":771,"watchers":6717,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/istio/istio/pulls/4455"},"html":{"href":"https://github.com/istio/istio/pull/4455"},"issue":{"href":"https://api.github.com/repos/istio/istio/issues/4455"},"comments":{"href":"https://api.github.com/repos/istio/istio/issues/4455/comments"},"review_comments":{"href":"https://api.github.com/repos/istio/istio/pulls/4455/comments"},"review_comment":{"href":"https://api.github.com/repos/istio/istio/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/istio/istio/pulls/4455/commits"},"statuses":{"href":"https://api.github.com/repos/istio/istio/statuses/9116ec73cf59e516ca5392e00b6b5e7a188aa807"}},"author_association":"CONTRIBUTOR"}}
{"actor":{"display_login":"geeknoid"}}