-
Notifications
You must be signed in to change notification settings - Fork 136
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
feat: [TKC-3016] add defaultConfigs for TestWorkflow executions #6090
Changes from all commits
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 |
---|---|---|
|
@@ -21,7 +21,10 @@ import ( | |
|
||
var _ Repository = (*MongoRepository)(nil) | ||
|
||
const CollectionName = "testworkflowresults" | ||
const ( | ||
CollectionName = "testworkflowresults" | ||
configParamSizeLimit = 100 | ||
) | ||
|
||
func NewMongoRepository(db *mongo.Database, allowDiskUse bool, opts ...MongoRepositoryOpt) *MongoRepository { | ||
r := &MongoRepository{ | ||
|
@@ -60,9 +63,39 @@ type MongoRepositoryOpt func(*MongoRepository) | |
|
||
func (r *MongoRepository) Get(ctx context.Context, id string) (result testkube.TestWorkflowExecution, err error) { | ||
err = r.Coll.FindOne(ctx, bson.M{"$or": bson.A{bson.M{"id": id}, bson.M{"name": id}}}).Decode(&result) | ||
|
||
if result.ResolvedWorkflow != nil && result.ResolvedWorkflow.Spec != nil && result.ConfigParams != nil { | ||
r.populateConfigParams(result.ResolvedWorkflow, result.ConfigParams) | ||
} | ||
|
||
return *result.UnscapeDots(), err | ||
} | ||
|
||
func (r *MongoRepository) populateConfigParams(resolvedWorkflow *testkube.TestWorkflow, configParams map[string]testkube.TestWorkflowExecutionConfigValue) { | ||
for k, v := range resolvedWorkflow.Spec.Config { | ||
if v.Default_ != nil { | ||
if _, ok := configParams[k]; !ok { | ||
configParams[k] = testkube.TestWorkflowExecutionConfigValue{ | ||
DefaultValue: v.Default_.Value, | ||
} | ||
} else { | ||
value := configParams[k].Value | ||
truncated := false | ||
if len(value) > configParamSizeLimit { | ||
value = value[:configParamSizeLimit] | ||
truncated = true | ||
} | ||
configParams[k] = testkube.TestWorkflowExecutionConfigValue{ | ||
DefaultValue: v.Default_.Value, | ||
Value: value, | ||
Truncated: truncated, | ||
} | ||
} | ||
} | ||
} | ||
return | ||
} | ||
|
||
func (r *MongoRepository) GetByNameAndTestWorkflow(ctx context.Context, name, workflowName string) (result testkube.TestWorkflowExecution, err error) { | ||
err = r.Coll.FindOne(ctx, bson.M{"$or": bson.A{bson.M{"id": name}, bson.M{"name": name}}, "workflow.name": workflowName}).Decode(&result) | ||
return *result.UnscapeDots(), err | ||
|
@@ -241,8 +274,13 @@ func (r *MongoRepository) GetExecutions(ctx context.Context, filter Filter) (res | |
return | ||
} | ||
|
||
type TestWorkflowExecutionSummaryWithResolvedWorkflow struct { | ||
testkube.TestWorkflowExecutionSummary `json:",inline" bson:",inline"` | ||
ResolvedWorkflow *testkube.TestWorkflow `json:"resolvedWorkflow,omitempty"` | ||
} | ||
|
||
func (r *MongoRepository) GetExecutionsSummary(ctx context.Context, filter Filter) (result []testkube.TestWorkflowExecutionSummary, err error) { | ||
result = make([]testkube.TestWorkflowExecutionSummary, 0) | ||
executions := make([]TestWorkflowExecutionSummaryWithResolvedWorkflow, 0) | ||
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 to avoid fetching unnecessary data there. You can either - change the query to fetch only important part, or even better - adjust the aggregate to provide these data. 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. Also, we have different pipelines for Enterprise, so it's very important to test it through. |
||
query, opts := composeQueryAndOpts(filter) | ||
if r.allowDiskUse { | ||
opts.SetAllowDiskUse(r.allowDiskUse) | ||
|
@@ -255,16 +293,20 @@ func (r *MongoRepository) GetExecutionsSummary(ctx context.Context, filter Filte | |
"result.steps": 0, | ||
"result.initialization": 0, | ||
"workflow.spec": 0, | ||
"resolvedWorkflow": 0, | ||
}) | ||
cursor, err := r.Coll.Find(ctx, query, opts) | ||
if err != nil { | ||
return | ||
} | ||
err = cursor.All(ctx, &result) | ||
err = cursor.All(ctx, &executions) | ||
result = make([]testkube.TestWorkflowExecutionSummary, len(executions)) | ||
for i := range executions { | ||
executions[i].UnscapeDots() | ||
|
||
for i := range result { | ||
result[i].UnscapeDots() | ||
if executions[i].ResolvedWorkflow != nil && executions[i].ResolvedWorkflow.Spec != nil && executions[i].ConfigParams != nil { | ||
r.populateConfigParams(executions[i].ResolvedWorkflow, executions[i].ConfigParams) | ||
} | ||
result[i] = executions[i].TestWorkflowExecutionSummary | ||
} | ||
return | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not important: I don't think it should be part of this struct, as it's completely independent