{"action":"created","comment":{"url":"https://api.github.com/repos/Azure/iotedge/pulls/comments/360665625","pull_request_review_id":335620734,"id":360665625,"node_id":"MDI0OlB1bGxSZXF1ZXN0UmV2aWV3Q29tbWVudDM2MDY2NTYyNQ==","diff_hunk":"@@ -0,0 +1,92 @@\n+// Copyright (c) Microsoft. All rights reserved.\n+\n+namespace Microsoft.Azure.Devices.Edge.Agent.Diagnostics\n+{\n+    using System;\n+    using System.Collections.Generic;\n+    using System.Linq;\n+    using System.Text;\n+    using Microsoft.Azure.Devices.Edge.Util;\n+    using Newtonsoft.Json;\n+\n+    /// <summary>\n+    /// This class acts as a pass through for a group of metrics.\n+    /// It will exclude metrics based on a tag whitelist and blacklist.\n+    /// After filtering, it will add or remove tags.\n+    /// </summary>\n+    public class MetricFilter\n+    {\n+        Option<List<KeyValuePair<string, string>>> tagsWhitelist = Option.None<List<KeyValuePair<string, string>>>();\n+        Option<List<KeyValuePair<string, string>>> tagsToAdd = Option.None<List<KeyValuePair<string, string>>>();\n+        Option<List<string>> tagsToRemove = Option.None<List<string>>();\n+\n+        public IEnumerable<Metric> FilterMetrics(IEnumerable<Metric> metrics)\n+        {\n+            foreach (Metric metric in metrics)\n+            {\n+                // Skip metric if the whitelist does not contain it.\n+                if (this.tagsWhitelist.Exists(wl => !wl.Any(metric.Tags.Contains)))\n+                {\n+                    continue;\n+                }\n+\n+                // Add or remove tags if needed.\n+                if (this.tagsToAdd.HasValue || this.tagsToRemove.HasValue)\n+                {\n+                    Dictionary<string, string> newTags = metric.Tags.ToDictionary(t => t.Key, t => t.Value);\n+\n+                    this.tagsToAdd.ForEach(tta => tta.ForEach(toAdd => newTags.Add(toAdd.Key, toAdd.Value)));\n+                    this.tagsToRemove.ForEach(ttr => ttr.ForEach(toRemove => newTags.Remove(toRemove)));\n+\n+                    yield return new Metric(metric.TimeGeneratedUtc, metric.Name, metric.Value, newTags);\n+                }\n+                else\n+                {\n+                    yield return metric;\n+                }\n+            }\n+        }\n+\n+        public MetricFilter AddToWhitelist(params KeyValuePair<string, string>[] pairs)","path":"edge-agent/src/Microsoft.Azure.Devices.Edge.Agent.Diagnostics/MetricFilter.cs","position":50,"original_position":50,"commit_id":"0c007829932c45155334bd3804369b49580d6154","original_commit_id":"0c007829932c45155334bd3804369b49580d6154","user":{"login":"kkdawkins","id":947949,"node_id":"MDQ6VXNlcjk0Nzk0OQ==","avatar_url":"https://avatars0.githubusercontent.com/u/947949?v=4","gravatar_id":"","url":"https://api.github.com/users/kkdawkins","html_url":"https://github.com/kkdawkins","followers_url":"https://api.github.com/users/kkdawkins/followers","following_url":"https://api.github.com/users/kkdawkins/following{/other_user}","gists_url":"https://api.github.com/users/kkdawkins/gists{/gist_id}","starred_url":"https://api.github.com/users/kkdawkins/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kkdawkins/subscriptions","organizations_url":"https://api.github.com/users/kkdawkins/orgs","repos_url":"https://api.github.com/users/kkdawkins/repos","events_url":"https://api.github.com/users/kkdawkins/events{/privacy}","received_events_url":"https://api.github.com/users/kkdawkins/received_events","type":"User","site_admin":false},"body":"This applies to all functions here.","created_at":"2019-12-21T20:06:09Z","updated_at":"2019-12-21T20:10:56Z","html_url":"https://github.com/Azure/iotedge/pull/2158#discussion_r360665625","pull_request_url":"https://api.github.com/repos/Azure/iotedge/pulls/2158","author_association":"CONTRIBUTOR","_links":{"self":{"href":"https://api.github.com/repos/Azure/iotedge/pulls/comments/360665625"},"html":{"href":"https://github.com/Azure/iotedge/pull/2158#discussion_r360665625"},"pull_request":{"href":"https://api.github.com/repos/Azure/iotedge/pulls/2158"}},"in_reply_to_id":360665591},"pull_request":{"url":"https://api.github.com/repos/Azure/iotedge/pulls/2158","id":354701878,"node_id":"MDExOlB1bGxSZXF1ZXN0MzU0NzAxODc4","html_url":"https://github.com/Azure/iotedge/pull/2158","diff_url":"https://github.com/Azure/iotedge/pull/2158.diff","patch_url":"https://github.com/Azure/iotedge/pull/2158.patch","issue_url":"https://api.github.com/repos/Azure/iotedge/issues/2158","number":2158,"state":"open","locked":false,"title":"Add and filter by ms_telemetry tag in edgeAgent","user":{"login":"lfitchett","id":13950901,"node_id":"MDQ6VXNlcjEzOTUwOTAx","avatar_url":"https://avatars0.githubusercontent.com/u/13950901?v=4","gravatar_id":"","url":"https://api.github.com/users/lfitchett","html_url":"https://github.com/lfitchett","followers_url":"https://api.github.com/users/lfitchett/followers","following_url":"https://api.github.com/users/lfitchett/following{/other_user}","gists_url":"https://api.github.com/users/lfitchett/gists{/gist_id}","starred_url":"https://api.github.com/users/lfitchett/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lfitchett/subscriptions","organizations_url":"https://api.github.com/users/lfitchett/orgs","repos_url":"https://api.github.com/users/lfitchett/repos","events_url":"https://api.github.com/users/lfitchett/events{/privacy}","received_events_url":"https://api.github.com/users/lfitchett/received_events","type":"User","site_admin":false},"body":"This adds ms_telemetry=true to the edgeAgent metrics. This tag serves two purposes: \r\n* It tells edgeAgent which metrics to upload\r\n* It acts as documentation for customers.\r\n    * WIll need to contact legal team to determine if this is sufficient for GDPR.\r\n\r\nThis also removes tags from metrics to reduce bandwidth. Device Id and Hub Name are already known in iothub, so damon's code adds them back in. \r\n\r\nIt also changes tags from a string to a dictionary","created_at":"2019-12-18T16:27:23Z","updated_at":"2019-12-21T20:10:56Z","closed_at":null,"merged_at":null,"merge_commit_sha":"3e09a97053a113b12062eef434760ce24d9ffd49","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[],"milestone":null,"commits_url":"https://api.github.com/repos/Azure/iotedge/pulls/2158/commits","review_comments_url":"https://api.github.com/repos/Azure/iotedge/pulls/2158/comments","review_comment_url":"https://api.github.com/repos/Azure/iotedge/pulls/comments{/number}","comments_url":"https://api.github.com/repos/Azure/iotedge/issues/2158/comments","statuses_url":"https://api.github.com/repos/Azure/iotedge/statuses/0c007829932c45155334bd3804369b49580d6154","head":{"label":"lfitchett:ms_telemetry","ref":"ms_telemetry","sha":"0c007829932c45155334bd3804369b49580d6154","user":{"login":"lfitchett","id":13950901,"node_id":"MDQ6VXNlcjEzOTUwOTAx","avatar_url":"https://avatars0.githubusercontent.com/u/13950901?v=4","gravatar_id":"","url":"https://api.github.com/users/lfitchett","html_url":"https://github.com/lfitchett","followers_url":"https://api.github.com/users/lfitchett/followers","following_url":"https://api.github.com/users/lfitchett/following{/other_user}","gists_url":"https://api.github.com/users/lfitchett/gists{/gist_id}","starred_url":"https://api.github.com/users/lfitchett/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lfitchett/subscriptions","organizations_url":"https://api.github.com/users/lfitchett/orgs","repos_url":"https://api.github.com/users/lfitchett/repos","events_url":"https://api.github.com/users/lfitchett/events{/privacy}","received_events_url":"https://api.github.com/users/lfitchett/received_events","type":"User","site_admin":false},"repo":{"id":209119816,"node_id":"MDEwOlJlcG9zaXRvcnkyMDkxMTk4MTY=","name":"iotedge","full_name":"lfitchett/iotedge","private":false,"owner":{"login":"lfitchett","id":13950901,"node_id":"MDQ6VXNlcjEzOTUwOTAx","avatar_url":"https://avatars0.githubusercontent.com/u/13950901?v=4","gravatar_id":"","url":"https://api.github.com/users/lfitchett","html_url":"https://github.com/lfitchett","followers_url":"https://api.github.com/users/lfitchett/followers","following_url":"https://api.github.com/users/lfitchett/following{/other_user}","gists_url":"https://api.github.com/users/lfitchett/gists{/gist_id}","starred_url":"https://api.github.com/users/lfitchett/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lfitchett/subscriptions","organizations_url":"https://api.github.com/users/lfitchett/orgs","repos_url":"https://api.github.com/users/lfitchett/repos","events_url":"https://api.github.com/users/lfitchett/events{/privacy}","received_events_url":"https://api.github.com/users/lfitchett/received_events","type":"User","site_admin":false},"html_url":"https://github.com/lfitchett/iotedge","description":"The IoT Edge OSS project","fork":true,"url":"https://api.github.com/repos/lfitchett/iotedge","forks_url":"https://api.github.com/repos/lfitchett/iotedge/forks","keys_url":"https://api.github.com/repos/lfitchett/iotedge/keys{/key_id}","collaborators_url":"https://api.github.com/repos/lfitchett/iotedge/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/lfitchett/iotedge/teams","hooks_url":"https://api.github.com/repos/lfitchett/iotedge/hooks","issue_events_url":"https://api.github.com/repos/lfitchett/iotedge/issues/events{/number}","events_url":"https://api.github.com/repos/lfitchett/iotedge/events","assignees_url":"https://api.github.com/repos/lfitchett/iotedge/assignees{/user}","branches_url":"https://api.github.com/repos/lfitchett/iotedge/branches{/branch}","tags_url":"https://api.github.com/repos/lfitchett/iotedge/tags","blobs_url":"https://api.github.com/repos/lfitchett/iotedge/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/lfitchett/iotedge/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/lfitchett/iotedge/git/refs{/sha}","trees_url":"https://api.github.com/repos/lfitchett/iotedge/git/trees{/sha}","statuses_url":"https://api.github.com/repos/lfitchett/iotedge/statuses/{sha}","languages_url":"https://api.github.com/repos/lfitchett/iotedge/languages","stargazers_url":"https://api.github.com/repos/lfitchett/iotedge/stargazers","contributors_url":"https://api.github.com/repos/lfitchett/iotedge/contributors","subscribers_url":"https://api.github.com/repos/lfitchett/iotedge/subscribers","subscription_url":"https://api.github.com/repos/lfitchett/iotedge/subscription","commits_url":"https://api.github.com/repos/lfitchett/iotedge/commits{/sha}","git_commits_url":"https://api.github.com/repos/lfitchett/iotedge/git/commits{/sha}","comments_url":"https://api.github.com/repos/lfitchett/iotedge/comments{/number}","issue_comment_url":"https://api.github.com/repos/lfitchett/iotedge/issues/comments{/number}","contents_url":"https://api.github.com/repos/lfitchett/iotedge/contents/{+path}","compare_url":"https://api.github.com/repos/lfitchett/iotedge/compare/{base}...{head}","merges_url":"https://api.github.com/repos/lfitchett/iotedge/merges","archive_url":"https://api.github.com/repos/lfitchett/iotedge/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/lfitchett/iotedge/downloads","issues_url":"https://api.github.com/repos/lfitchett/iotedge/issues{/number}","pulls_url":"https://api.github.com/repos/lfitchett/iotedge/pulls{/number}","milestones_url":"https://api.github.com/repos/lfitchett/iotedge/milestones{/number}","notifications_url":"https://api.github.com/repos/lfitchett/iotedge/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/lfitchett/iotedge/labels{/name}","releases_url":"https://api.github.com/repos/lfitchett/iotedge/releases{/id}","deployments_url":"https://api.github.com/repos/lfitchett/iotedge/deployments","created_at":"2019-09-17T17:44:22Z","updated_at":"2019-12-20T19:57:23Z","pushed_at":"2019-12-21T01:20:53Z","git_url":"git://github.com/lfitchett/iotedge.git","ssh_url":"git@github.com:lfitchett/iotedge.git","clone_url":"https://github.com/lfitchett/iotedge.git","svn_url":"https://github.com/lfitchett/iotedge","homepage":"","size":21162,"stargazers_count":0,"watchers_count":0,"language":"C#","has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"disabled":false,"open_issues_count":0,"license":{"key":"mit","name":"MIT License","spdx_id":"MIT","url":"https://api.github.com/licenses/mit","node_id":"MDc6TGljZW5zZTEz"},"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"Azure:master","ref":"master","sha":"d7a4fd0bce9dd9fdaa86ee5bd3fb7cbbee54c9c3","user":{"login":"Azure","id":6844498,"node_id":"MDEyOk9yZ2FuaXphdGlvbjY4NDQ0OTg=","avatar_url":"https://avatars0.githubusercontent.com/u/6844498?v=4","gravatar_id":"","url":"https://api.github.com/users/Azure","html_url":"https://github.com/Azure","followers_url":"https://api.github.com/users/Azure/followers","following_url":"https://api.github.com/users/Azure/following{/other_user}","gists_url":"https://api.github.com/users/Azure/gists{/gist_id}","starred_url":"https://api.github.com/users/Azure/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Azure/subscriptions","organizations_url":"https://api.github.com/users/Azure/orgs","repos_url":"https://api.github.com/users/Azure/repos","events_url":"https://api.github.com/users/Azure/events{/privacy}","received_events_url":"https://api.github.com/users/Azure/received_events","type":"Organization","site_admin":false},"repo":{"id":138646782,"node_id":"MDEwOlJlcG9zaXRvcnkxMzg2NDY3ODI=","name":"iotedge","full_name":"Azure/iotedge","private":false,"owner":{"login":"Azure","id":6844498,"node_id":"MDEyOk9yZ2FuaXphdGlvbjY4NDQ0OTg=","avatar_url":"https://avatars0.githubusercontent.com/u/6844498?v=4","gravatar_id":"","url":"https://api.github.com/users/Azure","html_url":"https://github.com/Azure","followers_url":"https://api.github.com/users/Azure/followers","following_url":"https://api.github.com/users/Azure/following{/other_user}","gists_url":"https://api.github.com/users/Azure/gists{/gist_id}","starred_url":"https://api.github.com/users/Azure/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Azure/subscriptions","organizations_url":"https://api.github.com/users/Azure/orgs","repos_url":"https://api.github.com/users/Azure/repos","events_url":"https://api.github.com/users/Azure/events{/privacy}","received_events_url":"https://api.github.com/users/Azure/received_events","type":"Organization","site_admin":false},"html_url":"https://github.com/Azure/iotedge","description":"The IoT Edge OSS project","fork":false,"url":"https://api.github.com/repos/Azure/iotedge","forks_url":"https://api.github.com/repos/Azure/iotedge/forks","keys_url":"https://api.github.com/repos/Azure/iotedge/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Azure/iotedge/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Azure/iotedge/teams","hooks_url":"https://api.github.com/repos/Azure/iotedge/hooks","issue_events_url":"https://api.github.com/repos/Azure/iotedge/issues/events{/number}","events_url":"https://api.github.com/repos/Azure/iotedge/events","assignees_url":"https://api.github.com/repos/Azure/iotedge/assignees{/user}","branches_url":"https://api.github.com/repos/Azure/iotedge/branches{/branch}","tags_url":"https://api.github.com/repos/Azure/iotedge/tags","blobs_url":"https://api.github.com/repos/Azure/iotedge/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Azure/iotedge/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Azure/iotedge/git/refs{/sha}","trees_url":"https://api.github.com/repos/Azure/iotedge/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Azure/iotedge/statuses/{sha}","languages_url":"https://api.github.com/repos/Azure/iotedge/languages","stargazers_url":"https://api.github.com/repos/Azure/iotedge/stargazers","contributors_url":"https://api.github.com/repos/Azure/iotedge/contributors","subscribers_url":"https://api.github.com/repos/Azure/iotedge/subscribers","subscription_url":"https://api.github.com/repos/Azure/iotedge/subscription","commits_url":"https://api.github.com/repos/Azure/iotedge/commits{/sha}","git_commits_url":"https://api.github.com/repos/Azure/iotedge/git/commits{/sha}","comments_url":"https://api.github.com/repos/Azure/iotedge/comments{/number}","issue_comment_url":"https://api.github.com/repos/Azure/iotedge/issues/comments{/number}","contents_url":"https://api.github.com/repos/Azure/iotedge/contents/{+path}","compare_url":"https://api.github.com/repos/Azure/iotedge/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Azure/iotedge/merges","archive_url":"https://api.github.com/repos/Azure/iotedge/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Azure/iotedge/downloads","issues_url":"https://api.github.com/repos/Azure/iotedge/issues{/number}","pulls_url":"https://api.github.com/repos/Azure/iotedge/pulls{/number}","milestones_url":"https://api.github.com/repos/Azure/iotedge/milestones{/number}","notifications_url":"https://api.github.com/repos/Azure/iotedge/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Azure/iotedge/labels{/name}","releases_url":"https://api.github.com/repos/Azure/iotedge/releases{/id}","deployments_url":"https://api.github.com/repos/Azure/iotedge/deployments","created_at":"2018-06-25T20:31:33Z","updated_at":"2019-12-21T13:40:41Z","pushed_at":"2019-12-21T07:14:21Z","git_url":"git://github.com/Azure/iotedge.git","ssh_url":"git@github.com:Azure/iotedge.git","clone_url":"https://github.com/Azure/iotedge.git","svn_url":"https://github.com/Azure/iotedge","homepage":"","size":21153,"stargazers_count":942,"watchers_count":942,"language":"C#","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":208,"mirror_url":null,"archived":false,"disabled":false,"open_issues_count":99,"license":{"key":"mit","name":"MIT License","spdx_id":"MIT","url":"https://api.github.com/licenses/mit","node_id":"MDc6TGljZW5zZTEz"},"forks":208,"open_issues":99,"watchers":942,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/Azure/iotedge/pulls/2158"},"html":{"href":"https://github.com/Azure/iotedge/pull/2158"},"issue":{"href":"https://api.github.com/repos/Azure/iotedge/issues/2158"},"comments":{"href":"https://api.github.com/repos/Azure/iotedge/issues/2158/comments"},"review_comments":{"href":"https://api.github.com/repos/Azure/iotedge/pulls/2158/comments"},"review_comment":{"href":"https://api.github.com/repos/Azure/iotedge/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/Azure/iotedge/pulls/2158/commits"},"statuses":{"href":"https://api.github.com/repos/Azure/iotedge/statuses/0c007829932c45155334bd3804369b49580d6154"}},"author_association":"CONTRIBUTOR"}}
{"actor":{"display_login":"kkdawkins"}}