Bug 1643395 - Allow configuring FOG server to localhost via pref r=janerik
authorChris H-C <chutten@mozilla.com>
Fri, 05 Jun 2020 12:52:20 +0000
changeset 534137 62626a107c76a790db4a039ecfffc65df1a72a57
parent 534136 c70d67a20c16f81a32122ab697d1d715c62d12b3
child 534138 c7b0e663eb1d6a9f55af064438afff01c3289b79
push id37483
push userapavel@mozilla.com
push dateFri, 05 Jun 2020 21:40:11 +0000
treeherdermozilla-central@dadc7312128e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjanerik
bugs1643395
milestone79.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1643395 - Allow configuring FOG server to localhost via pref r=janerik Differential Revision: https://phabricator.services.mozilla.com/D78347
modules/libpref/init/StaticPrefList.yaml
toolkit/components/glean/docs/preferences.md
toolkit/components/glean/docs/testing.md
toolkit/components/glean/src/api.rs
--- a/modules/libpref/init/StaticPrefList.yaml
+++ b/modules/libpref/init/StaticPrefList.yaml
@@ -8746,16 +8746,22 @@
   value: false
   mirror: always
 
 - name: telemetry.number_of_site_origin.min_interval
   type: uint32_t
   value: 300000
   mirror: always
 
+- name: telemetry.fog.test.localhost_port
+  type: RelaxedAtomicUint32
+  value: 0
+  mirror: always
+  rust: true
+
 #---------------------------------------------------------------------------
 # Prefs starting with "test."
 #---------------------------------------------------------------------------
 
 - name: test.events.async.enabled
   type: RelaxedAtomicBool
   value: false
   mirror: always
--- a/toolkit/components/glean/docs/preferences.md
+++ b/toolkit/components/glean/docs/preferences.md
@@ -1,7 +1,15 @@
 # Preferences
 
+## Test-only Preferences
+
 `telemetry.fog.temporary_and_just_for_testing.data_path`
 
 This controls the data path Glean is initialized with (`nightly` only).
 It is intended for manual testing only. It will be removed once FOG gets a fixed data path.
 By default it is not set. Change requires restart.
+
+`telemetry.fog.test.localhost_port`
+
+If set to a value `port` which is greater than 0, pings will be sent to
+`http://localhost:port` instead of `https://incoming.telemetry.mozilla.org`.
+Defaults to 0.
--- a/toolkit/components/glean/docs/testing.md
+++ b/toolkit/components/glean/docs/testing.md
@@ -1,13 +1,19 @@
 # Testing
 
 Given the multiple API languages, processes, and dependencies,
 testing FOG is a matter of choosing the right tool for the situation.
 
+## Logging
+
+An often-overlooked first line of testing is "what do the logs say?".
+To turn on logging for FOG, run Firefox with `RUST_LOG="glean,fog"`.
+This will also turn on logging for `glean_core` which is often illuminating.
+
 ## Rust
 
 Not all of our Rust code can be tested in a single fashion, unfortunately.
 
 ### Using `rusttests`
 
 If the crate you're testing has no Gecko symbols you can write standard
 [Rust tests](https://doc.rust-lang.org/book/ch11-01-writing-tests.html).
--- a/toolkit/components/glean/src/api.rs
+++ b/toolkit/components/glean/src/api.rs
@@ -143,17 +143,24 @@ pub fn set_upload_enabled(enabled: bool)
 fn register_uploader() {
     let result = ping_upload::register_uploader(Box::new(|ping_request| {
         log::trace!(
             "FOG Ping Uploader uploading ping {}",
             ping_request.document_id
         );
         let result: std::result::Result<UploadResult, viaduct::Error> = (move || {
             const SERVER: &str = "https://incoming.telemetry.mozilla.org";
-            let url = Url::parse(SERVER)?.join(&ping_request.path)?;
+            let mut server = String::from(SERVER);
+            let localhost_port = static_prefs::pref!("telemetry.fog.test.localhost_port");
+            if localhost_port > 0 {
+                server = format!("http://localhost:{}", localhost_port);
+            }
+            let url = Url::parse(&server)?.join(&ping_request.path)?;
+            log::info!("FOG Ping uploader uploading to {:?}", url);
+
             let mut req = Request::post(url).body(ping_request.body.clone());
             for (&header_key, header_value) in ping_request.headers.iter() {
                 req = req.header(header_key, header_value)?;
             }
 
             log::trace!(
                 "FOG Ping Uploader sending ping {}",
                 ping_request.document_id