-
Notifications
You must be signed in to change notification settings - Fork 226
Fixes #25293 - Puma support for smart proxy #613
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
Conversation
lib/launcher.rb
Outdated
|
|
||
| RACK_SERVERS = { | ||
| :webrick => Rack::Handler::WEBrick, | ||
| :puma => Rack::Handler::Puma |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
won't this will require both gems to load? e.g. if you dont have puma gem, this line will break?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does it hurt to load them both? If it don't let's ignore it? If it does, then let's definitely take care of this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So it looks like webrick is always present, dependency of sinatra or something. But we should be able to install foreman-proxy without puma bundler group, so this needs to be taken care of.
|
It does not work yet, and that's one of the reasons, also tests will be
broken at this time, due to refactoring of the code.
Also there are places still hard coded for webrick.
That's why I placed it as wip 😁
…On Sun, Oct 14, 2018, 14:56 Ohad Levy ***@***.***> wrote:
***@***.**** commented on this pull request.
------------------------------
In lib/launcher.rb
<#613 (comment)>
:
> @@ -10,6 +10,15 @@ class Launcher
attr_reader :settings
+ RACK_SERVERS = {
+ :webrick => Rack::Handler::WEBrick,
+ :puma => Rack::Handler::Puma
won't this will require both gems to load? e.g. if you dont have puma gem,
this line will break?
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#613 (review)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAEdg0liZZ1W9dmek2OrocJwneTrrHYAks5ukyaIgaJpZM4XbFxk>
.
|
lib/launcher.rb
Outdated
| { | ||
| :app => app, | ||
| :server => :webrick, | ||
| :server => Proxy::SETTINGS.http_server_type || :webrick, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This does not correspondend with the line above :server => Proxy::SETTINGS.http_server_type.to_sym, so either one or another. The settings stack handles the defaults, so I think the version from 58 is better.
bundler.d/puma.rb
Outdated
| @@ -0,0 +1 @@ | |||
| gem 'puma', '3.11.4' | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be in group :puma so users can turn it on or off via bundler. In RPM deployments, we need to do packaging change and do subpackage so installing foreman-proxy-puma will actually grab the dependency. Also I'd probably add '~> 3.11' requirement, not sure about the gemspec syntax tho.
|
Nicely done, if it boots up and can be properly disabled without the puma dependency, let's ship it to hear from our users after 1.20 is branched. We can test it many times, but only our community will really tell us. |
|
there are basics puma, but it does not handle the actual execution for the route properly, and still on it, and when that works, I will have to do two things: A. Fix tests |
|
Also, ssl doesn't work at all yet |
I haven't tested it yet, because the actual routing crashes, and now working on that part. |
| gem 'puma', '3.11.4', :require => 'puma' | ||
| else | ||
| gem 'puma', :require => 'puma' | ||
| end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Holy Moly, we are lucky that 3.11 was the last version supporting Ruby 2.0. Latest is 3.12 which only supports Ruby 2.2+. Unfortunately, SCLing proxy is imminent.
Can you avoid open-ended version requirement on line 5? Packagers will require us to have a specific version, something like '~> 3.12' or something like that.
bundler.d/development.rb
Outdated
| gem 'pry' | ||
| gem 'pry-rescue' | ||
| gem 'pry-stack_explorer' | ||
| gem 'pry-byebug' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These belong to bundler.d/Gemfile.local.rb
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ack, I thought it can help debug on development, but np :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It can, we tend to be little more strict in core, I'd probably follow this rule. Everyone use her own tools.
lib/puma_patch.rb
Outdated
| end | ||
|
|
||
| require 'puma' | ||
| Puma::Server.class_eval { include PumaPatch } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't like monkey patching just because of one or two simple calls. In the method where you call mount you already have case server_name anyway, I suggest to do the mapping there, or in a launcher helper.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ack
lib/launcher.rb
Outdated
| require 'webrick' | ||
| begin | ||
| require 'puma' | ||
| Bundler.require(:puma) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please test this on RPM installation, I think this will not work. We actually turn bundler off for RPM installations and use special stub called bundler_ext so it works seamlessly with Bundler for development.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will check it out at the end of my work (soon, very soon :) )
lib/launcher.rb
Outdated
| https_server_name = @settings.https_server_type | ||
| if https_app | ||
| t1 = case https_server_name | ||
| when :webrick |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would extract this to a method add_server() then then calls add_webrick_server or add_puma_server to reduce the duplication.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
executing the server is blocking, so at the moment actually playing around with my threading design.
the need for it, is to support multiple hosts, that the current way of working as a server (puma that is) is blocking.
|
Okay, almost there, now working on making SSL/TLS to work. Important thing, after investing a lot of time testing it out, I can't bind to many hosts per port, only for a single one. I think that as another task, such management can be written, |
|
Several notes: A. Last working version of Puma with Ruby v2.0.0 is 3.10.0 (puma/puma#1662). Once the tests are ready I'll remove the WIP part. |
lib/puma_patch.rb
Outdated
| @@ -0,0 +1,11 @@ | |||
|
|
|||
| class PumaMapperMiddleware | |||
| def initialize(app) | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this middleware needed for anything right now?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, it is the only way for Puma to enter the route and deal with it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
there is another way of doing it, but then we will ignore rack, and that by using add_xxx_listener (for example) of Puma, but we can then support multiple Ethernet devices, and that's the balance I was playing with.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, I don't get it. The only place this middleware is being used is in here https://github.com/theforeman/smart-proxy/pull/613/files#diff-b8fbcbffabe3ae5c9935bb21e3e94852R178, and I don't see the server variable being used anywhere.
| @settings = settings | ||
| @settings.http_server_type = Proxy::SETTINGS.http_server_type.to_sym | ||
| @settings.https_server_type = Proxy::SETTINGS.https_server_type.to_sym | ||
| if @settings.http_server_type == :puma && !$HAS_PUMA |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we need an extra $GLOBAL_VARIABLE, we can just check on defined? Puma
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
my issue with define puma is that if something else regarding puma was not loaded we do not know of it, and then looking for every point that is needed is a bit of an issue in my opinion.
You will end up either writing a function that does this, or have duplicate places that check that code.
So knowing that everything was loaded properly, even on other locations at the project when needed is a bit easier in my opinion and easier for the long run.
lib/launcher.rb
Outdated
| require 'thread' | ||
| require 'rack' | ||
| require 'webrick' | ||
| require 'pry' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
still a leftover from requiring pry for development
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
that's my bad, I added it when debug puma crashes, removing it
| require 'proxy/signal_handler' | ||
| require 'thread' | ||
| require 'rack' | ||
| require 'webrick' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need to require webrick in case we will not use it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if the loading of puma failed it is the fallback, and at the moment the SETTINGS constant is not available for me to know if to load it or not.
Do you have a better idea?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about loading webrick or puma just after we know what server we're going to use? We don't have to load everything at the very beginning, if we have a reason for that. That would also allow us not to use the $HAS_PUMA global variable
config/settings.yml.example
Outdated
| # https server type configuration | ||
| # A string that indicates the server type (possible values: 'webrick', 'puma'). | ||
| # Default value is 'webrick' | ||
| #:https_server_type: 'puma' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we really need separate server_type setting for http and https and I think it's just misleading. One option should rule them all
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
okay unifying them
|
When running via |
|
@iNecas the pressing of |
|
fixed all known test issues (ruby 2.0.0 crashes on a bug of kerberos), so using the following test mechanism to test my code :) |
|
There were the following issues with the commit message:
If you don't have a ticket number, please create an issue in Redmine. More guidelines are available in Coding Standards or on the Foreman wiki. This message was auto-generated by Foreman's prprocessor |
|
Interesting regarding the |
|
That sounds more like a race condition than a problem with a particular Ruby version. Anyway, what is the status of the PR? Is this still WIP? I want to do formal review and testing after it's finished. |
| when :puma | ||
| Thread.new do | ||
| add_puma_server(app, addresses, port, conn_type) | ||
| end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any particular reason why the two blocks don't have the same syntax (do vs {)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
originally there was a longer line and wanted to make it readable, use moved to do instead of proc.
|
I think the way we handle UNIX signals is incorrect in the current version, we kinda do this ( We should change that and do graceful shutdown. Puma server has methods for graceful stop for both Single and Cluster classes called |
|
To be able to do that, you'd probably need to use |
|
@lzap Puma has it's own handler for the signals: https://github.com/puma/puma/blob/v3.10.0/lib/rack/handler/puma.rb#L70 And as you can see at that file, it is using |
|
Interrupt Ruby exception is only for Ctrl-C interrupt for interactive mode. In production you run this as a daemon but it still needs to be able to respond to SIGTERM or SIGHUP and SIGUSR1. We use these to rotate logs and initiate graceful restart. So this is different thing, that's why I suggest to change how things are booted up. Anyway, what is the status? This is entitled WIP, so wondering what are the plans and timeframe. I like your work, would totally love to see this happening. |
|
@lzap, the status is that I waited for your comments. |
|
Sorry I haven't noticed you already removed the WIP tag, I would like to proceed with testing but it appears you closed the PR and deleted the branch? |
|
I can explain it not over this thread.
…On Mon, Nov 19, 2018 at 12:15 PM Lukáš Zapletal ***@***.***> wrote:
Sorry I haven't noticed you already removed the WIP tag, I would like to
proceed with testing but it appears you closed the PR and deleted the
branch?
—
You are receiving this because you modified the open/close state.
Reply to this email directly, view it on GitHub
<#613 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAEdg_FIfCiTfv0dJrwH-9hNaJcrAdkRks5uwoTLgaJpZM4XbFxk>
.
|

Work in progress (still did not test it or wrote any tests for it), loading puma (or) webrick as an HTTP Server.
Started earlier today to work on it, most of it done, but not all :)