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

pkg/cmd: add metric for logical checks #2170

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

jzelinskie
Copy link
Member

@jzelinskie jzelinskie commented Dec 16, 2024

This tracks the "logical checks" which includes not only check requests but each item in a bulk check request.

@jzelinskie jzelinskie added priority/3 low This would be nice to have area/observability Affects telemetry data labels Dec 16, 2024
@jzelinskie jzelinskie requested a review from a team as a code owner December 16, 2024 23:09
@github-actions github-actions bot added the area/CLI Affects the command line label Dec 16, 2024
This tracks the "logical checks" which includes
not only check requests but each item in a bulk
check request.

func LogicalChecksMetricUnary(ctx context.Context, request any, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (any, error) {
response, err := handler(ctx, request)
if err == nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do we want to exclude errors? For a 100 elements bulk check, 99 could have been successfully executed, but the last one took longer and made the bulk check fail. Do we not count the other successful 99?

Perhaps you could add another label error that is true if the request failed.

@@ -406,6 +415,11 @@ func DefaultStreamingMiddleware(opts MiddlewareOption) (*MiddlewareChain[grpc.St
WithInterceptor(serverversion.StreamServerInterceptor(opts.EnableVersionResponse)).
Done(),

NewStreamMiddleware().
WithName(DefaultMiddlewareLogicalChecks).
WithInterceptor(noopStreamInterceptor).
Copy link
Contributor

Choose a reason for hiding this comment

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

Should it be marked internal? I lean towards no, just thinking out loud. Internal middlewares should not be replaced or removed because they are crucial to SpiceDB's correct functioning. Nothing would break in SpiceDB, but if the metric disappears, it will affect folks running SpiceDB who rely on it.

Comment on lines +497 to +503
case *v1.CheckPermissionRequest:
svc, method := grpcutil.SplitMethodName(info.FullMethod)
LogicalChecksCounter.WithLabelValues(method, svc, "unary").Add(1)
case *v1.CheckBulkPermissionsRequest:
svc, method := grpcutil.SplitMethodName(info.FullMethod)
LogicalChecksCounter.WithLabelValues(method, svc, "unary").Add(float64(len(m.GetItems())))
default:
Copy link
Contributor

Choose a reason for hiding this comment

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

please add unit test testing testing both request types, and with/without error

Comment on lines +487 to +489
Namespace: "spicedb",
Subsystem: "logical",
Name: "permission_checks_total",
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there a better namespace for this metric? I'm not sure "logical" is a subsystem. Should it be aligned with the namespace of the grpc prom middleware? or perhaps the subsystem is a permissions service?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/CLI Affects the command line area/observability Affects telemetry data priority/3 low This would be nice to have
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants