-
Notifications
You must be signed in to change notification settings - Fork 218
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Split client/server interceptors (#289)
* Split client/server interceptors * Add client logger test
- Loading branch information
Showing
19 changed files
with
108 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
defmodule Helloworld.Endpoint do | ||
use GRPC.Endpoint | ||
|
||
intercept GRPC.Logger.Server | ||
intercept GRPC.Server.Interceptors.Logger | ||
run Helloworld.Greeter.Server | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
defmodule Routeguide.Endpoint do | ||
use GRPC.Endpoint | ||
|
||
intercept GRPC.Logger.Server | ||
intercept GRPC.Server.Interceptors.Logger | ||
run Routeguide.RouteGuide.Server | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
defmodule GRPC.Client.Interceptor do | ||
@moduledoc """ | ||
Interceptor on client side. See `GRPC.Stub.connect/2`. | ||
""" | ||
alias GRPC.Client.Stream | ||
|
||
@type options :: any() | ||
@type req :: struct() | nil | ||
@type next :: (Stream.t(), req -> GRPC.Stub.rpc_return()) | ||
|
||
@callback init(options) :: options | ||
@callback call(stream :: Stream.t(), req, next, options) :: GRPC.Stub.rpc_return() | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
defmodule GRPC.Client.Interceptors.LoggerTest do | ||
use ExUnit.Case, async: false | ||
|
||
import ExUnit.CaptureLog | ||
|
||
alias GRPC.Client.Interceptors.Logger, as: LoggerInterceptor | ||
alias GRPC.Client.Stream | ||
|
||
test "accepted_comparators filter logs correctly" do | ||
for {configured_level, accepted_comparators, should_log} <- | ||
[ | ||
{:error, [:lt], false}, | ||
{:error, [:eq], false}, | ||
{:error, [:gt], true}, | ||
{:debug, [:eq], false}, | ||
{:debug, [:eq, :gt], false}, | ||
{:info, [:lt, :eq], true} | ||
] do | ||
logger_level = Logger.level() | ||
assert logger_level == :info | ||
|
||
service_name = "service_name" | ||
rpc = {1, 2, 3} | ||
|
||
logs = | ||
capture_log(fn -> | ||
stream = %Stream{grpc_type: :unary, rpc: rpc, service_name: service_name} | ||
|
||
LoggerInterceptor.call( | ||
stream, | ||
:request, | ||
fn ^stream, :request -> {:ok, :ok} end, | ||
LoggerInterceptor.init( | ||
level: configured_level, | ||
accepted_comparators: accepted_comparators | ||
) | ||
) | ||
end) | ||
|
||
if should_log do | ||
assert Regex.match?( | ||
~r/\[#{configured_level}\]\s+Call #{to_string(elem(rpc, 0))} of #{service_name}/, | ||
logs | ||
) | ||
else | ||
assert logs == "" | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters