Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: fix samples region tags and test flakiness (#680)
* chore: fix list logs snippet define timestamp filter in UTC time. change filter to last minute entries. enforce closing logging client at the end of the snippet. apply formatting. * chore: enforce closing logging client in samples force closing logging client at the end of the snippet * fix: fix region tag for LogEntryWriteHttpRequest change logging_write_request_entry to logging_write_log_entry_advanced * fix: add snippet for missing logging_write_log_entry * chore: move testListLogNamesSample to separate test * fix: fix samples testing add closing logging client at the end of the test unit add multiple attempts to clean log after each test print debug info in a case cleaning fails * fix: add test for WriteLogEntry remove unused textPayload from the snippet * 🦉 Updates from OwlBot See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
- Loading branch information
1 parent
9db233f
commit 53481bd
Showing
8 changed files
with
216 additions
and
68 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
53 changes: 53 additions & 0 deletions
53
samples/snippets/src/main/java/com/example/logging/WriteLogEntry.java
This file contains 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 |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/* | ||
* Copyright 2021 Google LLC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.example.logging; | ||
|
||
// [START logging_write_log_entry] | ||
import com.google.cloud.MonitoredResource; | ||
import com.google.cloud.logging.LogEntry; | ||
import com.google.cloud.logging.Logging; | ||
import com.google.cloud.logging.LoggingOptions; | ||
import com.google.cloud.logging.Payload.JsonPayload; | ||
import com.google.cloud.logging.Severity; | ||
import com.google.common.collect.ImmutableMap; | ||
import java.util.Collections; | ||
import java.util.Map; | ||
|
||
public class WriteLogEntry { | ||
|
||
public static void main(String[] args) throws Exception { | ||
// TODO(developer): Optionally provide the logname as an argument | ||
String logName = args.length > 0 ? args[0] : "test-log"; | ||
|
||
// Instantiates a client | ||
try (Logging logging = LoggingOptions.getDefaultInstance().getService()) { | ||
Map<String, String> payload = | ||
ImmutableMap.of( | ||
"name", "King Arthur", "quest", "Find the Holy Grail", "favorite_color", "Blue"); | ||
LogEntry entry = | ||
LogEntry.newBuilder(JsonPayload.of(payload)) | ||
.setSeverity(Severity.INFO) | ||
.setLogName(logName) | ||
.setResource(MonitoredResource.newBuilder("global").build()) | ||
.build(); | ||
|
||
logging.write(Collections.singleton(entry)); | ||
} | ||
System.out.printf("Wrote to %s\n", logName); | ||
} | ||
} | ||
// [END logging_write_log_entry] |
This file contains 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
Oops, something went wrong.