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 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
relies on my WIP cadence fork, see: 56quarters/cadence#41 also move ua parsing into utils, adding in the setup of metrics' values Closes #1054
- Loading branch information
Showing
5 changed files
with
72 additions
and
34 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
use woothee::parser::{Parser, WootheeResult}; | ||
|
||
// List of valid user-agent attributes to keep, anything not in this | ||
// list is considered 'Other'. We log the user-agent on connect always | ||
// to retain the full string, but for DD more tags are expensive so we | ||
// limit to these. | ||
const VALID_UA_BROWSER: &[&str] = &["Chrome", "Firefox", "Safari", "Opera"]; | ||
|
||
// See dataset.rs in https://github.com/woothee/woothee-rust for the | ||
// full list (WootheeResult's 'os' field may fall back to its 'name' | ||
// field). Windows has many values and we only care that its Windows | ||
const VALID_UA_OS: &[&str] = &["Firefox OS", "Linux", "Mac OSX"]; | ||
|
||
pub fn parse_user_agent<'a>( | ||
parser: &'a Parser, | ||
agent: &str, | ||
) -> (WootheeResult<'a>, &'a str, &'a str) { | ||
let wresult = parser.parse(&agent).unwrap_or_else(|| WootheeResult { | ||
name: "", | ||
category: "", | ||
os: "", | ||
os_version: "".to_string(), | ||
browser_type: "", | ||
version: "".to_string(), | ||
vendor: "", | ||
}); | ||
|
||
// Determine a base os/browser for metrics' tags | ||
let metrics_os = if wresult.os.starts_with("Windows") { | ||
"Windows" | ||
} else if VALID_UA_OS.contains(&wresult.os) { | ||
wresult.os | ||
} else { | ||
"Other" | ||
}; | ||
let metrics_browser = if VALID_UA_BROWSER.contains(&wresult.name) { | ||
wresult.name | ||
} else { | ||
"Other" | ||
}; | ||
(wresult, metrics_os, metrics_browser) | ||
} |