@@ -1014,31 +1014,19 @@ static ListLogEntriesRequest listLogEntriesRequest(
1014
1014
if (orderBy != null ) {
1015
1015
builder .setOrderBy (orderBy );
1016
1016
}
1017
- String filter = EntryListOption .OptionType .FILTER .get (options );
1018
- // Make sure timestamp filter is either explicitly specified or we add a default
1019
- // time filter
1020
- // of 24 hours back to be inline with gcloud behavior for the same API
1017
+ String filter = generateFilter (EntryListOption .OptionType .FILTER .get (options ));
1021
1018
if (filter != null ) {
1022
- if (!Ascii .toLowerCase (filter ).contains ("timestamp" )) {
1023
- filter =
1024
- String .format (
1025
- "%s AND %s" , filter , defaultTimestampFilterCreator .createDefaultTimestampFilter ());
1026
- }
1027
1019
builder .setFilter (filter );
1028
- } else {
1029
- // If filter is not specified, default filter is looking back 24 hours in line
1030
- // with gcloud
1031
- // behavior
1032
- builder .setFilter (defaultTimestampFilterCreator .createDefaultTimestampFilter ());
1033
1020
}
1034
-
1035
1021
return builder .build ();
1036
1022
}
1037
1023
1038
1024
private static ApiFuture <AsyncPage <LogEntry >> listLogEntriesAsync (
1039
1025
final LoggingOptions serviceOptions , final Map <Option .OptionType , ?> options ) {
1026
+ // Make sure to set a filter option which later can be reused in subsequent calls
1027
+ final Map <Option .OptionType , ?> updatedOptions = updateFilter (options );
1040
1028
final ListLogEntriesRequest request =
1041
- listLogEntriesRequest (serviceOptions .getProjectId (), options );
1029
+ listLogEntriesRequest (serviceOptions .getProjectId (), updatedOptions );
1042
1030
ApiFuture <ListLogEntriesResponse > list = serviceOptions .getLoggingRpcV2 ().list (request );
1043
1031
return transform (
1044
1032
list ,
@@ -1055,7 +1043,7 @@ public AsyncPage<LogEntry> apply(ListLogEntriesResponse listLogEntriesResponse)
1055
1043
? null
1056
1044
: listLogEntriesResponse .getNextPageToken ();
1057
1045
return new AsyncPageImpl <>(
1058
- new LogEntryPageFetcher (serviceOptions , cursor , options ), cursor , entries );
1046
+ new LogEntryPageFetcher (serviceOptions , cursor , updatedOptions ), cursor , entries );
1059
1047
}
1060
1048
});
1061
1049
}
@@ -1137,6 +1125,37 @@ public void close() throws Exception {
1137
1125
return optionMap ;
1138
1126
}
1139
1127
1128
+ static Map <Option .OptionType , ?> updateFilter (final Map <Option .OptionType , ?> options ) {
1129
+ // We should see if filter provided in otiopns have a timestamp parameter
1130
+ // and if not, it should be added with further update of options map.
1131
+ String existingFilter = EntryListOption .OptionType .FILTER .get (options );
1132
+ String newFilter = generateFilter (existingFilter );
1133
+ if (newFilter .equals (existingFilter )) {
1134
+ return options ;
1135
+ }
1136
+ // Update
1137
+ Map <Option .OptionType , Object > optionsCopy = Maps .newHashMap (options );
1138
+ optionsCopy .put (EntryListOption .OptionType .FILTER , newFilter );
1139
+ return optionsCopy ;
1140
+ }
1141
+
1142
+ static String generateFilter (String filter ) {
1143
+ String newFilter = filter ;
1144
+ // Make sure timestamp filter is either explicitly specified or we add a default
1145
+ // time filter of 24 hours back to be inline with gcloud behavior for the same API
1146
+ if (newFilter != null ) {
1147
+ if (!Ascii .toLowerCase (filter ).contains ("timestamp" )) {
1148
+ newFilter =
1149
+ String .format (
1150
+ "%s AND %s" ,
1151
+ newFilter , defaultTimestampFilterCreator .createDefaultTimestampFilter ());
1152
+ }
1153
+ } else {
1154
+ newFilter = defaultTimestampFilterCreator .createDefaultTimestampFilter ();
1155
+ }
1156
+ return newFilter ;
1157
+ }
1158
+
1140
1159
@ VisibleForTesting
1141
1160
int getNumPendingWrites () {
1142
1161
return pendingWrites .size ();
0 commit comments