Skip to content

Commit

Permalink
chore: address disabled batching for writeLogEntries
Browse files Browse the repository at this point in the history
Changes GrpcLoggingServiceV2Stub stub to make it createBatchingCallable.
Modify WriteLogEntry sample to demo batching is working.

See #632 for problem description
  • Loading branch information
minherz committed Oct 4, 2021
1 parent 97e6113 commit 6e66498
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ protected GrpcLoggingServiceV2Stub(
callableFactory.createUnaryCallable(
deleteLogTransportSettings, settings.deleteLogSettings(), clientContext);
this.writeLogEntriesCallable =
callableFactory.createUnaryCallable(
callableFactory.createBatchingCallable(
writeLogEntriesTransportSettings, settings.writeLogEntriesSettings(), clientContext);
this.listLogEntriesCallable =
callableFactory.createUnaryCallable(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,25 +29,47 @@

public class WriteLogEntry {

private static String buildSuffix(int n) {
switch (n % 10) {
case 1:
return "st";
case 2:
return "nd";
case 3:
return "rd";
}
return "th";
}

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();
for (int i = 0; i < 100; i++) {
Map<String, String> payload =
ImmutableMap.of(
"name",
"King Arthur the " + (i + 1) + buildSuffix(i + 1),
"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));
logging.write(Collections.singleton(entry));
}
}
System.out.printf("Wrote to %s\n", logName);
System.out.printf("Wrote 100 entries to %s\n", logName);
System.out.printf(
"Wait for 2 minutes starting at %s\n", new java.util.Date(System.currentTimeMillis()));
Thread.sleep(120_000);
}
}
// [END logging_write_log_entry]

0 comments on commit 6e66498

Please sign in to comment.