Bug 1956726 - Migrate histograms to use Glean APIs in dom/security/, r=chutten.

Differential Revision: https://phabricator.services.mozilla.com/D244170
This commit is contained in:
Florian Quèze
2025-04-03 17:30:10 +00:00
parent 1cb736cf28
commit dde76c472e
3 changed files with 74 additions and 7 deletions

View File

@@ -32,7 +32,7 @@
#include "mozilla/StaticPrefs_network.h" #include "mozilla/StaticPrefs_network.h"
#include "mozilla/StorageAccess.h" #include "mozilla/StorageAccess.h"
#include "mozilla/StyleSheet.h" #include "mozilla/StyleSheet.h"
#include "mozilla/Telemetry.h" #include "mozilla/glean/DomSecurityMetrics.h"
#include "nsIWebProgressListener.h" #include "nsIWebProgressListener.h"
static mozilla::LazyLogModule gReferrerInfoLog("ReferrerInfo"); static mozilla::LazyLogModule gReferrerInfoLog("ReferrerInfo");
@@ -1695,7 +1695,7 @@ void ReferrerInfo::RecordTelemetry(nsIHttpChannel* aChannel) {
1 1
: 0; : 0;
Telemetry::Accumulate(Telemetry::REFERRER_POLICY_COUNT, glean::security::referrer_policy_count.AccumulateSingleSample(
static_cast<uint32_t>(mPolicy) + telemetryOffset); static_cast<uint32_t>(mPolicy) + telemetryOffset);
} }

View File

@@ -398,6 +398,71 @@ security:
type: string type: string
telemetry_mirror: Security_Javascriptload_Parentprocess telemetry_mirror: Security_Javascriptload_Parentprocess
https_only_mode_upgrade_time:
type: labeled_timing_distribution
description: >
Time it takes for a request that has been upgraded with HTTPS-Only Mode to
complete, broken down by top-level (top) / sub-resource (sub) and status
This metric was generated to correspond to the Legacy Telemetry
exponential histogram HTTPS_ONLY_MODE_UPGRADE_TIME_MS.
time_unit: millisecond
labels:
- top_successful
- sub_successful
- top_f_redirectloop
- sub_f_redirectloop
- top_f_timeout
- sub_f_timeout
- top_f_aborted
- sub_f_aborted
- top_f_cxnrefused
- sub_f_cxnrefused
- top_f_ssl_selfsignd
- sub_f_ssl_selfsignd
- top_f_ssl_badcertdm
- sub_f_ssl_badcertdm
- top_f_ssl_unkwnissr
- sub_f_ssl_unkwnissr
- top_f_ssl_other
- sub_f_ssl_other
- top_f_other
- sub_f_other
bugs:
- https://bugzilla.mozilla.org/show_bug.cgi?id=1627206
data_reviews:
- https://bugzilla.mozilla.org/show_bug.cgi?id=1627206
notification_emails:
- julianwels@mozilla.com
- seceng-telemetry@mozilla.com
expires: never
telemetry_mirror: HTTPS_ONLY_MODE_UPGRADE_TIME_MS
referrer_policy_count:
type: custom_distribution
description: >
The counter of each referrer policy which has been computed for a
referrer. The buckets (0-8) are for same-site requests and buckets (9-17)
are for cross-site requests. Note that the index matches to the order in
ReferrerPolicy.webidl
This metric was generated to correspond to the Legacy Telemetry enumerated
histogram REFERRER_POLICY_COUNT.
range_min: 0
range_max: 18
bucket_count: 19
histogram_type: linear
bugs:
- https://bugzilla.mozilla.org/show_bug.cgi?id=1720869
data_reviews:
- https://bugzilla.mozilla.org/show_bug.cgi?id=1720869
notification_emails:
- tihuang@mozilla.com
- ckerschbaumer@mozilla.com
- seceng-telemetry@mozilla.com
expires: never
telemetry_mirror: REFERRER_POLICY_COUNT
mixed_content: mixed_content:
page_load: page_load:
type: custom_distribution type: custom_distribution

View File

@@ -5,6 +5,7 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "NSSErrorsService.h" #include "NSSErrorsService.h"
#include "mozilla/glean/DomSecurityMetrics.h"
#include "mozilla/Telemetry.h" #include "mozilla/Telemetry.h"
#include "mozilla/TimeStamp.h" #include "mozilla/TimeStamp.h"
#include "mozilla/dom/WindowGlobalParent.h" #include "mozilla/dom/WindowGlobalParent.h"
@@ -84,8 +85,7 @@ nsHTTPSOnlyStreamListener::OnStopRequest(nsIRequest* request,
void nsHTTPSOnlyStreamListener::RecordUpgradeTelemetry(nsIRequest* request, void nsHTTPSOnlyStreamListener::RecordUpgradeTelemetry(nsIRequest* request,
nsresult aStatus) { nsresult aStatus) {
// 1. Get time between now and when the initial upgrade request started // 1. Get time between now and when the initial upgrade request started
int64_t duration = mozilla::TimeDuration duration = mozilla::TimeStamp::Now() - mCreationStart;
(mozilla::TimeStamp::Now() - mCreationStart).ToMilliseconds();
// 2. Assemble the category string // 2. Assemble the category string
// [!] All strings have to be present in Histograms.json // [!] All strings have to be present in Histograms.json
@@ -138,8 +138,8 @@ void nsHTTPSOnlyStreamListener::RecordUpgradeTelemetry(nsIRequest* request,
category.AppendLiteral("f_other"); category.AppendLiteral("f_other");
} }
} }
mozilla::Telemetry::Accumulate( mozilla::glean::security::https_only_mode_upgrade_time.Get(category)
mozilla::Telemetry::HTTPS_ONLY_MODE_UPGRADE_TIME_MS, category, duration); .AccumulateRawDuration(duration);
bool success = NS_SUCCEEDED(aStatus); bool success = NS_SUCCEEDED(aStatus);
ExtContentPolicyType externalType = loadInfo->GetExternalContentPolicyType(); ExtContentPolicyType externalType = loadInfo->GetExternalContentPolicyType();
@@ -243,6 +243,8 @@ void nsHTTPSOnlyStreamListener::RecordUpgradeTelemetry(nsIRequest* request,
} }
} }
// Needs bug 1657470 (New Metric Type: "Keyed Categorical") before
// this can be migrated to Glean.
mozilla::Telemetry::Accumulate( mozilla::Telemetry::Accumulate(
mozilla::Telemetry::HTTPS_ONLY_MODE_UPGRADE_TYPE, typeKey, success); mozilla::Telemetry::HTTPS_ONLY_MODE_UPGRADE_TYPE, typeKey, success);
} }