Skip to content

Conversation

@Jozott00
Copy link
Collaborator

@Jozott00 Jozott00 commented Sep 18, 2025

Subsystem
gRPC

Problem Description
A main feature of all gRPC libraries is their interceptor API.
We want a Kotlin idiomatic simple-to-use interceptor API (for client and server) that allows users to implement things like authentication, logging or tracing.

Solution
This PR adds a convenient Kotlin idiomatic interceptor API.

E.g. a (over-simplified) server-side authorization interceptor could look like this

val myAuthInterceptor = object : ServerInterceptor {
    override fun <Request, Response> ServerCallScope<Request, Response>.intercept(request: Flow<Request>): Flow<Response> =
        flow {
            val authorized = mySuspendAuth(requestHeaders)
            if (!authorized) {
                close(Status(StatusCode.PERMISSION_DENIED, "Not authorized"))
            }

            proceedUnmodified(request)
        }
     }

@Jozott00 Jozott00 self-assigned this Sep 18, 2025
@Jozott00 Jozott00 added the feature New feature or request label Sep 18, 2025
@Jozott00 Jozott00 requested a review from Mr3zee September 18, 2025 13:31
@Jozott00 Jozott00 marked this pull request as ready for review September 18, 2025 13:31
Copy link
Member

@Mr3zee Mr3zee left a comment

Choose a reason for hiding this comment

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

Great work! I have some comments nitpicking some details, mostly DSL, but everything else is well designed

and btw kDocs are really good there, quite easy to read and understand

@Jozott00 Jozott00 requested a review from Mr3zee September 19, 2025 17:45
Copy link
Member

@Mr3zee Mr3zee left a comment

Choose a reason for hiding this comment

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

Great, thank you!

@morki
Copy link

morki commented Sep 22, 2025

Will there be an interceptor feature in KRPC too? It would be really handy for the same use cases as presented here.

@Mr3zee
Copy link
Member

Mr3zee commented Sep 22, 2025

@morki in some sort, yes, though later, we only maintain kRPC now, until we finish with gRPC (which is not much else to do, but still will take a couple of months)

Signed-off-by: Johannes Zottele <[email protected]>
Signed-off-by: Johannes Zottele <[email protected]>
Signed-off-by: Johannes Zottele <[email protected]>
Signed-off-by: Johannes Zottele <[email protected]>
Signed-off-by: Johannes Zottele <[email protected]>
Signed-off-by: Johannes Zottele <[email protected]>
Signed-off-by: Johannes Zottele <[email protected]>
Signed-off-by: Johannes Zottele <[email protected]>
Signed-off-by: Johannes Zottele <[email protected]>
Signed-off-by: Johannes Zottele <[email protected]>
Signed-off-by: Johannes Zottele <[email protected]>
Signed-off-by: Johannes Zottele <[email protected]>
@Jozott00 Jozott00 merged commit aec6379 into grpc-common Sep 29, 2025
5 of 6 checks passed
@Jozott00 Jozott00 deleted the grpc/interceptors branch October 7, 2025 16:11
Mr3zee pushed a commit that referenced this pull request Oct 27, 2025
* grpc: Add client interceptor support

Signed-off-by: Johannes Zottele <[email protected]>

* grpc: Add client interceptor support

Signed-off-by: Johannes Zottele <[email protected]>

* grpc: Add server interceptor support

Signed-off-by: Johannes Zottele <[email protected]>

* grpc: Refactor server scope API

Signed-off-by: Johannes Zottele <[email protected]>

* grpc: Refactor client scope API

Signed-off-by: Johannes Zottele <[email protected]>

* grpc: Add tests

Signed-off-by: Johannes Zottele <[email protected]>

* grpc: Rename GrpcTrailers to GrpcMetadata.kt

Signed-off-by: Johannes Zottele <[email protected]>

* grpc: Refactor cancel API in ClientCallScope to return Nothing

Signed-off-by: Johannes Zottele <[email protected]>

* grpc: Remove println

Signed-off-by: Johannes Zottele <[email protected]>

* grpc: Adjust metadata names

Signed-off-by: Johannes Zottele <[email protected]>

* grpc: Fix Ktor server constructor

Signed-off-by: Johannes Zottele <[email protected]>

* grpc: Add documentation

Signed-off-by: Johannes Zottele <[email protected]>

* grpc: Adjust client/server DSL and provide documentation

Signed-off-by: Johannes Zottele <[email protected]>

* grpc: Fix race condition bug

Signed-off-by: Johannes Zottele <[email protected]>

* grpc: Fix context not set

Signed-off-by: Johannes Zottele <[email protected]>

* grpc: Add multi interceptor tests

Signed-off-by: Johannes Zottele <[email protected]>

* grpc: Address PR comments

Signed-off-by: Johannes Zottele <[email protected]>

* grpc: Add client interceptor execution order test

Signed-off-by: Johannes Zottele <[email protected]>

* grpc: Address PR comments

Signed-off-by: Johannes Zottele <[email protected]>

* grpc: Fixing bug after rebase

Signed-off-by: Johannes Zottele <[email protected]>

* grpc: Fix default proto package in service name

---------

Signed-off-by: Johannes Zottele <[email protected]>
Mr3zee pushed a commit that referenced this pull request Nov 12, 2025
* grpc: Add client interceptor support

Signed-off-by: Johannes Zottele <[email protected]>

* grpc: Add client interceptor support

Signed-off-by: Johannes Zottele <[email protected]>

* grpc: Add server interceptor support

Signed-off-by: Johannes Zottele <[email protected]>

* grpc: Refactor server scope API

Signed-off-by: Johannes Zottele <[email protected]>

* grpc: Refactor client scope API

Signed-off-by: Johannes Zottele <[email protected]>

* grpc: Add tests

Signed-off-by: Johannes Zottele <[email protected]>

* grpc: Rename GrpcTrailers to GrpcMetadata.kt

Signed-off-by: Johannes Zottele <[email protected]>

* grpc: Refactor cancel API in ClientCallScope to return Nothing

Signed-off-by: Johannes Zottele <[email protected]>

* grpc: Remove println

Signed-off-by: Johannes Zottele <[email protected]>

* grpc: Adjust metadata names

Signed-off-by: Johannes Zottele <[email protected]>

* grpc: Fix Ktor server constructor

Signed-off-by: Johannes Zottele <[email protected]>

* grpc: Add documentation

Signed-off-by: Johannes Zottele <[email protected]>

* grpc: Adjust client/server DSL and provide documentation

Signed-off-by: Johannes Zottele <[email protected]>

* grpc: Fix race condition bug

Signed-off-by: Johannes Zottele <[email protected]>

* grpc: Fix context not set

Signed-off-by: Johannes Zottele <[email protected]>

* grpc: Add multi interceptor tests

Signed-off-by: Johannes Zottele <[email protected]>

* grpc: Address PR comments

Signed-off-by: Johannes Zottele <[email protected]>

* grpc: Add client interceptor execution order test

Signed-off-by: Johannes Zottele <[email protected]>

* grpc: Address PR comments

Signed-off-by: Johannes Zottele <[email protected]>

* grpc: Fixing bug after rebase

Signed-off-by: Johannes Zottele <[email protected]>

* grpc: Fix default proto package in service name

---------

Signed-off-by: Johannes Zottele <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants