commit 8bc2dbb0bab4742d3e70f6bb8eab1b4c15d75b23
parent a7b2b6d5206d454b856c570eda5691a02f313b01
Author: Kershaw Chang <kershaw@mozilla.com>
Date: Wed, 15 Oct 2025 15:09:17 +0000
Bug 1992764 - Record trr_request_count_per_conn for HTTP/2 correctly, r=necko-reviewers,valentin
Differential Revision: https://phabricator.services.mozilla.com/D268668
Diffstat:
3 files changed, 34 insertions(+), 3 deletions(-)
diff --git a/netwerk/protocol/http/Http2Session.cpp b/netwerk/protocol/http/Http2Session.cpp
@@ -290,10 +290,9 @@ Http2Session::~Http2Session() {
Shutdown(NS_OK);
- RefPtr<nsHttpConnectionInfo> ci = ConnectionInfo();
- if (mTrrStreams && ci) {
+ if (mTrrStreams) {
mozilla::glean::networking::trr_request_count_per_conn
- .Get(nsPrintfCString("%s_h2", ci->Origin()))
+ .Get(nsPrintfCString("%s_h2", mTrrHost.get()))
.Add(static_cast<int32_t>(mTrrStreams));
}
glean::spdy::parallel_streams.AccumulateSingleSample(mConcurrentHighWater);
@@ -545,6 +544,9 @@ uint32_t Http2Session::RegisterStreamID(Http2StreamBase* stream,
// don't count push streams here
RefPtr<nsHttpConnectionInfo> ci(stream->ConnectionInfo());
if (ci && ci->GetIsTrrServiceChannel()) {
+ if (mTrrHost.IsEmpty()) {
+ mTrrHost = ci->GetOrigin();
+ }
IncrementTrrCounter();
}
}
diff --git a/netwerk/protocol/http/Http2Session.h b/netwerk/protocol/http/Http2Session.h
@@ -655,6 +655,7 @@ class Http2Session final : public ASpdySession,
private:
TimeStamp mLastTRRResponseTime; // Time of the last successful TRR response
uint32_t mTrrStreams;
+ nsCString mTrrHost;
// Whether we allow websockets, based on a pref
bool mEnableWebsockets = false;
diff --git a/netwerk/test/unit/test_trr.js b/netwerk/test/unit/test_trr.js
@@ -992,3 +992,31 @@ add_task(
);
}
);
+
+add_task(
+ { skip_if: () => mozinfo.socketprocess_networking },
+ async function test_trr_request_per_conn_telemetry() {
+ setModeAndURI(Ci.nsIDNSService.MODE_TRRONLY, `doh`);
+ Services.dns.clearCache(true);
+
+ // Close the previous TRR connection.
+ Services.obs.notifyObservers(null, "net:cancel-all-connections");
+ await new Promise(r => do_timeout(3000, r));
+
+ Services.fog.testResetFOG();
+ Services.prefs.setBoolPref("network.dns.disableIPv6", false);
+ await new TRRDNSListener("timing.com", { expectedAnswer: "5.5.5.5" });
+
+ // Close the TRR connection again, so trr_request_count_per_conn
+ // can be recorded.
+ Services.obs.notifyObservers(null, "net:cancel-all-connections");
+ await new Promise(r => do_timeout(3000, r));
+
+ let requestPerConn =
+ await Glean.networking.trrRequestCountPerConn.other.testGetValue();
+
+ info("requestPerConn=" + JSON.stringify(requestPerConn));
+
+ Assert.greaterOrEqual(requestPerConn, 2);
+ }
+);