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

authorize: build evaluators cache in parallel #4722

Merged
merged 7 commits into from Nov 9, 2023

Conversation

wasaga
Copy link
Contributor

@wasaga wasaga commented Nov 8, 2023

Summary

Builds Rego evaluators in parallel, which makes sense for large route counts.
Also moves the parallel building code into separate utility package.

Related issues

User Explanation

Checklist

  • reference any related issues
  • updated docs
  • updated unit tests
  • updated UPGRADING.md
  • add appropriate tag (improvement / bug / etc)
  • ready for review

@wasaga wasaga requested a review from a team as a code owner November 8, 2023 04:33
@coveralls
Copy link

coveralls commented Nov 8, 2023

Coverage Status

coverage: 63.89% (+0.2%) from 63.655%
when pulling affdd67 on wasaga/parallel-build-evaluators
into 62a9299 on main.

evals, errs := errgrouputil.Build(ctx, builders...)
if len(errs) > 0 {
for _, err := range errs {
log.Error(ctx).Msg(err.Error())
Copy link
Contributor

Choose a reason for hiding this comment

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

If a single error will fail this operation, I wonder if we should take advantage of the error handling behavior built in to errgroup.Group, and have Build() return the first error encountered?

Copy link
Contributor Author

@wasaga wasaga Nov 9, 2023

Choose a reason for hiding this comment

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

that would be behaviour in authorize, but not in databroker package, which is why we return results and errors separately so that calling package may decide what to do next. use of errgroup is primarily for the SetLimit convenience

// and returns the results and any errors.
func Build[T any](
ctx context.Context,
builders ...BuilderFunc[T],
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not entirely sure about this API. I'm wondering if there's an alternative where we wouldn't need to allocate this entire slice of functions up front.

Have you considered something more like this?

func Build[I, O any](ctx context.Context, f func(I) (O, error))

Copy link
Contributor Author

Choose a reason for hiding this comment

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

agree its not the most elegant interface. i primarily wanted to concentrate the logic of concurrent building (and the magic formula of SetLimit(runtime.NumCPU()/2+1)) somewhere in one place for the config building speedup in v0.24

we can certainly iterate on a design that looks cleaner, as we still seem to have a few places where we can build heavy configs in parallel.


fn := func(i int) func() error {
return func() error {
result, err := builders[i](ctx)
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure about this context propagation either. Would it be better to check for cancellation here (or around line 41?), and return early if cancelled, without the builder function needing to know about the errgroup context?

@wasaga wasaga merged commit bf1cd0a into main Nov 9, 2023
9 checks passed
@wasaga wasaga deleted the wasaga/parallel-build-evaluators branch November 9, 2023 16:49
backport-actions-token bot pushed a commit that referenced this pull request Nov 9, 2023
* authorize: build evaluators cache in parallel

* session: add unit tests for gRPC wrapper methods (#4713)

* core/config: add support for maps in environments (#4717)

* reconciler: allow custom comparison function (#4726)

* add loopvar alias

---------

Co-authored-by: Kenneth Jenkins <51246568+kenjenkins@users.noreply.github.com>
Co-authored-by: Caleb Doxsey <cdoxsey@pomerium.com>
wasaga added a commit that referenced this pull request Nov 9, 2023
authorize: build evaluators cache in parallel (#4722)

* authorize: build evaluators cache in parallel

* session: add unit tests for gRPC wrapper methods (#4713)

* core/config: add support for maps in environments (#4717)

* reconciler: allow custom comparison function (#4726)

* add loopvar alias

---------

Co-authored-by: Denis Mishin <dmishin@pomerium.com>
Co-authored-by: Kenneth Jenkins <51246568+kenjenkins@users.noreply.github.com>
Co-authored-by: Caleb Doxsey <cdoxsey@pomerium.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants