Bug 1891185 - Collect different downgrade time on timer for HTTPS-First telemetry r=freddyb

It does not make sense to collect the "downgrade time" as we currently do it
when a upgrade was caused by a faster http request on a timer. We can not
compare the navigation start timestamp with the current time, as the replacing
http channel has started loading earlier than the current time. So leave out the
case where the downgrade happens because of a faster http request on the timer,
as we already know that the time overhead there is exactly 3s.

Differential Revision: https://phabricator.services.mozilla.com/D207338
This commit is contained in:
Malte Juergens 2024-04-29 13:52:15 +00:00
parent 8600838345
commit b93092a9f4
3 changed files with 25 additions and 33 deletions

View file

@ -118,8 +118,8 @@ httpsfirst:
description: > description: >
If a HTTPS-First (`dom.security.https_first` enabled) upgrade isn't If a HTTPS-First (`dom.security.https_first` enabled) upgrade isn't
successful, measures the timespan between the navigation start and the successful, measures the timespan between the navigation start and the
downgrade. This is essentially the overhead caused by HTTPS-First if a downgrade. This does not include the case in which the https request times
site does not support HTTPS. out and the http request sent after 3s gets a response faster.
time_unit: millisecond time_unit: millisecond
bugs: bugs:
- https://bugzilla.mozilla.org/show_bug.cgi?id=1868380 - https://bugzilla.mozilla.org/show_bug.cgi?id=1868380
@ -135,11 +135,11 @@ httpsfirst:
downgrade_time_schemeless: downgrade_time_schemeless:
type: timing_distribution type: timing_distribution
description: > description: >
If a schemeless HTTPS-First (`dom.security.https_first` disabled, but If a schemeless HTTPS-First (`dom.security.https_first` disabled, but load
load marked as schemeless) upgrade isn't successful, measures the marked as schemeless) upgrade isn't successful, measures the timespan
timespan between the navigation start and the downgrade. This is between the navigation start and the downgrade. This does not include the
essentially the overhead caused by HTTPS-First if a site does not support case in which the https request times out and the http request sent after
HTTPS. 3s gets a response faster.
time_unit: millisecond time_unit: millisecond
bugs: bugs:
- https://bugzilla.mozilla.org/show_bug.cgi?id=1868380 - https://bugzilla.mozilla.org/show_bug.cgi?id=1868380

View file

@ -601,35 +601,28 @@ nsHTTPSOnlyUtils::PotentiallyDowngradeHttpsFirstRequest(
if (navigationStart) { if (navigationStart) {
mozilla::TimeDuration duration = mozilla::TimeDuration duration =
mozilla::TimeStamp::Now() - navigationStart; mozilla::TimeStamp::Now() - navigationStart;
bool isPrivateWin = bool isPrivateWin =
loadInfo->GetOriginAttributes().mPrivateBrowsingId > 0; loadInfo->GetOriginAttributes().mPrivateBrowsingId > 0;
bool isSchemeless =
loadInfo->GetWasSchemelessInput() &&
!nsHTTPSOnlyUtils::IsHttpsFirstModeEnabled(isPrivateWin);
if (loadInfo->GetWasSchemelessInput() && using namespace mozilla::glean::httpsfirst;
!IsHttpsFirstModeEnabled(isPrivateWin)) { auto downgradedMetric = isSchemeless ? downgraded_schemeless : downgraded;
mozilla::glean::httpsfirst::downgraded_schemeless.Add(); auto downgradedOnTimerMetric =
if (timing) { isSchemeless ? downgraded_on_timer_schemeless : downgraded_on_timer;
mozilla::glean::httpsfirst::downgrade_time_schemeless auto downgradeTimeMetric =
.AccumulateRawDuration(duration); isSchemeless ? downgrade_time_schemeless : downgrade_time;
}
} else {
mozilla::glean::httpsfirst::downgraded.Add();
if (timing) {
mozilla::glean::httpsfirst::downgrade_time.AccumulateRawDuration(
duration);
}
}
nsresult channelStatus; nsresult channelStatus;
channel->GetStatus(&channelStatus); channel->GetStatus(&channelStatus);
if (channelStatus == NS_ERROR_NET_TIMEOUT_EXTERNAL) { if (channelStatus == NS_ERROR_NET_TIMEOUT_EXTERNAL) {
if (loadInfo->GetWasSchemelessInput() && downgradedOnTimerMetric.AddToNumerator();
!nsHTTPSOnlyUtils::IsHttpsFirstModeEnabled(isPrivateWin)) { } else {
mozilla::glean::httpsfirst::downgraded_on_timer_schemeless downgradeTimeMetric.AccumulateRawDuration(duration);
.AddToNumerator();
} else {
mozilla::glean::httpsfirst::downgraded_on_timer.AddToNumerator();
}
} }
downgradedMetric.Add();
} }
} }

View file

@ -99,11 +99,10 @@ add_task(async function () {
is(Glean.httpsfirst.downgradedOnTimerSchemeless.testGetValue(), null); is(Glean.httpsfirst.downgradedOnTimerSchemeless.testGetValue(), null);
const downgradeSeconds = const downgradeSeconds =
Glean.httpsfirst.downgradeTime.testGetValue().sum / 1_000_000_000; Glean.httpsfirst.downgradeTime.testGetValue().sum / 1_000_000_000;
ok( Assert.less(
downgradeSeconds > 2 && downgradeSeconds < 30, downgradeSeconds,
`Summed downgrade time should be above 2 and below 30 seconds (is ${downgradeSeconds.toFixed( 10,
2 "Summed downgrade time should be below 10 seconds"
)}s)`
); );
is(null, Glean.httpsfirst.downgradeTimeSchemeless.testGetValue()); is(null, Glean.httpsfirst.downgradeTimeSchemeless.testGetValue());
}); });