Skip to content

Commit

Permalink
remove submodule protobuf (elixir-grpc#26)
Browse files Browse the repository at this point in the history
* remove submodule protobuf

* up version to v0.2.0

* update readme for example/helloworld

* update readme for example/helloworld

* to publish v0.1.1

Co-authored-by: Michael Heilmann <[email protected]>

* remove google module from test_coverage/ignore_modules

* update readme and docs

* fix mix dialyzer

* mix format

---------

Co-authored-by: Michael Heilmann <[email protected]>
  • Loading branch information
zhihuizhang17 and mjheilmann authored Feb 21, 2024
1 parent 2603dd3 commit 9754a08
Show file tree
Hide file tree
Showing 16 changed files with 46 additions and 962 deletions.
3 changes: 0 additions & 3 deletions .gitmodules

This file was deleted.

15 changes: 13 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
# GrpcReflection

GrpcReclection is a grpc server built using `grpc-elixir`. This server adds grpc reflection support to a `grpc-elixir` based application.
Server reflection allows servers to assist clients in runtime construction of requests without having stub information precompiled into the client.

Accoring to the [GRPC Server Reflection Protocol
](https://github.com/grpc/grpc/blob/master/doc/server-reflection.md), the primary usecase for server reflection is to write (typically) command line debugging tools for talking to a grpc server. In particular, such a tool will take in a method and a payload (in human readable text format) send it to the server (typically in binary proto wire format), and then take the response and decode it to text to present to the user.

GrpcReflection, implemented as a gRPC server using `grpc-elixir`, adds reflection support to a `grpc-elixir` based application.

## Installation

Expand All @@ -21,7 +26,7 @@ be found at <https://hexdocs.pm/grpc_reflection>.

# Reflection

This is written and tested using grpcurl and postman. It supports both v1alpha and v1 reflection by using one or both of the provided servers: `rpcReflection.V1.Server` or `rpcReflection.V1alpha.Server`
This is written and tested using [grpcurl](https://github.com/fullstorydev/grpcurl) and postman. It supports both v1alpha and v1 reflection by using one or both of the provided servers: `rpcReflection.V1.Server` or `rpcReflection.V1alpha.Server`

## Enable reflection on your application

Expand Down Expand Up @@ -74,6 +79,12 @@ message HelloReply {
optional string message = 1;
optional .google.protobuf.Timestamp today = 2;
}

$ grpcurl -plaintext -format text -d 'name: "faker"' localhost:50051 helloworld.Greeter.SayHello
message: "Hello faker"
today: <
seconds:1708412184 nanos:671267628
>
```

## Protobuf Version Support
Expand Down
11 changes: 6 additions & 5 deletions examples/helloworld/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,6 @@ This example is mostly copied directly from `grpc-elixir`, with the exception th

## Usage

1. Fetch Protobuf Dependencies
```shell
git submodule init
```

1. Install deps and compile
```shell
$ mix do deps.get, compile
Expand Down Expand Up @@ -52,6 +47,12 @@ message HelloReply {
optional string message = 1;
optional .google.protobuf.Timestamp today = 2;
}

$ grpcurl -plaintext -format text -d 'name: "faker"' localhost:50051 helloworld.Greeter.SayHello
message: "Hello faker"
today: <
seconds:1708412184 nanos:671267628
>
```

## Regenerate Elixir code from proto
Expand Down
14 changes: 0 additions & 14 deletions examples/helloworld/generate_protos.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,6 @@
rm -rf ./lib/protos
mkdir ./lib/protos

GOOGLE_PROTOS=("
protobuf/src/google/protobuf/any.proto
protobuf/src/google/protobuf/duration.proto
protobuf/src/google/protobuf/empty.proto
protobuf/src/google/protobuf/field_mask.proto
protobuf/src/google/protobuf/struct.proto
protobuf/src/google/protobuf/timestamp.proto
protobuf/src/google/protobuf/wrappers.proto
")

for file in $GOOGLE_PROTOS; do
protoc --elixir_opt=include_docs=true --elixir_out=plugins=grpc,gen_descriptors=true:./lib/protos --proto_path=protobuf/src/ $file
done

PROTOS=("
priv/protos/helloworld.proto
")
Expand Down
2 changes: 1 addition & 1 deletion examples/helloworld/mix.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"cowlib": {:hex, :cowlib, "2.12.1", "a9fa9a625f1d2025fe6b462cb865881329b5caff8f1854d1cbc9f9533f00e1e1", [:make, :rebar3], [], "hexpm", "163b73f6367a7341b33c794c4e88e7dbfe6498ac42dcd69ef44c5bc5507c8db0"},
"dialyxir": {:hex, :dialyxir, "1.4.2", "764a6e8e7a354f0ba95d58418178d486065ead1f69ad89782817c296d0d746a5", [:mix], [{:erlex, ">= 0.2.6", [hex: :erlex, repo: "hexpm", optional: false]}], "hexpm", "516603d8067b2fd585319e4b13d3674ad4f314a5902ba8130cd97dc902ce6bbd"},
"erlex": {:hex, :erlex, "0.2.6", "c7987d15e899c7a2f34f5420d2a2ea0d659682c06ac607572df55a43753aa12e", [:mix], [], "hexpm", "2ed2e25711feb44d52b17d2780eabf998452f6efda104877a3881c2f8c0c0c75"},
"google_protos": {:hex, :google_protos, "0.3.0", "15faf44dce678ac028c289668ff56548806e313e4959a3aaf4f6e1ebe8db83f4", [:mix], [{:protobuf, "~> 0.10", [hex: :protobuf, repo: "hexpm", optional: false]}], "hexpm", "1f6b7fb20371f72f418b98e5e48dae3e022a9a6de1858d4b254ac5a5d0b4035f"},
"google_protos": {:hex, :google_protos, "0.4.0", "93e1be2c1a07517ffed761f69047776caf35e4acd385aac4f5ce4fedd07f3660", [:mix], [{:protobuf, "~> 0.10", [hex: :protobuf, repo: "hexpm", optional: false]}], "hexpm", "4c54983d78761a3643e2198adf0f5d40a5a8b08162f3fc91c50faa257f3fa19f"},
"grpc": {:hex, :grpc, "0.7.0", "a86eab356b0b84406b526786a947ca50e9b9eae87108c873b51e321f8a71e8ed", [:mix], [{:cowboy, "~> 2.10", [hex: :cowboy, repo: "hexpm", optional: false]}, {:cowlib, "~> 2.12", [hex: :cowlib, repo: "hexpm", optional: false]}, {:gun, "~> 2.0", [hex: :gun, repo: "hexpm", optional: false]}, {:mint, "~> 1.5", [hex: :mint, repo: "hexpm", optional: false]}, {:telemetry, "~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "632a9507da8d3c12b112b197db4d60da3c95bad02594d37711eeb622d032f254"},
"gun": {:hex, :gun, "2.0.1", "160a9a5394800fcba41bc7e6d421295cf9a7894c2252c0678244948e3336ad73", [:make, :rebar3], [{:cowlib, "2.12.1", [hex: :cowlib, repo: "hexpm", optional: false]}], "hexpm", "a10bc8d6096b9502205022334f719cc9a08d9adcfbfc0dbee9ef31b56274a20b"},
"hpax": {:hex, :hpax, "0.1.2", "09a75600d9d8bbd064cdd741f21fc06fc1f4cf3d0fcc335e5aa19be1a7235c84", [:mix], [], "hexpm", "2c87843d5a23f5f16748ebe77969880e29809580efdaccd615cd3bed628a8c13"},
Expand Down
1 change: 0 additions & 1 deletion examples/helloworld/protobuf
Submodule protobuf deleted from ecc2ba
11 changes: 7 additions & 4 deletions lib/grpc_reflection/server.ex
Original file line number Diff line number Diff line change
Expand Up @@ -35,31 +35,34 @@ defmodule GrpcReflection.Server do
@doc """
Get the reflection reponse containing the given symbol, if it is exposed by a configured service
"""
@spec get_by_symbol(binary()) :: {:ok, GrpcReflection.descriptor_t()} | {:error, binary}
@spec get_by_symbol(binary()) ::
{:ok, GrpcReflection.Server.descriptor_t()} | {:error, binary}
def get_by_symbol(symbol) do
Service.get_by_symbol(@cfg, symbol)
end

@doc """
Get the reflection response for the named file, if it is exposed by a configured service
"""
@spec get_by_filename(binary()) :: {:ok, GrpcReflection.descriptor_t()} | {:error, binary}
@spec get_by_filename(binary()) ::
{:ok, GrpcReflection.Server.descriptor_t()} | {:error, binary}
def get_by_filename(filename) do
Service.get_by_filename(@cfg, filename)
end

@doc """
Get the extension numbers for the given type, if it is exposed by a configured service
"""
@spec get_extension_numbers_by_type(module()) :: {:ok, list(integer())} | {:error, binary}
@spec get_extension_numbers_by_type(binary()) :: {:ok, list(integer())} | {:error, binary}
def get_extension_numbers_by_type(mod) do
Service.get_extension_numbers_by_type(@cfg, mod)
end

@doc """
Get the reflection response for the given extension, if it is exposed by a configured service
"""
@spec get_by_extension(binary()) :: {:ok, GrpcReflection.descriptor_t()} | {:error, binary}
@spec get_by_extension(binary()) ::
{:ok, GrpcReflection.Server.descriptor_t()} | {:error, binary}
def get_by_extension(containing_type) do
Service.get_by_extension(@cfg, containing_type)
end
Expand Down
22 changes: 18 additions & 4 deletions mix.exs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
defmodule GrpcReflection.MixProject do
use Mix.Project

@version "0.1.0"
@version "0.1.1"
@source_url "https://github.com/elixir-grpc/grpc-reflection"
@description "gRPC reflection server for Elixir"

def project do
Expand All @@ -14,10 +15,10 @@ defmodule GrpcReflection.MixProject do
start_permanent: Mix.env() == :prod,
deps: deps(),
package: package(),
docs: docs(),
aliases: aliases(),
test_coverage: [
ignore_modules: [
~r/^Google\./,
~r/^Grpc\./,
~r/^Helloworld\./,
~r/^TestserviceV2\./,
Expand All @@ -42,7 +43,8 @@ defmodule GrpcReflection.MixProject do
{:credo, "~> 1.7", only: [:dev, :test], runtime: false},
{:dialyxir, "~> 1.4", only: [:dev, :test], runtime: false},
{:grpc, "~> 0.7"},
{:protobuf, "~> 0.11"}
{:protobuf, "~> 0.11"},
{:google_protos, "~> 0.4.0"}
]
end

Expand Down Expand Up @@ -96,8 +98,20 @@ defmodule GrpcReflection.MixProject do
%{
name: "grpc_reflection",
files: ~w(.formatter.exs mix.exs lib),
links: %{"GitHub" => "https://github.com/elixir-grpc/grpc-reflection"},
links: %{"GitHub" => @source_url},
licenses: ["Apache-2.0"]
}
end

defp docs do
[
extras: [
"README.md": [title: "Overview"]
],
main: "readme",
source_url: @source_url,
source_ref: "#{@version}",
formatters: ["html"]
]
end
end
1 change: 1 addition & 0 deletions mix.lock
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"dialyxir": {:hex, :dialyxir, "1.4.2", "764a6e8e7a354f0ba95d58418178d486065ead1f69ad89782817c296d0d746a5", [:mix], [{:erlex, ">= 0.2.6", [hex: :erlex, repo: "hexpm", optional: false]}], "hexpm", "516603d8067b2fd585319e4b13d3674ad4f314a5902ba8130cd97dc902ce6bbd"},
"erlex": {:hex, :erlex, "0.2.6", "c7987d15e899c7a2f34f5420d2a2ea0d659682c06ac607572df55a43753aa12e", [:mix], [], "hexpm", "2ed2e25711feb44d52b17d2780eabf998452f6efda104877a3881c2f8c0c0c75"},
"file_system": {:hex, :file_system, "0.2.10", "fb082005a9cd1711c05b5248710f8826b02d7d1784e7c3451f9c1231d4fc162d", [:mix], [], "hexpm", "41195edbfb562a593726eda3b3e8b103a309b733ad25f3d642ba49696bf715dc"},
"google_protos": {:hex, :google_protos, "0.4.0", "93e1be2c1a07517ffed761f69047776caf35e4acd385aac4f5ce4fedd07f3660", [:mix], [{:protobuf, "~> 0.10", [hex: :protobuf, repo: "hexpm", optional: false]}], "hexpm", "4c54983d78761a3643e2198adf0f5d40a5a8b08162f3fc91c50faa257f3fa19f"},
"grpc": {:hex, :grpc, "0.7.0", "a86eab356b0b84406b526786a947ca50e9b9eae87108c873b51e321f8a71e8ed", [:mix], [{:cowboy, "~> 2.10", [hex: :cowboy, repo: "hexpm", optional: false]}, {:cowlib, "~> 2.12", [hex: :cowlib, repo: "hexpm", optional: false]}, {:gun, "~> 2.0", [hex: :gun, repo: "hexpm", optional: false]}, {:mint, "~> 1.5", [hex: :mint, repo: "hexpm", optional: false]}, {:telemetry, "~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "632a9507da8d3c12b112b197db4d60da3c95bad02594d37711eeb622d032f254"},
"gun": {:hex, :gun, "2.0.1", "160a9a5394800fcba41bc7e6d421295cf9a7894c2252c0678244948e3336ad73", [:make, :rebar3], [{:cowlib, "2.12.1", [hex: :cowlib, repo: "hexpm", optional: false]}], "hexpm", "a10bc8d6096b9502205022334f719cc9a08d9adcfbfc0dbee9ef31b56274a20b"},
"hpax": {:hex, :hpax, "0.1.2", "09a75600d9d8bbd064cdd741f21fc06fc1f4cf3d0fcc335e5aa19be1a7235c84", [:mix], [], "hexpm", "2c87843d5a23f5f16748ebe77969880e29809580efdaccd615cd3bed628a8c13"},
Expand Down
54 changes: 0 additions & 54 deletions test/support/protos/google/protobuf/any.pb.ex

This file was deleted.

54 changes: 0 additions & 54 deletions test/support/protos/google/protobuf/duration.pb.ex

This file was deleted.

22 changes: 0 additions & 22 deletions test/support/protos/google/protobuf/empty.pb.ex

This file was deleted.

39 changes: 0 additions & 39 deletions test/support/protos/google/protobuf/field_mask.pb.ex

This file was deleted.

Loading

0 comments on commit 9754a08

Please sign in to comment.