Skip to content
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

Fix fsoc optimize configure fails if multiple workloads match filter #344

Merged
Changes from 1 commit
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
29 changes: 24 additions & 5 deletions cmd/optimize/configure.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ and push the configuration to the knowledge store. You may optionally override t
func configureOptimizer(flags *configureFlags) func(cmd *cobra.Command, args []string) error {
var workloadTemplate = template.Must(template.New("").Parse(`
SINCE -1w
FETCH id
FETCH id, isActive
FROM entities(k8s:deployment)[attributes("k8s.cluster.name") = "{{.Cluster}}" && attributes("k8s.namespace.name") = "{{.Namespace}}" && attributes("k8s.workload.name") = "{{.WorkloadName}}"]
`))

Expand Down Expand Up @@ -182,13 +182,32 @@ FROM entities(k8s:deployment)[attributes("k8s.cluster.name") = "{{.Cluster}}" &&
if mainDataSet == nil {
return errors.New("unable to configure optimizer; UQL main data set was nil for the given criteria")
}
if workloadIdsFound := len(mainDataSet.Data); workloadIdsFound != 1 {
return fmt.Errorf("unable to configure optimizer; found %v workload IDs for the given criteria", workloadIdsFound)

var workloadIdAny any
workloadIdsFound := len(mainDataSet.Data)
if workloadIdsFound < 1 {
return errors.New("unable to configure optimizer; no workload IDs matched the given criteria")
} else if workloadIdsFound > 1 {
log.Warnf("found %v workload IDs for the given criteria, pruning inactive results")

var activeIds []any
for _, workloadRow := range mainDataSet.Data {
if workloadRow[1].(string) == "true" {
activeIds = append(activeIds, workloadRow[0])
}
}
if activeIdsFound := len(activeIds); activeIdsFound != 1 {
return fmt.Errorf("unable to configure optimizer; found %v active workload IDs for the given criteria", activeIdsFound)
}

workloadIdAny = activeIds[0]
} else {
workloadIdAny = mainDataSet.Data[0][0]
}
var ok bool
workloadId, ok = mainDataSet.Data[0][0].(string)
workloadId, ok = workloadIdAny.(string)
if !ok {
return fmt.Errorf("unable to convert workloadId query value %q to string", mainDataSet.Data[0][0])
return fmt.Errorf("unable to convert workloadId query value %q to string", workloadIdAny)
}

profilerReport, err = getProfilerReport(workloadId)
Expand Down
Loading