Skip to content

Commit

Permalink
samples: limit list log in samples (#227)
Browse files Browse the repository at this point in the history
Updates the `logging_list_log_entries` sample to limit logs fetched by timestamp. Querying over the entire log history can take minutes.
  • Loading branch information
chingor13 committed Sep 8, 2020
1 parent a4b45eb commit b635585
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 88 deletions.
76 changes: 0 additions & 76 deletions samples/install-with-bom/pom.xml

This file was deleted.

23 changes: 20 additions & 3 deletions samples/install-without-bom/pom.xml
Expand Up @@ -7,10 +7,14 @@
<name>Google Cloud Logging Install Without BOM Sample</name>
<url>https://github.com/googleapis/java-logging</url>

<!--
The parent pom defines common style checks and testing strategies for our samples.
Removing or replacing it should not affect the execution of the samples in anyway.
-->
<parent>
<groupId>com.google.cloud</groupId>
<artifactId>google-cloud-logging-samples</artifactId>
<version>0.0.1-SNAPSHOT</version>
<groupId>com.google.cloud.samples</groupId>
<artifactId>shared-configuration</artifactId>
<version>1.0.18</version>
</parent>

<properties>
Expand All @@ -28,6 +32,19 @@
<version>1.101.3-SNAPSHOT</version>
</dependency>
<!-- [END logging_install_without_bom] -->

<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.google.truth</groupId>
<artifactId>truth</artifactId>
<version>1.0.1</version>
<scope>test</scope>
</dependency>
</dependencies>
<!-- {x-version-update-end} -->

Expand Down
2 changes: 1 addition & 1 deletion samples/pom.xml
Expand Up @@ -28,7 +28,7 @@
</properties>

<modules>
<module>install-with-bom</module>
<module>snapshot</module>
<module>install-without-bom</module>
<module>snippets</module>
</modules>
Expand Down
5 changes: 2 additions & 3 deletions samples/snapshot/pom.xml
Expand Up @@ -23,14 +23,14 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<!-- {x-version-update-start::current} -->
<!-- {x-version-update-start:google-cloud-logging:current} -->
<dependencies>
<dependency>
<groupId>com.google.cloud</groupId>
<artifactId>google-cloud-logging</artifactId>
<version>1.101.2</version>
</dependency>

<!-- {x-version-update-end} -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
Expand All @@ -44,7 +44,6 @@
<scope>test</scope>
</dependency>
</dependencies>
<!-- {x-version-update-end} -->

<!-- compile and run all snippet tests -->
<build>
Expand Down
39 changes: 35 additions & 4 deletions samples/snippets/pom.xml
Expand Up @@ -7,10 +7,14 @@
<name>Google Cloud Logging Snippets</name>
<url>https://github.com/googleapis/java-logging</url>

<!--
The parent pom defines common style checks and testing strategies for our samples.
Removing or replacing it should not affect the execution of the samples in anyway.
-->
<parent>
<groupId>com.google.cloud</groupId>
<artifactId>google-cloud-logging-samples</artifactId>
<version>0.0.1-SNAPSHOT</version>
<groupId>com.google.cloud.samples</groupId>
<artifactId>shared-configuration</artifactId>
<version>1.0.18</version>
</parent>

<properties>
Expand All @@ -19,11 +23,38 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<!-- [START logging_install_with_bom] -->
<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.google.cloud</groupId>
<artifactId>libraries-bom</artifactId>
<version>10.0.0</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>

<dependencies>
<dependency>
<groupId>com.google.cloud</groupId>
<artifactId>google-cloud-logging</artifactId>
<version>1.101.3-SNAPSHOT</version><!-- {x-version-update:google-cloud-logging:current} -->
</dependency>
<!-- [START_EXCLUDE] -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.google.truth</groupId>
<artifactId>truth</artifactId>
<version>1.0.1</version>
<scope>test</scope>
</dependency>
<!-- [END_EXCLUDE] -->
</dependencies>
<!-- [END logging_install_with_bom] -->
</project>
Expand Up @@ -35,7 +35,8 @@ public static void main(String... args) throws Exception {

try (Logging logging = options.getService()) {

String logFilter = "logName=projects/" + options.getProjectId() + "/logs/" + logName;
String logFilter = "logName=projects/" + options.getProjectId() + "/logs/" + logName +
" AND timestamp>=\"2020-09-01T00:00:00.000Z\"";

// List all log entries
Page<LogEntry> entries = logging.listLogEntries(EntryListOption.filter(logFilter));
Expand Down

0 comments on commit b635585

Please sign in to comment.