diff options
author | Yaw Frempong <yawfrempong@google.com> | 2023-09-19 18:22:40 +0000 |
---|---|---|
committer | Yaw Frempong <yawfrempong@google.com> | 2023-09-21 14:18:04 +0000 |
commit | 61edd85ef4582b7fb8610910e5385759c20e477c (patch) | |
tree | 7415364bfbc4f0daf248e8d93988e13599105570 | |
parent | a760f47a2e108e10af84fb5b68c20d03024d2260 (diff) | |
download | AdServices-61edd85ef4582b7fb8610910e5385759c20e477c.tar.gz |
[Measurement] Add latency logging for failure event
Details: Expand logging implementation to include logging of latency in events of failure for reporting a for reporting and attribution.
Bug: 301113244
Test: AdServicesServiceCoreUnitTests
Change-Id: I185833de254d332ce9ef2ff0802783fb19555b64
8 files changed, 36 insertions, 60 deletions
diff --git a/adservices/service-core/java/com/android/adservices/service/measurement/attribution/AttributionJobHandler.java b/adservices/service-core/java/com/android/adservices/service/measurement/attribution/AttributionJobHandler.java index a8ec6ccecf..073fd001bf 100644 --- a/adservices/service-core/java/com/android/adservices/service/measurement/attribution/AttributionJobHandler.java +++ b/adservices/service-core/java/com/android/adservices/service/measurement/attribution/AttributionJobHandler.java @@ -176,6 +176,8 @@ class AttributionJobHandler { return mDatastoreManager.runInTransaction( measurementDao -> { Trigger trigger = measurementDao.getTrigger(triggerId); + attributionStatus.setAttributionDelay( + System.currentTimeMillis() - trigger.getTriggerTime()); if (trigger.getStatus() != Trigger.Status.PENDING) { attributionStatus.setFailureTypeFromTriggerStatus(trigger.getStatus()); @@ -258,8 +260,6 @@ class AttributionJobHandler { trigger.getEnrollmentId()); } attributeTriggerAndInsertAttribution(trigger, source, measurementDao); - long endTime = System.currentTimeMillis(); - attributionStatus.setAttributionDelay(endTime - trigger.getTriggerTime()); attributionStatus.setAttributionResult( AttributionStatus.AttributionResult.SUCCESS, isAggregateTriggeringStatusAttributed, @@ -1215,10 +1215,6 @@ class AttributionJobHandler { } private void logAttributionStats(AttributionStatus attributionStatus) { - if (!attributionStatus.getAttributionDelay().isPresent()) { - attributionStatus.setAttributionDelay(0L); - } - mLogger.logMeasurementAttributionStats( new MeasurementAttributionStats.Builder() .setCode(AD_SERVICES_MEASUREMENT_ATTRIBUTION) @@ -1228,7 +1224,7 @@ class AttributionJobHandler { .setFailureType(attributionStatus.getFailureType().ordinal()) .setSourceDerived(attributionStatus.isSourceDerived()) .setInstallAttribution(attributionStatus.isInstallAttribution()) - .setAttributionDelay(attributionStatus.getAttributionDelay().get()) + .setAttributionDelay(attributionStatus.getAttributionDelay()) .setSourceRegistrant(attributionStatus.getSourceRegistrant()) .build()); } diff --git a/adservices/service-core/java/com/android/adservices/service/measurement/attribution/AttributionStatus.java b/adservices/service-core/java/com/android/adservices/service/measurement/attribution/AttributionStatus.java index 85cf96481d..5a41fc8fb6 100644 --- a/adservices/service-core/java/com/android/adservices/service/measurement/attribution/AttributionStatus.java +++ b/adservices/service-core/java/com/android/adservices/service/measurement/attribution/AttributionStatus.java @@ -20,9 +20,7 @@ import com.android.adservices.service.measurement.EventSurfaceType; import com.android.adservices.service.measurement.Source; import com.android.adservices.service.measurement.Trigger; -import java.util.Optional; -import javax.annotation.Nullable; /** POJO for storing attribution status */ public class AttributionStatus { @@ -67,7 +65,7 @@ public class AttributionStatus { private FailureType mFailureType; private boolean mIsSourceDerived; private boolean mIsInstallAttribution; - @Nullable private Long mAttributionDelay; + private long mAttributionDelay; private String mSourceRegistrant; public AttributionStatus() { @@ -78,6 +76,7 @@ public class AttributionStatus { mIsSourceDerived = false; mIsInstallAttribution = false; mSourceRegistrant = ""; + mAttributionDelay = 0L; } /** Get the type of the source that is getting attributed. */ @@ -196,12 +195,12 @@ public class AttributionStatus { } /** Get attribution delay. */ - public Optional<Long> getAttributionDelay() { - return Optional.ofNullable(mAttributionDelay); + public long getAttributionDelay() { + return mAttributionDelay; } /** Set attribution delay. */ - public void setAttributionDelay(Long attributionDelay) { + public void setAttributionDelay(long attributionDelay) { mAttributionDelay = attributionDelay; } diff --git a/adservices/service-core/java/com/android/adservices/service/measurement/registration/AsyncFetchStatus.java b/adservices/service-core/java/com/android/adservices/service/measurement/registration/AsyncFetchStatus.java index 17dbb29226..0fda1cc61a 100644 --- a/adservices/service-core/java/com/android/adservices/service/measurement/registration/AsyncFetchStatus.java +++ b/adservices/service-core/java/com/android/adservices/service/measurement/registration/AsyncFetchStatus.java @@ -16,9 +16,7 @@ package com.android.adservices.service.measurement.registration; -import java.util.Optional; -import javax.annotation.Nullable; /** POJO for storing source and trigger fetcher status */ public class AsyncFetchStatus { @@ -45,9 +43,9 @@ public class AsyncFetchStatus { private EntityStatus mEntityStatus; - @Nullable private Long mResponseSize; + private long mResponseSize; - @Nullable private Long mRegistrationDelay; + private long mRegistrationDelay; private boolean mIsRedirectError; @@ -55,6 +53,8 @@ public class AsyncFetchStatus { mResponseStatus = ResponseStatus.UNKNOWN; mEntityStatus = EntityStatus.UNKNOWN; mIsRedirectError = false; + mResponseSize = 0L; + mRegistrationDelay = 0L; } /** Get the status of a communication with an Ad Tech server. */ @@ -83,22 +83,22 @@ public class AsyncFetchStatus { } /** Get response header size. */ - public Optional<Long> getResponseSize() { - return Optional.ofNullable(mResponseSize); + public long getResponseSize() { + return mResponseSize; } /** Set response header size. */ - public void setResponseSize(Long responseSize) { + public void setResponseSize(long responseSize) { mResponseSize = responseSize; } /** Get registration delay. */ - public Optional<Long> getRegistrationDelay() { - return Optional.ofNullable(mRegistrationDelay); + public long getRegistrationDelay() { + return mRegistrationDelay; } /** Set registration delay. */ - public void setRegistrationDelay(Long registrationDelay) { + public void setRegistrationDelay(long registrationDelay) { mRegistrationDelay = registrationDelay; } diff --git a/adservices/service-core/java/com/android/adservices/service/measurement/registration/FetcherUtil.java b/adservices/service-core/java/com/android/adservices/service/measurement/registration/FetcherUtil.java index 158f0859ba..e9fd73d79e 100644 --- a/adservices/service-core/java/com/android/adservices/service/measurement/registration/FetcherUtil.java +++ b/adservices/service-core/java/com/android/adservices/service/measurement/registration/FetcherUtil.java @@ -250,10 +250,7 @@ class FetcherUtil { AdServicesLogger logger, AsyncRegistration asyncRegistration, AsyncFetchStatus asyncFetchStatus) { - long headerSize = 0; - if (asyncFetchStatus.getResponseSize().isPresent()) { - headerSize = asyncFetchStatus.getResponseSize().get(); - } + long headerSize = asyncFetchStatus.getResponseSize(); long maxSize = flags.getMaxResponseBasedRegistrationPayloadSizeBytes(); String adTechDomain = null; @@ -273,7 +270,7 @@ class FetcherUtil { getSurfaceType(asyncRegistration), getStatus(asyncFetchStatus), getFailureType(asyncFetchStatus), - asyncFetchStatus.getRegistrationDelay().get(), + asyncFetchStatus.getRegistrationDelay(), getSourceRegistrantToLog(asyncRegistration)) .setAdTechDomain(adTechDomain) .build()); diff --git a/adservices/service-core/java/com/android/adservices/service/measurement/reporting/AggregateReportingJobHandler.java b/adservices/service-core/java/com/android/adservices/service/measurement/reporting/AggregateReportingJobHandler.java index 2c4d3cc5f1..6e527bb9d9 100644 --- a/adservices/service-core/java/com/android/adservices/service/measurement/reporting/AggregateReportingJobHandler.java +++ b/adservices/service-core/java/com/android/adservices/service/measurement/reporting/AggregateReportingJobHandler.java @@ -156,12 +156,8 @@ public class AggregateReportingJobHandler { } ReportingStatus reportingStatus = new ReportingStatus(); - if (mReportType != null) { - reportingStatus.setReportType(mReportType); - } - if (mUploadMethod != null) { - reportingStatus.setUploadMethod(mUploadMethod); - } + reportingStatus.setReportType(mReportType); + reportingStatus.setUploadMethod(mUploadMethod); final String aggregateReportId = reportIds.get(i); @AdServicesStatusUtils.StatusCode int result = performReport(aggregateReportId, keys.get(i), reportingStatus); @@ -246,6 +242,8 @@ public class AggregateReportingJobHandler { return AdServicesStatusUtils.STATUS_IO_ERROR; } AggregateReport aggregateReport = aggregateReportOpt.get(); + reportingStatus.setReportingDelay( + System.currentTimeMillis() - aggregateReport.getScheduledReportTime()); reportingStatus.setSourceRegistrant(getAppPackageName(aggregateReport)); if (mIsDebugInstance && aggregateReport.getDebugReportStatus() @@ -278,9 +276,6 @@ public class AggregateReportingJobHandler { }); if (success) { - long deliveryTime = System.currentTimeMillis(); - reportingStatus.setReportingDelay( - deliveryTime - aggregateReport.getScheduledReportTime()); return AdServicesStatusUtils.STATUS_SUCCESS; } else { reportingStatus.setFailureStatus(ReportingStatus.FailureStatus.DATASTORE); @@ -302,8 +297,8 @@ public class AggregateReportingJobHandler { return AdServicesStatusUtils.STATUS_IO_ERROR; } catch (JSONException e) { LogUtil.d(e, "Serialization error occurred at aggregate report delivery."); - // TODO(b/298330312): Change to defined error codes reportingStatus.setFailureStatus(ReportingStatus.FailureStatus.SERIALIZATION_ERROR); + // TODO(b/298330312): Change to defined error codes ErrorLogUtil.e( e, AD_SERVICES_ERROR_REPORTED__ERROR_CODE__ERROR_CODE_UNSPECIFIED, @@ -327,8 +322,8 @@ public class AggregateReportingJobHandler { return AdServicesStatusUtils.STATUS_UNKNOWN_ERROR; } catch (CryptoException e) { LogUtil.e(e, e.toString()); - // TODO(b/298330312): Change to defined error codes reportingStatus.setFailureStatus(ReportingStatus.FailureStatus.ENCRYPTION_ERROR); + // TODO(b/298330312): Change to defined error codes ErrorLogUtil.e( e, AD_SERVICES_ERROR_REPORTED__ERROR_CODE__ERROR_CODE_UNSPECIFIED, @@ -398,9 +393,6 @@ public class AggregateReportingJobHandler { } private void logReportingStats(ReportingStatus reportingStatus) { - if (!reportingStatus.getReportingDelay().isPresent()) { - reportingStatus.setReportingDelay(0L); - } mLogger.logMeasurementReports( new MeasurementReportsStats.Builder() .setCode(AD_SERVICES_MESUREMENT_REPORTS_UPLOADED) @@ -408,7 +400,7 @@ public class AggregateReportingJobHandler { .setResultCode(reportingStatus.getUploadStatus().getValue()) .setFailureType(reportingStatus.getFailureStatus().getValue()) .setUploadMethod(reportingStatus.getUploadMethod().getValue()) - .setReportingDelay(reportingStatus.getReportingDelay().get()) + .setReportingDelay(reportingStatus.getReportingDelay()) .setSourceRegistrant(reportingStatus.getSourceRegistrant()) .build()); } diff --git a/adservices/service-core/java/com/android/adservices/service/measurement/reporting/DebugReportingJobHandler.java b/adservices/service-core/java/com/android/adservices/service/measurement/reporting/DebugReportingJobHandler.java index 23d2fe4d24..a2b3331c6b 100644 --- a/adservices/service-core/java/com/android/adservices/service/measurement/reporting/DebugReportingJobHandler.java +++ b/adservices/service-core/java/com/android/adservices/service/measurement/reporting/DebugReportingJobHandler.java @@ -256,9 +256,6 @@ public class DebugReportingJobHandler { } private void logReportingStats(ReportingStatus reportingStatus) { - if (!reportingStatus.getReportingDelay().isPresent()) { - reportingStatus.setReportingDelay(0L); - } mLogger.logMeasurementReports( new MeasurementReportsStats.Builder() .setCode(AD_SERVICES_MESUREMENT_REPORTS_UPLOADED) @@ -266,7 +263,7 @@ public class DebugReportingJobHandler { .setResultCode(reportingStatus.getUploadStatus().getValue()) .setFailureType(reportingStatus.getFailureStatus().getValue()) .setUploadMethod(reportingStatus.getUploadMethod().getValue()) - .setReportingDelay(reportingStatus.getReportingDelay().get()) + .setReportingDelay(reportingStatus.getReportingDelay()) .setSourceRegistrant(reportingStatus.getSourceRegistrant()) .build()); } diff --git a/adservices/service-core/java/com/android/adservices/service/measurement/reporting/EventReportingJobHandler.java b/adservices/service-core/java/com/android/adservices/service/measurement/reporting/EventReportingJobHandler.java index 94e98d8ffa..574199d211 100644 --- a/adservices/service-core/java/com/android/adservices/service/measurement/reporting/EventReportingJobHandler.java +++ b/adservices/service-core/java/com/android/adservices/service/measurement/reporting/EventReportingJobHandler.java @@ -221,6 +221,7 @@ public class EventReportingJobHandler { return AdServicesStatusUtils.STATUS_IO_ERROR; } EventReport eventReport = eventReportOpt.get(); + reportingStatus.setReportingDelay(System.currentTimeMillis() - eventReport.getReportTime()); reportingStatus.setSourceRegistrant(getAppPackageName(eventReport)); if (mIsDebugInstance && eventReport.getDebugReportStatus() != EventReport.DebugReportStatus.PENDING) { @@ -252,17 +253,15 @@ public class EventReportingJobHandler { }); if (success) { - long deliveryTime = System.currentTimeMillis(); - reportingStatus.setReportingDelay(deliveryTime - eventReport.getReportTime()); return AdServicesStatusUtils.STATUS_SUCCESS; } else { reportingStatus.setFailureStatus(ReportingStatus.FailureStatus.DATASTORE); return AdServicesStatusUtils.STATUS_IO_ERROR; } } else { - // TODO: Determine behavior for other response codes? reportingStatus.setFailureStatus( ReportingStatus.FailureStatus.UNSUCCESSFUL_HTTP_RESPONSE_CODE); + // TODO: Determine behavior for other response codes? return AdServicesStatusUtils.STATUS_IO_ERROR; } } catch (IOException e) { @@ -348,9 +347,6 @@ public class EventReportingJobHandler { } private void logReportingStats(ReportingStatus reportingStatus) { - if (!reportingStatus.getReportingDelay().isPresent()) { - reportingStatus.setReportingDelay(0L); - } mLogger.logMeasurementReports( new MeasurementReportsStats.Builder() .setCode(AD_SERVICES_MESUREMENT_REPORTS_UPLOADED) @@ -358,7 +354,7 @@ public class EventReportingJobHandler { .setResultCode(reportingStatus.getUploadStatus().getValue()) .setFailureType(reportingStatus.getFailureStatus().getValue()) .setUploadMethod(reportingStatus.getUploadMethod().getValue()) - .setReportingDelay(reportingStatus.getReportingDelay().get()) + .setReportingDelay(reportingStatus.getReportingDelay()) .setSourceRegistrant(reportingStatus.getSourceRegistrant()) .build()); } diff --git a/adservices/service-core/java/com/android/adservices/service/measurement/reporting/ReportingStatus.java b/adservices/service-core/java/com/android/adservices/service/measurement/reporting/ReportingStatus.java index 0f0a5676f5..d7aa811fd1 100644 --- a/adservices/service-core/java/com/android/adservices/service/measurement/reporting/ReportingStatus.java +++ b/adservices/service-core/java/com/android/adservices/service/measurement/reporting/ReportingStatus.java @@ -16,9 +16,7 @@ package com.android.adservices.service.measurement.reporting; -import android.annotation.Nullable; -import java.util.Optional; /** POJO for storing aggregate and event reporting status */ public class ReportingStatus { @@ -124,7 +122,7 @@ public class ReportingStatus { private UploadMethod mUploadMethod; - @Nullable private Long mReportingDelay; + private long mReportingDelay; private String mSourceRegistrant; @@ -133,6 +131,7 @@ public class ReportingStatus { mUploadStatus = UploadStatus.UNKNOWN; mFailureStatus = FailureStatus.UNKNOWN; mUploadMethod = UploadMethod.UNKNOWN; + mReportingDelay = 0L; } /** Get the type of report that is being uploaded. */ @@ -232,12 +231,12 @@ public class ReportingStatus { } /** Get registration delay. */ - public Optional<Long> getReportingDelay() { - return Optional.ofNullable(mReportingDelay); + public long getReportingDelay() { + return mReportingDelay; } /** Set registration delay. */ - public void setReportingDelay(Long reportingDelay) { + public void setReportingDelay(long reportingDelay) { mReportingDelay = reportingDelay; } |