Skip to content

Commit 5a7845a

Browse files
authored
feat: add support for tailLogEntry API
Implements tailLogEntries API to stream new log entries. Provides unit and system/integration tests for the new API. Fixes #592 [![WhiteSource Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com) This PR contains the following updates: | Package | Change | Age | Adoption | Passing | Confidence | |---|---|---|---|---|---| | [com.google.cloud:libraries-bom](https://togithub.com/GoogleCloudPlatform/cloud-opensource-java) | `22.0.0` -> `23.0.0` | [![age](https://badges.renovateapi.com/packages/maven/com.google.cloud:libraries-bom/23.0.0/age-slim)](https://docs.renovatebot.com/merge-confidence/) | [![adoption](https://badges.renovateapi.com/packages/maven/com.google.cloud:libraries-bom/23.0.0/adoption-slim)](https://docs.renovatebot.com/merge-confidence/) | [![passing](https://badges.renovateapi.com/packages/maven/com.google.cloud:libraries-bom/23.0.0/compatibility-slim/22.0.0)](https://docs.renovatebot.com/merge-confidence/) | [![confidence](https://badges.renovateapi.com/packages/maven/com.google.cloud:libraries-bom/23.0.0/confidence-slim/22.0.0)](https://docs.renovatebot.com/merge-confidence/) | --- ### Configuration 📅 **Schedule**: At any time (no schedule defined). 🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied. ♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this PR and you won't be reminded about this update again. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box. --- This PR has been generated by [WhiteSource Renovate](https://renovate.whitesourcesoftware.com). View repository job log [here](https://app.renovatebot.com/dashboard#github/googleapis/java-logging). * build(deps): update dependency com.google.cloud:google-cloud-shared-config to v1.0.2 (#668) [![WhiteSource Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com) This PR contains the following updates: | Package | Change | Age | Adoption | Passing | Confidence | |---|---|---|---|---|---| | [com.google.cloud:google-cloud-shared-config](https://togithub.com/googleapis/java-shared-config) | `1.0.1` -> `1.0.2` | [![age](https://badges.renovateapi.com/packages/maven/com.google.cloud:google-cloud-shared-config/1.0.2/age-slim)](https://docs.renovatebot.com/merge-confidence/) | [![adoption](https://badges.renovateapi.com/packages/maven/com.google.cloud:google-cloud-shared-config/1.0.2/adoption-slim)](https://docs.renovatebot.com/merge-confidence/) | [![passing](https://badges.renovateapi.com/packages/maven/com.google.cloud:google-cloud-shared-config/1.0.2/compatibility-slim/1.0.1)](https://docs.renovatebot.com/merge-confidence/) | [![confidence](https://badges.renovateapi.com/packages/maven/com.google.cloud:google-cloud-shared-config/1.0.2/confidence-slim/1.0.1)](https://docs.renovatebot.com/merge-confidence/) | --- ### Release Notes <details> <summary>googleapis/java-shared-config</summary> ### [`v1.0.2`](https://togithub.com/googleapis/java-shared-config/blob/master/CHANGELOG.md#&#8203;102-httpswwwgithubcomgoogleapisjava-shared-configcomparev101v102-2021-09-13) [Compare Source](https://togithub.com/googleapis/java-shared-config/compare/v1.0.1...v1.0.2) </details> --- ### Configuration 📅 **Schedule**: At any time (no schedule defined). 🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied. ♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this PR and you won't be reminded about this update again. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box. --- This PR has been generated by [WhiteSource Renovate](https://renovate.whitesourcesoftware.com). View repository job log [here](https://app.renovatebot.com/dashboard#github/googleapis/java-logging). * deps: update dependency com.google.cloud:google-cloud-shared-dependencies to v2.2.1 (#667) [![WhiteSource Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com) This PR contains the following updates: | Package | Change | Age | Adoption | Passing | Confidence | |---|---|---|---|---|---| | [com.google.cloud:google-cloud-shared-dependencies](https://togithub.com/googleapis/java-shared-dependencies) | `2.2.0` -> `2.2.1` | [![age](https://badges.renovateapi.com/packages/maven/com.google.cloud:google-cloud-shared-dependencies/2.2.1/age-slim)](https://docs.renovatebot.com/merge-confidence/) | [![adoption](https://badges.renovateapi.com/packages/maven/com.google.cloud:google-cloud-shared-dependencies/2.2.1/adoption-slim)](https://docs.renovatebot.com/merge-confidence/) | [![passing](https://badges.renovateapi.com/packages/maven/com.google.cloud:google-cloud-shared-dependencies/2.2.1/compatibility-slim/2.2.0)](https://docs.renovatebot.com/merge-confidence/) | [![confidence](https://badges.renovateapi.com/packages/maven/com.google.cloud:google-cloud-shared-dependencies/2.2.1/confidence-slim/2.2.0)](https://docs.renovatebot.com/merge-confidence/) | --- ### Release Notes <details> <summary>googleapis/java-shared-dependencies</summary> ### [`v2.2.1`](https://togithub.com/googleapis/java-shared-dependencies/blob/master/CHANGELOG.md#&#8203;221-httpswwwgithubcomgoogleapisjava-shared-dependenciescompare220v221-2021-09-13) [Compare Source](https://togithub.com/googleapis/java-shared-dependencies/compare/v2.2.0...v2.2.1) </details> --- ### Configuration 📅 **Schedule**: At any time (no schedule defined). 🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied. ♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this PR and you won't be reminded about this update again. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box. --- This PR has been Co-authored-by [WhiteSource Renovate](https://renovate.whitesourcesoftware.com). View repository job log [here](https://app.renovatebot.com/dashboard#github/googleapis/java-logging).
1 parent ff7c4d1 commit 5a7845a

