forked from mirrors/gecko-dev
Bug 1942797 - Apply interesting_serverknobs.json when running in automation. r=mkmelin a=pascalc
For non-Firefox builds, automatically apply interesting_serverknobs.json when running tests. Differential Revision: https://phabricator.services.mozilla.com/D242915
This commit is contained in:
parent
316d89486f
commit
c8783c897e
4 changed files with 84 additions and 5 deletions
|
|
@ -19,7 +19,8 @@
|
|||
|
||||
use firefox_on_glean::{ipc, metrics, pings};
|
||||
use nserror::{nsresult, NS_ERROR_FAILURE, NS_OK};
|
||||
use nsstring::{nsACString, nsCString};
|
||||
use nsstring::{nsACString, nsAString, nsCString};
|
||||
use std::fs;
|
||||
use thin_vec::ThinVec;
|
||||
|
||||
#[macro_use]
|
||||
|
|
@ -212,3 +213,23 @@ pub extern "C" fn fog_apply_server_knobs_config(config_json: &nsACString) {
|
|||
pub extern "C" fn fog_internal_glean_handle_client_inactive() {
|
||||
glean::handle_client_inactive();
|
||||
}
|
||||
|
||||
/// Apply a serverknobs config from the given path.
|
||||
#[no_mangle]
|
||||
pub extern "C" fn fog_apply_serverknobs(serverknobs_path: &nsAString) -> bool {
|
||||
let config_json = match fs::read_to_string(serverknobs_path.to_string()) {
|
||||
Ok(c) => c,
|
||||
_ => {
|
||||
log::error!(
|
||||
"Boo, couldn't open serverknobs file at {}",
|
||||
serverknobs_path.to_string()
|
||||
);
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
log::trace!("Loaded serverknobs config. Applying.");
|
||||
glean::glean_apply_server_knobs_config(config_json);
|
||||
|
||||
true
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ head = "head.js"
|
|||
["test_FOGIPCLimit.js"]
|
||||
|
||||
["test_FOGInit.js"]
|
||||
skip-if = ["appname == 'thunderbird'"] # Won't run on thunderbird due to a race condition with the generated serverknobs conf.
|
||||
|
||||
["test_FOGPrefs.js"]
|
||||
skip-if = ["os == 'android'"] # FOG isn't responsible for monitoring prefs and controlling upload on Android
|
||||
|
|
@ -26,11 +27,15 @@ skip-if = ["os == 'android'"] # FOG isn't responsible for experiment annotations
|
|||
skip-if = ["os == 'android'"] # Server Knobs on mobile will be handled by the specific app
|
||||
|
||||
["test_JOG.js"]
|
||||
skip-if = ["appname == 'thunderbird'"] # Won't run on thunderbird due to a race condition with the generated serverknobs conf.
|
||||
|
||||
["test_JOGIPC.js"]
|
||||
|
||||
["test_MillionQ.js"]
|
||||
skip-if = ["os == 'android'"] # Android inits its own FOG, so the test won't work.
|
||||
skip-if = [
|
||||
"os == 'android'", # Android inits its own FOG, so the test won't work.
|
||||
"appname == 'thunderbird'" # interesting_serverknobs.json isn't applied before init.
|
||||
]
|
||||
|
||||
["test_OHTTP.js"]
|
||||
skip-if = ["os == 'android'"] # FOG isn't responsible for monitoring prefs and controlling upload on Android
|
||||
|
|
|
|||
|
|
@ -20,7 +20,10 @@
|
|||
#include "mozilla/ShutdownPhase.h"
|
||||
#include "mozilla/Unused.h"
|
||||
#include "nsContentUtils.h"
|
||||
#include "nsDirectoryServiceDefs.h"
|
||||
#include "nsDirectoryServiceUtils.h"
|
||||
#include "nsIFOG.h"
|
||||
#include "nsIFile.h"
|
||||
#include "nsIUserIdleService.h"
|
||||
#include "nsServiceManagerUtils.h"
|
||||
#include "xpcpublic.h"
|
||||
|
|
@ -142,8 +145,49 @@ FOG::InitializeFOG(const nsACString& aDataPathOverride,
|
|||
},
|
||||
ShutdownPhase::AppShutdownConfirmed);
|
||||
|
||||
return glean::impl::fog_init(&aDataPathOverride, &aAppIdOverride,
|
||||
aDisableInternalPings);
|
||||
nsresult rv = glean::impl::fog_init(&aDataPathOverride, &aAppIdOverride,
|
||||
aDisableInternalPings);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
#ifndef MOZ_BUILD_APP_IS_BROWSER
|
||||
if (xpc::IsInAutomation()) {
|
||||
ApplyInterestingServerKnobs();
|
||||
}
|
||||
#endif
|
||||
return rv;
|
||||
}
|
||||
|
||||
/**
|
||||
* Enable desired metrics, so that tests work even if some metrics were
|
||||
* disabled.
|
||||
* @see JOG::EnsureRuntimeMetricsRegistered()
|
||||
*/
|
||||
// static
|
||||
bool FOG::ApplyInterestingServerKnobs() {
|
||||
// The config we need to process were placed in GreD in
|
||||
// interesting_serverknobs.json.
|
||||
// That file was generated by
|
||||
// toolkit/components/glean/build_scripts/glean_parser_ext/interesting_serverknobs.py
|
||||
nsCOMPtr<nsIFile> knobsFile;
|
||||
if (NS_WARN_IF(NS_FAILED(
|
||||
NS_GetSpecialDirectory(NS_GRE_DIR, getter_AddRefs(knobsFile))))) {
|
||||
return false;
|
||||
}
|
||||
if (NS_WARN_IF(
|
||||
NS_FAILED(knobsFile->Append(u"interesting_serverknobs.json"_ns)))) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// We _could_ read the file and apply it here in C++ land,
|
||||
// but let's use Rust because (among other reasons) it's more fun.
|
||||
nsAutoString knobsfileString;
|
||||
if (NS_WARN_IF(NS_FAILED(knobsFile->GetPath(knobsfileString)))) {
|
||||
return false;
|
||||
}
|
||||
if (!glean::impl::fog_apply_serverknobs(&knobsfileString)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
|
|
@ -372,7 +416,15 @@ NS_IMETHODIMP
|
|||
FOG::TestResetFOG(const nsACString& aDataPathOverride,
|
||||
const nsACString& aAppIdOverride) {
|
||||
MOZ_ASSERT(XRE_IsParentProcess());
|
||||
return glean::impl::fog_test_reset(&aDataPathOverride, &aAppIdOverride);
|
||||
nsresult rv =
|
||||
glean::impl::fog_test_reset(&aDataPathOverride, &aAppIdOverride);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
#ifndef MOZ_BUILD_APP_IS_BROWSER
|
||||
if (xpc::IsInAutomation()) {
|
||||
ApplyInterestingServerKnobs();
|
||||
}
|
||||
#endif
|
||||
return rv;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
|
|
|
|||
|
|
@ -24,6 +24,7 @@ class FOG final : public nsIFOG, public nsIObserver, public nsIMemoryReporter {
|
|||
|
||||
private:
|
||||
~FOG() = default;
|
||||
static bool ApplyInterestingServerKnobs();
|
||||
void Shutdown();
|
||||
};
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue