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

Provide a mechanism to inject a custom status handler #171

Conversation

carrascoacd
Copy link
Contributor

@carrascoacd carrascoacd commented Aug 19, 2020

Problem

In order to support Traefik we need to listen in the same port the h1 health checks, more info here traefik/traefik#6211

Expected outcome

Add a way to inject a custom status handler, so we can listen for h1 requests in the same port using the desired handler.

Let me know if it works for you in order to update the doc as well or if you have another solution.

The configuration could be:

config :grpc,
       :status_handler,
       {"/status", Phoenix.Endpoint.Cowboy2Handler, {My.Endpoint, []}}

@carrascoacd
Copy link
Contributor Author

@tony612 could you review it when you have time, please?

@polvalente
Copy link
Contributor

@carrascoacd is this still relevant?

])
# Custom handler to be able to listen in the same port, more info:
# https://github.com/containous/traefik/issues/6211
status_handler = Application.get_env(:grpc, :status_handler)
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we should avoid using global config as per the general library guidelines for Elixir. Instead, we should accept this through opts.

Is this able to be passed down already, or would something more need to change?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hi @polvalente, thanks for answering. This is something we still need. Let me try injecting the configuration using opts and check if it works.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@polvalente I managed to get it working in that way. When starting the server under a Supervisor we get something like this:

    status_handler = {"/status", Plug.Cowboy.Handler, {GrpcEx.StatusHandler, []}}
    children = [
      supervisor(GRPC.Server.Supervisor, [{GrpcEx.Endpoint, 50051, adapter_opts: [status_handler: status_handler]}])
    ]

Let me know if it works for you and I'll submit the changes.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes! This is what I had in mind.
The benefit of doing it this way is that 2 processes can be started with different configs

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Great, much better. I've submitted the change!

@polvalente polvalente merged commit 109bcd3 into elixir-grpc:master Jul 19, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants