-
Notifications
You must be signed in to change notification settings - Fork 39
fix: add default time range filter for ListLogEntries API #304
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
simonz130
merged 12 commits into
googleapis:master
from
simonz130:fixListLogsFlackiness
Nov 11, 2020
Merged
Changes from 5 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
552997c
fix: make ListLogEntries use 24hr filter
fa981c4
fix: lint
78b7564
Update google-cloud-logging/src/test/java/com/google/cloud/logging/Lo…
71a33d1
Update google-cloud-logging/src/test/java/com/google/cloud/logging/Lo…
cf9f0db
Merge branch 'master' into fixListLogsFlackiness
7a46890
Merge branch 'master' of github.com:googleapis/java-logging into fixL…
3cfa258
fix: fixing lint
896666d
fix: lint2
5abdb07
fix: autoadd timestamp if not there
641acb9
feat!: listLogEntries now appends default 24h filter
ddfd50d
fix: added lowercase check
a0e16a9
chore: lint
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,6 +36,7 @@ | |
import com.google.cloud.MonitoredResource; | ||
import com.google.cloud.MonitoredResourceDescriptor; | ||
import com.google.cloud.PageImpl; | ||
import com.google.cloud.logging.Logging.EntryListOption.OptionType; | ||
import com.google.cloud.logging.spi.v2.LoggingRpc; | ||
import com.google.common.annotations.VisibleForTesting; | ||
import com.google.common.base.Function; | ||
|
@@ -77,7 +78,11 @@ | |
import com.google.logging.v2.WriteLogEntriesRequest; | ||
import com.google.logging.v2.WriteLogEntriesResponse; | ||
import com.google.protobuf.Empty; | ||
import java.text.DateFormat; | ||
import java.text.SimpleDateFormat; | ||
import java.util.ArrayList; | ||
import java.util.Calendar; | ||
import java.util.Date; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.concurrent.ConcurrentHashMap; | ||
|
@@ -782,6 +787,11 @@ static ListLogEntriesRequest listLogEntriesRequest( | |
if (filter != null) { | ||
builder.setFilter(filter); | ||
} | ||
else { | ||
// If filter is not specified, default filter is looking back 24 hours in line with gcloud behavior | ||
builder.setFilter(createDefaultTimeRangeFilter()); | ||
} | ||
|
||
return builder.build(); | ||
} | ||
|
||
|
@@ -843,4 +853,20 @@ public void close() throws Exception { | |
int getNumPendingWrites() { | ||
return pendingWrites.size(); | ||
} | ||
|
||
private static String createDefaultTimeRangeFilter() { | ||
DateFormat rfcDateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"); | ||
return "timestamp>=\"" + rfcDateFormat.format(yesterday()) + "\""; | ||
} | ||
|
||
private static Date yesterday() { | ||
Calendar calendar = Calendar.getInstance(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What timezone is used here? Is that accounted for? |
||
calendar.add(Calendar.DATE, -1); | ||
calendar.set(Calendar.HOUR_OF_DAY, 0); | ||
calendar.set(Calendar.MINUTE, 0); | ||
calendar.set(Calendar.SECOND, 0); | ||
calendar.set(Calendar.MILLISECOND, 0); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This reads to me like "yesterday at midnight", not "24 hours ago". Is that right? |
||
|
||
return calendar.getTime(); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.