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(controller): run log save doesn't break status report #2994

Merged
merged 1 commit into from
Nov 17, 2023
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 @@ -21,6 +21,9 @@
import ai.starwhale.mlops.schedule.executor.RunExecutor;
import ai.starwhale.mlops.schedule.log.RunLogSaver;
import ai.starwhale.mlops.schedule.reporting.listener.RunUpdateListener;
import io.github.resilience4j.core.IntervalFunction;
import io.github.resilience4j.retry.Retry;
import io.github.resilience4j.retry.RetryConfig;
import java.time.Instant;
import java.util.concurrent.DelayQueue;
import java.util.concurrent.Delayed;
Expand Down Expand Up @@ -58,7 +61,24 @@ public RunUpdateListenerForGc(
public void onRunUpdate(Run run) {
RunStatus runStatus = run.getStatus();
if (runStatus == RunStatus.FAILED || runStatus == RunStatus.FINISHED) {
runLogSaver.saveLog(run);
try {
Retry.decorateCheckedRunnable(
Retry.of("save run log", RetryConfig.custom()
.maxAttempts(3)
.intervalFunction(
IntervalFunction.ofExponentialRandomBackoff(
100,
2.0,
0.5,
10000
)
)
.build()), () -> runLogSaver.saveLog(run)
)
.run();
} catch (Throwable e) {
log.warn("save run log failed", e);
}
if (deletionDelayMilliseconds <= 0) {
runExecutor.remove(run);
log.debug("delete run {}", run.getId());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

package ai.starwhale.mlops.schedule.reporting.listener.impl;

import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.mockStatic;
import static org.mockito.Mockito.times;
Expand All @@ -31,6 +33,8 @@
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.MockedStatic;
import org.mockito.invocation.InvocationOnMock;
import org.mockito.stubbing.Answer;

public class RunUpdateListenerForGcTest {

Expand Down Expand Up @@ -91,4 +95,44 @@ public void testDelayStopScheduleWithNegativeDelay() throws InterruptedException
verify(runExecutor, times(1)).remove(run);
}
}

@Test
public void testLogSaverRetry() {
doAnswer(new Answer<Void>() {
private int count = 0;

public Void answer(InvocationOnMock invocation) {
count++;
if (count < 2) {
throw new RuntimeException("");
}
return null;
}
}).when(runLogSaver).saveLog(any());
runUpdateListenerForGc = new RunUpdateListenerForGc(runLogSaver, 1L, runExecutor);
Run run = Run.builder()
.id(1L)
.status(RunStatus.FINISHED)
.build();
runUpdateListenerForGc.onRunUpdate(run);
verify(runLogSaver, times(2)).saveLog(run);
}

@Test
public void testLogExceptionQuite() {
doAnswer(new Answer<Void>() {

public Void answer(InvocationOnMock invocation) {
throw new RuntimeException("");
}
}).when(runLogSaver).saveLog(any());
runUpdateListenerForGc = new RunUpdateListenerForGc(runLogSaver, -1L, runExecutor);
Run run = Run.builder()
.id(1L)
.status(RunStatus.FINISHED)
.build();
runUpdateListenerForGc.onRunUpdate(run);
verify(runLogSaver, times(3)).saveLog(run);
verify(runExecutor).remove(run);
}
}
Loading