Bug 1848542 - Add telemetry for residual cache folder removal or failure r=necko-reviewers,kershaw

Differential Revision: https://phabricator.services.mozilla.com/D194076
This commit is contained in:
Valentin Gosu 2023-11-21 17:29:08 +00:00
parent ce931ebd84
commit e4b4f23ffb
3 changed files with 87 additions and 1 deletions

View file

@ -34,6 +34,7 @@
#include "mozilla/IntegerPrintfMacros.h"
#include "mozilla/Preferences.h"
#include "nsNetUtil.h"
#include "mozilla/glean/GleanMetrics.h"
#ifdef MOZ_BACKGROUNDTASKS
# include "mozilla/BackgroundTasksRunner.h"
@ -1462,7 +1463,17 @@ nsresult CacheFileIOManager::OnIdleDaily() {
continue;
}
if (leafName.Find(kPurgeExtension) != kNotFound) {
subdir->Remove(true);
mozilla::glean::networking::residual_cache_folder_count.Add(1);
rv = subdir->Remove(true);
if (NS_SUCCEEDED(rv)) {
mozilla::glean::networking::residual_cache_folder_removal
.Get("success"_ns)
.Add(1);
} else {
mozilla::glean::networking::residual_cache_folder_removal
.Get("failure"_ns)
.Add(1);
}
}
}

View file

@ -402,3 +402,32 @@ networking:
- acreskey@mozilla.com
expires: never
telemetry_mirror: HTTP_UPLOAD_THROUGHPUT_MBPS_HTTP_3
residual_cache_folder_count:
type: counter
description: >
Counts how often we find a cache folder that wasn't purged
at shutdown by a background task process.
bugs:
- https://bugzilla.mozilla.org/1848542
data_reviews:
- https://bugzilla.mozilla.org/show_bug.cgi?id=1848542
notification_emails:
- vgosu@mozilla.com
expires: 136
residual_cache_folder_removal:
type: labeled_counter
description: >
Counts how often succeed/fail in removing cache folder
that wasn't purged at shutdown
bugs:
- https://bugzilla.mozilla.org/1848542
data_reviews:
- https://bugzilla.mozilla.org/show_bug.cgi?id=1848542
notification_emails:
- vgosu@mozilla.com
expires: 136
labels:
- success
- failure

View file

@ -5,6 +5,7 @@
"use strict";
add_task(async function test_idle_cleanup() {
Services.fog.testResetFOG();
Services.prefs.setBoolPref(
"network.cache.shutdown_purge_in_background_task",
true
@ -32,6 +33,51 @@ add_task(async function test_idle_cleanup() {
false,
`Folder ${dir.path} should have been purged by background task`
);
Assert.equal(
await Glean.networking.residualCacheFolderCount.testGetValue(),
1
);
Assert.equal(
await Glean.networking.residualCacheFolderRemoval.success.testGetValue(),
1
);
Assert.equal(
await Glean.networking.residualCacheFolderRemoval.failure.testGetValue(),
null
);
// Check that telemetry properly detects folders failing to be deleted when readonly
// Making folders readonly only works on windows
if (AppConstants.platform == "win") {
dir.create(Ci.nsIFile.DIRECTORY_TYPE, 0o744);
dir.QueryInterface(Ci.nsILocalFileWin).readOnly = true;
Services.obs.notifyObservers(null, "idle-daily");
await BrowserTestUtils.waitForCondition(async () => {
return (
(await Glean.networking.residualCacheFolderRemoval.failure.testGetValue()) ==
1
);
});
Assert.equal(
await Glean.networking.residualCacheFolderCount.testGetValue(),
2
);
Assert.equal(
await Glean.networking.residualCacheFolderRemoval.success.testGetValue(),
1
);
Assert.equal(
await Glean.networking.residualCacheFolderRemoval.failure.testGetValue(),
1
);
dir.QueryInterface(Ci.nsILocalFileWin).readOnly = false;
dir.remove(true);
}
Services.prefs.clearUserPref(
"network.cache.shutdown_purge_in_background_task"
);