Bug 1922235 - Add probe to record the TRR fetch duration, r=necko-reviewers,valentin

Differential Revision: https://phabricator.services.mozilla.com/D225040
This commit is contained in:
Kershaw Chang 2024-10-16 09:48:41 +00:00
parent e3152c73f3
commit 4c94c8c405
2 changed files with 67 additions and 15 deletions

View File

@ -36,6 +36,7 @@
#include "mozilla/Base64.h"
#include "mozilla/DebugOnly.h"
#include "mozilla/Logging.h"
#include "mozilla/Maybe.h"
#include "mozilla/Preferences.h"
#include "mozilla/StaticPrefs_network.h"
#include "mozilla/Telemetry.h"
@ -757,6 +758,23 @@ void TRR::StoreIPHintAsDNSRecord(const struct SVCB& aSVCBRecord) {
}
nsresult TRR::ReturnData(nsIChannel* aChannel) {
Maybe<TimeDuration> trrFetchDuration;
Maybe<TimeDuration> trrFetchDurationNetworkOnly;
// Set timings.
nsCOMPtr<nsITimedChannel> timedChan = do_QueryInterface(aChannel);
if (timedChan) {
TimeStamp asyncOpen, start, end;
if (NS_SUCCEEDED(timedChan->GetAsyncOpen(&asyncOpen)) &&
!asyncOpen.IsNull()) {
trrFetchDuration = Some(TimeStamp::Now() - asyncOpen);
}
if (NS_SUCCEEDED(timedChan->GetRequestStart(&start)) &&
NS_SUCCEEDED(timedChan->GetResponseEnd(&end)) && !start.IsNull() &&
!end.IsNull()) {
trrFetchDurationNetworkOnly = Some(end - start);
}
}
if (mType != TRRTYPE_TXT && mType != TRRTYPE_HTTPSSVC) {
// create and populate an AddrInfo instance to pass on
RefPtr<AddrInfo> ai(new AddrInfo(mHost, ResolverType(), mType,
@ -764,21 +782,12 @@ nsresult TRR::ReturnData(nsIChannel* aChannel) {
auto builder = ai->Build();
builder.SetAddresses(std::move(mDNS.mAddresses));
builder.SetCanonicalHostname(mCname);
// Set timings.
nsCOMPtr<nsITimedChannel> timedChan = do_QueryInterface(aChannel);
if (timedChan) {
TimeStamp asyncOpen, start, end;
if (NS_SUCCEEDED(timedChan->GetAsyncOpen(&asyncOpen)) &&
!asyncOpen.IsNull()) {
builder.SetTrrFetchDuration(
(TimeStamp::Now() - asyncOpen).ToMilliseconds());
}
if (NS_SUCCEEDED(timedChan->GetRequestStart(&start)) &&
NS_SUCCEEDED(timedChan->GetResponseEnd(&end)) && !start.IsNull() &&
!end.IsNull()) {
builder.SetTrrFetchDurationNetworkOnly((end - start).ToMilliseconds());
}
if (trrFetchDuration) {
builder.SetTrrFetchDuration((*trrFetchDuration).ToMilliseconds());
}
if (trrFetchDurationNetworkOnly) {
builder.SetTrrFetchDurationNetworkOnly(
(*trrFetchDurationNetworkOnly).ToMilliseconds());
}
ai = builder.Finish();
@ -795,6 +804,29 @@ nsresult TRR::ReturnData(nsIChannel* aChannel) {
(void)mHostResolver->CompleteLookupByType(mRec, NS_OK, mResult,
mTRRSkippedReason, mTTL, mPB);
}
nsCOMPtr<nsIHttpChannel> httpChannel = do_QueryInterface(aChannel);
if (httpChannel) {
nsAutoCString version;
if (NS_SUCCEEDED(httpChannel->GetProtocolVersion(version))) {
nsAutoCString key("h1"_ns);
if (version.Equals("h3"_ns)) {
key.Assign("h3"_ns);
} else if (version.Equals("h2"_ns)) {
key.Assign("h2"_ns);
}
if (trrFetchDuration) {
glean::networking::trr_fetch_duration.Get(key).AccumulateRawDuration(
*trrFetchDuration);
}
if (trrFetchDurationNetworkOnly) {
key.Append("_network_only"_ns);
glean::networking::trr_fetch_duration.Get(key).AccumulateRawDuration(
*trrFetchDurationNetworkOnly);
}
}
}
return NS_OK;
}

View File

@ -400,6 +400,26 @@ networking:
expires: never
telemetry_mirror: DNS_LOOKUP_TIME
trr_fetch_duration:
type: labeled_timing_distribution
time_unit: millisecond
description: >
Time for a successful DoH request, from AsyncOpen to ReturnData
bugs:
- https://bugzilla.mozilla.org/show_bug.cgi?id=1922235
data_reviews:
- https://bugzilla.mozilla.org/show_bug.cgi?id=1922235
notification_emails:
- necko@mozilla.com
labels:
- h1
- h1_network_only
- h2
- h2_network_only
- h3
- h3_network_only
expires: never
dns_renewal_time:
type: timing_distribution
time_unit: millisecond