This repository has been archived by the owner on Jul 13, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: normalize user-agent for datadog and parse for raw logging
The user-agent string is now parsed and normalized to fewer values for DataDog. The raw parsed version is also included in all websocket.py logging statements for easier filtering in our logging. Existing raw user_agent string will remain so that existing log parsing systems using it can function as normal. Closes #487
- Loading branch information
Showing
7 changed files
with
127 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import unittest | ||
|
||
from nose.tools import eq_ | ||
|
||
|
||
class TestUserAgentParser(unittest.TestCase): | ||
def _makeFUT(self, *args): | ||
from autopush.utils import parse_user_agent | ||
return parse_user_agent(*args) | ||
|
||
def test_linux_extraction(self): | ||
dd, raw = self._makeFUT('Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1.2) Gecko/20090807 Mandriva Linux/1.9.1.2-1.1mud2009.1 (2009.1) Firefox/3.5.2 FirePHP/0.3,gzip(gfe),gzip(gfe)') # NOQA | ||
eq_(dd["ua_os_family"], "Linux") | ||
eq_(raw["ua_os_family"], "Mandriva") | ||
|
||
def test_windows_extraction(self): | ||
dd, raw = self._makeFUT('Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2.3) Gecko/20100401 Firefox/3.6.3 (.NET CLR 3.5.30729)') # NOQA | ||
eq_(dd["ua_os_family"], "Windows") | ||
eq_(raw["ua_os_family"], "Windows 7") | ||
|
||
def test_valid_os(self): | ||
dd, raw = self._makeFUT('Mozilla/5.0 (Macintosh; Intel Mac OS X 10.5; rv:2.1.1) Gecko/ Firefox/5.0.1') # NOQA | ||
eq_(dd["ua_os_family"], "Mac OS X") | ||
eq_(raw["ua_os_family"], "Mac OS X") | ||
|
||
def test_other_os_and_browser(self): | ||
dd, raw = self._makeFUT('BlackBerry9000/4.6.0.167 Profile/MIDP-2.0 Configuration/CLDC-1.1 VendorID/102') # NOQA | ||
eq_(dd["ua_os_family"], "Other") | ||
eq_(raw["ua_os_family"], "BlackBerry OS") | ||
eq_(dd["ua_browser_family"], "Other") | ||
eq_(raw["ua_browser_family"], "BlackBerry") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters