{"action":"created","comment":{"url":"https://api.github.com/repos/edx/edx-analytics-pipeline/pulls/comments/50416807","id":50416807,"diff_hunk":"@@ -104,8 +124,29 @@ def reducer(self, key, values):\n \n         # This ip address might not provide a country name.\n         try:\n-            country = self.geoip.country_name_by_addr(last_ip)\n-            code = self.geoip.country_code_by_addr(last_ip)\n+            ipaddr = ipaddress.ip_address(unicode(last_ip))\n+\n+            # Raise an exception if 'last_ip' cannot be converted\n+            # into a valid IPv4 or IPv6 address\n+            if ipaddr is None: raise ValueError()\n+\n+            # Convert IPv4 address to its mapped IPv6 version,\n+            # so that we can use a single IPv6 database for both\n+            # IPv4 and IPv6 addresses.\n+            if ipaddr.version == 4:\n+                last_ip = '::ffff:' + last_ip\n+\n+            # The IP database doesn't provide geo data for private address\n+            # like '192.168.0.1'. However, for an open edx deployment\n+            # inside a institution, the private address may exist in\n+            # tracking logs. It is more reasonable to use a specific\n+            # country name/code for such addresses rather than 'UNKNOWN'.\n+            if ipaddr.is_private:","path":"edx/analytics/tasks/user_location.py","position":70,"original_position":70,"commit_id":"573b7a4e14bd7ea94a11970873e2178408098d3d","original_commit_id":"573b7a4e14bd7ea94a11970873e2178408098d3d","user":{"login":"louyihua","id":1275238,"avatar_url":"https://avatars.githubusercontent.com/u/1275238?v=3","gravatar_id":"","url":"https://api.github.com/users/louyihua","html_url":"https://github.com/louyihua","followers_url":"https://api.github.com/users/louyihua/followers","following_url":"https://api.github.com/users/louyihua/following{/other_user}","gists_url":"https://api.github.com/users/louyihua/gists{/gist_id}","starred_url":"https://api.github.com/users/louyihua/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/louyihua/subscriptions","organizations_url":"https://api.github.com/users/louyihua/orgs","repos_url":"https://api.github.com/users/louyihua/repos","events_url":"https://api.github.com/users/louyihua/events{/privacy}","received_events_url":"https://api.github.com/users/louyihua/received_events","type":"User","site_admin":false},"body":"This is required as we need to use single IPv6 database to serve both IPv4 and IPv6 addresses.","created_at":"2016-01-21T15:41:41Z","updated_at":"2016-01-21T15:41:41Z","html_url":"https://github.com/edx/edx-analytics-pipeline/pull/177#discussion_r50416807","pull_request_url":"https://api.github.com/repos/edx/edx-analytics-pipeline/pulls/177","_links":{"self":{"href":"https://api.github.com/repos/edx/edx-analytics-pipeline/pulls/comments/50416807"},"html":{"href":"https://github.com/edx/edx-analytics-pipeline/pull/177#discussion_r50416807"},"pull_request":{"href":"https://api.github.com/repos/edx/edx-analytics-pipeline/pulls/177"}}},"pull_request":{"url":"https://api.github.com/repos/edx/edx-analytics-pipeline/pulls/177","id":51052277,"html_url":"https://github.com/edx/edx-analytics-pipeline/pull/177","diff_url":"https://github.com/edx/edx-analytics-pipeline/pull/177.diff","patch_url":"https://github.com/edx/edx-analytics-pipeline/pull/177.patch","issue_url":"https://api.github.com/repos/edx/edx-analytics-pipeline/issues/177","number":177,"state":"open","locked":false,"title":"Add IPv6 address support","user":{"login":"louyihua","id":1275238,"avatar_url":"https://avatars.githubusercontent.com/u/1275238?v=3","gravatar_id":"","url":"https://api.github.com/users/louyihua","html_url":"https://github.com/louyihua","followers_url":"https://api.github.com/users/louyihua/followers","following_url":"https://api.github.com/users/louyihua/following{/other_user}","gists_url":"https://api.github.com/users/louyihua/gists{/gist_id}","starred_url":"https://api.github.com/users/louyihua/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/louyihua/subscriptions","organizations_url":"https://api.github.com/users/louyihua/orgs","repos_url":"https://api.github.com/users/louyihua/repos","events_url":"https://api.github.com/users/louyihua/events{/privacy}","received_events_url":"https://api.github.com/users/louyihua/received_events","type":"User","site_admin":false},"body":"Currently, we assume that the addresses in tracking log are always IPv4 or IPv6 in pipeline. However, in a dual-stack configuration, both IPv4 and IPv6 addresses may occur in the tracking log.\r\nThis PR adds support for both IPv4 and IPv6 address by using the \"IPv4-Mapped IPv6 Address\" feature. An IPv4 address is always converted into its equivalent IPv6 version, so that we can just use the single IPv6 database for processing.\r\nThis PR also adds support for specifying country code & name for private addresses (such as \"192.168.0.0/16\", \"172.16.0.0/12\" and \"10.0.0.0/8\").","created_at":"2015-11-18T07:49:32Z","updated_at":"2016-01-21T15:41:41Z","closed_at":null,"merged_at":null,"merge_commit_sha":"61c7686f9215286b6f93f54a4f8c22b6b7e61340","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/edx/edx-analytics-pipeline/pulls/177/commits","review_comments_url":"https://api.github.com/repos/edx/edx-analytics-pipeline/pulls/177/comments","review_comment_url":"https://api.github.com/repos/edx/edx-analytics-pipeline/pulls/comments{/number}","comments_url":"https://api.github.com/repos/edx/edx-analytics-pipeline/issues/177/comments","statuses_url":"https://api.github.com/repos/edx/edx-analytics-pipeline/statuses/573b7a4e14bd7ea94a11970873e2178408098d3d","head":{"label":"louyihua:geoipv6","ref":"geoipv6","sha":"573b7a4e14bd7ea94a11970873e2178408098d3d","user":{"login":"louyihua","id":1275238,"avatar_url":"https://avatars.githubusercontent.com/u/1275238?v=3","gravatar_id":"","url":"https://api.github.com/users/louyihua","html_url":"https://github.com/louyihua","followers_url":"https://api.github.com/users/louyihua/followers","following_url":"https://api.github.com/users/louyihua/following{/other_user}","gists_url":"https://api.github.com/users/louyihua/gists{/gist_id}","starred_url":"https://api.github.com/users/louyihua/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/louyihua/subscriptions","organizations_url":"https://api.github.com/users/louyihua/orgs","repos_url":"https://api.github.com/users/louyihua/repos","events_url":"https://api.github.com/users/louyihua/events{/privacy}","received_events_url":"https://api.github.com/users/louyihua/received_events","type":"User","site_admin":false},"repo":{"id":44817090,"name":"edx-analytics-pipeline","full_name":"louyihua/edx-analytics-pipeline","owner":{"login":"louyihua","id":1275238,"avatar_url":"https://avatars.githubusercontent.com/u/1275238?v=3","gravatar_id":"","url":"https://api.github.com/users/louyihua","html_url":"https://github.com/louyihua","followers_url":"https://api.github.com/users/louyihua/followers","following_url":"https://api.github.com/users/louyihua/following{/other_user}","gists_url":"https://api.github.com/users/louyihua/gists{/gist_id}","starred_url":"https://api.github.com/users/louyihua/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/louyihua/subscriptions","organizations_url":"https://api.github.com/users/louyihua/orgs","repos_url":"https://api.github.com/users/louyihua/repos","events_url":"https://api.github.com/users/louyihua/events{/privacy}","received_events_url":"https://api.github.com/users/louyihua/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/louyihua/edx-analytics-pipeline","description":"","fork":true,"url":"https://api.github.com/repos/louyihua/edx-analytics-pipeline","forks_url":"https://api.github.com/repos/louyihua/edx-analytics-pipeline/forks","keys_url":"https://api.github.com/repos/louyihua/edx-analytics-pipeline/keys{/key_id}","collaborators_url":"https://api.github.com/repos/louyihua/edx-analytics-pipeline/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/louyihua/edx-analytics-pipeline/teams","hooks_url":"https://api.github.com/repos/louyihua/edx-analytics-pipeline/hooks","issue_events_url":"https://api.github.com/repos/louyihua/edx-analytics-pipeline/issues/events{/number}","events_url":"https://api.github.com/repos/louyihua/edx-analytics-pipeline/events","assignees_url":"https://api.github.com/repos/louyihua/edx-analytics-pipeline/assignees{/user}","branches_url":"https://api.github.com/repos/louyihua/edx-analytics-pipeline/branches{/branch}","tags_url":"https://api.github.com/repos/louyihua/edx-analytics-pipeline/tags","blobs_url":"https://api.github.com/repos/louyihua/edx-analytics-pipeline/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/louyihua/edx-analytics-pipeline/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/louyihua/edx-analytics-pipeline/git/refs{/sha}","trees_url":"https://api.github.com/repos/louyihua/edx-analytics-pipeline/git/trees{/sha}","statuses_url":"https://api.github.com/repos/louyihua/edx-analytics-pipeline/statuses/{sha}","languages_url":"https://api.github.com/repos/louyihua/edx-analytics-pipeline/languages","stargazers_url":"https://api.github.com/repos/louyihua/edx-analytics-pipeline/stargazers","contributors_url":"https://api.github.com/repos/louyihua/edx-analytics-pipeline/contributors","subscribers_url":"https://api.github.com/repos/louyihua/edx-analytics-pipeline/subscribers","subscription_url":"https://api.github.com/repos/louyihua/edx-analytics-pipeline/subscription","commits_url":"https://api.github.com/repos/louyihua/edx-analytics-pipeline/commits{/sha}","git_commits_url":"https://api.github.com/repos/louyihua/edx-analytics-pipeline/git/commits{/sha}","comments_url":"https://api.github.com/repos/louyihua/edx-analytics-pipeline/comments{/number}","issue_comment_url":"https://api.github.com/repos/louyihua/edx-analytics-pipeline/issues/comments{/number}","contents_url":"https://api.github.com/repos/louyihua/edx-analytics-pipeline/contents/{+path}","compare_url":"https://api.github.com/repos/louyihua/edx-analytics-pipeline/compare/{base}...{head}","merges_url":"https://api.github.com/repos/louyihua/edx-analytics-pipeline/merges","archive_url":"https://api.github.com/repos/louyihua/edx-analytics-pipeline/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/louyihua/edx-analytics-pipeline/downloads","issues_url":"https://api.github.com/repos/louyihua/edx-analytics-pipeline/issues{/number}","pulls_url":"https://api.github.com/repos/louyihua/edx-analytics-pipeline/pulls{/number}","milestones_url":"https://api.github.com/repos/louyihua/edx-analytics-pipeline/milestones{/number}","notifications_url":"https://api.github.com/repos/louyihua/edx-analytics-pipeline/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/louyihua/edx-analytics-pipeline/labels{/name}","releases_url":"https://api.github.com/repos/louyihua/edx-analytics-pipeline/releases{/id}","created_at":"2015-10-23T14:10:01Z","updated_at":"2015-10-23T14:10:03Z","pushed_at":"2015-11-19T06:28:19Z","git_url":"git://github.com/louyihua/edx-analytics-pipeline.git","ssh_url":"git@github.com:louyihua/edx-analytics-pipeline.git","clone_url":"https://github.com/louyihua/edx-analytics-pipeline.git","svn_url":"https://github.com/louyihua/edx-analytics-pipeline","homepage":null,"size":2147,"stargazers_count":0,"watchers_count":0,"language":"Python","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"edx:master","ref":"master","sha":"5d5fa503812e8e08e9dfc93c97dca02c7599c569","user":{"login":"edx","id":3179841,"avatar_url":"https://avatars.githubusercontent.com/u/3179841?v=3","gravatar_id":"","url":"https://api.github.com/users/edx","html_url":"https://github.com/edx","followers_url":"https://api.github.com/users/edx/followers","following_url":"https://api.github.com/users/edx/following{/other_user}","gists_url":"https://api.github.com/users/edx/gists{/gist_id}","starred_url":"https://api.github.com/users/edx/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/edx/subscriptions","organizations_url":"https://api.github.com/users/edx/orgs","repos_url":"https://api.github.com/users/edx/repos","events_url":"https://api.github.com/users/edx/events{/privacy}","received_events_url":"https://api.github.com/users/edx/received_events","type":"Organization","site_admin":false},"repo":{"id":22929261,"name":"edx-analytics-pipeline","full_name":"edx/edx-analytics-pipeline","owner":{"login":"edx","id":3179841,"avatar_url":"https://avatars.githubusercontent.com/u/3179841?v=3","gravatar_id":"","url":"https://api.github.com/users/edx","html_url":"https://github.com/edx","followers_url":"https://api.github.com/users/edx/followers","following_url":"https://api.github.com/users/edx/following{/other_user}","gists_url":"https://api.github.com/users/edx/gists{/gist_id}","starred_url":"https://api.github.com/users/edx/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/edx/subscriptions","organizations_url":"https://api.github.com/users/edx/orgs","repos_url":"https://api.github.com/users/edx/repos","events_url":"https://api.github.com/users/edx/events{/privacy}","received_events_url":"https://api.github.com/users/edx/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/edx/edx-analytics-pipeline","description":"","fork":false,"url":"https://api.github.com/repos/edx/edx-analytics-pipeline","forks_url":"https://api.github.com/repos/edx/edx-analytics-pipeline/forks","keys_url":"https://api.github.com/repos/edx/edx-analytics-pipeline/keys{/key_id}","collaborators_url":"https://api.github.com/repos/edx/edx-analytics-pipeline/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/edx/edx-analytics-pipeline/teams","hooks_url":"https://api.github.com/repos/edx/edx-analytics-pipeline/hooks","issue_events_url":"https://api.github.com/repos/edx/edx-analytics-pipeline/issues/events{/number}","events_url":"https://api.github.com/repos/edx/edx-analytics-pipeline/events","assignees_url":"https://api.github.com/repos/edx/edx-analytics-pipeline/assignees{/user}","branches_url":"https://api.github.com/repos/edx/edx-analytics-pipeline/branches{/branch}","tags_url":"https://api.github.com/repos/edx/edx-analytics-pipeline/tags","blobs_url":"https://api.github.com/repos/edx/edx-analytics-pipeline/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/edx/edx-analytics-pipeline/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/edx/edx-analytics-pipeline/git/refs{/sha}","trees_url":"https://api.github.com/repos/edx/edx-analytics-pipeline/git/trees{/sha}","statuses_url":"https://api.github.com/repos/edx/edx-analytics-pipeline/statuses/{sha}","languages_url":"https://api.github.com/repos/edx/edx-analytics-pipeline/languages","stargazers_url":"https://api.github.com/repos/edx/edx-analytics-pipeline/stargazers","contributors_url":"https://api.github.com/repos/edx/edx-analytics-pipeline/contributors","subscribers_url":"https://api.github.com/repos/edx/edx-analytics-pipeline/subscribers","subscription_url":"https://api.github.com/repos/edx/edx-analytics-pipeline/subscription","commits_url":"https://api.github.com/repos/edx/edx-analytics-pipeline/commits{/sha}","git_commits_url":"https://api.github.com/repos/edx/edx-analytics-pipeline/git/commits{/sha}","comments_url":"https://api.github.com/repos/edx/edx-analytics-pipeline/comments{/number}","issue_comment_url":"https://api.github.com/repos/edx/edx-analytics-pipeline/issues/comments{/number}","contents_url":"https://api.github.com/repos/edx/edx-analytics-pipeline/contents/{+path}","compare_url":"https://api.github.com/repos/edx/edx-analytics-pipeline/compare/{base}...{head}","merges_url":"https://api.github.com/repos/edx/edx-analytics-pipeline/merges","archive_url":"https://api.github.com/repos/edx/edx-analytics-pipeline/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/edx/edx-analytics-pipeline/downloads","issues_url":"https://api.github.com/repos/edx/edx-analytics-pipeline/issues{/number}","pulls_url":"https://api.github.com/repos/edx/edx-analytics-pipeline/pulls{/number}","milestones_url":"https://api.github.com/repos/edx/edx-analytics-pipeline/milestones{/number}","notifications_url":"https://api.github.com/repos/edx/edx-analytics-pipeline/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/edx/edx-analytics-pipeline/labels{/name}","releases_url":"https://api.github.com/repos/edx/edx-analytics-pipeline/releases{/id}","created_at":"2014-08-13T19:57:17Z","updated_at":"2016-01-19T01:42:22Z","pushed_at":"2016-01-21T15:22:22Z","git_url":"git://github.com/edx/edx-analytics-pipeline.git","ssh_url":"git@github.com:edx/edx-analytics-pipeline.git","clone_url":"https://github.com/edx/edx-analytics-pipeline.git","svn_url":"https://github.com/edx/edx-analytics-pipeline","homepage":null,"size":2816,"stargazers_count":18,"watchers_count":18,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":32,"mirror_url":null,"open_issues_count":11,"forks":32,"open_issues":11,"watchers":18,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/edx/edx-analytics-pipeline/pulls/177"},"html":{"href":"https://github.com/edx/edx-analytics-pipeline/pull/177"},"issue":{"href":"https://api.github.com/repos/edx/edx-analytics-pipeline/issues/177"},"comments":{"href":"https://api.github.com/repos/edx/edx-analytics-pipeline/issues/177/comments"},"review_comments":{"href":"https://api.github.com/repos/edx/edx-analytics-pipeline/pulls/177/comments"},"review_comment":{"href":"https://api.github.com/repos/edx/edx-analytics-pipeline/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/edx/edx-analytics-pipeline/pulls/177/commits"},"statuses":{"href":"https://api.github.com/repos/edx/edx-analytics-pipeline/statuses/573b7a4e14bd7ea94a11970873e2178408098d3d"}}}}