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

Running multiple servers with decision in runtime with GRPC.Endpoint #306

Open
hamir-suspect opened this issue Mar 10, 2023 · 3 comments
Open
Labels

Comments

@hamir-suspect
Copy link

Describe the question
I tried incoorporating GRPC.Endpoint and interceptors into my project, the issue I have with it is that it does not seem posible to decide in runtime what servers to run.
I have some mock grpc servers that are used for dev and test enviorments, but also in runtime I start some of the servers based on some enviorment flags, any ideas on how this can be accomplished? If needed I would be glad to contribute to the project as well if provided with some guidance.
For the dev and test envs I can leave those servers out when building the prod app, but the decision with env flags does not seem possible since macros expand when compiling.
Versions:

  • OS: alpine-3.14.3
  • Erlang: 24.3.2
  • Elixir: 1.13.4
  • mix.lock(grpc, gun, cowboy, cowlib):
    "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"},
    "grpc": {:hex, :grpc, "0.5.0-beta.1", "7d43f52e138fe261f5b4981f1ada515dfc2e1bfa9dc92c7022e8f41e7e49b571", [:mix], [{:cowboy, "> 2.7.0", [hex: :cowboy, repo: "hexpm", optional: false]}, {:gun, "> 2.0.0", [hex: :grpc_gun, repo: "hexpm", optional: false]}, {:protobuf, "> 0.5", [hex: :protobuf, repo: "hexpm", optional: false]}], "hexpm", "fbbf8872935c295b7575435fe4128372c23c6ded89c2ef8058af3c6167bb3f65"},
    "gun": {:hex, :grpc_gun, "2.0.1", "221b792df3a93e8fead96f697cbaf920120deacced85c6cd3329d2e67f0871f8", [:rebar3], [{:cowlib, "
    > 2.11", [hex: :cowlib, repo: "hexpm", optional: false]}], "hexpm", "795a65eb9d0ba16697e6b0e1886009ce024799e43bb42753f0c59b029f592831"},
@beligante
Copy link
Contributor

beligante commented Mar 13, 2023

Not sure if I fully understand your issue, but you can decide which of them to run by passing a list of endpoints to your app supervision tree.

  def start(_type, _args) do
    endpoints = [MyApp.Endpoint.One, MyApp.Endpoint.Two]
    children = [{GRPC.Server.Supervisor, endpoint: endoints, port: 10000}]

    opts = [strategy: :one_for_one, name: __MODULE__]
    Supervisor.start_link(children, opts)
  end

The list of endpoints you can decide in run time when starting the app by checking some config. You can also decide not to append the server supervisor into your app supervision tree

@hamir-suspect
Copy link
Author

I will try that out, the issue might have happened because I had a mix of endpoints and servers in the list of arguments for GRPC.Server.Supervisor

@polvalente
Copy link
Contributor

@hamir-suspect you can have that list be decided at startup though config, for instance.

If you need those to be changed during your application's runtime instead, you should look up Dynamic Supervisors

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants