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

Allow to set the decisionID from an external function #516

Merged

Conversation

Pushpalanka
Copy link
Contributor

@Pushpalanka Pushpalanka commented Feb 8, 2024

Short description

An improvement to allow sending the decision ID from outside avoiding the default UUID generation here

Expected behavior

Suggesting improvement will allow passing a function from outside which can operate on the result. Current behavior of the default UUID generation is left intact, unless the function set a decision ID.

Additional context

In a benchmark test we noticed the UUID generation is comparatively costly. (Below image shows a branch of it.)

Screenshot 2024-02-08 at 17 13 34

Hence it will benefit if we can send an externally generated ID and set it here, avoiding the costly operation.

CC: @mjungsbluth

Copy link
Member

@ashutosh-narkar ashutosh-narkar left a comment

Choose a reason for hiding this comment

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

Thanks for working on this @Pushpalanka! The changes lgtm. Just few comments below and we can then get this in.

@@ -34,14 +34,24 @@ type StopFunc = func()
// TransactionCloser should be called to abort the transaction
type TransactionCloser func(ctx context.Context, err error) error

// An Opt allowing externally setting the decision ID
type Opt func(*EvalResult)
Copy link
Member

Choose a reason for hiding this comment

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

Nit: do we need to define this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We can remove it. Thanks for the suggestion.

// NewEvalResult creates a new EvalResult and a StopFunc that is used to stop the timer for metrics
func NewEvalResult() (*EvalResult, StopFunc, error) {
func NewEvalResult(opts ...Opt) (*EvalResult, StopFunc, error) {
Copy link
Member

Choose a reason for hiding this comment

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

Can we do something like:

func NewEvalResult(opts ...func(*EvalResult)) (*EvalResult, StopFunc, 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.

Yes, improved.

Signed-off-by: Pushpalanka Jayawardhana <pushpalanka.jayawardhana@zalando.de>
Copy link
Member

@ashutosh-narkar ashutosh-narkar left a comment

Choose a reason for hiding this comment

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

Thanks @Pushpalanka!

@ashutosh-narkar ashutosh-narkar merged commit 6cf8de2 into open-policy-agent:main Feb 9, 2024
8 checks passed
@Pushpalanka
Copy link
Contributor Author

Pushpalanka commented Feb 9, 2024

Thanks @Pushpalanka!

Thanks @ashutosh-narkar for your support as well. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants