• 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.MddDownloadLatency;
25 import com.google.mobiledatadownload.LogProto.MddFileGroupStatus;
26 import com.google.mobiledatadownload.LogProto.MddLibApiResultLog;
27 import com.google.mobiledatadownload.LogProto.MddNetworkStats;
28 import com.google.mobiledatadownload.LogProto.MddStorageStats;
29 
30 import java.util.List;
31 
32 /** Interface for remote logging. */
33 public interface EventLogger {
34 
35     /** Log an mdd event */
logEventSampled(MddClientEvent.Code eventCode)36     void logEventSampled(MddClientEvent.Code eventCode);
37 
38     /** Log an mdd event with an associated file group. */
logEventSampled( MddClientEvent.Code eventCode, String fileGroupName, int fileGroupVersionNumber, long buildId, String variantId)39     void logEventSampled(
40             MddClientEvent.Code eventCode,
41             String fileGroupName,
42             int fileGroupVersionNumber,
43             long buildId,
44             String variantId);
45 
46     /**
47      * Log an mdd event. This not sampled. Caller should make sure this method is called after
48      * sampling at the passed in value of sample interval.
49      */
logEventAfterSample(MddClientEvent.Code eventCode, int sampleInterval)50     void logEventAfterSample(MddClientEvent.Code eventCode, int sampleInterval);
51 
52     /**
53      * Log mdd file group stats. The buildFileGroupStats callable is only called if the event is
54      * going
55      * to be logged.
56      *
57      * @param buildFileGroupStats callable which builds a List of FileGroupStatusWithDetails. Each
58      *                            file group status will be logged individually.
59      * @return a future that completes when the logging work is done. The future will complete
60      * with a
61      * failure if the callable fails or if there is an error when logging.
62      */
logMddFileGroupStats( AsyncCallable<List<FileGroupStatusWithDetails>> buildFileGroupStats)63     ListenableFuture<Void> logMddFileGroupStats(
64             AsyncCallable<List<FileGroupStatusWithDetails>> buildFileGroupStats);
65 
66     /** Simple wrapper class for MDD file group stats and details. */
67     @AutoValue
68     abstract class FileGroupStatusWithDetails {
fileGroupStatus()69         abstract MddFileGroupStatus fileGroupStatus();
70 
fileGroupDetails()71         abstract DataDownloadFileGroupStats fileGroupDetails();
72 
create( MddFileGroupStatus fileGroupStatus, DataDownloadFileGroupStats fileGroupDetails)73         static FileGroupStatusWithDetails create(
74                 MddFileGroupStatus fileGroupStatus, DataDownloadFileGroupStats fileGroupDetails) {
75             return new AutoValue_EventLogger_FileGroupStatusWithDetails(
76                     fileGroupStatus, fileGroupDetails);
77         }
78     }
79 
80     /** Log mdd api call stats. */
logMddApiCallStats(DataDownloadFileGroupStats fileGroupDetails, Void apiCallStats)81     void logMddApiCallStats(DataDownloadFileGroupStats fileGroupDetails, Void apiCallStats);
82 
logMddLibApiResultLog(MddLibApiResultLog mddLibApiResultLog)83     void logMddLibApiResultLog(MddLibApiResultLog mddLibApiResultLog);
84 
85     /**
86      * Log mdd storage stats. The buildMddStorageStats callable is only called if the event is going
87      * to be logged.
88      *
89      * @param buildMddStorageStats callable which builds the MddStorageStats to log.
90      * @return a future that completes when the logging work is done. The future will complete
91      * with a
92      * failure if the callable fails or if there is an error when logging.
93      */
logMddStorageStats(AsyncCallable<MddStorageStats> buildMddStorageStats)94     ListenableFuture<Void> logMddStorageStats(AsyncCallable<MddStorageStats> buildMddStorageStats);
95 
96     /**
97      * Log mdd network stats. The buildMddNetworkStats callable is only called if the event is going
98      * to be logged.
99      *
100      * @param buildMddNetworkStats callable which builds the MddNetworkStats to log.
101      * @return a future that completes when the logging work is done. The future will complete
102      * with a
103      * failure if the callable fails or if there is an error when logging.
104      */
logMddNetworkStats(AsyncCallable<MddNetworkStats> buildMddNetworkStats)105     ListenableFuture<Void> logMddNetworkStats(AsyncCallable<MddNetworkStats> buildMddNetworkStats);
106 
107     /** Log the number of unaccounted files/metadata deleted during maintenance */
logMddDataDownloadFileExpirationEvent(int eventCode, int count)108     void logMddDataDownloadFileExpirationEvent(int eventCode, int count);
109 
110     /** Log the network savings of MDD download features */
logMddNetworkSavings( DataDownloadFileGroupStats fileGroupDetails, int code, long fullFileSize, long downloadedFileSize, String fileId, int deltaIndex)111     void logMddNetworkSavings(
112             DataDownloadFileGroupStats fileGroupDetails,
113             int code,
114             long fullFileSize,
115             long downloadedFileSize,
116             String fileId,
117             int deltaIndex);
118 
119     /** Log mdd download result events. */
logMddDownloadResult( MddDownloadResult.Code code, DataDownloadFileGroupStats fileGroupDetails)120     void logMddDownloadResult(
121             MddDownloadResult.Code code, DataDownloadFileGroupStats fileGroupDetails);
122 
123     /** Log stats of mdd {@code getFileGroup} and {@code getFileGroupByFilter} calls. */
logMddQueryStats(DataDownloadFileGroupStats fileGroupDetails)124     void logMddQueryStats(DataDownloadFileGroupStats fileGroupDetails);
125 
126     /** Log mdd stats on android sharing events. */
logMddAndroidSharingLog(Void event)127     void logMddAndroidSharingLog(Void event);
128 
129     /** Log mdd download latency. */
logMddDownloadLatency( DataDownloadFileGroupStats fileGroupStats, MddDownloadLatency downloadLatency)130     void logMddDownloadLatency(
131             DataDownloadFileGroupStats fileGroupStats, MddDownloadLatency downloadLatency);
132 
133     /** Log mdd usage event. */
logMddUsageEvent(DataDownloadFileGroupStats fileGroupDetails, Void usageEventLog)134     void logMddUsageEvent(DataDownloadFileGroupStats fileGroupDetails, Void usageEventLog);
135 
136     /** Log new config received event. */
logNewConfigReceived( DataDownloadFileGroupStats fileGroupDetails, Void newConfigReceivedInfo)137     void logNewConfigReceived(
138             DataDownloadFileGroupStats fileGroupDetails, Void newConfigReceivedInfo);
139 }
140