Connectivity metrics: log DnsEvents in-band
This patch changes how DnsEvents are logged in IpConnectivityMetrics.
The following changes are made:
- DnsEventBatch are not logged after 100 queries on the same network
- this allows to merge DnsEvent and DnsEventBatch into one class
- DnsEventBatch are not logged after a network disconnect
- this allows to remove the NetworkCallback
- DnsEvent are now logged similarly to ConnectStats when statistics are
flushed, in a direct call from IpConnectivityMetrics into
NetdEventListenerService, in a direct call from IpConnectivityMetrics
into NetdEventListenerService.
- this allows to remove the Parcelable implementation of DnsEvent
- transports information is added to DnsEvent.
Test: - simplified NetdEventListenerServiceTest covering dns logging
- updated IpConnectivityEventBuilderTest
- updated IpConnectivityMetricsTest
- $ runtest frameworks-net passes
- manually verified $ adb shell dumpsys connmetrics list proto
Bug: 34901696
Change-Id: I4fcd0ad7a7b85d587647f471a90c1e53a18fc95a
Merged-In: Ia4b33fd4212741152662a2adbb0533bd1b4902ee
(cherry picked from commit 0699cf98042a64e41ee076c464eb115a6579be08)
diff --git a/services/core/java/com/android/server/connectivity/IpConnectivityEventBuilder.java b/services/core/java/com/android/server/connectivity/IpConnectivityEventBuilder.java
index ad66faa..f05acef 100644
--- a/services/core/java/com/android/server/connectivity/IpConnectivityEventBuilder.java
+++ b/services/core/java/com/android/server/connectivity/IpConnectivityEventBuilder.java
@@ -91,6 +91,21 @@
return out;
}
+ public static IpConnectivityEvent toProto(DnsEvent in) {
+ final IpConnectivityEvent out = new IpConnectivityEvent();
+ IpConnectivityLogClass.DNSLookupBatch dnsLookupBatch =
+ new IpConnectivityLogClass.DNSLookupBatch();
+ in.resize(in.eventCount);
+ dnsLookupBatch.eventTypes = bytesToInts(in.eventTypes);
+ dnsLookupBatch.returnCodes = bytesToInts(in.returnCodes);
+ dnsLookupBatch.latenciesMs = in.latenciesMs;
+ out.setDnsLookupBatch(dnsLookupBatch);
+ out.networkId = in.netId;
+ out.transports = in.transports;
+ inferLinkLayer(out);
+ return out;
+ }
+
private static boolean setEvent(IpConnectivityEvent out, Parcelable in) {
if (in instanceof DhcpErrorEvent) {
setDhcpErrorEvent(out, (DhcpErrorEvent) in);
@@ -102,11 +117,6 @@
return true;
}
- if (in instanceof DnsEvent) {
- setDnsEvent(out, (DnsEvent) in);
- return true;
- }
-
if (in instanceof IpManagerEvent) {
setIpManagerEvent(out, (IpManagerEvent) in);
return true;
@@ -163,16 +173,6 @@
out.setDhcpEvent(dhcpEvent);
}
- private static void setDnsEvent(IpConnectivityEvent out, DnsEvent in) {
- IpConnectivityLogClass.DNSLookupBatch dnsLookupBatch =
- new IpConnectivityLogClass.DNSLookupBatch();
- dnsLookupBatch.networkId = netIdOf(in.netId);
- dnsLookupBatch.eventTypes = bytesToInts(in.eventTypes);
- dnsLookupBatch.returnCodes = bytesToInts(in.returnCodes);
- dnsLookupBatch.latenciesMs = in.latenciesMs;
- out.setDnsLookupBatch(dnsLookupBatch);
- }
-
private static void setIpManagerEvent(IpConnectivityEvent out, IpManagerEvent in) {
IpConnectivityLogClass.IpProvisioningEvent ipProvisioningEvent =
new IpConnectivityLogClass.IpProvisioningEvent();