Skip to content

Commit b635585

Browse files
authored
samples: limit list log in samples (#227)
Updates the `logging_list_log_entries` sample to limit logs fetched by timestamp. Querying over the entire log history can take minutes.
1 parent a4b45eb commit b635585

File tree

6 files changed

+60
-88
lines changed

6 files changed

+60
-88
lines changed

samples/install-with-bom/pom.xml

Lines changed: 0 additions & 76 deletions
This file was deleted.

samples/install-without-bom/pom.xml

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,14 @@
77
<name>Google Cloud Logging Install Without BOM Sample</name>
88
<url>https://github.com/googleapis/java-logging</url>
99

10+
<!--
11+
The parent pom defines common style checks and testing strategies for our samples.
12+
Removing or replacing it should not affect the execution of the samples in anyway.
13+
-->
1014
<parent>
11-
<groupId>com.google.cloud</groupId>
12-
<artifactId>google-cloud-logging-samples</artifactId>
13-
<version>0.0.1-SNAPSHOT</version>
15+
<groupId>com.google.cloud.samples</groupId>
16+
<artifactId>shared-configuration</artifactId>
17+
<version>1.0.18</version>
1418
</parent>
1519

1620
<properties>
@@ -28,6 +32,19 @@
2832
<version>1.101.3-SNAPSHOT</version>
2933
</dependency>
3034
<!-- [END logging_install_without_bom] -->
35+
36+
<dependency>
37+
<groupId>junit</groupId>
38+
<artifactId>junit</artifactId>
39+
<version>4.13</version>
40+
<scope>test</scope>
41+
</dependency>
42+
<dependency>
43+
<groupId>com.google.truth</groupId>
44+
<artifactId>truth</artifactId>
45+
<version>1.0.1</version>
46+
<scope>test</scope>
47+
</dependency>
3148
</dependencies>
3249
<!-- {x-version-update-end} -->
3350

samples/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
</properties>
2929

3030
<modules>
31-
<module>install-with-bom</module>
31+
<module>snapshot</module>
3232
<module>install-without-bom</module>
3333
<module>snippets</module>
3434
</modules>

samples/snapshot/pom.xml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,14 @@
2323
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
2424
</properties>
2525

26-
<!-- {x-version-update-start::current} -->
26+
<!-- {x-version-update-start:google-cloud-logging:current} -->
2727
<dependencies>
2828
<dependency>
2929
<groupId>com.google.cloud</groupId>
3030
<artifactId>google-cloud-logging</artifactId>
3131
<version>1.101.2</version>
3232
</dependency>
33-
33+
<!-- {x-version-update-end} -->
3434
<dependency>
3535
<groupId>junit</groupId>
3636
<artifactId>junit</artifactId>
@@ -44,7 +44,6 @@
4444
<scope>test</scope>
4545
</dependency>
4646
</dependencies>
47-
<!-- {x-version-update-end} -->
4847

4948
<!-- compile and run all snippet tests -->
5049
<build>

samples/snippets/pom.xml

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,14 @@
77
<name>Google Cloud Logging Snippets</name>
88
<url>https://github.com/googleapis/java-logging</url>
99

10+
<!--
11+
The parent pom defines common style checks and testing strategies for our samples.
12+
Removing or replacing it should not affect the execution of the samples in anyway.
13+
-->
1014
<parent>
11-
<groupId>com.google.cloud</groupId>
12-
<artifactId>google-cloud-logging-samples</artifactId>
13-
<version>0.0.1-SNAPSHOT</version>
15+
<groupId>com.google.cloud.samples</groupId>
16+
<artifactId>shared-configuration</artifactId>
17+
<version>1.0.18</version>
1418
</parent>
1519

1620
<properties>
@@ -19,11 +23,38 @@
1923
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
2024
</properties>
2125

26+
<!-- [START logging_install_with_bom] -->
27+
<dependencyManagement>
28+
<dependencies>
29+
<dependency>
30+
<groupId>com.google.cloud</groupId>
31+
<artifactId>libraries-bom</artifactId>
32+
<version>10.0.0</version>
33+
<type>pom</type>
34+
<scope>import</scope>
35+
</dependency>
36+
</dependencies>
37+
</dependencyManagement>
38+
2239
<dependencies>
2340
<dependency>
2441
<groupId>com.google.cloud</groupId>
2542
<artifactId>google-cloud-logging</artifactId>
26-
<version>1.101.3-SNAPSHOT</version><!-- {x-version-update:google-cloud-logging:current} -->
2743
</dependency>
44+
<!-- [START_EXCLUDE] -->
45+
<dependency>
46+
<groupId>junit</groupId>
47+
<artifactId>junit</artifactId>
48+
<version>4.13</version>
49+
<scope>test</scope>
50+
</dependency>
51+
<dependency>
52+
<groupId>com.google.truth</groupId>
53+
<artifactId>truth</artifactId>
54+
<version>1.0.1</version>
55+
<scope>test</scope>
56+
</dependency>
57+
<!-- [END_EXCLUDE] -->
2858
</dependencies>
59+
<!-- [END logging_install_with_bom] -->
2960
</project>

samples/snippets/src/main/java/com/example/logging/ListLogs.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ public static void main(String... args) throws Exception {
3535

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

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

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

0 commit comments

Comments
 (0)