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

Merge upstream v0.7.0 version and prepare v0.9.0 release #16

Merged
merged 16 commits into from
Jan 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 24 additions & 22 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ jobs:
- uses: actions/checkout@v3
- uses: erlef/setup-beam@v1
with:
otp-version: 24
elixir-version: 1.13.1
otp-version: 25.1.x
elixir-version: 1.14.x
- name: Retrieve dependencies cache
uses: actions/cache@v3
id: mix-cache # id to use in retrieve action
Expand All @@ -28,19 +28,20 @@ jobs:
run: mix deps.get 1>/dev/null
- name: Check format
run: mix format --check-formatted

tests:
runs-on: ubuntu-20.04
name: OTP ${{matrix.otp}} / Elixir ${{matrix.elixir}}
strategy:
matrix:
otp: [22.x, 23.x, 24.x, 25.x]
elixir: [1.11.x, 1.12.x, 1.13.x]
otp: [22.x, 23.x, 24.x, 25.1.x]
elixir: [1.11.x, 1.12.x, 1.13.x, 1.14.x]
exclude:
- otp: 25.x
- otp: 25.1.x
elixir: 1.11.x
- otp: 25.x
- otp: 25.1.x
elixir: 1.12.x
- otp: 22.x
elixir: 1.14.x
needs: check_format
steps:
- uses: actions/checkout@v3
Expand All @@ -58,7 +59,6 @@ jobs:
run: mix deps.get 1>/dev/null
- name: Run Tests
run: mix test

interop-tests:
runs-on: ubuntu-20.04
name: Interop tests
Expand All @@ -68,8 +68,8 @@ jobs:
- uses: actions/checkout@v3
- uses: erlef/setup-beam@v1
with:
otp-version: 25.x
elixir-version: 1.13.x
otp-version: 25.1.x
elixir-version: 1.14.x
- name: Retrieve dependencies cache
uses: actions/cache@v3
id: mix-cache # id to use in retrieve action
Expand All @@ -80,7 +80,7 @@ jobs:
run: mix deps.get 1>/dev/null
working-directory: ./interop
- name: Run interop tests
run: mix run script/run.exs --rounds 64
run: mix run script/run.exs
working-directory: ./interop

interop-tests-all:
Expand All @@ -90,19 +90,21 @@ jobs:
if: ${{ github.ref == 'refs/heads/master' }}
strategy:
matrix:
otp: [22.x, 23.x, 24.x, 25.x]
elixir: [1.11.x, 1.12.x, 1.13.x]
otp: [22.x, 23.x, 24.x, 25.1.x]
elixir: [1.11.x, 1.12.x, 1.13.x, 1.14.x]
exclude:
- otp: 25.x
- otp: 25.1.x
elixir: 1.11.x
- otp: 25.x
- otp: 25.1.x
elixir: 1.12.x
- otp: 22.x
elixir: 1.14.x
steps:
- uses: actions/checkout@v3
- uses: erlef/setup-beam@v1
with:
otp-version: 25.x
elixir-version: 1.13.x
otp-version: ${{ matrix.otp }}
elixir-version: ${{ matrix.elixir }}
- name: Retrieve dependencies cache
uses: actions/cache@v3
id: mix-cache # id to use in retrieve action
Expand All @@ -113,16 +115,16 @@ jobs:
run: mix deps.get 1>/dev/null
working-directory: ./interop
- name: Run interop tests
run: mix run script/run.exs --rounds 64
run: mix run script/run.exs
working-directory: ./interop

