Recover managed process log sessions
This commit is contained in:
+30
-4
@@ -1185,14 +1185,19 @@ type durableLogClient interface {
|
||||
IngestLogBatch(context.Context, protocol.LogBatchIngestRequest) (protocol.LogBatchIngestResponse, error)
|
||||
}
|
||||
|
||||
type durableLogProgressClient interface {
|
||||
GetRunLogStreamProgress(context.Context, protocol.RunLogStreamProgressRequest) (protocol.RunLogStreamProgressResponse, error)
|
||||
}
|
||||
|
||||
type durableArtifactClient interface {
|
||||
UploadArtifactChunk(context.Context, protocol.ArtifactChunkUploadRequest) (protocol.ArtifactChunkUploadResponse, error)
|
||||
}
|
||||
|
||||
type sessionLogBatchClient struct {
|
||||
client durableLogClient
|
||||
runEndpointID string
|
||||
sessionToken string
|
||||
client durableLogClient
|
||||
progressClient durableLogProgressClient
|
||||
runEndpointID string
|
||||
sessionToken string
|
||||
}
|
||||
|
||||
type sessionLogStreamProgressClient struct {
|
||||
@@ -1250,6 +1255,26 @@ func (client sessionLogBatchClient) IngestLogBatch(ctx context.Context, batch pr
|
||||
return response, err
|
||||
}
|
||||
|
||||
func (client sessionLogBatchClient) LogStreamLatestSeq(ctx context.Context, batch protocol.LogBatchIngestRequest) (uint64, error) {
|
||||
if client.progressClient == nil {
|
||||
return 0, fmt.Errorf("platform log progress client is unavailable")
|
||||
}
|
||||
response, err := client.progressClient.GetRunLogStreamProgress(ctx, protocol.RunLogStreamProgressRequest{
|
||||
RunEndpointID: client.runEndpointID,
|
||||
SessionToken: client.sessionToken,
|
||||
ServerInstanceID: batch.ServerInstanceID,
|
||||
LogStreamID: batch.LogStreamID,
|
||||
})
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
if !response.Accepted || response.LogStreamID != batch.LogStreamID {
|
||||
return 0, fmt.Errorf("platform log stream progress response is invalid")
|
||||
}
|
||||
log.Printf("RUN phase=durable_uploaders.logs status=sequence_recover stream=%s localFirstSeq=%d platformLatestSeq=%d", safeOptional(batch.LogStreamID), batch.FirstSeq, response.LatestSeq)
|
||||
return response.LatestSeq, nil
|
||||
}
|
||||
|
||||
func logBatchNotFoundError(err error) bool {
|
||||
var httpErr interface{ HTTPStatus() int }
|
||||
return errors.As(err, &httpErr) && httpErr.HTTPStatus() == http.StatusNotFound
|
||||
@@ -1305,6 +1330,7 @@ func (worker *Worker) runDurableUploaders(ctx context.Context, done chan<- struc
|
||||
logSink, hasLogSink := worker.executor.logSink.(*SpoolLogSink)
|
||||
artifactHook, hasArtifactHook := worker.executor.artifactHook.(*QueueArtifactHook)
|
||||
logClient, hasLogClient := worker.client.(durableLogClient)
|
||||
progressClient, _ := worker.client.(durableLogProgressClient)
|
||||
artifactClient, hasArtifactClient := worker.client.(durableArtifactClient)
|
||||
if (!hasLogSink || !hasLogClient) && (!hasArtifactHook || !hasArtifactClient) {
|
||||
log.Printf("RUN phase=durable_uploaders status=disabled logs=%t artifacts=%t", hasLogSink && hasLogClient, hasArtifactHook && hasArtifactClient)
|
||||
@@ -1328,7 +1354,7 @@ func (worker *Worker) runDurableUploaders(ctx context.Context, done chan<- struc
|
||||
startedAt := time.Now()
|
||||
log.Printf("RUN phase=durable_uploaders.logs status=flush_start timeoutMs=%d", durableUploaderFlushTimeout.Milliseconds())
|
||||
flushCtx, cancel := context.WithTimeout(ctx, durableUploaderFlushTimeout)
|
||||
client := sessionLogBatchClient{client: logClient, runEndpointID: state.RunEndpointID, sessionToken: state.SessionToken}
|
||||
client := sessionLogBatchClient{client: logClient, progressClient: progressClient, runEndpointID: state.RunEndpointID, sessionToken: state.SessionToken}
|
||||
flushed, err := logSink.Spool.Flush(flushCtx, client)
|
||||
if err != nil {
|
||||
log.Printf("RUN phase=durable_uploaders.logs status=flush_failed flushed=%d durationMs=%d error=%s", flushed, time.Since(startedAt).Milliseconds(), RedactText(err.Error()))
|
||||
|
||||
Reference in New Issue
Block a user