Report resolution stop
Report the nsd metrics event of resolution stop. Bug: 287546772 Test: atest FrameworksNetTestCases Change-Id: I2e6de22c946d58a3410f16b2f2689fd3ffc635a4
This commit is contained in:
@@ -206,4 +206,19 @@ public class NetworkNsdReportedMetrics {
|
|||||||
builder.setEventDurationMillisec(durationMs);
|
builder.setEventDurationMillisec(durationMs);
|
||||||
mDependencies.statsWrite(builder.build());
|
mDependencies.statsWrite(builder.build());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Report service resolution stop metric data.
|
||||||
|
*
|
||||||
|
* @param transactionId The transaction id of service resolution.
|
||||||
|
* @param durationMs The duration before stop resolving the service.
|
||||||
|
*/
|
||||||
|
public void reportServiceResolutionStop(int transactionId, long durationMs) {
|
||||||
|
final Builder builder = makeReportedBuilder();
|
||||||
|
builder.setTransactionId(transactionId);
|
||||||
|
builder.setType(NsdEventType.NET_RESOLVE);
|
||||||
|
builder.setQueryResult(MdnsQueryResult.MQR_SERVICE_RESOLUTION_STOP);
|
||||||
|
builder.setEventDurationMillisec(durationMs);
|
||||||
|
mDependencies.statsWrite(builder.build());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1062,12 +1062,12 @@ public class NsdService extends INsdManager.Stub {
|
|||||||
if (request instanceof DiscoveryManagerRequest) {
|
if (request instanceof DiscoveryManagerRequest) {
|
||||||
stopDiscoveryManagerRequest(
|
stopDiscoveryManagerRequest(
|
||||||
request, clientRequestId, transactionId, clientInfo);
|
request, clientRequestId, transactionId, clientInfo);
|
||||||
clientInfo.onStopResolutionSucceeded(clientRequestId);
|
clientInfo.onStopResolutionSucceeded(clientRequestId, request);
|
||||||
clientInfo.log("Unregister the ResolutionListener " + transactionId);
|
clientInfo.log("Unregister the ResolutionListener " + transactionId);
|
||||||
} else {
|
} else {
|
||||||
removeRequestMap(clientRequestId, transactionId, clientInfo);
|
removeRequestMap(clientRequestId, transactionId, clientInfo);
|
||||||
if (stopResolveService(transactionId)) {
|
if (stopResolveService(transactionId)) {
|
||||||
clientInfo.onStopResolutionSucceeded(clientRequestId);
|
clientInfo.onStopResolutionSucceeded(clientRequestId, request);
|
||||||
} else {
|
} else {
|
||||||
clientInfo.onStopResolutionFailed(
|
clientInfo.onStopResolutionFailed(
|
||||||
clientRequestId, NsdManager.FAILURE_OPERATION_NOT_RUNNING);
|
clientRequestId, NsdManager.FAILURE_OPERATION_NOT_RUNNING);
|
||||||
@@ -2393,6 +2393,9 @@ public class NsdService extends INsdManager.Stub {
|
|||||||
request.getFoundServiceCount(),
|
request.getFoundServiceCount(),
|
||||||
request.getLostServiceCount(),
|
request.getLostServiceCount(),
|
||||||
request.getServicesCount());
|
request.getServicesCount());
|
||||||
|
} else if (listener instanceof ResolutionListener) {
|
||||||
|
mMetrics.reportServiceResolutionStop(transactionId,
|
||||||
|
request.calculateRequestDurationMs(mClock.elapsedRealtime()));
|
||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@@ -2419,6 +2422,8 @@ public class NsdService extends INsdManager.Stub {
|
|||||||
break;
|
break;
|
||||||
case NsdManager.RESOLVE_SERVICE:
|
case NsdManager.RESOLVE_SERVICE:
|
||||||
stopResolveService(transactionId);
|
stopResolveService(transactionId);
|
||||||
|
mMetrics.reportServiceResolutionStop(transactionId,
|
||||||
|
request.calculateRequestDurationMs(mClock.elapsedRealtime()));
|
||||||
break;
|
break;
|
||||||
case NsdManager.REGISTER_SERVICE:
|
case NsdManager.REGISTER_SERVICE:
|
||||||
unregisterService(transactionId);
|
unregisterService(transactionId);
|
||||||
@@ -2605,7 +2610,10 @@ public class NsdService extends INsdManager.Stub {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void onStopResolutionSucceeded(int listenerKey) {
|
void onStopResolutionSucceeded(int listenerKey, ClientRequest request) {
|
||||||
|
mMetrics.reportServiceResolutionStop(
|
||||||
|
request.mTransactionId,
|
||||||
|
request.calculateRequestDurationMs(mClock.elapsedRealtime()));
|
||||||
try {
|
try {
|
||||||
mCb.onStopResolutionSucceeded(listenerKey);
|
mCb.onStopResolutionSucceeded(listenerKey);
|
||||||
} catch (RemoteException e) {
|
} catch (RemoteException e) {
|
||||||
|
|||||||
@@ -201,4 +201,24 @@ class NetworkNsdReportedMetricsTest {
|
|||||||
assertEquals(durationMs, it.eventDurationMillisec)
|
assertEquals(durationMs, it.eventDurationMillisec)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun testReportServiceResolutionStop() {
|
||||||
|
val clientId = 99
|
||||||
|
val transactionId = 100
|
||||||
|
val durationMs = 10L
|
||||||
|
val metrics = NetworkNsdReportedMetrics(true /* isLegacy */, clientId, deps)
|
||||||
|
metrics.reportServiceResolutionStop(transactionId, durationMs)
|
||||||
|
|
||||||
|
val eventCaptor = ArgumentCaptor.forClass(NetworkNsdReported::class.java)
|
||||||
|
verify(deps).statsWrite(eventCaptor.capture())
|
||||||
|
eventCaptor.value.let {
|
||||||
|
assertTrue(it.isLegacy)
|
||||||
|
assertEquals(clientId, it.clientId)
|
||||||
|
assertEquals(transactionId, it.transactionId)
|
||||||
|
assertEquals(NsdEventType.NET_RESOLVE, it.type)
|
||||||
|
assertEquals(MdnsQueryResult.MQR_SERVICE_RESOLUTION_STOP, it.queryResult)
|
||||||
|
assertEquals(durationMs, it.eventDurationMillisec)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -717,6 +717,7 @@ public class NsdServiceTest {
|
|||||||
eq("local.") /* domain */, eq(IFACE_IDX_ANY));
|
eq("local.") /* domain */, eq(IFACE_IDX_ANY));
|
||||||
|
|
||||||
final int resolveId = resolvIdCaptor.getValue();
|
final int resolveId = resolvIdCaptor.getValue();
|
||||||
|
doReturn(TEST_TIME_MS + 10L).when(mClock).elapsedRealtime();
|
||||||
client.stopServiceResolution(resolveListener);
|
client.stopServiceResolution(resolveListener);
|
||||||
waitForIdle();
|
waitForIdle();
|
||||||
|
|
||||||
@@ -724,6 +725,7 @@ public class NsdServiceTest {
|
|||||||
verify(resolveListener, timeout(TIMEOUT_MS)).onResolutionStopped(argThat(ns ->
|
verify(resolveListener, timeout(TIMEOUT_MS)).onResolutionStopped(argThat(ns ->
|
||||||
request.getServiceName().equals(ns.getServiceName())
|
request.getServiceName().equals(ns.getServiceName())
|
||||||
&& request.getServiceType().equals(ns.getServiceType())));
|
&& request.getServiceType().equals(ns.getServiceType())));
|
||||||
|
verify(mMetrics).reportServiceResolutionStop(resolveId, 10L /* durationMs */);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -786,6 +788,7 @@ public class NsdServiceTest {
|
|||||||
eq(IFACE_IDX_ANY));
|
eq(IFACE_IDX_ANY));
|
||||||
|
|
||||||
final int getAddrId = getAddrIdCaptor.getValue();
|
final int getAddrId = getAddrIdCaptor.getValue();
|
||||||
|
doReturn(TEST_TIME_MS + 10L).when(mClock).elapsedRealtime();
|
||||||
client.stopServiceResolution(resolveListener);
|
client.stopServiceResolution(resolveListener);
|
||||||
waitForIdle();
|
waitForIdle();
|
||||||
|
|
||||||
@@ -793,6 +796,7 @@ public class NsdServiceTest {
|
|||||||
verify(resolveListener, timeout(TIMEOUT_MS)).onResolutionStopped(argThat(ns ->
|
verify(resolveListener, timeout(TIMEOUT_MS)).onResolutionStopped(argThat(ns ->
|
||||||
request.getServiceName().equals(ns.getServiceName())
|
request.getServiceName().equals(ns.getServiceName())
|
||||||
&& request.getServiceType().equals(ns.getServiceType())));
|
&& request.getServiceType().equals(ns.getServiceType())));
|
||||||
|
verify(mMetrics).reportServiceResolutionStop(getAddrId, 10L /* durationMs */);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void verifyUpdatedServiceInfo(NsdServiceInfo info, String serviceName,
|
private void verifyUpdatedServiceInfo(NsdServiceInfo info, String serviceName,
|
||||||
@@ -1355,8 +1359,8 @@ public class NsdServiceTest {
|
|||||||
final Network network = new Network(999);
|
final Network network = new Network(999);
|
||||||
final String serviceType = "_nsd._service._tcp";
|
final String serviceType = "_nsd._service._tcp";
|
||||||
final String constructedServiceType = "_service._tcp.local";
|
final String constructedServiceType = "_service._tcp.local";
|
||||||
final ArgumentCaptor<MdnsServiceBrowserListener> listenerCaptor =
|
final ArgumentCaptor<MdnsListener> listenerCaptor =
|
||||||
ArgumentCaptor.forClass(MdnsServiceBrowserListener.class);
|
ArgumentCaptor.forClass(MdnsListener.class);
|
||||||
final NsdServiceInfo request = new NsdServiceInfo(SERVICE_NAME, serviceType);
|
final NsdServiceInfo request = new NsdServiceInfo(SERVICE_NAME, serviceType);
|
||||||
request.setNetwork(network);
|
request.setNetwork(network);
|
||||||
client.resolveService(request, resolveListener);
|
client.resolveService(request, resolveListener);
|
||||||
@@ -1371,16 +1375,19 @@ public class NsdServiceTest {
|
|||||||
// Subtypes are not used for resolution, only for discovery
|
// Subtypes are not used for resolution, only for discovery
|
||||||
assertEquals(Collections.emptyList(), optionsCaptor.getValue().getSubtypes());
|
assertEquals(Collections.emptyList(), optionsCaptor.getValue().getSubtypes());
|
||||||
|
|
||||||
|
doReturn(TEST_TIME_MS + 10L).when(mClock).elapsedRealtime();
|
||||||
client.stopServiceResolution(resolveListener);
|
client.stopServiceResolution(resolveListener);
|
||||||
waitForIdle();
|
waitForIdle();
|
||||||
|
|
||||||
// Verify the listener has been unregistered.
|
// Verify the listener has been unregistered.
|
||||||
|
final MdnsListener listener = listenerCaptor.getValue();
|
||||||
verify(mDiscoveryManager, timeout(TIMEOUT_MS))
|
verify(mDiscoveryManager, timeout(TIMEOUT_MS))
|
||||||
.unregisterListener(eq(constructedServiceType), eq(listenerCaptor.getValue()));
|
.unregisterListener(eq(constructedServiceType), eq(listener));
|
||||||
verify(resolveListener, timeout(TIMEOUT_MS)).onResolutionStopped(argThat(ns ->
|
verify(resolveListener, timeout(TIMEOUT_MS)).onResolutionStopped(argThat(ns ->
|
||||||
request.getServiceName().equals(ns.getServiceName())
|
request.getServiceName().equals(ns.getServiceName())
|
||||||
&& request.getServiceType().equals(ns.getServiceType())));
|
&& request.getServiceType().equals(ns.getServiceType())));
|
||||||
verify(mSocketProvider, timeout(CLEANUP_DELAY_MS + TIMEOUT_MS)).requestStopWhenInactive();
|
verify(mSocketProvider, timeout(CLEANUP_DELAY_MS + TIMEOUT_MS)).requestStopWhenInactive();
|
||||||
|
verify(mMetrics).reportServiceResolutionStop(listener.mTransactionId, 10L /* durationMs */);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|||||||
Reference in New Issue
Block a user