Skip to content
Merged
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
8 changes: 8 additions & 0 deletions pkg/search/postgres/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"github.com/pkg/errors"
v1 "github.com/stackrox/rox/generated/api/v1"
"github.com/stackrox/rox/pkg/buildinfo"
"github.com/stackrox/rox/pkg/contextutil"
"github.com/stackrox/rox/pkg/devbuild"
"github.com/stackrox/rox/pkg/errox"
"github.com/stackrox/rox/pkg/logging"
Expand Down Expand Up @@ -581,6 +582,7 @@ func RunSearchRequest(ctx context.Context, category v1.SearchCategory, q *v1.Que
schema := mapping.GetTableFromCategory(category)

return pgutils.Retry2(func() ([]searchPkg.Result, error) {
ctx := contextutil.WithValuesFrom(context.Background(), ctx)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I don't understand this :(
Why we need to use context.Background here? How do we propagate timeouts or cancelation then?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

// WithValuesFrom returns a context that takes its deadline, errors and cancellation signal
// from ctx, but its values from valueProvider.

return RunSearchRequestForSchema(ctx, schema, q, db)
})
}
Expand Down Expand Up @@ -704,6 +706,7 @@ func RunSearchRequestForSchema(ctx context.Context, schema *walker.Schema, q *v1
return nil, nil
}
return pgutils.Retry2(func() ([]searchPkg.Result, error) {
ctx := contextutil.WithValuesFrom(context.Background(), ctx)
return retryableRunSearchRequestForSchema(ctx, query, schema, db)
})
}
Expand All @@ -713,6 +716,7 @@ func RunCountRequest(ctx context.Context, category v1.SearchCategory, q *v1.Quer
schema := mapping.GetTableFromCategory(category)

return pgutils.Retry2(func() (int, error) {
ctx := contextutil.WithValuesFrom(context.Background(), ctx)
return RunCountRequestForSchema(ctx, schema, q, db)
})
}
Expand All @@ -726,6 +730,7 @@ func RunCountRequestForSchema(ctx context.Context, schema *walker.Schema, q *v1.
queryStr := query.AsSQL()

return pgutils.Retry2(func() (int, error) {
ctx := contextutil.WithValuesFrom(context.Background(), ctx)
var count int
row := tracedQueryRow(ctx, db, queryStr, query.Data...)
if err := row.Scan(&count); err != nil {
Expand Down Expand Up @@ -758,6 +763,7 @@ func RunGetQueryForSchema[T any, PT unmarshaler[T]](ctx context.Context, schema
queryStr := query.AsSQL()

return pgutils.Retry2(func() (*T, error) {
ctx := contextutil.WithValuesFrom(context.Background(), ctx)
row := tracedQueryRow(ctx, db, queryStr, query.Data...)
return unmarshal[T, PT](row)
})
Expand Down Expand Up @@ -785,6 +791,7 @@ func RunGetManyQueryForSchema[T any, PT unmarshaler[T]](ctx context.Context, sch
}

return pgutils.Retry2(func() ([]*T, error) {
ctx := contextutil.WithValuesFrom(context.Background(), ctx)
return retryableRunGetManyQueryForSchema[T, PT](ctx, query, db)
})
}
Expand Down Expand Up @@ -841,6 +848,7 @@ func RunDeleteRequestForSchema(ctx context.Context, schema *walker.Schema, q *v1
}

return pgutils.Retry(func() error {
ctx := contextutil.WithValuesFrom(context.Background(), ctx)
_, err = db.Exec(ctx, query.AsSQL(), query.Data...)
if err != nil {
return errors.Wrapf(err, "could not delete from %q", schema.Table)
Expand Down