{"action":"created","comment":{"url":"https://api.github.com/repos/m3db/m3metrics/pulls/comments/181156973","pull_request_review_id":111714170,"id":181156973,"diff_hunk":"@@ -0,0 +1,125 @@\n+// Copyright (c) 2018 Uber Technologies, Inc.\n+//\n+// Permission is hereby granted, free of charge, to any person obtaining a copy\n+// of this software and associated documentation files (the \"Software\"), to deal\n+// in the Software without restriction, including without limitation the rights\n+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n+// copies of the Software, and to permit persons to whom the Software is\n+// furnished to do so, subject to the following conditions:\n+//\n+// The above copyright notice and this permission notice shall be included in\n+// all copies or substantial portions of the Software.\n+//\n+// THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n+// THE SOFTWARE.\n+\n+package migration\n+\n+import (\n+\t\"fmt\"\n+\n+\t\"github.com/m3db/m3metrics/encoding\"\n+\t\"github.com/m3db/m3metrics/metadata\"\n+\t\"github.com/m3db/m3metrics/metric/unaggregated\"\n+\t\"github.com/m3db/m3metrics/policy\"\n+)\n+\n+func toUnaggregatedMessageUnion(\n+\tmetric unaggregated.MetricUnion,\n+\tpoliciesList policy.PoliciesList,\n+) (encoding.UnaggregatedMessageUnion, error) {\n+\tmetadatas := toStagedMetadatas(policiesList)\n+\tswitch metric.Type {\n+\tcase unaggregated.CounterType:\n+\t\treturn encoding.UnaggregatedMessageUnion{\n+\t\t\tType: encoding.CounterWithMetadatasType,\n+\t\t\tCounterWithMetadatas: unaggregated.CounterWithMetadatas{\n+\t\t\t\tCounter:         metric.Counter(),\n+\t\t\t\tStagedMetadatas: metadatas,\n+\t\t\t},\n+\t\t}, nil\n+\tcase unaggregated.BatchTimerType:\n+\t\treturn encoding.UnaggregatedMessageUnion{\n+\t\t\tType: encoding.BatchTimerWithMetadatasType,\n+\t\t\tBatchTimerWithMetadatas: unaggregated.BatchTimerWithMetadatas{\n+\t\t\t\tBatchTimer:      metric.BatchTimer(),\n+\t\t\t\tStagedMetadatas: metadatas,\n+\t\t\t},\n+\t\t}, nil\n+\tcase unaggregated.GaugeType:\n+\t\treturn encoding.UnaggregatedMessageUnion{\n+\t\t\tType: encoding.GaugeWithMetadatasType,\n+\t\t\tGaugeWithMetadatas: unaggregated.GaugeWithMetadatas{\n+\t\t\t\tGauge:           metric.Gauge(),\n+\t\t\t\tStagedMetadatas: metadatas,\n+\t\t\t},\n+\t\t}, nil\n+\tdefault:\n+\t\treturn encoding.UnaggregatedMessageUnion{}, fmt.Errorf(\"unknown metric type: %v\", metric.Type)\n+\t}\n+}\n+\n+// TODO: look into reuse metadatas during conversion.\n+func toStagedMetadatas(\n+\tpoliciesList policy.PoliciesList,\n+) metadata.StagedMetadatas {\n+\tnumStagedPolicies := len(policiesList)\n+\tres := make(metadata.StagedMetadatas, 0, numStagedPolicies)\n+\tfor _, sp := range policiesList {\n+\t\tif sp.IsDefault() {\n+\t\t\tsm := metadata.DefaultStagedMetadata\n+\t\t\tres = append(res, sm)\n+\t\t\tcontinue\n+\t\t}\n+\t\tsm := metadata.StagedMetadata{}\n+\t\tsm.CutoverNanos = sp.CutoverNanos\n+\t\tsm.Tombstoned = sp.Tombstoned\n+\t\tpolicies, _ := sp.Policies()\n+\t\tsm.Metadata = toMetadata(policies)\n+\t\tres = append(res, sm)\n+\t}\n+\treturn res\n+}\n+\n+// TODO: look into reuse metadata during conversion.\n+func toMetadata(policies []policy.Policy) metadata.Metadata {\n+\tres := metadata.Metadata{}\n+\tfor _, p := range policies {\n+\t\t// Find if there is an existing pipeline in the set of metadatas\n+\t\t// with the same aggregation ID.\n+\t\tpipelineIdx := -1\n+\t\tfor i := 0; i < len(res.Pipelines); i++ {\n+\t\t\tif p.AggregationID == res.Pipelines[i].AggregationID {\n+\t\t\t\tpipelineIdx = i\n+\t\t\t\tbreak\n+\t\t\t}\n+\t\t}\n+\t\tif pipelineIdx == -1 {\n+\t\t\tres.Pipelines = append(res.Pipelines, metadata.PipelineMetadata{\n+\t\t\t\tAggregationID: p.AggregationID,\n+\t\t\t})\n+\t\t\tpipelineIdx = len(res.Pipelines) - 1\n+\t\t}\n+\n+\t\t// Find if the storage policy already exists in the set of storage\n+\t\t// policies in the pipeline.\n+\t\tpipelines := res.Pipelines\n+\t\tpolicyIdx := -1\n+\t\tfor i := 0; i < len(pipelines[pipelineIdx].StoragePolicies); i++ {\n+\t\t\tif pipelines[pipelineIdx].StoragePolicies[i] == p.StoragePolicy {\n+\t\t\t\tpolicyIdx = i\n+\t\t\t\tbreak\n+\t\t\t}\n+\t\t}\n+\t\tif policyIdx != -1 {","path":"encoding/migration/convert.go","position":119,"original_position":119,"commit_id":"5d9e15ed846d40f21d3d21a7121f1f1cb9dedeba","original_commit_id":"5d9e15ed846d40f21d3d21a7121f1f1cb9dedeba","user":{"login":"xichen2020","id":12239421,"avatar_url":"https://avatars1.githubusercontent.com/u/12239421?v=4","gravatar_id":"","url":"https://api.github.com/users/xichen2020","html_url":"https://github.com/xichen2020","followers_url":"https://api.github.com/users/xichen2020/followers","following_url":"https://api.github.com/users/xichen2020/following{/other_user}","gists_url":"https://api.github.com/users/xichen2020/gists{/gist_id}","starred_url":"https://api.github.com/users/xichen2020/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/xichen2020/subscriptions","organizations_url":"https://api.github.com/users/xichen2020/orgs","repos_url":"https://api.github.com/users/xichen2020/repos","events_url":"https://api.github.com/users/xichen2020/events{/privacy}","received_events_url":"https://api.github.com/users/xichen2020/received_events","type":"User","site_admin":false},"body":"Yes, granted it shouldn't happen so this is just defensive programming.","created_at":"2018-04-12T17:14:59Z","updated_at":"2018-04-12T17:14:59Z","html_url":"https://github.com/m3db/m3metrics/pull/150#discussion_r181156973","pull_request_url":"https://api.github.com/repos/m3db/m3metrics/pulls/150","author_association":"CONTRIBUTOR","_links":{"self":{"href":"https://api.github.com/repos/m3db/m3metrics/pulls/comments/181156973"},"html":{"href":"https://github.com/m3db/m3metrics/pull/150#discussion_r181156973"},"pull_request":{"href":"https://api.github.com/repos/m3db/m3metrics/pulls/150"}},"in_reply_to_id":181153064},"pull_request":{"url":"https://api.github.com/repos/m3db/m3metrics/pulls/150","id":181261497,"html_url":"https://github.com/m3db/m3metrics/pull/150","diff_url":"https://github.com/m3db/m3metrics/pull/150.diff","patch_url":"https://github.com/m3db/m3metrics/pull/150.patch","issue_url":"https://api.github.com/repos/m3db/m3metrics/issues/150","number":150,"state":"open","locked":false,"title":"Add migration decoder","user":{"login":"xichen2020","id":12239421,"avatar_url":"https://avatars1.githubusercontent.com/u/12239421?v=4","gravatar_id":"","url":"https://api.github.com/users/xichen2020","html_url":"https://github.com/xichen2020","followers_url":"https://api.github.com/users/xichen2020/followers","following_url":"https://api.github.com/users/xichen2020/following{/other_user}","gists_url":"https://api.github.com/users/xichen2020/gists{/gist_id}","starred_url":"https://api.github.com/users/xichen2020/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/xichen2020/subscriptions","organizations_url":"https://api.github.com/users/xichen2020/orgs","repos_url":"https://api.github.com/users/xichen2020/repos","events_url":"https://api.github.com/users/xichen2020/events{/privacy}","received_events_url":"https://api.github.com/users/xichen2020/received_events","type":"User","site_admin":false},"body":"cc @cw9 @jeromefroe \r\n\r\nThis PR adds the migration iterator that is capable for decoding both msgpack-encoded and protobuf-encoded data.","created_at":"2018-04-12T16:35:55Z","updated_at":"2018-04-12T17:14:59Z","closed_at":null,"merged_at":null,"merge_commit_sha":"43e55ef54a5683b7a0d50fdda12da6af7945e9d0","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[],"milestone":null,"commits_url":"https://api.github.com/repos/m3db/m3metrics/pulls/150/commits","review_comments_url":"https://api.github.com/repos/m3db/m3metrics/pulls/150/comments","review_comment_url":"https://api.github.com/repos/m3db/m3metrics/pulls/comments{/number}","comments_url":"https://api.github.com/repos/m3db/m3metrics/issues/150/comments","statuses_url":"https://api.github.com/repos/m3db/m3metrics/statuses/5d9e15ed846d40f21d3d21a7121f1f1cb9dedeba","head":{"label":"m3db:xichen-encoding-api-migration-iterator","ref":"xichen-encoding-api-migration-iterator","sha":"5d9e15ed846d40f21d3d21a7121f1f1cb9dedeba","user":{"login":"m3db","id":19937171,"avatar_url":"https://avatars0.githubusercontent.com/u/19937171?v=4","gravatar_id":"","url":"https://api.github.com/users/m3db","html_url":"https://github.com/m3db","followers_url":"https://api.github.com/users/m3db/followers","following_url":"https://api.github.com/users/m3db/following{/other_user}","gists_url":"https://api.github.com/users/m3db/gists{/gist_id}","starred_url":"https://api.github.com/users/m3db/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/m3db/subscriptions","organizations_url":"https://api.github.com/users/m3db/orgs","repos_url":"https://api.github.com/users/m3db/repos","events_url":"https://api.github.com/users/m3db/events{/privacy}","received_events_url":"https://api.github.com/users/m3db/received_events","type":"Organization","site_admin":false},"repo":{"id":76399863,"name":"m3metrics","full_name":"m3db/m3metrics","owner":{"login":"m3db","id":19937171,"avatar_url":"https://avatars0.githubusercontent.com/u/19937171?v=4","gravatar_id":"","url":"https://api.github.com/users/m3db","html_url":"https://github.com/m3db","followers_url":"https://api.github.com/users/m3db/followers","following_url":"https://api.github.com/users/m3db/following{/other_user}","gists_url":"https://api.github.com/users/m3db/gists{/gist_id}","starred_url":"https://api.github.com/users/m3db/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/m3db/subscriptions","organizations_url":"https://api.github.com/users/m3db/orgs","repos_url":"https://api.github.com/users/m3db/repos","events_url":"https://api.github.com/users/m3db/events{/privacy}","received_events_url":"https://api.github.com/users/m3db/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/m3db/m3metrics","description":"Metrics data structures and serialization/deserialization protocols","fork":false,"url":"https://api.github.com/repos/m3db/m3metrics","forks_url":"https://api.github.com/repos/m3db/m3metrics/forks","keys_url":"https://api.github.com/repos/m3db/m3metrics/keys{/key_id}","collaborators_url":"https://api.github.com/repos/m3db/m3metrics/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/m3db/m3metrics/teams","hooks_url":"https://api.github.com/repos/m3db/m3metrics/hooks","issue_events_url":"https://api.github.com/repos/m3db/m3metrics/issues/events{/number}","events_url":"https://api.github.com/repos/m3db/m3metrics/events","assignees_url":"https://api.github.com/repos/m3db/m3metrics/assignees{/user}","branches_url":"https://api.github.com/repos/m3db/m3metrics/branches{/branch}","tags_url":"https://api.github.com/repos/m3db/m3metrics/tags","blobs_url":"https://api.github.com/repos/m3db/m3metrics/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/m3db/m3metrics/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/m3db/m3metrics/git/refs{/sha}","trees_url":"https://api.github.com/repos/m3db/m3metrics/git/trees{/sha}","statuses_url":"https://api.github.com/repos/m3db/m3metrics/statuses/{sha}","languages_url":"https://api.github.com/repos/m3db/m3metrics/languages","stargazers_url":"https://api.github.com/repos/m3db/m3metrics/stargazers","contributors_url":"https://api.github.com/repos/m3db/m3metrics/contributors","subscribers_url":"https://api.github.com/repos/m3db/m3metrics/subscribers","subscription_url":"https://api.github.com/repos/m3db/m3metrics/subscription","commits_url":"https://api.github.com/repos/m3db/m3metrics/commits{/sha}","git_commits_url":"https://api.github.com/repos/m3db/m3metrics/git/commits{/sha}","comments_url":"https://api.github.com/repos/m3db/m3metrics/comments{/number}","issue_comment_url":"https://api.github.com/repos/m3db/m3metrics/issues/comments{/number}","contents_url":"https://api.github.com/repos/m3db/m3metrics/contents/{+path}","compare_url":"https://api.github.com/repos/m3db/m3metrics/compare/{base}...{head}","merges_url":"https://api.github.com/repos/m3db/m3metrics/merges","archive_url":"https://api.github.com/repos/m3db/m3metrics/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/m3db/m3metrics/downloads","issues_url":"https://api.github.com/repos/m3db/m3metrics/issues{/number}","pulls_url":"https://api.github.com/repos/m3db/m3metrics/pulls{/number}","milestones_url":"https://api.github.com/repos/m3db/m3metrics/milestones{/number}","notifications_url":"https://api.github.com/repos/m3db/m3metrics/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/m3db/m3metrics/labels{/name}","releases_url":"https://api.github.com/repos/m3db/m3metrics/releases{/id}","deployments_url":"https://api.github.com/repos/m3db/m3metrics/deployments","created_at":"2016-12-13T21:28:26Z","updated_at":"2018-04-12T13:48:27Z","pushed_at":"2018-04-12T17:10:45Z","git_url":"git://github.com/m3db/m3metrics.git","ssh_url":"git@github.com:m3db/m3metrics.git","clone_url":"https://github.com/m3db/m3metrics.git","svn_url":"https://github.com/m3db/m3metrics","homepage":"","size":782,"stargazers_count":2,"watchers_count":2,"language":"Go","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"open_issues_count":12,"license":{"key":"mit","name":"MIT License","spdx_id":"MIT","url":"https://api.github.com/licenses/mit"},"forks":0,"open_issues":12,"watchers":2,"default_branch":"master"}},"base":{"label":"m3db:xichen-encoding-api","ref":"xichen-encoding-api","sha":"d0f18b1168205cef6d8affd533a7a07503b107b3","user":{"login":"m3db","id":19937171,"avatar_url":"https://avatars0.githubusercontent.com/u/19937171?v=4","gravatar_id":"","url":"https://api.github.com/users/m3db","html_url":"https://github.com/m3db","followers_url":"https://api.github.com/users/m3db/followers","following_url":"https://api.github.com/users/m3db/following{/other_user}","gists_url":"https://api.github.com/users/m3db/gists{/gist_id}","starred_url":"https://api.github.com/users/m3db/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/m3db/subscriptions","organizations_url":"https://api.github.com/users/m3db/orgs","repos_url":"https://api.github.com/users/m3db/repos","events_url":"https://api.github.com/users/m3db/events{/privacy}","received_events_url":"https://api.github.com/users/m3db/received_events","type":"Organization","site_admin":false},"repo":{"id":76399863,"name":"m3metrics","full_name":"m3db/m3metrics","owner":{"login":"m3db","id":19937171,"avatar_url":"https://avatars0.githubusercontent.com/u/19937171?v=4","gravatar_id":"","url":"https://api.github.com/users/m3db","html_url":"https://github.com/m3db","followers_url":"https://api.github.com/users/m3db/followers","following_url":"https://api.github.com/users/m3db/following{/other_user}","gists_url":"https://api.github.com/users/m3db/gists{/gist_id}","starred_url":"https://api.github.com/users/m3db/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/m3db/subscriptions","organizations_url":"https://api.github.com/users/m3db/orgs","repos_url":"https://api.github.com/users/m3db/repos","events_url":"https://api.github.com/users/m3db/events{/privacy}","received_events_url":"https://api.github.com/users/m3db/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/m3db/m3metrics","description":"Metrics data structures and serialization/deserialization protocols","fork":false,"url":"https://api.github.com/repos/m3db/m3metrics","forks_url":"https://api.github.com/repos/m3db/m3metrics/forks","keys_url":"https://api.github.com/repos/m3db/m3metrics/keys{/key_id}","collaborators_url":"https://api.github.com/repos/m3db/m3metrics/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/m3db/m3metrics/teams","hooks_url":"https://api.github.com/repos/m3db/m3metrics/hooks","issue_events_url":"https://api.github.com/repos/m3db/m3metrics/issues/events{/number}","events_url":"https://api.github.com/repos/m3db/m3metrics/events","assignees_url":"https://api.github.com/repos/m3db/m3metrics/assignees{/user}","branches_url":"https://api.github.com/repos/m3db/m3metrics/branches{/branch}","tags_url":"https://api.github.com/repos/m3db/m3metrics/tags","blobs_url":"https://api.github.com/repos/m3db/m3metrics/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/m3db/m3metrics/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/m3db/m3metrics/git/refs{/sha}","trees_url":"https://api.github.com/repos/m3db/m3metrics/git/trees{/sha}","statuses_url":"https://api.github.com/repos/m3db/m3metrics/statuses/{sha}","languages_url":"https://api.github.com/repos/m3db/m3metrics/languages","stargazers_url":"https://api.github.com/repos/m3db/m3metrics/stargazers","contributors_url":"https://api.github.com/repos/m3db/m3metrics/contributors","subscribers_url":"https://api.github.com/repos/m3db/m3metrics/subscribers","subscription_url":"https://api.github.com/repos/m3db/m3metrics/subscription","commits_url":"https://api.github.com/repos/m3db/m3metrics/commits{/sha}","git_commits_url":"https://api.github.com/repos/m3db/m3metrics/git/commits{/sha}","comments_url":"https://api.github.com/repos/m3db/m3metrics/comments{/number}","issue_comment_url":"https://api.github.com/repos/m3db/m3metrics/issues/comments{/number}","contents_url":"https://api.github.com/repos/m3db/m3metrics/contents/{+path}","compare_url":"https://api.github.com/repos/m3db/m3metrics/compare/{base}...{head}","merges_url":"https://api.github.com/repos/m3db/m3metrics/merges","archive_url":"https://api.github.com/repos/m3db/m3metrics/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/m3db/m3metrics/downloads","issues_url":"https://api.github.com/repos/m3db/m3metrics/issues{/number}","pulls_url":"https://api.github.com/repos/m3db/m3metrics/pulls{/number}","milestones_url":"https://api.github.com/repos/m3db/m3metrics/milestones{/number}","notifications_url":"https://api.github.com/repos/m3db/m3metrics/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/m3db/m3metrics/labels{/name}","releases_url":"https://api.github.com/repos/m3db/m3metrics/releases{/id}","deployments_url":"https://api.github.com/repos/m3db/m3metrics/deployments","created_at":"2016-12-13T21:28:26Z","updated_at":"2018-04-12T13:48:27Z","pushed_at":"2018-04-12T17:10:45Z","git_url":"git://github.com/m3db/m3metrics.git","ssh_url":"git@github.com:m3db/m3metrics.git","clone_url":"https://github.com/m3db/m3metrics.git","svn_url":"https://github.com/m3db/m3metrics","homepage":"","size":782,"stargazers_count":2,"watchers_count":2,"language":"Go","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"open_issues_count":12,"license":{"key":"mit","name":"MIT License","spdx_id":"MIT","url":"https://api.github.com/licenses/mit"},"forks":0,"open_issues":12,"watchers":2,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/m3db/m3metrics/pulls/150"},"html":{"href":"https://github.com/m3db/m3metrics/pull/150"},"issue":{"href":"https://api.github.com/repos/m3db/m3metrics/issues/150"},"comments":{"href":"https://api.github.com/repos/m3db/m3metrics/issues/150/comments"},"review_comments":{"href":"https://api.github.com/repos/m3db/m3metrics/pulls/150/comments"},"review_comment":{"href":"https://api.github.com/repos/m3db/m3metrics/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/m3db/m3metrics/pulls/150/commits"},"statuses":{"href":"https://api.github.com/repos/m3db/m3metrics/statuses/5d9e15ed846d40f21d3d21a7121f1f1cb9dedeba"}},"author_association":"CONTRIBUTOR"}}
{"actor":{"display_login":"xichen2020"}}