Skip to content

Commit e2b6bd7

Browse files
bonigarciadiemol
andauthored
[rust] Tracking Selenium Manager usage through Plausible (#11211) (#13173)
* [rust] Send stats to Plausible (#11211) * [rust] Read selenium version from clap cargo feature * [rust] Set language binding in test * [rust] Include assertion about stats error message * [rust] Use selenium domain (selenium.dev) as plausible stats target * [rust] Make asynchronous request to plausible * [rust] Include argument --avoid-stats to not send statistics to plausible.io * [rust] Include request timeout and improve error handling * [rust] Spawn new thread for calling to stats function * [rust] Use message channel for passing errors when sending stats * [rust] Update checksum un lock file * Update rust/src/stats.rs * [rust] Check if SM is offline before sending the stats * [rust] Send custom properties to plausible in lowercase --------- Co-authored-by: Diego Molina <[email protected]>
1 parent 5b1b449 commit e2b6bd7

File tree

14 files changed

+280
-5
lines changed

14 files changed

+280
-5
lines changed

rust/Cargo.Bazel.lock

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"checksum": "0b0c238a314773ea2af41d5e13962f5a27ffdf2974cab7953267ab4b6b99c34f",
2+
"checksum": "3468f2b2abc234888e072c953d9cafe64affe1c53711fb6bf961f97743525229",
33
"crates": {
44
"addr2line 0.19.0": {
55
"name": "addr2line",
@@ -1610,6 +1610,7 @@
16101610
],
16111611
"crate_features": {
16121612
"common": [
1613+
"cargo",
16131614
"color",
16141615
"default",
16151616
"derive",
@@ -1671,6 +1672,7 @@
16711672
],
16721673
"crate_features": {
16731674
"common": [
1675+
"cargo",
16741676
"color",
16751677
"error-context",
16761678
"help",

rust/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Selenium Manager is a CLI tool that automatically manages the browser/driver inf
1212
"""
1313

1414
[dependencies]
15-
clap = { version = "4.4.8", features = ["derive"] }
15+
clap = { version = "4.4.8", features = ["derive", "cargo"] }
1616
log = "0.4.20"
1717
env_logger = "0.10.1"
1818
regex = "1.10.2"

rust/src/chrome.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ use serde::{Deserialize, Serialize};
3636
use std::collections::HashMap;
3737
use std::option::Option;
3838
use std::path::PathBuf;
39+
use std::sync::mpsc;
40+
use std::sync::mpsc::{Receiver, Sender};
3941

4042
pub const CHROME_NAME: &str = "chrome";
4143
pub const CHROMEDRIVER_NAME: &str = "chromedriver";
@@ -55,6 +57,8 @@ pub struct ChromeManager {
5557
pub config: ManagerConfig,
5658
pub http_client: Client,
5759
pub log: Logger,
60+
pub tx: Sender<String>,
61+
pub rx: Receiver<String>,
5862
pub download_browser: bool,
5963
pub driver_url: Option<String>,
6064
pub browser_url: Option<String>,
@@ -67,12 +71,15 @@ impl ChromeManager {
6771
let config = ManagerConfig::default(browser_name, driver_name);
6872
let default_timeout = config.timeout.to_owned();
6973
let default_proxy = &config.proxy;
74+
let (tx, rx): (Sender<String>, Receiver<String>) = mpsc::channel();
7075
Ok(Box::new(ChromeManager {
7176
browser_name,
7277
driver_name,
7378
http_client: create_http_client(default_timeout, default_proxy)?,
7479
config,
7580
log: Logger::new(),
81+
tx,
82+
rx,
7683
download_browser: false,
7784
driver_url: None,
7885
browser_url: None,
@@ -416,6 +423,14 @@ impl SeleniumManager for ChromeManager {
416423
self.log = log;
417424
}
418425

426+
fn get_sender(&self) -> &Sender<String> {
427+
&self.tx
428+
}
429+
430+
fn get_receiver(&self) -> &Receiver<String> {
431+
&self.rx
432+
}
433+
419434
fn get_platform_label(&self) -> &str {
420435
let os = self.get_os();
421436
let arch = self.get_arch();

rust/src/config.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,9 @@ pub struct ManagerConfig {
5555
pub offline: bool,
5656
pub force_browser_download: bool,
5757
pub avoid_browser_download: bool,
58+
pub language_binding: String,
59+
pub selenium_version: String,
60+
pub avoid_stats: bool,
5861
}
5962

6063
impl ManagerConfig {
@@ -111,6 +114,9 @@ impl ManagerConfig {
111114
offline: BooleanKey("offline", false).get_value(),
112115
force_browser_download: BooleanKey("force-browser-download", false).get_value(),
113116
avoid_browser_download: BooleanKey("avoid-browser-download", false).get_value(),
117+
language_binding: StringKey(vec!["language-binding"], "").get_value(),
118+
selenium_version: StringKey(vec!["selenium-version"], "").get_value(),
119+
avoid_stats: BooleanKey("avoid-stats", false).get_value(),
114120
}
115121
}
116122
}

rust/src/edge.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ use serde::{Deserialize, Serialize};
3434
use std::collections::HashMap;
3535
use std::env;
3636
use std::path::{Path, PathBuf};
37+
use std::sync::mpsc;
38+
use std::sync::mpsc::{Receiver, Sender};
3739

3840
pub const EDGE_NAMES: &[&str] = &[
3941
"edge",
@@ -61,6 +63,8 @@ pub struct EdgeManager {
6163
pub config: ManagerConfig,
6264
pub http_client: Client,
6365
pub log: Logger,
66+
pub tx: Sender<String>,
67+
pub rx: Receiver<String>,
6468
pub download_browser: bool,
6569
pub browser_url: Option<String>,
6670
}
@@ -76,12 +80,15 @@ impl EdgeManager {
7680
let config = ManagerConfig::default(static_browser_name, driver_name);
7781
let default_timeout = config.timeout.to_owned();
7882
let default_proxy = &config.proxy;
83+
let (tx, rx): (Sender<String>, Receiver<String>) = mpsc::channel();
7984
Ok(Box::new(EdgeManager {
8085
browser_name: static_browser_name,
8186
driver_name,
8287
http_client: create_http_client(default_timeout, default_proxy)?,
8388
config,
8489
log: Logger::new(),
90+
tx,
91+
rx,
8592
download_browser: false,
8693
browser_url: None,
8794
}))
@@ -322,6 +329,14 @@ impl SeleniumManager for EdgeManager {
322329
self.log = log;
323330
}
324331

332+
fn get_sender(&self) -> &Sender<String> {
333+
&self.tx
334+
}
335+
336+
fn get_receiver(&self) -> &Receiver<String> {
337+
&self.rx
338+
}
339+
325340
fn get_platform_label(&self) -> &str {
326341
let os = self.get_os();
327342
let arch = self.get_arch();

rust/src/firefox.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ use serde::Serialize;
3636
use serde_json::Value;
3737
use std::collections::HashMap;
3838
use std::path::PathBuf;
39+
use std::sync::mpsc;
40+
use std::sync::mpsc::{Receiver, Sender};
3941

4042
pub const FIREFOX_NAME: &str = "firefox";
4143
pub const GECKODRIVER_NAME: &str = "geckodriver";
@@ -71,6 +73,8 @@ pub struct FirefoxManager {
7173
pub config: ManagerConfig,
7274
pub http_client: Client,
7375
pub log: Logger,
76+
pub tx: Sender<String>,
77+
pub rx: Receiver<String>,
7478
pub download_browser: bool,
7579
}
7680

@@ -81,12 +85,15 @@ impl FirefoxManager {
8185
let config = ManagerConfig::default(browser_name, driver_name);
8286
let default_timeout = config.timeout.to_owned();
8387
let default_proxy = &config.proxy;
88+
let (tx, rx): (Sender<String>, Receiver<String>) = mpsc::channel();
8489
Ok(Box::new(FirefoxManager {
8590
browser_name,
8691
driver_name,
8792
http_client: create_http_client(default_timeout, default_proxy)?,
8893
config,
8994
log: Logger::new(),
95+
tx,
96+
rx,
9097
download_browser: false,
9198
}))
9299
}
@@ -361,6 +368,14 @@ impl SeleniumManager for FirefoxManager {
361368
self.log = log;
362369
}
363370

371+
fn get_sender(&self) -> &Sender<String> {
372+
&self.tx
373+
}
374+
375+
fn get_receiver(&self) -> &Receiver<String> {
376+
&self.rx
377+
}
378+
364379
fn get_platform_label(&self) -> &str {
365380
let driver_version = self.get_driver_version();
366381
let os = self.get_os();

rust/src/grid.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ use anyhow::Error;
3030
use reqwest::Client;
3131
use std::collections::HashMap;
3232
use std::path::PathBuf;
33+
use std::sync::mpsc;
34+
use std::sync::mpsc::{Receiver, Sender};
3335

3436
pub const GRID_NAME: &str = "grid";
3537
const GRID_RELEASE: &str = "selenium-server";
@@ -45,6 +47,8 @@ pub struct GridManager {
4547
pub config: ManagerConfig,
4648
pub http_client: Client,
4749
pub log: Logger,
50+
pub tx: Sender<String>,
51+
pub rx: Receiver<String>,
4852
pub download_browser: bool,
4953
pub driver_url: Option<String>,
5054
}
@@ -57,12 +61,15 @@ impl GridManager {
5761
config.driver_version = driver_version;
5862
let default_timeout = config.timeout.to_owned();
5963
let default_proxy = &config.proxy;
64+
let (tx, rx): (Sender<String>, Receiver<String>) = mpsc::channel();
6065
Ok(Box::new(GridManager {
6166
browser_name,
6267
driver_name,
6368
http_client: create_http_client(default_timeout, default_proxy)?,
6469
config,
6570
log: Logger::new(),
71+
tx,
72+
rx,
6673
download_browser: false,
6774
driver_url: None,
6875
}))
@@ -227,6 +234,14 @@ impl SeleniumManager for GridManager {
227234
self.log = log;
228235
}
229236

237+
fn get_sender(&self) -> &Sender<String> {
238+
&self.tx
239+
}
240+
241+
fn get_receiver(&self) -> &Receiver<String> {
242+
&self.rx
243+
}
244+
230245
fn get_platform_label(&self) -> &str {
231246
""
232247
}

rust/src/iexplorer.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ use anyhow::Error;
2727
use reqwest::Client;
2828
use std::collections::HashMap;
2929
use std::path::PathBuf;
30+
use std::sync::mpsc;
31+
use std::sync::mpsc::{Receiver, Sender};
3032

3133
use crate::metadata::{
3234
create_driver_metadata, get_driver_version_from_metadata, get_metadata, write_metadata,
@@ -51,6 +53,8 @@ pub struct IExplorerManager {
5153
pub config: ManagerConfig,
5254
pub http_client: Client,
5355
pub log: Logger,
56+
pub tx: Sender<String>,
57+
pub rx: Receiver<String>,
5458
pub download_browser: bool,
5559
pub driver_url: Option<String>,
5660
}
@@ -63,12 +67,15 @@ impl IExplorerManager {
6367
let default_timeout = config.timeout.to_owned();
6468
let default_proxy = &config.proxy;
6569
config.os = WINDOWS.to_str_vector().first().unwrap().to_string();
70+
let (tx, rx): (Sender<String>, Receiver<String>) = mpsc::channel();
6671
Ok(Box::new(IExplorerManager {
6772
browser_name,
6873
driver_name,
6974
http_client: create_http_client(default_timeout, default_proxy)?,
7075
config,
7176
log: Logger::new(),
77+
tx,
78+
rx,
7279
download_browser: false,
7380
driver_url: None,
7481
}))
@@ -233,6 +240,14 @@ impl SeleniumManager for IExplorerManager {
233240
self.log = log;
234241
}
235242

243+
fn get_sender(&self) -> &Sender<String> {
244+
&self.tx
245+
}
246+
247+
fn get_receiver(&self) -> &Receiver<String> {
248+
&self.rx
249+
}
250+
236251
fn get_platform_label(&self) -> &str {
237252
"win32"
238253
}

0 commit comments

Comments
 (0)