13 files changed

+970
-376
lines changed

google-cloud-logging/clirr-ignored-differences.xml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,20 @@
88
<className>com/google/cloud/logging/Logging</className>
99
<method>* listLogs*(com.google.cloud.logging.Logging$ListOption[])</method>
1010
</difference>
11+
<difference>
12+
<differenceType>7012</differenceType>
13+
<className>com/google/cloud/logging/Logging</className>
14+
<method>com.google.cloud.logging.LogEntryServerStream tailLogEntries(com.google.cloud.logging.Logging$TailOption[])</method>
15+
</difference>
1116
<!-- Added methods to com.google.cloud.logging.spi.v2.LoggingRpc interface with implementation in GrpcLoggingRpc is always okay -->
1217
<difference>
1318
<differenceType>7012</differenceType>
1419
<className>com/google/cloud/logging/spi/v2/LoggingRpc</className>
1520
<method>* listLogs(com.google.logging.v2.ListLogsRequest)</method>
1621
</difference>
22+
<difference>
23+
<differenceType>7012</differenceType>
24+
<className>com/google/cloud/logging/spi/v2/LoggingRpc</className>
25+
<method>com.google.api.gax.rpc.BidiStream getTailLogEntriesStream()</method>
26+
</difference>
1727
</differences>
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/*
2+
* Copyright 2021 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.google.cloud.logging;
18+
19+
import com.google.common.collect.Lists;
20+
import com.google.logging.v2.TailLogEntriesResponse;
21+
import java.util.Iterator;
22+
import java.util.LinkedList;
23+
24+
public class LogEntryIterator implements Iterator<LogEntry> {
25+
private final Iterator<TailLogEntriesResponse> streamIterator;
26+
private final LinkedList<LogEntry> buffer = new LinkedList<>();
27+
28+
LogEntryIterator(Iterator<TailLogEntriesResponse> streamIterator) {
29+
this.streamIterator = streamIterator;
30+
}
31+
32+
/** {@inheritDoc} */
33+
@Override
34+
public boolean hasNext() {
35+
return !buffer.isEmpty() || streamIterator.hasNext();
36+
}
37+
38+
/** {@inheritDoc} */
39+
@Override
40+
public LogEntry next() {
41+
if (buffer.isEmpty()) {
42+
TailLogEntriesResponse response = streamIterator.next();
43+
buffer.addAll(Lists.transform(response.getEntriesList(), LogEntry.FROM_PB_FUNCTION));
44+
}
45+
return buffer.pop();
46+
}
47+
}
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/*
2+
* Copyright 2021 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.google.cloud.logging;
18+
19+
import com.google.api.gax.rpc.BidiStream;
20+
import com.google.common.collect.Lists;
21+
import com.google.logging.v2.TailLogEntriesRequest;
22+
import com.google.logging.v2.TailLogEntriesResponse;
23+
import java.util.Iterator;
24+
25+
public class LogEntryServerStream implements Iterable<LogEntry> {
26+
private final BidiStream<TailLogEntriesRequest, TailLogEntriesResponse> serverStream;
27+
28+
LogEntryServerStream(BidiStream<TailLogEntriesRequest, TailLogEntriesResponse> serverStream) {
29+
this.serverStream = serverStream;
30+
}
31+
32+
/** {@inheritDoc} */
33+
@Override
34+
public Iterator<LogEntry> iterator() {
35+
return new LogEntryIterator(serverStream.iterator());
36+
}
37+
38+
public BidiStream<TailLogEntriesRequest, TailLogEntriesResponse> getInternalStream() {
39+
return serverStream;
40+
}
41+
42+
public java.util.List<LogEntry> convert(TailLogEntriesResponse resp) {
43+
return Lists.transform(resp.getEntriesList(), LogEntry.FROM_PB_FUNCTION);
44+
}
45+
46+
/**
47+
* Returns true if the next call to the iterator's hasNext() or next() is guaranteed to be
48+
* nonblocking.
49+
*
50+
* @return If the call on any of the iterator's methods is guaranteed to be nonblocking.
51+
*/
52+
public boolean isReceiveReady() {
53+
return serverStream.isReceiveReady();
54+
}
55+
56+
/**
57+
* Cleanly cancels a partially consumed stream. The associated iterator will return false for the
58+
* hasNext() in the next iteration. This maintains the contract that an observed true from
59+
* hasNext() will yield an item in next(), but afterwards will return false.
60+
*/
61+
public void cancel() {
62+
serverStream.cancel();
63+
}
64+
}

0 commit comments

Comments
 (0)