Skip to content

Commit

Permalink
Ensure Athena Plugin ClientRequestToken is within allowed limits (fly…
Browse files Browse the repository at this point in the history
…teorg#243)

* Ensure Athena Plugin ClientRequestToken is within allowed limits

Signed-off-by: Haytham Abuelfutuh <[email protected]>

* Update interface

Signed-off-by: Haytham Abuelfutuh <[email protected]>

* Unit tests

Signed-off-by: Haytham Abuelfutuh <[email protected]>
  • Loading branch information
EngHabu authored Feb 15, 2022
1 parent 4244f20 commit ec275d2
Show file tree
Hide file tree
Showing 6 changed files with 78 additions and 19 deletions.
22 changes: 11 additions & 11 deletions flyteplugins/go/tasks/logs/logconfig_flags.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 13 additions & 5 deletions flyteplugins/go/tasks/pluginmachinery/core/exec_metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,32 @@ import (
"k8s.io/apimachinery/pkg/types"
)

// Interface to expose any overrides that have been set for this task (like resource overrides etc)
// TaskOverrides interface to expose any overrides that have been set for this task (like resource overrides etc)
type TaskOverrides interface {
GetResources() *v1.ResourceRequirements
GetConfig() *v1.ConfigMap
}

// Simple Interface to expose the ExecutionID of the running Task
// TaskExecutionID is a simple Interface to expose the ExecutionID of the running Task
type TaskExecutionID interface {
// GetGeneratedName returns the computed/generated name for the task id
// deprecated: use GetGeneratedNameWithLength
GetGeneratedName() string

// GetGeneratedNameWith returns the generated name within a bounded length. If the name is smaller than minLength,
// it'll get right-padded with character '0'. If the name is bigger than maxLength, it'll get hashed to fit within.
GetGeneratedNameWith(minLength, maxLength int) (string, error)

// GetID returns the underlying idl task identifier.
GetID() core.TaskExecutionIdentifier
}

// TaskContext represents any execution information for a Task. It is used to communicate meta information about the
// TaskExecutionMetadata represents any execution information for a Task. It is used to communicate meta information about the
// execution or any previously stored information
type TaskExecutionMetadata interface {
// The owning Kubernetes object
// GetOwnerID returns the owning Kubernetes object
GetOwnerID() types.NamespacedName
// A specially generated task execution id, that is guaranteed to be unique and consistent for subsequent calls
// GetTaskExecutionID is a specially generated task execution id, that is guaranteed to be unique and consistent for subsequent calls
GetTaskExecutionID() TaskExecutionID
GetNamespace() string
GetOwnerReference() v12.OwnerReference
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,10 @@ func (m mockTaskExecutionIdentifier) GetID() core.TaskExecutionIdentifier {
return testTaskExecutionIdentifier
}

func (m mockTaskExecutionIdentifier) GetGeneratedNameWith(minLength, maxLength int) (string, error) {
return "task-exec-name", nil
}

func (m mockTaskExecutionIdentifier) GetGeneratedName() string {
return "task-exec-name"
}
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 10 additions & 2 deletions flyteplugins/go/tasks/plugins/webapi/athena/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,17 @@ func (p Plugin) Create(ctx context.Context, tCtx webapi.TaskExecutionContextRead
return nil, nil, errors.Errorf(errors2.BadTaskSpecification, "Database must not be empty.")
}

execID := tCtx.TaskExecutionMetadata().GetTaskExecutionID().GetID().NodeExecutionId.GetExecutionId()
// https://docs.aws.amazon.com/athena/latest/APIReference/API_StartQueryExecution.html dictates that the length
// must be within the range [32, 128].
clientRequestToken, err := tCtx.TaskExecutionMetadata().GetTaskExecutionID().GetGeneratedNameWith(32, 128)
if err != nil {
return nil, nil, errors.Wrapf(errors2.BadTaskSpecification, err,
"Generated Name [%v] couldn't be converted to a ClientRequestToken",
tCtx.TaskExecutionMetadata().GetTaskExecutionID().GetGeneratedName())
}

resp, err := p.client.StartQueryExecution(ctx, &athena.StartQueryExecutionInput{
ClientRequestToken: awsSdk.String(fmt.Sprintf("%v-%v-%v", execID.Project, execID.Domain, tCtx.TaskExecutionMetadata().GetTaskExecutionID().GetGeneratedName())),
ClientRequestToken: awsSdk.String(clientRequestToken),
QueryExecutionContext: &athenaTypes.QueryExecutionContext{
Database: awsSdk.String(queryInfo.Database),
Catalog: awsSdk.String(queryInfo.Catalog),
Expand Down

0 comments on commit ec275d2

Please sign in to comment.