> listMonitoredResourceDescripto
* {@link EntryListOption#pageToken(String)} to specify the page token from which to start listing
* entries. Use {@link EntryListOption#sortOrder(SortingField, SortingOrder)} to sort log entries
* according to your preferred order (default is most-recent last). Use {@link
- * EntryListOption#filter(String)} to filter listed log entries.
+ * EntryListOption#filter(String)} to filter listed log entries. By default a 24 hour filter is
+ * applied.
*
* Example of listing log entries for a specific log.
*
@@ -1231,7 +1232,8 @@ ApiFuture> listMonitoredResourceDescripto
* specify the page size. Use {@link EntryListOption#pageToken(String)} to specify the page token
* from which to start listing entries. Use {@link EntryListOption#sortOrder(SortingField,
* SortingOrder)} to sort log entries according to your preferred order (default is most-recent
- * last). Use {@link EntryListOption#filter(String)} to filter listed log entries.
+ * last). Use {@link EntryListOption#filter(String)} to filter listed log entries. By default a 24
+ * hour filter is applied.
*
* Example of asynchronously listing log entries for a specific log.
*
diff --git a/google-cloud-logging/src/main/java/com/google/cloud/logging/LoggingImpl.java b/google-cloud-logging/src/main/java/com/google/cloud/logging/LoggingImpl.java
index e6bc7a1ec..48aca324c 100644
--- a/google-cloud-logging/src/main/java/com/google/cloud/logging/LoggingImpl.java
+++ b/google-cloud-logging/src/main/java/com/google/cloud/logging/LoggingImpl.java
@@ -1014,31 +1014,19 @@ static ListLogEntriesRequest listLogEntriesRequest(
if (orderBy != null) {
builder.setOrderBy(orderBy);
}
- String filter = EntryListOption.OptionType.FILTER.get(options);
- // Make sure timestamp filter is either explicitly specified or we add a default
- // time filter
- // of 24 hours back to be inline with gcloud behavior for the same API
+ String filter = generateFilter(EntryListOption.OptionType.FILTER.get(options));
if (filter != null) {
- if (!Ascii.toLowerCase(filter).contains("timestamp")) {
- filter =
- String.format(
- "%s AND %s", filter, defaultTimestampFilterCreator.createDefaultTimestampFilter());
- }
builder.setFilter(filter);
- } else {
- // If filter is not specified, default filter is looking back 24 hours in line
- // with gcloud
- // behavior
- builder.setFilter(defaultTimestampFilterCreator.createDefaultTimestampFilter());
}
-
return builder.build();
}
private static ApiFuture> listLogEntriesAsync(
final LoggingOptions serviceOptions, final Map options) {
+ // Make sure to set a filter option which later can be reused in subsequent calls
+ final Map updatedOptions = updateFilter(options);
final ListLogEntriesRequest request =
- listLogEntriesRequest(serviceOptions.getProjectId(), options);
+ listLogEntriesRequest(serviceOptions.getProjectId(), updatedOptions);
ApiFuture list = serviceOptions.getLoggingRpcV2().list(request);
return transform(
list,
@@ -1055,7 +1043,7 @@ public AsyncPage apply(ListLogEntriesResponse listLogEntriesResponse)
? null
: listLogEntriesResponse.getNextPageToken();
return new AsyncPageImpl<>(
- new LogEntryPageFetcher(serviceOptions, cursor, options), cursor, entries);
+ new LogEntryPageFetcher(serviceOptions, cursor, updatedOptions), cursor, entries);
}
});
}
@@ -1137,6 +1125,37 @@ public void close() throws Exception {
return optionMap;
}
+ static Map updateFilter(final Map options) {
+ // We should see if filter provided in otiopns have a timestamp parameter
+ // and if not, it should be added with further update of options map.
+ String existingFilter = EntryListOption.OptionType.FILTER.get(options);
+ String newFilter = generateFilter(existingFilter);
+ if (newFilter.equals(existingFilter)) {
+ return options;
+ }
+ // Update
+ Map optionsCopy = Maps.newHashMap(options);
+ optionsCopy.put(EntryListOption.OptionType.FILTER, newFilter);
+ return optionsCopy;
+ }
+
+ static String generateFilter(String filter) {
+ String newFilter = filter;
+ // Make sure timestamp filter is either explicitly specified or we add a default
+ // time filter of 24 hours back to be inline with gcloud behavior for the same API
+ if (newFilter != null) {
+ if (!Ascii.toLowerCase(filter).contains("timestamp")) {
+ newFilter =
+ String.format(
+ "%s AND %s",
+ newFilter, defaultTimestampFilterCreator.createDefaultTimestampFilter());
+ }
+ } else {
+ newFilter = defaultTimestampFilterCreator.createDefaultTimestampFilter();
+ }
+ return newFilter;
+ }
+
@VisibleForTesting
int getNumPendingWrites() {
return pendingWrites.size();
diff --git a/google-cloud-logging/src/test/java/com/google/cloud/logging/LoggingTest.java b/google-cloud-logging/src/test/java/com/google/cloud/logging/LoggingTest.java
index 61200c4c6..5c59c9519 100644
--- a/google-cloud-logging/src/test/java/com/google/cloud/logging/LoggingTest.java
+++ b/google-cloud-logging/src/test/java/com/google/cloud/logging/LoggingTest.java
@@ -18,6 +18,9 @@
import static com.google.common.truth.Truth.assertThat;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotEquals;
+import static org.junit.Assert.assertTrue;
import com.google.cloud.MonitoredResource;
import com.google.cloud.logging.Logging.EntryListOption;
@@ -27,6 +30,7 @@
import com.google.cloud.logging.Logging.WriteOption;
import com.google.common.collect.ImmutableMap;
import com.google.logging.v2.ListLogEntriesRequest;
+import java.util.Map;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
@@ -100,6 +104,18 @@ public void testEntryListOption() {
"folders/test-folder");
}
+ @Test
+ public void testFilterUpdate() {
+ Map options = LoggingImpl.optionMap(EntryListOption.filter(FILTER));
+ assertThat((String) EntryListOption.OptionType.FILTER.get(options)).isEqualTo(FILTER);
+ Map updated = LoggingImpl.updateFilter(options);
+ assertTrue(((String) EntryListOption.OptionType.FILTER.get(updated)).contains("timestamp"));
+ assertFalse(options == updated);
+ assertNotEquals(EntryListOption.OptionType.FILTER.get(updated), FILTER);
+ Map anotherUpdated = LoggingImpl.updateFilter(updated);
+ assertTrue(anotherUpdated == updated);
+ }
+
@Test
public void testWriteOption() {
WriteOption writeOption = WriteOption.labels(LABELS);
From 1323a6db30cd1866dae24f0d420a81fac365a2c9 Mon Sep 17 00:00:00 2001
From: "release-please[bot]"
<55107282+release-please[bot]@users.noreply.github.com>
Date: Wed, 7 Dec 2022 11:27:41 -0800
Subject: [PATCH 4/4] chore(main): release 3.13.6 (#1225)
Co-authored-by: release-please[bot] <55107282+release-please[bot]@users.noreply.github.com>
---
CHANGELOG.md | 7 +++++++
google-cloud-logging-bom/pom.xml | 8 ++++----
google-cloud-logging/pom.xml | 4 ++--
.../java/com/google/cloud/logging/Instrumentation.java | 2 +-
grpc-google-cloud-logging-v2/pom.xml | 4 ++--
pom.xml | 8 ++++----
proto-google-cloud-logging-v2/pom.xml | 4 ++--
samples/snapshot/pom.xml | 2 +-
versions.txt | 6 +++---
9 files changed, 26 insertions(+), 19 deletions(-)
diff --git a/CHANGELOG.md b/CHANGELOG.md
index a25e7284b..b4d82b329 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,5 +1,12 @@
# Changelog
+## [3.13.6](https://github.com/googleapis/java-logging/compare/v3.13.5...v3.13.6) (2022-12-07)
+
+
+### Bug Fixes
+
+* Retrieving logentries pagewise always results in an exception ([#1220](https://github.com/googleapis/java-logging/issues/1220)) ([662a439](https://github.com/googleapis/java-logging/commit/662a4394688661e7da2da51446cb3a73658ead62))
+
## [3.13.5](https://github.com/googleapis/java-logging/compare/v3.13.4...v3.13.5) (2022-12-06)
diff --git a/google-cloud-logging-bom/pom.xml b/google-cloud-logging-bom/pom.xml
index b7d83137a..daaa3bcc4 100644
--- a/google-cloud-logging-bom/pom.xml
+++ b/google-cloud-logging-bom/pom.xml
@@ -3,7 +3,7 @@
4.0.0
com.google.cloud
google-cloud-logging-bom
- 3.13.6-SNAPSHOT
+ 3.13.6
pom
com.google.cloud
@@ -53,17 +53,17 @@
com.google.cloud
google-cloud-logging
- 3.13.6-SNAPSHOT
+ 3.13.6
com.google.api.grpc
grpc-google-cloud-logging-v2
- 0.102.6-SNAPSHOT
+ 0.102.6
com.google.api.grpc
proto-google-cloud-logging-v2
- 0.102.6-SNAPSHOT
+ 0.102.6