Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Make partialSuccess to be true by default #1173

Merged
merged 3 commits into from
Nov 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -859,6 +859,8 @@ public void write(Iterable<LogEntry> logEntries, WriteOption... options) {
try {
final Map<Option.OptionType, ?> writeOptions = optionMap(options);
final Boolean loggingOptionsPopulateFlag = getOptions().getAutoPopulateMetadata();
final Boolean writeOptionPartialSuccessFlag =
WriteOption.OptionType.PARTIAL_SUCCESS.get(writeOptions);
final Boolean writeOptionPopulateFlag =
WriteOption.OptionType.AUTO_POPULATE_METADATA.get(writeOptions);
Tuple<Boolean, Iterable<LogEntry>> pair =
Expand All @@ -872,9 +874,14 @@ public void write(Iterable<LogEntry> logEntries, WriteOption... options) {
logEntries =
populateMetadata(logEntries, sharedResourceMetadata, this.getClass().getName());
}
// Add partialSuccess option always for request containing instrumentation data
writeLogEntries(
logEntries, pair.x() ? Instrumentation.addPartialSuccessOption(options) : options);
// Add partialSuccess = true option always for request which does not have
// it set explicitly in options.
// For request containing instrumentation data (e.g. when pair.x() == true),
// always set or override partialSuccess with true.
if (pair.x() || writeOptionPartialSuccessFlag == null) {
losalex marked this conversation as resolved.
Show resolved Hide resolved
options = Instrumentation.addPartialSuccessOption(options);
}
writeLogEntries(logEntries, options);
if (flushSeverity != null) {
for (LogEntry logEntry : logEntries) {
// flush pending writes if log severity at or above flush severity
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1851,6 +1851,7 @@ public void testWriteLogEntries() {
.addAllEntries(
Iterables.transform(
ImmutableList.of(LOG_ENTRY1, LOG_ENTRY2), LogEntry.toPbFunction(PROJECT)))
.setPartialSuccess(true)
.build();
WriteLogEntriesResponse response = WriteLogEntriesResponse.getDefaultInstance();
EasyMock.expect(loggingRpcMock.write(request)).andReturn(ApiFutures.immediateFuture(response));
Expand All @@ -1869,6 +1870,7 @@ public void testWriteLogEntriesDoesNotEnableFlushByDefault() {
ImmutableList.of(
LOG_ENTRY1, LOG_ENTRY2.toBuilder().setSeverity(Severity.EMERGENCY).build()),
LogEntry.toPbFunction(PROJECT)))
.setPartialSuccess(true)
.build();
ApiFuture<WriteLogEntriesResponse> apiFuture = SettableApiFuture.create();
EasyMock.expect(loggingRpcMock.write(request)).andReturn(apiFuture);
Expand All @@ -1886,6 +1888,7 @@ public void testWriteLogEntriesWithSeverityFlushEnabled() {
.addAllEntries(
Iterables.transform(
ImmutableList.of(LOG_ENTRY1, LOG_ENTRY2), LogEntry.toPbFunction(PROJECT)))
.setPartialSuccess(true)
.build();
WriteLogEntriesResponse response = WriteLogEntriesResponse.getDefaultInstance();
EasyMock.expect(loggingRpcMock.write(request)).andReturn(ApiFutures.immediateFuture(response));
Expand Down Expand Up @@ -1934,6 +1937,7 @@ public void testWriteLogEntriesAsync() {
ImmutableList.of(
LOG_ENTRY1, LOG_ENTRY2, LOG_ENTRY_NO_DESTINATION, LOG_ENTRY_EMPTY),
LogEntry.toPbFunction(PROJECT)))
.setPartialSuccess(true)
.build();
WriteLogEntriesResponse response = WriteLogEntriesResponse.getDefaultInstance();
EasyMock.expect(loggingRpcMock.write(request)).andReturn(ApiFutures.immediateFuture(response));
Expand All @@ -1955,6 +1959,7 @@ public void testWriteLogEntriesAsyncWithOptions() {
.addAllEntries(
Iterables.transform(
ImmutableList.of(LOG_ENTRY1, LOG_ENTRY2), LogEntry.toPbFunction(PROJECT)))
.setPartialSuccess(true)
.build();
WriteLogEntriesResponse response = WriteLogEntriesResponse.getDefaultInstance();
EasyMock.expect(loggingRpcMock.write(request)).andReturn(ApiFutures.immediateFuture(response));
Expand Down Expand Up @@ -2229,6 +2234,7 @@ public void testFlush() throws InterruptedException {
.addAllEntries(
Iterables.transform(
ImmutableList.of(LOG_ENTRY1, LOG_ENTRY2), LogEntry.toPbFunction(PROJECT)))
.setPartialSuccess(true)
.build();
EasyMock.expect(loggingRpcMock.write(request)).andReturn(mockRpcResponse);
EasyMock.replay(loggingRpcMock);
Expand Down Expand Up @@ -2264,6 +2270,7 @@ public void testFlushStress() throws InterruptedException {
WriteLogEntriesRequest.newBuilder()
.addAllEntries(
Iterables.transform(ImmutableList.of(LOG_ENTRY1), LogEntry.toPbFunction(PROJECT)))
.setPartialSuccess(true)
.build();

Thread[] threads = new Thread[100];
Expand Down Expand Up @@ -2304,6 +2311,22 @@ public void testDiagnosticInfoWithPartialSuccess() {
testDiagnosticInfoGeneration(true);
}

@Test
public void testPartialSuccessNotOverridenIfPresent() {
WriteLogEntriesRequest request =
WriteLogEntriesRequest.newBuilder()
.addAllEntries(
Iterables.transform(
ImmutableList.of(LOG_ENTRY1, LOG_ENTRY2), LogEntry.toPbFunction(PROJECT)))
.setPartialSuccess(false)
.build();
WriteLogEntriesResponse response = WriteLogEntriesResponse.getDefaultInstance();
EasyMock.expect(loggingRpcMock.write(request)).andReturn(ApiFutures.immediateFuture(response));
EasyMock.replay(rpcFactoryMock, loggingRpcMock);
logging = options.getService();
logging.write(ImmutableList.of(LOG_ENTRY1, LOG_ENTRY2), WriteOption.partialSuccess(false));
}
losalex marked this conversation as resolved.
Show resolved Hide resolved

private void testDiagnosticInfoGeneration(boolean addPartialSuccessOption) {
Instrumentation.setInstrumentationStatus(false);
LogEntry jsonEntry =
Expand Down Expand Up @@ -2362,6 +2385,7 @@ private void testWriteLogEntriesWithDestination(
LOG_ENTRY_NO_DESTINATION,
LOG_ENTRY_EMPTY),
LogEntry.toPbFunction(projectId)))
.setPartialSuccess(true)
.build();
WriteLogEntriesResponse response = WriteLogEntriesResponse.getDefaultInstance();
EasyMock.expect(loggingRpcMock.write(expectedWriteLogEntriesRequest))
Expand Down