in firebase-perf/src/main/java/com/google/firebase/perf/metrics/validator/FirebasePerfNetworkValidator.java [49:135]
public boolean isValidPerfMetric() {
if (isEmptyUrl(networkMetric.getUrl())) {
logger.warn("URL is missing:" + networkMetric.getUrl());
return false;
}
URI uri = getResultUrl(networkMetric.getUrl());
if (uri == null) {
logger.warn("URL cannot be parsed");
return false;
}
if (!isAllowlisted(uri, appContext)) {
logger.warn("URL fails allowlist rule: " + uri);
return false;
}
if (!isValidHost(uri.getHost())) {
logger.warn("URL host is null or invalid");
return false;
}
if (!isValidScheme(uri.getScheme())) {
logger.warn("URL scheme is null or invalid");
return false;
}
if (!isValidUserInfo(uri.getUserInfo())) {
logger.warn("URL user info is null");
return false;
}
if (!isValidPort(uri.getPort())) {
logger.warn("URL port is less than or equal to 0");
return false;
}
if (!isValidHttpMethod(networkMetric.hasHttpMethod() ? networkMetric.getHttpMethod() : null)) {
logger.warn("HTTP Method is null or invalid: " + networkMetric.getHttpMethod());
return false;
}
if (networkMetric.hasHttpResponseCode()
&& !isValidHttpResponseCode(networkMetric.getHttpResponseCode())) {
logger.warn("HTTP ResponseCode is a negative value:" + networkMetric.getHttpResponseCode());
return false;
}
if (networkMetric.hasRequestPayloadBytes()
&& !isValidPayload(networkMetric.getRequestPayloadBytes())) {
logger.warn("Request Payload is a negative value:" + networkMetric.getRequestPayloadBytes());
return false;
}
if (networkMetric.hasResponsePayloadBytes()
&& !isValidPayload(networkMetric.getResponsePayloadBytes())) {
logger.warn(
"Response Payload is a negative value:" + networkMetric.getResponsePayloadBytes());
return false;
}
if (!networkMetric.hasClientStartTimeUs() || networkMetric.getClientStartTimeUs() <= 0) {
logger.warn(
"Start time of the request is null, or zero, or a negative value:"
+ networkMetric.getClientStartTimeUs());
return false;
}
if (networkMetric.hasTimeToRequestCompletedUs()
&& !isValidTime(networkMetric.getTimeToRequestCompletedUs())) {
logger.warn(
"Time to complete the request is a negative value:"
+ networkMetric.getTimeToRequestCompletedUs());
return false;
}
if (networkMetric.hasTimeToResponseInitiatedUs()
&& !isValidTime(networkMetric.getTimeToResponseInitiatedUs())) {
logger.warn(
"Time from the start of the request to the start of the response is null or a "
+ "negative value:"
+ networkMetric.getTimeToResponseInitiatedUs());
return false;
}
if (!networkMetric.hasTimeToResponseCompletedUs()
|| networkMetric.getTimeToResponseCompletedUs() <= 0) {
logger.warn(
"Time from the start of the request to the end of the response is null, negative or "
+ "zero:"
+ networkMetric.getTimeToResponseCompletedUs());
return false;
}
// Don't log any requests with a connection error set
if (!networkMetric.hasHttpResponseCode()) {
logger.warn("Did not receive a HTTP Response Code");
return false;
}
return true;
}