-
Notifications
You must be signed in to change notification settings - Fork 800
[flytepropeller][flyteadmin] Streaming Decks V2 #6053
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
Changes from 11 commits
54aa165
9ed6b6e
4b4f6bd
dd774cb
0bb8e91
25fea29
4e24e91
8d1d0e4
31853bb
4068043
65b6efe
137579f
04f7fbc
aa56d64
a16851f
7314455
19498f5
74f595f
3bd3336
f6d8493
4b56e52
db4b19e
2737251
564dc5f
69ba94e
c992eae
0b91b5c
1d18265
96500c1
dd9dbaa
f51ff8c
bd5e682
561a43c
a33ba09
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -40,6 +40,15 @@ import ( | |
| ) | ||
|
|
||
| const pluginContextKey = contextutils.Key("plugin") | ||
| const FLYTE_ENABLE_DECK = string("FLYTE_ENABLE_DECK") | ||
|
|
||
| type DeckStatus int | ||
|
|
||
| const ( | ||
| DeckUnknown DeckStatus = iota | ||
| DeckEnabled | ||
| DeckDisabled | ||
| ) | ||
|
|
||
| type metrics struct { | ||
| pluginPanics labeled.Counter | ||
|
|
@@ -71,10 +80,47 @@ func getPluginMetricKey(pluginID, taskType string) string { | |
| return taskType + "_" + pluginID | ||
| } | ||
|
|
||
| func (p *pluginRequestedTransition) CacheHit(outputPath storage.DataReference, deckPath *storage.DataReference, entry catalog.Entry) { | ||
| func (p *pluginRequestedTransition) AddDeckURI(tCtx *taskExecutionContext) { | ||
| var deckURI *storage.DataReference | ||
| deckURIValue := tCtx.ow.GetDeckPath() | ||
| deckURI = &deckURIValue | ||
|
|
||
| if p.execInfo.OutputInfo == nil { | ||
| p.execInfo.OutputInfo = &handler.OutputInfo{} | ||
| } | ||
|
|
||
| p.execInfo.OutputInfo.DeckURI = deckURI | ||
| } | ||
|
|
||
| func (p *pluginRequestedTransition) AddDeckURIIfDeckExists(ctx context.Context, tCtx *taskExecutionContext) error { | ||
| reader := tCtx.ow.GetReader() | ||
| if reader == nil && p.execInfo.OutputInfo != nil { | ||
| p.execInfo.OutputInfo.DeckURI = nil | ||
| return nil | ||
| } | ||
|
|
||
| exists, err := reader.DeckExists(ctx) | ||
| if err != nil { | ||
| logger.Errorf(ctx, "Failed to check deck file existence. Error: %v", err) | ||
| return regErrors.Wrapf(err, "failed to check existence of deck file") | ||
| } | ||
|
|
||
| if p.execInfo.OutputInfo == nil { | ||
| p.execInfo.OutputInfo = &handler.OutputInfo{} | ||
| } | ||
|
|
||
| if exists { | ||
| deckURIValue := tCtx.ow.GetDeckPath() | ||
| p.execInfo.OutputInfo.DeckURI = &deckURIValue | ||
| } | ||
|
|
||
| return nil | ||
| } | ||
|
|
||
| func (p *pluginRequestedTransition) CacheHit(outputPath storage.DataReference, entry catalog.Entry) { | ||
eapolinario marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| p.ttype = handler.TransitionTypeEphemeral | ||
| p.pInfo = pluginCore.PhaseInfoSuccess(nil) | ||
| p.ObserveSuccess(outputPath, deckPath, &event.TaskNodeMetadata{CacheStatus: entry.GetStatus().GetCacheStatus(), CatalogKey: entry.GetStatus().GetMetadata()}) | ||
| p.ObserveSuccess(outputPath, &event.TaskNodeMetadata{CacheStatus: entry.GetStatus().GetCacheStatus(), CatalogKey: entry.GetStatus().GetMetadata()}) | ||
| } | ||
|
|
||
| func (p *pluginRequestedTransition) PopulateCacheInfo(entry catalog.Entry) { | ||
|
|
@@ -144,10 +190,13 @@ func (p *pluginRequestedTransition) FinalTaskEvent(input ToTaskExecutionEventInp | |
| return ToTaskExecutionEvent(input) | ||
| } | ||
|
|
||
| func (p *pluginRequestedTransition) ObserveSuccess(outputPath storage.DataReference, deckPath *storage.DataReference, taskMetadata *event.TaskNodeMetadata) { | ||
| p.execInfo.OutputInfo = &handler.OutputInfo{ | ||
| OutputURI: outputPath, | ||
| DeckURI: deckPath, | ||
| func (p *pluginRequestedTransition) ObserveSuccess(outputPath storage.DataReference, taskMetadata *event.TaskNodeMetadata) { | ||
| if p.execInfo.OutputInfo == nil { | ||
| p.execInfo.OutputInfo = &handler.OutputInfo{ | ||
| OutputURI: outputPath, | ||
| } | ||
| } else { | ||
| p.execInfo.OutputInfo.OutputURI = outputPath | ||
eapolinario marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| p.execInfo.TaskNodeInfo = &handler.TaskNodeInfo{ | ||
|
|
@@ -171,7 +220,8 @@ func (p *pluginRequestedTransition) FinalTransition(ctx context.Context) (handle | |
| } | ||
|
|
||
| logger.Debugf(ctx, "Task still running") | ||
| return handler.DoTransition(p.ttype, handler.PhaseInfoRunning(nil)), nil | ||
| // Here will send the deck uri to flyteadmin | ||
| return handler.DoTransition(p.ttype, handler.PhaseInfoRunning(&p.execInfo)), nil | ||
| } | ||
|
|
||
| // The plugin interface available especially for testing. | ||
|
|
@@ -380,6 +430,27 @@ func (t Handler) fetchPluginTaskMetrics(pluginID, taskType string) (*taskMetrics | |
| return t.taskMetricsMap[metricNameKey], nil | ||
| } | ||
|
|
||
| func GetDeckStatus(ctx context.Context, tCtx *taskExecutionContext) (DeckStatus, error) { | ||
| // FLYTE_ENABLE_DECK is used when flytekit > 1.14.0 | ||
|
||
| // For backward compatibility, | ||
| // we will return DeckUnknown and call a HEAD request to check if the deck file exists in the terminal state. | ||
|
|
||
| template, err := tCtx.tr.Read(ctx) | ||
|
Comment on lines
+432
to
+445
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Better comments! |
||
| if err != nil { | ||
| return DeckUnknown, regErrors.Wrapf(err, "failed to read task template") | ||
| } | ||
|
|
||
| metadata := template.GetMetadata() | ||
| if metadata == nil { | ||
| return DeckUnknown, nil | ||
eapolinario marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
| if metadata.GetGeneratesDeck() { | ||
| return DeckEnabled, nil | ||
| } | ||
|
|
||
| return DeckDisabled, nil | ||
| } | ||
|
|
||
| func (t Handler) invokePlugin(ctx context.Context, p pluginCore.Plugin, tCtx *taskExecutionContext, ts handler.TaskNodeState) (*pluginRequestedTransition, error) { | ||
| pluginTrns := &pluginRequestedTransition{} | ||
|
|
||
|
|
@@ -464,8 +535,41 @@ func (t Handler) invokePlugin(ctx context.Context, p pluginCore.Plugin, tCtx *ta | |
| } | ||
| } | ||
|
|
||
| // Regardless of the observed phase, we always add the DeckUri to support real-time deck functionality. | ||
| // The deck should be accessible even if the task is still running or has failed. | ||
| // It's possible that the deck URI may not exist in remote storage yet or will never exist. | ||
| // So, it is console's responsibility to handle the case when the deck URI actually does not exist. | ||
| deckStatus, err := GetDeckStatus(ctx, tCtx) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
| if deckStatus == DeckEnabled { | ||
| pluginTrns.AddDeckURI(tCtx) | ||
| } | ||
|
|
||
| // Handle backward compatibility for Flyte deck display behavior. | ||
| // | ||
| // Before (legacy behavior): | ||
| // - Deck URI was only shown if the deck file existed in the terminal state. | ||
| // - We relied on a HEAD request to check if the deck file exists, then added the URI to the event. | ||
| // | ||
| // After (new behavior): | ||
| // - If `FLYTE_ENABLE_DECK = true` is set in the task template config (requires Flytekit > 1.14.0), | ||
|
||
| // we display the deck URI from the beginning rather than waiting until the terminal state. | ||
| // | ||
| // For backward compatibility with older Flytekit versions (which don't support `FLYTE_ENABLE_DECK`), | ||
| // we still need to check deck file existence in the terminal state. This ensures that when the deck | ||
| // isn't enabled via config or doesn't exist, we only show the URI in terminal states if the deck file | ||
| // is actually present. | ||
| switch pluginTrns.pInfo.Phase() { | ||
| case pluginCore.PhaseSuccess: | ||
| // This is for backward compatibility with older Flytekit versions. | ||
| if deckStatus == DeckUnknown { | ||
| err = pluginTrns.AddDeckURIIfDeckExists(ctx, tCtx) | ||
|
||
| } | ||
| if err != nil { | ||
| return pluginTrns, err | ||
| } | ||
| // ------------------------------------- | ||
| // TODO: @kumare create Issue# Remove the code after we use closures to handle dynamic nodes | ||
| // This code only exists to support Dynamic tasks. Eventually dynamic tasks will use closure nodes to execute | ||
|
|
@@ -501,25 +605,21 @@ func (t Handler) invokePlugin(ctx context.Context, p pluginCore.Plugin, tCtx *ta | |
| CheckpointUri: tCtx.ow.GetCheckpointPrefix().String(), | ||
| }) | ||
| } else { | ||
| var deckURI *storage.DataReference | ||
| if tCtx.ow.GetReader() != nil { | ||
| exists, err := tCtx.ow.GetReader().DeckExists(ctx) | ||
| if err != nil { | ||
| logger.Errorf(ctx, "Failed to check deck file existence. Error: %v", err) | ||
| return pluginTrns, regErrors.Wrapf(err, "failed to check existence of deck file") | ||
| } else if exists { | ||
| deckURIValue := tCtx.ow.GetDeckPath() | ||
| deckURI = &deckURIValue | ||
| } | ||
| } | ||
| pluginTrns.ObserveSuccess(tCtx.ow.GetOutputPath(), deckURI, | ||
| pluginTrns.ObserveSuccess(tCtx.ow.GetOutputPath(), | ||
eapolinario marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| &event.TaskNodeMetadata{ | ||
| CheckpointUri: tCtx.ow.GetCheckpointPrefix().String(), | ||
| }) | ||
| } | ||
| case pluginCore.PhaseRetryableFailure: | ||
| fallthrough | ||
| case pluginCore.PhasePermanentFailure: | ||
| // This is for backward compatibility with older Flytekit versions. | ||
| if deckStatus == DeckUnknown { | ||
| err = pluginTrns.AddDeckURIIfDeckExists(ctx, tCtx) | ||
| } | ||
| if err != nil { | ||
| return pluginTrns, err | ||
| } | ||
| pluginTrns.ObservedFailure( | ||
| &event.TaskNodeMetadata{ | ||
| CheckpointUri: tCtx.ow.GetCheckpointPrefix().String(), | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.