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

Add caching to Lookup dispatcher #217

Merged
merged 2 commits into from
Oct 29, 2021
Merged

Conversation

josephschorr
Copy link
Member

Also adds cached dispatcher tests to the overall consistency test suite, and an more complicated lookup example

@josephschorr josephschorr requested a review from jakedt October 26, 2021 19:45
@github-actions github-actions bot added area/api v1 Affects the v1 API area/tooling Affects the dev or user toolchain (e.g. tests, ci, build tools) labels Oct 26, 2021
@josephschorr josephschorr force-pushed the lookup-caching branch 2 times, most recently from c67714b to 23c5b52 Compare October 26, 2021 19:48
Copy link
Member

@jakedt jakedt left a comment

Choose a reason for hiding this comment

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

I think we should discuss again why you think check and lookup are different w.r.t depth.

checkTotalCounter prometheus.Counter
checkFromCacheCounter prometheus.Counter
checkTotalCounter prometheus.Counter

Copy link
Member

Choose a reason for hiding this comment

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

remove empty line or group properly

Copy link
Member Author

Choose a reason for hiding this comment

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

Whoops


var (
checkResultEntryCost = int64(unsafe.Sizeof(checkResultEntry{}))
lookupResultEntryCost = int64(unsafe.Sizeof(lookupResultEntry{}))
Copy link
Member

Choose a reason for hiding this comment

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

This doesn't work because the response objects can contain a variable amount of data. We'll have to compute the costs dynamically per response.

Copy link
Member Author

Choose a reason for hiding this comment

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

Good point. I'll change it

@@ -158,6 +212,10 @@ func (cd *cachingDispatcher) Close() error {
return nil
}

func requestToKey(req *v1.DispatchCheckRequest) string {
func checkRequestToKey(req *v1.DispatchCheckRequest) string {
return fmt.Sprintf("%s@%s@%s", tuple.StringONR(req.ObjectAndRelation), tuple.StringONR(req.Subject), req.Metadata.AtRevision)
Copy link
Member

Choose a reason for hiding this comment

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

Feel free to throw check// or some such in this one too

@@ -146,7 +178,29 @@ func (cd *cachingDispatcher) DispatchExpand(ctx context.Context, req *v1.Dispatc

// DispatchLookup implements dispatch.Lookup interface and does not do any caching yet.
func (cd *cachingDispatcher) DispatchLookup(ctx context.Context, req *v1.DispatchLookupRequest) (*v1.DispatchLookupResponse, error) {
return cd.d.DispatchLookup(ctx, req)
cd.lookupTotalCounter.Inc()
if req.Metadata.DepthRemaining > 0 {
Copy link
Member

Choose a reason for hiding this comment

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

This conditional seems wrong. If it's < 1 shouldn't the whole thing just error immediately?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, but I didn't want to duplicate the error raising code, so I just have it go to dispatch, which will raise the error

Copy link
Member

Choose a reason for hiding this comment

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

This should be changed now to just let this flow through to the required depth budget > depth remaining the way check works.

Copy link
Member

Choose a reason for hiding this comment

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

Check should also be updated.

Copy link
Member Author

Choose a reason for hiding this comment

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

What the hell... I changed this... I think my VSCode didn't save my changes to this file :(

Also adds cached dispatcher tests to the overall consistency test suite, and an more complicated lookup example
@josephschorr
Copy link
Member Author

Added the DepthRequired and changed the cache to use it

@@ -362,6 +374,7 @@ func checkResultError(err error, numRequests uint32) CheckResult {
&v1.DispatchCheckResponse{
Metadata: &v1.ResponseMeta{
DispatchCount: numRequests,
DepthRequired: 1,
Copy link
Member

Choose a reason for hiding this comment

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

Don't we want to actually thread the max depth required through here too?

Copy link
Member

Choose a reason for hiding this comment

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

For expand and lookup as well....

Copy link
Member Author

Choose a reason for hiding this comment

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

I went back and forth, but I was thinking for errors that it made sense to just always return them, rather than caring about the depth required for them in the cache.

Copy link
Member

Choose a reason for hiding this comment

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

I think the idea is that the DepthRequired should stand on its own in a CheckResponse. If it's there, it should be accurate.

Copy link
Member Author

Choose a reason for hiding this comment

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

Okay, I can change it.

var checkResultEntryCost = int64(unsafe.Sizeof(checkResultEntry{}))
type lookupResultEntry struct {
result *v1.DispatchLookupResponse
computedWithDepthRemaining uint32
Copy link
Member

Choose a reason for hiding this comment

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

This should be changed to storing the required depth budget.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, I lost this change too. Re-fixed

@@ -146,7 +178,29 @@ func (cd *cachingDispatcher) DispatchExpand(ctx context.Context, req *v1.Dispatc

// DispatchLookup implements dispatch.Lookup interface and does not do any caching yet.
func (cd *cachingDispatcher) DispatchLookup(ctx context.Context, req *v1.DispatchLookupRequest) (*v1.DispatchLookupResponse, error) {
return cd.d.DispatchLookup(ctx, req)
cd.lookupTotalCounter.Inc()
if req.Metadata.DepthRemaining > 0 {
Copy link
Member

Choose a reason for hiding this comment

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

This should be changed now to just let this flow through to the required depth budget > depth remaining the way check works.

@@ -146,7 +178,29 @@ func (cd *cachingDispatcher) DispatchExpand(ctx context.Context, req *v1.Dispatc

// DispatchLookup implements dispatch.Lookup interface and does not do any caching yet.
func (cd *cachingDispatcher) DispatchLookup(ctx context.Context, req *v1.DispatchLookupRequest) (*v1.DispatchLookupResponse, error) {
return cd.d.DispatchLookup(ctx, req)
cd.lookupTotalCounter.Inc()
if req.Metadata.DepthRemaining > 0 {
Copy link
Member

Choose a reason for hiding this comment

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

Check should also be updated.

@josephschorr
Copy link
Member Author

josephschorr commented Oct 29, 2021

Updated

@jakedt jakedt merged commit f225a86 into authzed:main Oct 29, 2021
@github-actions github-actions bot locked and limited conversation to collaborators Oct 29, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area/api v1 Affects the v1 API area/tooling Affects the dev or user toolchain (e.g. tests, ci, build tools)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants