Skip to content
This repository has been archived by the owner on Oct 9, 2023. It is now read-only.

[wip] Perf test inmemory plugin - sleeper #362

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
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
1 change: 1 addition & 0 deletions cmd/controller/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
_ "github.com/flyteorg/flyteplugins/go/tasks/plugins/k8s/sagemaker"
_ "github.com/flyteorg/flyteplugins/go/tasks/plugins/k8s/sidecar"
_ "github.com/flyteorg/flyteplugins/go/tasks/plugins/k8s/spark"
_ "github.com/flyteorg/flytepropeller/pkg/controller/nodes/task"
"github.com/flyteorg/flytestdlib/contextutils"
"github.com/flyteorg/flytestdlib/promutils/labeled"

Expand Down
1 change: 1 addition & 0 deletions config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ tasks:
- container
- sidecar
- K8S-ARRAY
- sleep
# Uncomment to enable sagemaker plugin
# - sagemaker_training
# - sagemaker_hyperparameter_tuning
Expand Down
61 changes: 61 additions & 0 deletions pkg/controller/nodes/task/sleeper_plugin.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package task
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit:

Suggested change
package task
// +build test_tools
package task

build with the plugin:
go build -tags test_tools


import (
"context"
pluginMachinery "github.com/flyteorg/flyteplugins/go/tasks/pluginmachinery"
pluginCore "github.com/flyteorg/flyteplugins/go/tasks/pluginmachinery/core"
"github.com/flyteorg/flytestdlib/logger"
"time"
)

type SleeperPlugin struct {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add one that simulates K8s APIs? I think that might be more useful to start with...


}

func (s SleeperPlugin) GetID() string {
return "sleep"
}

func (s SleeperPlugin) GetProperties() pluginCore.PluginProperties {
return pluginCore.PluginProperties{}
}

func (s SleeperPlugin) Handle(ctx context.Context, tCtx pluginCore.TaskExecutionContext) (pluginCore.Transition, error) {
logger.Infof(ctx, "Sleeper plugin invoked!")
tk, err := tCtx.TaskReader().Read(ctx)
if err != nil {
return pluginCore.UnknownTransition, err
}
sleepTime := time.Millisecond * 1000
if tk.GetConfig() != nil {
v, ok := tk.GetConfig()["sleep"]
if ok {
i, err := time.ParseDuration(v)
if err == nil {
sleepTime = i
}
}
}
logger.Infof(ctx, "Sleeping for %v", sleepTime)
time.Sleep(sleepTime)
return pluginCore.DoTransition(pluginCore.PhaseInfoSuccess(nil)), nil
}

func (s SleeperPlugin) Abort(ctx context.Context, tCtx pluginCore.TaskExecutionContext) error {
return nil
}

func (s SleeperPlugin) Finalize(ctx context.Context, tCtx pluginCore.TaskExecutionContext) error {
return nil
}

func init() {
pluginMachinery.PluginRegistry().RegisterCorePlugin(pluginCore.PluginEntry{
ID: "sleep",
RegisteredTaskTypes: []pluginCore.TaskType{"sleep"},
LoadPlugin: func(ctx context.Context, iCtx pluginCore.SetupContext) (pluginCore.Plugin, error) {
return SleeperPlugin{}, nil
},
DefaultForTaskTypes: []pluginCore.TaskType{"sleep"},
})
}