• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2022 Google LLC
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 package com.google.android.libraries.mobiledatadownload.internal.logging;
17 
18 import com.google.auto.value.AutoValue;
19 import com.google.common.util.concurrent.AsyncCallable;
20 import com.google.common.util.concurrent.ListenableFuture;
21 import com.google.mobiledatadownload.LogEnumsProto.MddClientEvent;
22 import com.google.mobiledatadownload.LogEnumsProto.MddDownloadResult;
23 import com.google.mobiledatadownload.LogProto.DataDownloadFileGroupStats;
24 import com.google.mobiledatadownload.LogProto.MddFileGroupStatus;
25 import com.google.mobiledatadownload.LogProto.MddStorageStats;
26 import java.util.List;
27 
28 /** Interface for remote logging. */
29 public interface EventLogger {
30 
31   /** Log an mdd event */
logEventSampled(MddClientEvent.Code eventCode)32   void logEventSampled(MddClientEvent.Code eventCode);
33 
34   /** Log an mdd event with an associated file group. */
logEventSampled( MddClientEvent.Code eventCode, String fileGroupName, int fileGroupVersionNumber, long buildId, String variantId)35   void logEventSampled(
36       MddClientEvent.Code eventCode,
37       String fileGroupName,
38       int fileGroupVersionNumber,
39       long buildId,
40       String variantId);
41 
42   /**
43    * Log an mdd event. This not sampled. Caller should make sure this method is called after
44    * sampling at the passed in value of sample interval.
45    */
logEventAfterSample(MddClientEvent.Code eventCode, int sampleInterval)46   void logEventAfterSample(MddClientEvent.Code eventCode, int sampleInterval);
47 
48   /**
49    * Log mdd file group stats. The buildFileGroupStats callable is only called if the event is going
50    * to be logged.
51    *
52    * @param buildFileGroupStats callable which builds a List of FileGroupStatusWithDetails. Each
53    *     file group status will be logged individually.
54    * @return a future that completes when the logging work is done. The future will complete with a
55    *     failure if the callable fails or if there is an error when logging.
56    */
logMddFileGroupStats( AsyncCallable<List<FileGroupStatusWithDetails>> buildFileGroupStats)57   ListenableFuture<Void> logMddFileGroupStats(
58       AsyncCallable<List<FileGroupStatusWithDetails>> buildFileGroupStats);
59 
60   /** Simple wrapper class for MDD file group stats and details. */
61   @AutoValue
62   abstract class FileGroupStatusWithDetails {
fileGroupStatus()63     abstract MddFileGroupStatus fileGroupStatus();
64 
fileGroupDetails()65     abstract DataDownloadFileGroupStats fileGroupDetails();
66 
create( MddFileGroupStatus fileGroupStatus, DataDownloadFileGroupStats fileGroupDetails)67     static FileGroupStatusWithDetails create(
68         MddFileGroupStatus fileGroupStatus, DataDownloadFileGroupStats fileGroupDetails) {
69       return new AutoValue_EventLogger_FileGroupStatusWithDetails(
70           fileGroupStatus, fileGroupDetails);
71     }
72   }
73 
74   /** Log mdd api call stats. */
logMddApiCallStats(DataDownloadFileGroupStats fileGroupDetails, Void apiCallStats)75   void logMddApiCallStats(DataDownloadFileGroupStats fileGroupDetails, Void apiCallStats);
76 
logMddLibApiResultLog(Void mddLibApiResultLog)77   void logMddLibApiResultLog(Void mddLibApiResultLog);
78 
79   /**
80    * Log mdd storage stats. The buildMddStorageStats callable is only called if the event is going
81    * to be logged.
82    *
83    * @param buildMddStorageStats callable which builds the MddStorageStats to log.
84    * @return a future that completes when the logging work is done. The future will complete with a
85    *     failure if the callable fails or if there is an error when logging.
86    */
logMddStorageStats(AsyncCallable<MddStorageStats> buildMddStorageStats)87   ListenableFuture<Void> logMddStorageStats(AsyncCallable<MddStorageStats> buildMddStorageStats);
88 
89   /**
90    * Log mdd network stats. The buildMddNetworkStats callable is only called if the event is going
91    * to be logged.
92    *
93    * @param buildMddNetworkStats callable which builds the Void to log.
94    * @return a future that completes when the logging work is done. The future will complete with a
95    *     failure if the callable fails or if there is an error when logging.
96    */
logMddNetworkStats(AsyncCallable<Void> buildMddNetworkStats)97   ListenableFuture<Void> logMddNetworkStats(AsyncCallable<Void> buildMddNetworkStats);
98 
99   /** Log the number of unaccounted files/metadata deleted during maintenance */
logMddDataDownloadFileExpirationEvent(int eventCode, int count)100   void logMddDataDownloadFileExpirationEvent(int eventCode, int count);
101 
102   /** Log the network savings of MDD download features */
logMddNetworkSavings( DataDownloadFileGroupStats fileGroupDetails, int code, long fullFileSize, long downloadedFileSize, String fileId, int deltaIndex)103   void logMddNetworkSavings(
104       DataDownloadFileGroupStats fileGroupDetails,
105       int code,
106       long fullFileSize,
107       long downloadedFileSize,
108       String fileId,
109       int deltaIndex);
110 
111   /** Log mdd download result events. */
logMddDownloadResult( MddDownloadResult.Code code, DataDownloadFileGroupStats fileGroupDetails)112   void logMddDownloadResult(
113       MddDownloadResult.Code code, DataDownloadFileGroupStats fileGroupDetails);
114 
115   /** Log stats of mdd {@code getFileGroup} and {@code getFileGroupByFilter} calls. */
logMddQueryStats(DataDownloadFileGroupStats fileGroupDetails)116   void logMddQueryStats(DataDownloadFileGroupStats fileGroupDetails);
117 
118   /** Log mdd stats on android sharing events. */
logMddAndroidSharingLog(Void event)119   void logMddAndroidSharingLog(Void event);
120 
121   /** Log mdd download latency. */
logMddDownloadLatency(DataDownloadFileGroupStats fileGroupStats, Void downloadLatency)122   void logMddDownloadLatency(DataDownloadFileGroupStats fileGroupStats, Void downloadLatency);
123 
124   /** Log mdd usage event. */
logMddUsageEvent(DataDownloadFileGroupStats fileGroupDetails, Void usageEventLog)125   void logMddUsageEvent(DataDownloadFileGroupStats fileGroupDetails, Void usageEventLog);
126 
127   /** Log new config received event. */
logNewConfigReceived( DataDownloadFileGroupStats fileGroupDetails, Void newConfigReceivedInfo)128   void logNewConfigReceived(
129       DataDownloadFileGroupStats fileGroupDetails, Void newConfigReceivedInfo);
130 }
131