Skip to content

Commit d1e02bf

Browse files
committed
Bug 1533363 - Part 2: Add HTTP Traffic category Telemetry; r=chutten
Differential Revision: https://phabricator.services.mozilla.com/D25135 --HG-- extra : moz-landing-system : lando
1 parent 187eba7 commit d1e02bf

File tree

3 files changed

+70
-0
lines changed

3 files changed

+70
-0
lines changed

netwerk/protocol/http/HttpTrafficAnalyzer.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include "HttpLog.h"
88

99
#include "mozilla/StaticPrefs.h"
10+
#include "mozilla/Telemetry.h"
1011
#include "mozilla/Unused.h"
1112

1213
namespace mozilla {
@@ -102,6 +103,9 @@ nsresult HttpTrafficAnalyzer::IncrementHttpTransaction(
102103
LOG(("HttpTrafficAnalyzer::IncrementHttpTransaction [%s] [this=%p]\n",
103104
gKeyName[aCategory].get(), this));
104105

106+
Telemetry::AccumulateCategoricalKeyed(
107+
gKeyName[aCategory],
108+
Telemetry::LABELS_HTTP_TRAFFIC_ANALYSIS::Transaction);
105109
return NS_OK;
106110
}
107111

@@ -114,6 +118,8 @@ nsresult HttpTrafficAnalyzer::IncrementHttpConnection(
114118
LOG(("HttpTrafficAnalyzer::IncrementHttpConnection [%s] [this=%p]\n",
115119
gKeyName[aCategory].get(), this));
116120

121+
Telemetry::AccumulateCategoricalKeyed(
122+
gKeyName[aCategory], Telemetry::LABELS_HTTP_TRAFFIC_ANALYSIS::Connection);
117123
return NS_OK;
118124
}
119125

@@ -144,6 +150,9 @@ nsresult HttpTrafficAnalyzer::IncrementHttpConnection(
144150
return NS_OK;
145151
}
146152

153+
#define CLAMP_U32(num) \
154+
Clamp<uint32_t>(num, 0, std::numeric_limits<uint32_t>::max())
155+
147156
nsresult HttpTrafficAnalyzer::AccumulateHttpTransferredSize(
148157
HttpTrafficCategory aCategory, uint64_t aBytesRead, uint64_t aBytesSent) {
149158
MOZ_ASSERT(OnSocketThread(), "not on socket thread");
@@ -154,6 +163,10 @@ nsresult HttpTrafficAnalyzer::AccumulateHttpTransferredSize(
154163
"sb=%" PRIu64 " [this=%p]\n",
155164
gKeyName[aCategory].get(), aBytesRead, aBytesSent, this));
156165

166+
// Telemetry supports uint32_t only.
167+
auto total = CLAMP_U32(CLAMP_U32(aBytesRead) + CLAMP_U32(aBytesSent));
168+
Telemetry::ScalarAdd(Telemetry::ScalarID::NETWORKING_DATA_TRANSFERRED,
169+
NS_ConvertUTF8toUTF16(gKeyName[aCategory]), total);
157170
return NS_OK;
158171
}
159172

toolkit/components/telemetry/Histograms.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14563,5 +14563,19 @@
1456314563
],
1456414564
"keyed": true,
1456514565
"description": "Getting the number of errors in QuotaManager initialization."
14566+
},
14567+
"HTTP_TRAFFIC_ANALYSIS": {
14568+
"record_in_processes": ["main"],
14569+
"alert_emails": ["gachen@mozilla.com"],
14570+
"bug_numbers": [1533363],
14571+
"expires_in_version": "73",
14572+
"kind": "categorical",
14573+
"n_values": 8,
14574+
"labels": [
14575+
"Connection",
14576+
"Transaction"
14577+
],
14578+
"keyed": true,
14579+
"description": "Numbers of HTTP transactions and connections by type. There are some categories separated by keys based on 4 parameters: 1. normal browsing or private browsing 2. first party or third party 3. class of service 4. tracking classification. Available keys are: ['Y=0|NormalFirstParty', 'Y=1|NormalThirdPartyOther', 'Y=2|NormalThirdPartyContentLeader', 'Y=3|NormalThirdPartyContentBackground', 'Y=4|NormalThirdPartyContentOther', 'Y=5|NormalThirdPartyBasicLeader', 'Y=6|NormalThirdPartyBasicBackground', 'Y=7|NormalThirdPartyBasicOther', 'Y=8|NormalThirdPartyFingerprintingLeader', 'Y=9|NormalThirdPartyFingerprintingBackground', 'Y=10|NormalThirdPartyFingerprintingOther', 'Y=11|PrivateFirstParty', 'Y=12|PrivateThirdPartyOther', 'Y=13|PrivateThirdPartyContentLeader', 'Y=14|PrivateThirdPartyContentBackground', 'Y=15|PrivateThirdPartyContentOther', 'Y=16|PrivateThirdPartyBasicLeader', 'Y=17|PrivateThirdPartyBasicBackground', 'Y=18|PrivateThirdPartyBasicOther', 'Y=19|PrivateThirdPartyFingerprintingLeader', 'Y=20|PrivateThirdPartyFingerprintingBackground', 'Y=21|PrivateThirdPartyFingerprintingOther']."
1456614580
}
1456714581
}

toolkit/components/telemetry/Scalars.yaml

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2698,6 +2698,49 @@ script.preloader:
26982698
- 'main'
26992699
- 'content'
27002700

2701+
networking:
2702+
data_transferred:
2703+
bug_numbers:
2704+
- 1533363
2705+
description: >
2706+
How many bytes of HTTP data transferred by type, there are some categories
2707+
separated by keys based on 4 parameters:
2708+
1. normal browsing or private browsing
2709+
2. first party or third party
2710+
3. class of service
2711+
4. tracking classification
2712+
2713+
Available keys are:
2714+
Y=0|NormalFirstParty
2715+
Y=1|NormalThirdPartyOther
2716+
Y=2|NormalThirdPartyContentLeader
2717+
Y=3|NormalThirdPartyContentBackground
2718+
Y=4|NormalThirdPartyContentOther
2719+
Y=5|NormalThirdPartyBasicLeader
2720+
Y=6|NormalThirdPartyBasicBackground
2721+
Y=7|NormalThirdPartyBasicOther
2722+
Y=8|NormalThirdPartyFingerprintingLeader
2723+
Y=9|NormalThirdPartyFingerprintingBackground
2724+
Y=10|NormalThirdPartyFingerprintingOther
2725+
Y=11|PrivateFirstParty
2726+
Y=12|PrivateThirdPartyOther
2727+
Y=13|PrivateThirdPartyContentLeader
2728+
Y=14|PrivateThirdPartyContentBackground
2729+
Y=15|PrivateThirdPartyContentOther
2730+
Y=16|PrivateThirdPartyBasicLeader
2731+
Y=17|PrivateThirdPartyBasicBackground
2732+
Y=18|PrivateThirdPartyBasicOther
2733+
Y=19|PrivateThirdPartyFingerprintingLeader
2734+
Y=20|PrivateThirdPartyFingerprintingBackground
2735+
Y=21|PrivateThirdPartyFingerprintingOther
2736+
expires: "73"
2737+
keyed: true
2738+
kind: uint
2739+
notification_emails:
2740+
- gachen@mozilla.com
2741+
record_in_processes:
2742+
- 'main'
2743+
27012744
# The following section is for probes testing the Telemetry system. They will not be
27022745
# submitted in pings and are only used for testing.
27032746
telemetry.test:

0 commit comments

Comments
 (0)