dialyzer:
name: Dialyzer
runs-on: ubuntu-20.04
strategy:
matrix:
otp: [24.x, 25.x]
elixir: [1.13.x]
otp: [24.x, 25.1.x]
elixir: [1.14.x]
env:
MIX_ENV: test
steps:
Expand Down Expand Up @@ -155,8 +157,8 @@ jobs:
- uses: actions/checkout@v3
- uses: erlef/setup-beam@v1
with:
otp-version: 24
elixir-version: 1.13.1
otp-version: 25.1.x
elixir-version: 1.14.x
- name: Retrieve dependencies cache
uses: actions/cache@v3
id: mix-cache # id to use in retrieve action
Expand Down
4 changes: 2 additions & 2 deletions .tool-versions
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
elixir 1.13.1
erlang 24.2
elixir 1.14.2-otp-25
erlang 25.1.1
27 changes: 14 additions & 13 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,46 +2,48 @@

## 0.9.0 (Unreleased)

- Update to upstream `v0.7.0` (9/5/2023) release.

## 0.8.0 (2023-01-30)

- Updates to the recent upstream `elixir-grpc` that includes Mint support [`f5f5fab4`](https://github.com/elixir-grpc/grpc/commit/f5f5fab412dcf37826e583980a61190e865e96be)

### Added `mint` client adapter

Now, when spawning your connections it is possible for developers to choose
Now, when spawning your connections it is possible for developers to choose
which adapter to use.

```elixir
GRPC.Stub.connect("localhost:5001", adapter: GRPC.Client.Adapters.Mint)
# or (Gun is the current default adapter)
GRPC.Stub.connect("localhost:5001")
# the above is has the same effect as:
GRPC.Stub.connect("localhost:5001", adapter: GRPC.Client.Adapters.Gun)
# the above is has the same effect as:
GRPC.Stub.connect("localhost:5001", adapter: GRPC.Client.Adapters.Gun)
```

### Why choose `mint` over `gun`?
Both clients will solve the same problems and recent load tests showed almost no
difference of performance between them.
difference of performance between them.

The reason why the additional `Mint` adapter is introduced, is because we are
attempting to integrate with LaunchDarkly and their erlang client is
incompatible with the current version of Gun which `elixir-grpc` is using.
Using an adapter based on `Mint` resolves the `gun` version conflict.
The reason why the additional `Mint` adapter is introduced, is because we are
attempting to integrate with LaunchDarkly and their erlang client is
incompatible with the current version of Gun which `elixir-grpc` is using.
Using an adapter based on `Mint` resolves the `gun` version conflict.

## 0.7.0 (2022-08-10)
- Updates to the recent upstream release of `elixir-grpc` [`v0.5.0`](https://github.com/elixir-grpc/grpc/releases/tag/v0.5.0)

### Breaking Changes

- Spawn supervisor now expects a Keyword list instead of a tuple.
- Before:
- Spawn supervisor now expects a Keyword list instead of a tuple.
- Before:
``` elixir
def children, do: [
# ... other supervisors
{GRPC.Server.Supervisor, {MyCoolEndPoint, @my_grpc_port}}
]
```
- Now:
- Now:
```elixir
def children, do: [
# ... other supervisors
Expand All @@ -53,9 +55,8 @@ Using an adapter based on `Mint` resolves the `gun` version conflict.
- Before:
```elixir
[adapter_opts: %{http2_opts: %{keepalive: @keep_alive}}]
```
```
- After:
```elixir
[adapter_opts: [http2_opts: %{keepalive: @keep_alive}]]
```

8 changes: 1 addition & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,26 +11,20 @@ An Elixir implementation of [gRPC](http://www.grpc.io/).

## Table of contents

- [Notice](#notice)
- [Installation](#installation)
- [Usage](#usage)
- [Features](#features)
- [Benchmark](#benchmark)
- [Contributing](#contributing)

## Notice
> __Note__
> The [Gun](https://github.com/ninenines/gun) library doesn't have a full 2.0 release yet, so we depend on `:grcp_gun 2.0.1` for now.
This is the same as `:gun 2.0.0-rc.2`, but [Hex](https://hex.pm/) doesn't let us depend on RC versions for releases.

## Installation

The package can be installed as:

```elixir
def deps do
[
{:grpc, "~> 0.5.0"},
{:grpc, "~> 0.7"},
# We don't force protobuf as a dependency for more
# flexibility on which protobuf library is used,
# but you probably want to use it as well
Expand Down
6 changes: 0 additions & 6 deletions interop/config/config.exs
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
import Config

config :prometheus, GRPCPrometheus.ServerInterceptor,
latency: :histogram

config :prometheus, GRPCPrometheus.ClientInterceptor,
latency: :histogram

config :logger, level: :warn
2 changes: 0 additions & 2 deletions interop/lib/interop/app.ex
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ defmodule Interop.App do
def start(_type, _args) do
children = [{GRPC.Server.Supervisor, endpoint: Interop.Endpoint, port: 10000}]

GRPCPrometheus.ServerInterceptor.setup()
GRPCPrometheus.ClientInterceptor.setup()
Interop.ServerInterceptor.Statix.connect()

opts = [strategy: :one_for_one, name: __MODULE__]
Expand Down
2 changes: 0 additions & 2 deletions interop/lib/interop/endpoint.ex
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
defmodule Interop.Endpoint do
use GRPC.Endpoint

intercept GRPC.Server.Interceptors.Logger
intercept GRPCPrometheus.ServerInterceptor
intercept Interop.ServerInterceptor

run Interop.Server
Expand Down
2 changes: 0 additions & 2 deletions interop/mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,9 @@ defmodule Interop.MixProject do
[
{:grpc, path: "..", override: true},
{:protobuf, "~> 0.11"},
{:grpc_prometheus, ">= 0.1.0"},
{:grpc_statsd, "~> 0.1.0"},
{:statix, ">= 1.2.1"},
{:extrace, "~> 0.2"},
{:prometheus, "~> 4.0", override: true}
]
end
end
5 changes: 0 additions & 5 deletions interop/mix.lock
Original file line number Diff line number Diff line change
@@ -1,17 +1,12 @@
%{
"accept": {:hex, :accept, "0.3.5", "b33b127abca7cc948bbe6caa4c263369abf1347cfa9d8e699c6d214660f10cd1", [:rebar3], [], "hexpm", "11b18c220bcc2eab63b5470c038ef10eb6783bcb1fcdb11aa4137defa5ac1bb8"},
"cowboy": {:hex, :cowboy, "2.9.0", "865dd8b6607e14cf03282e10e934023a1bd8be6f6bacf921a7e2a96d800cd452", [:make, :rebar3], [{:cowlib, "2.11.0", [hex: :cowlib, repo: "hexpm", optional: false]}, {:ranch, "1.8.0", [hex: :ranch, repo: "hexpm", optional: false]}], "hexpm", "2c729f934b4e1aa149aff882f57c6372c15399a20d54f65c8d67bef583021bde"},
"cowlib": {:hex, :cowlib, "2.11.0", "0b9ff9c346629256c42ebe1eeb769a83c6cb771a6ee5960bd110ab0b9b872063", [:make, :rebar3], [], "hexpm", "2b3e9da0b21c4565751a6d4901c20d1b4cc25cbb7fd50d91d2ab6dd287bc86a9"},
"extrace": {:hex, :extrace, "0.2.1", "e234f1f64df8c989771b7b5d047a3412f10512c0e3d414fc7eb0e8fc633779f8", [:mix], [{:recon, "~> 2.5", [hex: :recon, repo: "hexpm", optional: false]}], "hexpm", "1b2d9fc4bacc208d5aaa97f61e7c47b66ff4dfc155e9b95647e68ca316ab3981"},
"grpc": {:git, "https://github.com/elixir-grpc/grpc.git", "21422839798e49bf6d29327fab0a7add51becedd", []},
"grpc_prometheus": {:hex, :grpc_prometheus, "0.1.0", "a2f45ca83018c4ae59e4c293b7455634ac09e38c36cba7cc1fb8affdf462a6d5", [:mix], [{:grpc, ">= 0.0.0", [hex: :grpc, repo: "hexpm", optional: true]}, {:prometheus, "~> 4.0", [hex: :prometheus, repo: "hexpm", optional: false]}, {:prometheus_ex, "~> 3.0", [hex: :prometheus_ex, repo: "hexpm", optional: false]}], "hexpm", "8b9ab3098657e7daec0b3edc78e1d02418bc0871618d8ca89b51b74a8086bb71"},
"grpc_statsd": {:hex, :grpc_statsd, "0.1.0", "a95ae388188486043f92a3c5091c143f5a646d6af80c9da5ee616546c4d8f5ff", [:mix], [{:grpc, ">= 0.0.0", [hex: :grpc, repo: "hexpm", optional: true]}, {:statix, ">= 0.0.0", [hex: :statix, repo: "hexpm", optional: true]}], "hexpm", "de0c05db313c7b3ffeff345855d173fd82fec3de16591a126b673f7f698d9e74"},
"gun": {:hex, :grpc_gun, "2.0.1", "221b792df3a93e8fead96f697cbaf920120deacced85c6cd3329d2e67f0871f8", [:rebar3], [{:cowlib, "~> 2.11", [hex: :cowlib, repo: "hexpm", optional: false]}], "hexpm", "795a65eb9d0ba16697e6b0e1886009ce024799e43bb42753f0c59b029f592831"},
"hpax": {:hex, :hpax, "0.1.2", "09a75600d9d8bbd064cdd741f21fc06fc1f4cf3d0fcc335e5aa19be1a7235c84", [:mix], [], "hexpm", "2c87843d5a23f5f16748ebe77969880e29809580efdaccd615cd3bed628a8c13"},
"mint": {:hex, :mint, "1.4.2", "50330223429a6e1260b2ca5415f69b0ab086141bc76dc2fbf34d7c389a6675b2", [:mix], [{:castore, "~> 0.1.0", [hex: :castore, repo: "hexpm", optional: true]}, {:hpax, "~> 0.1.1", [hex: :hpax, repo: "hexpm", optional: false]}], "hexpm", "ce75a5bbcc59b4d7d8d70f8b2fc284b1751ffb35c7b6a6302b5192f8ab4ddd80"},
"prometheus": {:hex, :prometheus, "4.2.2", "a830e77b79dc6d28183f4db050a7cac926a6c58f1872f9ef94a35cd989aceef8", [:mix, :rebar3], [], "hexpm", "b479a33d4aa4ba7909186e29bb6c1240254e0047a8e2a9f88463f50c0089370e"},
"prometheus_ex": {:hex, :prometheus_ex, "3.0.5", "fa58cfd983487fc5ead331e9a3e0aa622c67232b3ec71710ced122c4c453a02f", [:mix], [{:prometheus, "~> 4.0", [hex: :prometheus, repo: "hexpm", optional: false]}], "hexpm", "9fd13404a48437e044b288b41f76e64acd9735fb8b0e3809f494811dfa66d0fb"},
"prometheus_httpd": {:hex, :prometheus_httpd, "2.1.11", "f616ed9b85b536b195d94104063025a91f904a4cfc20255363f49a197d96c896", [:rebar3], [{:accept, "~> 0.3", [hex: :accept, repo: "hexpm", optional: false]}, {:prometheus, "~> 4.2", [hex: :prometheus, repo: "hexpm", optional: false]}], "hexpm", "0bbe831452cfdf9588538eb2f570b26f30c348adae5e95a7d87f35a5910bcf92"},
"protobuf": {:hex, :protobuf, "0.11.0", "58d5531abadea3f71135e97bd214da53b21adcdb5b1420aee63f4be8173ec927", [:mix], [{:jason, "~> 1.2", [hex: :jason, repo: "hexpm", optional: true]}], "hexpm", "30ad9a867a5c5a0616cac9765c4d2c2b7b0030fa81ea6d0c14c2eb5affb6ac52"},
"ranch": {:hex, :ranch, "1.8.0", "8c7a100a139fd57f17327b6413e4167ac559fbc04ca7448e9be9057311597a1d", [:make, :rebar3], [], "hexpm", "49fbcfd3682fab1f5d109351b61257676da1a2fdbe295904176d5e521a2ddfe5"},
"recon": {:hex, :recon, "2.5.0", "2f7fcbec2c35034bade2f9717f77059dc54eb4e929a3049ca7ba6775c0bd66cd", [:mix, :rebar3], [], "hexpm", "72f3840fedd94f06315c523f6cecf5b4827233bed7ae3fe135b2a0ebeab5e196"},
Expand Down
2 changes: 1 addition & 1 deletion interop/script/run.exs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ alias Interop.Client

defmodule InteropTestRunner do
def run(_cli, adapter, port, rounds) do
opts = [interceptors: [GRPCPrometheus.ClientInterceptor, GRPC.Client.Interceptors.Logger], adapter: adapter]
opts = [interceptors: [GRPC.Client.Interceptors.Logger], adapter: adapter]
ch = Client.connect("127.0.0.1", port, opts)

for _ <- 1..rounds do
Expand Down
17 changes: 17 additions & 0 deletions lib/grpc/client/interceptor.ex
Original file line number Diff line number Diff line change
@@ -1,3 +1,20 @@
defmodule GRPC.ClientInterceptor do
@moduledoc """
Interceptor on client side. See `GRPC.Stub.connect/2`.
"""

@moduledoc deprecated: "Use `GRPC.Client.Interceptor` instead"

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

defmodule GRPC.Client.Interceptor do
@moduledoc """
Interceptor on client side. See `GRPC.Stub.connect/2`.
Expand Down
18 changes: 6 additions & 12 deletions lib/grpc/client/interceptors/logger.ex
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,14 @@ defmodule GRPC.Client.Interceptors.Logger do
## Options

* `:level` - the desired log level. Defaults to `:info`
* `:accepted_comparators` - a list with the accepted `Logger.compare_levels(configured_level, Logger.level())` results.
Defaults to `[:lt, :eq]`

## Usage

{:ok, channel} = GRPC.Stub.connect("localhost:50051", interceptors: [GRPC.Client.Interceptors.Logger])
# This will log on `:info` and greater priority
{:ok, channel} = GRPC.Stub.connect("localhost:50051", interceptors: [{GRPC.Client.Interceptors.Logger, level: :info}])
# This will log only on `:info`
{:ok, channel} = GRPC.Stub.connect("localhost:50051", interceptors: [{GRPC.Client.Interceptors.Logger, level: :info, accepted_comparators: [:eq]}])
# This will log on `:info` and lower priority
{:ok, channel} = GRPC.Stub.connect("localhost:50051", interceptors: [{GRPC.Client.Interceptors.Logger, level: :info, accepted_comparators: [:eq, :gt]}])

## Usage with custom level

{:ok, channel} = GRPC.Stub.connect("localhost:50051", interceptors: [{GRPC.Client.Interceptors.Logger, level: :warn}])
"""

require Logger
Expand All @@ -29,16 +25,14 @@ defmodule GRPC.Client.Interceptors.Logger do
@impl true
def init(opts) do
level = Keyword.get(opts, :level) || :info
accepted_comparators = Keyword.get(opts, :accepted_comparators) || [:lt, :eq]
[level: level, accepted_comparators: accepted_comparators]
[level: level]
end

@impl true
def call(%{grpc_type: grpc_type} = stream, req, next, opts) do
level = Keyword.fetch!(opts, :level)
accepted_comparators = Keyword.fetch!(opts, :accepted_comparators)

if Logger.compare_levels(level, Logger.level()) in accepted_comparators do
if Logger.compare_levels(level, Logger.level()) != :lt do
Logger.log(level, fn ->
["Call ", to_string(elem(stream.rpc, 0)), " of ", stream.service_name]
end)
Expand Down
Loading
Loading