{"action":"created","comment":{"url":"https://api.github.com/repos/awslabs/swage/pulls/comments/218947100","pull_request_review_id":156995948,"id":218947100,"node_id":"MDI0OlB1bGxSZXF1ZXN0UmV2aWV3Q29tbWVudDIxODk0NzEwMA==","diff_hunk":"@@ -126,33 +131,46 @@ private DimensionMapper(\n      * the dimension will be added with a value of \"null\".\n      *\n      * @param metric Metric being sent\n-     * @param context TypedMap containing metric context attributes\n+     * @param context the context in which the metric was recorded.\n      * @return A list of Dimensions appropriate to send to CloudWatch\n      */\n-    public List<Dimension> getDimensions(final Metric metric, final TypedMap context)\n+    public List<Dimension> getDimensions(final Metric metric, final MetricRecorder.RecorderContext context)\n     {\n+        TypedMap attributes = flattenContextHierarchy(context);\n         Set<TypedMap.Key> dimensionKeys = filterMap.get(metric);\n         if (dimensionKeys == null) {\n             dimensionKeys = Collections.emptySet();\n         }\n \n-        Set<Dimension> dimensions = new HashSet<>(globalDimensions.size() + dimensionKeys.size());\n+        Stream<TypedMap.Key> keys = Stream.concat(globalDimensions.stream(), dimensionKeys.stream());\n+        return keys.map(key -> new Dimension().withName(key.name).withValue(String.valueOf(attributes.get(key))))\n+            .distinct()\n+            .sorted(Comparator.comparing(Dimension::getName))\n+            .collect(Collectors.toList());\n+    }\n \n-        for (TypedMap.Key k : globalDimensions) {\n-            Dimension d = new Dimension();\n-            d.setName(k.name);\n-            d.setValue(String.valueOf(context.get(k)));\n-            dimensions.add(d);\n+     /**\n+     * Flatten the attributes in the context hierarchy to produce the full set of\n+     * attributes which describe the environment in which measurements were taken.\n+     * Parent attributes are overridden by child attributes with the same key.\n+     *\n+     * @param context the context used for recording measurements.\n+     * @return the flattened attributes with parent values overriden by child.\n+     */\n+    private TypedMap flattenContextHierarchy(MetricRecorder.RecorderContext context) {\n+        MetricRecorder.RecorderContext parent = context;\n+        ImmutableTypedMap.Builder attributes = ImmutableTypedMap.Builder.from(TypedMap.empty());\n+        Stack<MetricRecorder.RecorderContext> parents =  new Stack<>();","path":"metrics-core/src/main/java/software/amazon/swage/metrics/record/cloudwatch/DimensionMapper.java","position":67,"original_position":67,"commit_id":"bd8d0f166666c7bc760161c626b4736fdc1d25d1","original_commit_id":"bd8d0f166666c7bc760161c626b4736fdc1d25d1","user":{"login":"jerpowers","id":2896015,"node_id":"MDQ6VXNlcjI4OTYwMTU=","avatar_url":"https://avatars3.githubusercontent.com/u/2896015?v=4","gravatar_id":"","url":"https://api.github.com/users/jerpowers","html_url":"https://github.com/jerpowers","followers_url":"https://api.github.com/users/jerpowers/followers","following_url":"https://api.github.com/users/jerpowers/following{/other_user}","gists_url":"https://api.github.com/users/jerpowers/gists{/gist_id}","starred_url":"https://api.github.com/users/jerpowers/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jerpowers/subscriptions","organizations_url":"https://api.github.com/users/jerpowers/orgs","repos_url":"https://api.github.com/users/jerpowers/repos","events_url":"https://api.github.com/users/jerpowers/events{/privacy}","received_events_url":"https://api.github.com/users/jerpowers/received_events","type":"User","site_admin":false},"body":"Spacing","created_at":"2018-09-19T20:11:13Z","updated_at":"2018-09-19T20:15:54Z","html_url":"https://github.com/awslabs/swage/pull/38#discussion_r218947100","pull_request_url":"https://api.github.com/repos/awslabs/swage/pulls/38","author_association":"NONE","_links":{"self":{"href":"https://api.github.com/repos/awslabs/swage/pulls/comments/218947100"},"html":{"href":"https://github.com/awslabs/swage/pull/38#discussion_r218947100"},"pull_request":{"href":"https://api.github.com/repos/awslabs/swage/pulls/38"}}},"pull_request":{"url":"https://api.github.com/repos/awslabs/swage/pulls/38","id":216702914,"node_id":"MDExOlB1bGxSZXF1ZXN0MjE2NzAyOTE0","html_url":"https://github.com/awslabs/swage/pull/38","diff_url":"https://github.com/awslabs/swage/pull/38.diff","patch_url":"https://github.com/awslabs/swage/pull/38.patch","issue_url":"https://api.github.com/repos/awslabs/swage/issues/38","number":38,"state":"open","locked":false,"title":"Add child MetircContext functionality.","user":{"login":"dainstber","id":38336471,"node_id":"MDQ6VXNlcjM4MzM2NDcx","avatar_url":"https://avatars3.githubusercontent.com/u/38336471?v=4","gravatar_id":"","url":"https://api.github.com/users/dainstber","html_url":"https://github.com/dainstber","followers_url":"https://api.github.com/users/dainstber/followers","following_url":"https://api.github.com/users/dainstber/following{/other_user}","gists_url":"https://api.github.com/users/dainstber/gists{/gist_id}","starred_url":"https://api.github.com/users/dainstber/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dainstber/subscriptions","organizations_url":"https://api.github.com/users/dainstber/orgs","repos_url":"https://api.github.com/users/dainstber/repos","events_url":"https://api.github.com/users/dainstber/events{/privacy}","received_events_url":"https://api.github.com/users/dainstber/received_events","type":"User","site_admin":false},"body":"Allow creating a child MetricContext from an instance. A context\r\ncontains the attributes which differentiate it from its parent.\r\nA MetricRecorder implementation can reconstruct the whole view\r\nof the environment by combining the\r\nattributes from all parents in the hierarchy.\r\n\r\nAddresses: https://github.com/awslabs/swage/issues/11","created_at":"2018-09-19T16:32:40Z","updated_at":"2018-09-19T20:15:54Z","closed_at":null,"merged_at":null,"merge_commit_sha":"1e116dd957b9e60caf09b12406e5c58b4b471dfe","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[],"milestone":null,"commits_url":"https://api.github.com/repos/awslabs/swage/pulls/38/commits","review_comments_url":"https://api.github.com/repos/awslabs/swage/pulls/38/comments","review_comment_url":"https://api.github.com/repos/awslabs/swage/pulls/comments{/number}","comments_url":"https://api.github.com/repos/awslabs/swage/issues/38/comments","statuses_url":"https://api.github.com/repos/awslabs/swage/statuses/bd8d0f166666c7bc760161c626b4736fdc1d25d1","head":{"label":"dainstber:child","ref":"child","sha":"bd8d0f166666c7bc760161c626b4736fdc1d25d1","user":{"login":"dainstber","id":38336471,"node_id":"MDQ6VXNlcjM4MzM2NDcx","avatar_url":"https://avatars3.githubusercontent.com/u/38336471?v=4","gravatar_id":"","url":"https://api.github.com/users/dainstber","html_url":"https://github.com/dainstber","followers_url":"https://api.github.com/users/dainstber/followers","following_url":"https://api.github.com/users/dainstber/following{/other_user}","gists_url":"https://api.github.com/users/dainstber/gists{/gist_id}","starred_url":"https://api.github.com/users/dainstber/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dainstber/subscriptions","organizations_url":"https://api.github.com/users/dainstber/orgs","repos_url":"https://api.github.com/users/dainstber/repos","events_url":"https://api.github.com/users/dainstber/events{/privacy}","received_events_url":"https://api.github.com/users/dainstber/received_events","type":"User","site_admin":false},"repo":{"id":144067770,"node_id":"MDEwOlJlcG9zaXRvcnkxNDQwNjc3NzA=","name":"swage","full_name":"dainstber/swage","private":false,"owner":{"login":"dainstber","id":38336471,"node_id":"MDQ6VXNlcjM4MzM2NDcx","avatar_url":"https://avatars3.githubusercontent.com/u/38336471?v=4","gravatar_id":"","url":"https://api.github.com/users/dainstber","html_url":"https://github.com/dainstber","followers_url":"https://api.github.com/users/dainstber/followers","following_url":"https://api.github.com/users/dainstber/following{/other_user}","gists_url":"https://api.github.com/users/dainstber/gists{/gist_id}","starred_url":"https://api.github.com/users/dainstber/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dainstber/subscriptions","organizations_url":"https://api.github.com/users/dainstber/orgs","repos_url":"https://api.github.com/users/dainstber/repos","events_url":"https://api.github.com/users/dainstber/events{/privacy}","received_events_url":"https://api.github.com/users/dainstber/received_events","type":"User","site_admin":false},"html_url":"https://github.com/dainstber/swage","description":"A collection of libraries useful for developing and running services. ","fork":true,"url":"https://api.github.com/repos/dainstber/swage","forks_url":"https://api.github.com/repos/dainstber/swage/forks","keys_url":"https://api.github.com/repos/dainstber/swage/keys{/key_id}","collaborators_url":"https://api.github.com/repos/dainstber/swage/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/dainstber/swage/teams","hooks_url":"https://api.github.com/repos/dainstber/swage/hooks","issue_events_url":"https://api.github.com/repos/dainstber/swage/issues/events{/number}","events_url":"https://api.github.com/repos/dainstber/swage/events","assignees_url":"https://api.github.com/repos/dainstber/swage/assignees{/user}","branches_url":"https://api.github.com/repos/dainstber/swage/branches{/branch}","tags_url":"https://api.github.com/repos/dainstber/swage/tags","blobs_url":"https://api.github.com/repos/dainstber/swage/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/dainstber/swage/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/dainstber/swage/git/refs{/sha}","trees_url":"https://api.github.com/repos/dainstber/swage/git/trees{/sha}","statuses_url":"https://api.github.com/repos/dainstber/swage/statuses/{sha}","languages_url":"https://api.github.com/repos/dainstber/swage/languages","stargazers_url":"https://api.github.com/repos/dainstber/swage/stargazers","contributors_url":"https://api.github.com/repos/dainstber/swage/contributors","subscribers_url":"https://api.github.com/repos/dainstber/swage/subscribers","subscription_url":"https://api.github.com/repos/dainstber/swage/subscription","commits_url":"https://api.github.com/repos/dainstber/swage/commits{/sha}","git_commits_url":"https://api.github.com/repos/dainstber/swage/git/commits{/sha}","comments_url":"https://api.github.com/repos/dainstber/swage/comments{/number}","issue_comment_url":"https://api.github.com/repos/dainstber/swage/issues/comments{/number}","contents_url":"https://api.github.com/repos/dainstber/swage/contents/{+path}","compare_url":"https://api.github.com/repos/dainstber/swage/compare/{base}...{head}","merges_url":"https://api.github.com/repos/dainstber/swage/merges","archive_url":"https://api.github.com/repos/dainstber/swage/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/dainstber/swage/downloads","issues_url":"https://api.github.com/repos/dainstber/swage/issues{/number}","pulls_url":"https://api.github.com/repos/dainstber/swage/pulls{/number}","milestones_url":"https://api.github.com/repos/dainstber/swage/milestones{/number}","notifications_url":"https://api.github.com/repos/dainstber/swage/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/dainstber/swage/labels{/name}","releases_url":"https://api.github.com/repos/dainstber/swage/releases{/id}","deployments_url":"https://api.github.com/repos/dainstber/swage/deployments","created_at":"2018-08-08T21:09:04Z","updated_at":"2018-08-08T21:09:06Z","pushed_at":"2018-09-19T00:03:29Z","git_url":"git://github.com/dainstber/swage.git","ssh_url":"git@github.com:dainstber/swage.git","clone_url":"https://github.com/dainstber/swage.git","svn_url":"https://github.com/dainstber/swage","homepage":null,"size":155,"stargazers_count":0,"watchers_count":0,"language":"Java","has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":false,"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","node_id":"MDc6TGljZW5zZTI="},"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"awslabs:master","ref":"master","sha":"5e4556f998ee70850296a6cbbaafc10c2e4e4a41","user":{"login":"awslabs","id":3299148,"node_id":"MDEyOk9yZ2FuaXphdGlvbjMyOTkxNDg=","avatar_url":"https://avatars0.githubusercontent.com/u/3299148?v=4","gravatar_id":"","url":"https://api.github.com/users/awslabs","html_url":"https://github.com/awslabs","followers_url":"https://api.github.com/users/awslabs/followers","following_url":"https://api.github.com/users/awslabs/following{/other_user}","gists_url":"https://api.github.com/users/awslabs/gists{/gist_id}","starred_url":"https://api.github.com/users/awslabs/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/awslabs/subscriptions","organizations_url":"https://api.github.com/users/awslabs/orgs","repos_url":"https://api.github.com/users/awslabs/repos","events_url":"https://api.github.com/users/awslabs/events{/privacy}","received_events_url":"https://api.github.com/users/awslabs/received_events","type":"Organization","site_admin":false},"repo":{"id":99742967,"node_id":"MDEwOlJlcG9zaXRvcnk5OTc0Mjk2Nw==","name":"swage","full_name":"awslabs/swage","private":false,"owner":{"login":"awslabs","id":3299148,"node_id":"MDEyOk9yZ2FuaXphdGlvbjMyOTkxNDg=","avatar_url":"https://avatars0.githubusercontent.com/u/3299148?v=4","gravatar_id":"","url":"https://api.github.com/users/awslabs","html_url":"https://github.com/awslabs","followers_url":"https://api.github.com/users/awslabs/followers","following_url":"https://api.github.com/users/awslabs/following{/other_user}","gists_url":"https://api.github.com/users/awslabs/gists{/gist_id}","starred_url":"https://api.github.com/users/awslabs/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/awslabs/subscriptions","organizations_url":"https://api.github.com/users/awslabs/orgs","repos_url":"https://api.github.com/users/awslabs/repos","events_url":"https://api.github.com/users/awslabs/events{/privacy}","received_events_url":"https://api.github.com/users/awslabs/received_events","type":"Organization","site_admin":false},"html_url":"https://github.com/awslabs/swage","description":"A collection of libraries useful for developing and running services. ","fork":false,"url":"https://api.github.com/repos/awslabs/swage","forks_url":"https://api.github.com/repos/awslabs/swage/forks","keys_url":"https://api.github.com/repos/awslabs/swage/keys{/key_id}","collaborators_url":"https://api.github.com/repos/awslabs/swage/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/awslabs/swage/teams","hooks_url":"https://api.github.com/repos/awslabs/swage/hooks","issue_events_url":"https://api.github.com/repos/awslabs/swage/issues/events{/number}","events_url":"https://api.github.com/repos/awslabs/swage/events","assignees_url":"https://api.github.com/repos/awslabs/swage/assignees{/user}","branches_url":"https://api.github.com/repos/awslabs/swage/branches{/branch}","tags_url":"https://api.github.com/repos/awslabs/swage/tags","blobs_url":"https://api.github.com/repos/awslabs/swage/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/awslabs/swage/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/awslabs/swage/git/refs{/sha}","trees_url":"https://api.github.com/repos/awslabs/swage/git/trees{/sha}","statuses_url":"https://api.github.com/repos/awslabs/swage/statuses/{sha}","languages_url":"https://api.github.com/repos/awslabs/swage/languages","stargazers_url":"https://api.github.com/repos/awslabs/swage/stargazers","contributors_url":"https://api.github.com/repos/awslabs/swage/contributors","subscribers_url":"https://api.github.com/repos/awslabs/swage/subscribers","subscription_url":"https://api.github.com/repos/awslabs/swage/subscription","commits_url":"https://api.github.com/repos/awslabs/swage/commits{/sha}","git_commits_url":"https://api.github.com/repos/awslabs/swage/git/commits{/sha}","comments_url":"https://api.github.com/repos/awslabs/swage/comments{/number}","issue_comment_url":"https://api.github.com/repos/awslabs/swage/issues/comments{/number}","contents_url":"https://api.github.com/repos/awslabs/swage/contents/{+path}","compare_url":"https://api.github.com/repos/awslabs/swage/compare/{base}...{head}","merges_url":"https://api.github.com/repos/awslabs/swage/merges","archive_url":"https://api.github.com/repos/awslabs/swage/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/awslabs/swage/downloads","issues_url":"https://api.github.com/repos/awslabs/swage/issues{/number}","pulls_url":"https://api.github.com/repos/awslabs/swage/pulls{/number}","milestones_url":"https://api.github.com/repos/awslabs/swage/milestones{/number}","notifications_url":"https://api.github.com/repos/awslabs/swage/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/awslabs/swage/labels{/name}","releases_url":"https://api.github.com/repos/awslabs/swage/releases{/id}","deployments_url":"https://api.github.com/repos/awslabs/swage/deployments","created_at":"2017-08-08T22:53:58Z","updated_at":"2018-09-11T22:01:55Z","pushed_at":"2018-09-19T16:32:41Z","git_url":"git://github.com/awslabs/swage.git","ssh_url":"git@github.com:awslabs/swage.git","clone_url":"https://github.com/awslabs/swage.git","svn_url":"https://github.com/awslabs/swage","homepage":null,"size":156,"stargazers_count":10,"watchers_count":10,"language":"Java","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":11,"mirror_url":null,"archived":false,"open_issues_count":22,"license":{"key":"apache-2.0","name":"Apache License 2.0","spdx_id":"Apache-2.0","url":"https://api.github.com/licenses/apache-2.0","node_id":"MDc6TGljZW5zZTI="},"forks":11,"open_issues":22,"watchers":10,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/awslabs/swage/pulls/38"},"html":{"href":"https://github.com/awslabs/swage/pull/38"},"issue":{"href":"https://api.github.com/repos/awslabs/swage/issues/38"},"comments":{"href":"https://api.github.com/repos/awslabs/swage/issues/38/comments"},"review_comments":{"href":"https://api.github.com/repos/awslabs/swage/pulls/38/comments"},"review_comment":{"href":"https://api.github.com/repos/awslabs/swage/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/awslabs/swage/pulls/38/commits"},"statuses":{"href":"https://api.github.com/repos/awslabs/swage/statuses/bd8d0f166666c7bc760161c626b4736fdc1d25d1"}},"author_association":"NONE"}}
{"actor":{"display_login":"jerpowers"}}