Bug 1772124 - Added Glean metrics to track different type of resources for Early Hints r=dragana,mbucher,necko-reviewers

Differential Revision: https://phabricator.services.mozilla.com/D148741
This commit is contained in:
mleclair 2022-07-11 22:46:22 +00:00
Родитель 07c1520097
Коммит f15f91dc56
6 изменённых файлов: 61 добавлений и 6 удалений

Просмотреть файл

@ -3,7 +3,7 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
"use strict";
console.log("hello");
/**
* NetworkObserver is the main class in DevTools to observe network requests
* out of many events fired by the platform code.

Просмотреть файл

@ -9,6 +9,8 @@
#include "mozilla/CORSMode.h"
#include "mozilla/dom/Element.h"
#include "mozilla/dom/ReferrerInfo.h"
#include "mozilla/StaticPrefs_network.h"
#include "mozilla/glean/GleanMetrics.h"
#include "mozilla/Logging.h"
#include "nsAttrValue.h"
#include "nsAttrValueInlines.h"
@ -154,6 +156,14 @@ void EarlyHintPreloader::MaybeCreateAndInsertPreload(
nsAttrValue as;
ParseAsValue(aHeader.mAs, as);
ASDestination destination = static_cast<ASDestination>(as.GetEnumValue());
CollectResourcesTypeTelemetry(destination);
if (!StaticPrefs::network_early_hints_enabled()) {
return;
}
if (as.GetEnumValue() == ASDestination::DESTINATION_INVALID) {
// return early when it's definitly not an asset type we preload
// would be caught later as well, e.g. when creating the PreloadHashKey
@ -378,4 +388,20 @@ EarlyHintPreloader::GetInterface(const nsIID& aIID, void** aResult) {
return NS_ERROR_NO_INTERFACE;
}
void EarlyHintPreloader::CollectResourcesTypeTelemetry(
ASDestination aASDestination) {
if (aASDestination == ASDestination::DESTINATION_FONT) {
glean::netwerk::early_hints.Get("font"_ns).Add(1);
} else if (aASDestination == ASDestination::DESTINATION_SCRIPT) {
glean::netwerk::early_hints.Get("script"_ns).Add(1);
} else if (aASDestination == ASDestination::DESTINATION_STYLE) {
glean::netwerk::early_hints.Get("stylesheet"_ns).Add(1);
} else if (aASDestination == ASDestination::DESTINATION_IMAGE) {
glean::netwerk::early_hints.Get("image"_ns).Add(1);
} else if (aASDestination == ASDestination::DESTINATION_FETCH) {
glean::netwerk::early_hints.Get("fetch"_ns).Add(1);
} else {
glean::netwerk::early_hints.Get("other"_ns).Add(1);
}
}
} // namespace mozilla::net

Просмотреть файл

@ -87,6 +87,7 @@ class EarlyHintPreloader final : public nsIStreamListener,
nsIReferrerInfo* aReferrerInfo,
nsICookieJarSettings* aCookieJarSettings);
static void CollectResourcesTypeTelemetry(ASDestination aASDestination);
// keep opening uri to not preload cross origins on redirects for now
nsCOMPtr<nsIURI> mURI;
nsCOMPtr<nsIChannel> mChannel;

Просмотреть файл

@ -12,7 +12,6 @@
#include "nsICookieJarSettings.h"
#include "nsNetUtil.h"
#include "nsString.h"
#include "mozilla/StaticPrefs_network.h"
#include "nsIPrincipal.h"
#include "nsILoadInfo.h"
@ -33,10 +32,6 @@ void EarlyHintsService::EarlyHint(const nsACString& aLinkHeader,
mFirstEarlyHint.emplace(TimeStamp::NowLoRes());
}
if (!StaticPrefs::network_early_hints_enabled()) {
return;
}
nsCOMPtr<nsIPrincipal> triggeringPrincipal = aLoadInfo->TriggeringPrincipal();
nsCOMPtr<nsICookieJarSettings> cookieJarSettings;

Просмотреть файл

@ -0,0 +1,32 @@
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
# Adding a new metric? We have docs for that!
# https://firefox-source-docs.mozilla.org/toolkit/components/glean/user/new_definitions_file.html
---
$schema: moz://mozilla.org/schemas/glean/metrics/2-0-0
$tags:
- 'Core :: Networking: HTTP'
netwerk:
early_hints:
type: labeled_counter
labels:
- stylesheet
- fonts
- scripts
- fetch
- image
description: >
Counts the different type of resources that are sent for early hints.
bugs:
- https://bugzilla.mozilla.org/show_bug.cgi?id=1772124
data_reviews:
- https://bugzilla.mozilla.org/show_bug.cgi?id=1772124
notification_emails:
- necko@mozilla.com
- ddamjanovic@mozilla.com
expires: 109

Просмотреть файл

@ -20,6 +20,7 @@ metrics_yamls = [
"dom/media/metrics.yaml",
"dom/metrics.yaml",
"gfx/metrics.yaml",
"netwerk/protocol/http/metrics.yaml",
"toolkit/components/extensions/metrics.yaml",
"toolkit/components/glean/metrics.yaml",
"toolkit/components/glean/tests/test_metrics.yaml",