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

Bump Sinatra to 4.1.1 #411

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
Open

Bump Sinatra to 4.1.1 #411

wants to merge 11 commits into from

Conversation

jlledom
Copy link
Contributor

@jlledom jlledom commented Dec 11, 2024

This is to properly implement #410

Jira: https://issues.redhat.com/browse/THREESCALE-11458

Due to a dependency hell, updating sinatra forces to update:

  • rack/rackup
  • falcon
  • puma

I also had to fork rspec_api_documentation because the gem it's abandoned and it's not compatible with Rack 3.

I also updated hiredis-client which I don't think it's necessary, but #410 does it for some reason so I'll do it as well, just in case I'm missing something.

I did some testing locally and seems to work fine, also the test suite in CircleCI passes for all environments, and the benchmark results doesn't show ant impact in performance.

Needed by yabeda-prometheus after upgrading rack to >= 3.0
Is not compatible with Rack 3 and apparently the gem is abandoned
Disables `prune_bundler`

It's causing problems on our test suite, and we don't need this really.

prune_bundler is intended to read changes in the Gemfile between phased
restarts, but it's only enabled on development and test, where we don't
need phased restarting.

In production, besides, we use openshift which doesn't
use phased restarts
A failing test is removed because the same scenario now returns 403,
but I don't think it's important
@jlledom jlledom marked this pull request as ready for review December 11, 2024 16:38
@jlledom jlledom requested review from eguzki, mayorova, akostadinov and lvillen and removed request for eguzki December 11, 2024 16:48
@@ -145,7 +145,7 @@
# is preserved across a phased-restart. (incompatible with preload_app)
# (off by default)

prune_bundler
# prune_bundler
Copy link
Contributor Author

Choose a reason for hiding this comment

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

prune_bundler is required to phase restart puma. However, it's only enabled on test and development envs, where we never phase restart.

It's causing us a lot of problems to run our test suite in Puma 6, so I'm disabling it.

Copy link
Contributor

Choose a reason for hiding this comment

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

So, this config/puma.rb file is only used for dev/test?

What happens if preload_app! is enabled also?

If it can be, we could probably simplify the config, and remove openshift/config/puma.rb ?

@@ -411,8 +406,7 @@ def do_api_method(method_name)

raise_provider_key_error(params) if blank?(provider_key)

# no need to check params key encoding. Sinatra framework does it for us.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not anymore... rack/rack#1797

Comment on lines +43 to +47
rescue ArgumentError => e
return unhandled_exception(e) unless e.message.include?(INVALID_BYTE_SEQUENCE_ERR_MSG)

delete_sinatra_error! env
respond_with 400, Backend::NotValidData.new.to_xml
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Check 25d53c9

Basically, an Invalid UTF8 error can be raised at any place in the code and we centralize the handling here.

@@ -35,7 +35,7 @@ def call(env)
raise e
end

header = ::Rack::Utils::HeaderHash.new(header)
header = ::Rack::Headers.new.merge(header)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@@ -34,7 +34,7 @@ def self.start(global_options, options, args)
argv_add argv, true, '-C', CONFIG
ss_dir = socket_state_dir(global_options[:environment], global_options[:directory] || EXPANDED_ROOT_PATH)
argv_add argv, true, '-S', File.join(ss_dir, STATE)
argv_add argv, true, '--control', "unix://#{File.join(ss_dir, CONTROL_SOCKET)}"
argv_add argv, true, '--control-url', "unix://#{File.join(ss_dir, CONTROL_SOCKET)}"
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Comment on lines +8 to +9
REQUIRED_ENDPOINT_HEADERS = %w[access-control-allow-origin access-control-expose-headers]
REQUIRED_OPTIONS_HEADERS = REQUIRED_ENDPOINT_HEADERS + %w[access-control-allow-methods access-control-allow-headers]
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@@ -130,7 +130,7 @@ def process_jobs(worker, num)

def shutdown_metrics_server
# Yabeda does not expose this
::Rack::Handler::WEBrick.shutdown
::Rackup::Handler::WEBrick.shutdown
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Rackup was part of Rack, then moved to an independent gem. Rack 3 compatible apps use Rackup.

@@ -566,7 +566,7 @@ def setup
'HTTP_3SCALE_OPTIONS' => Extensions::REJECTION_REASON_HEADER

assert_equal 409, last_response.status
assert_equal 'limits_exceeded', last_response.header['3scale-rejection-reason']
assert_equal 'limits_exceeded', last_response.headers['3scale-rejection-reason']
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Comment on lines -941 to -946
test 'returns 400 when param key encoding is not valid utf-8' do
post '/transactions.xml', "\xf0\x90\x28\xbc" => 1

assert_equal 400, last_response.status
assert_equal ThreeScale::Backend::NotValidData.new.to_xml, last_response.body
end
Copy link
Contributor Author

Choose a reason for hiding this comment

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

After rack/rack#1797, this doesn't happen anymore.

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't quite understand how that PR fixes this behavior... but if this is now considered a valid input, maybe let's keep the test, and just change the expected response?

end

# Default server by platform
gem 'puma', git: 'https://github.com/3scale/puma', branch: '3scale-4.3.9'
gem 'puma'
Copy link
Contributor

Choose a reason for hiding this comment

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

Not fixing the version?...

@@ -35,7 +35,7 @@ def call(env)
raise e
end

header = ::Rack::Utils::HeaderHash.new(header)
header = ::Rack::Headers.new.merge(header)
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
header = ::Rack::Headers.new.merge(header)
header = ::Rack::Headers[header]

param_value = input_params[p]
if !param_value.nil? && !param_value.valid_encoding?
halt 400, ThreeScale::Backend::NotValidData.new.to_xml
def check_params_encoding!(input_params)
Copy link
Contributor

Choose a reason for hiding this comment

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

So, you're now checking all parameters, not only the list predefined in REPORT_EXPECTED_PARAMS ?

delete_sinatra_error! env
resp = respond_with 400, Backend::BadRequest.new.to_xml
elsif resp_body.start_with?(INVALID_PERCENT_ENCODING_ERR_MSG)
else resp_body.start_with?(INVALID_PERCENT_ENCODING_ERR_MSG)
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
else resp_body.start_with?(INVALID_PERCENT_ENCODING_ERR_MSG)
elsif resp_body.start_with?(INVALID_PERCENT_ENCODING_ERR_MSG)

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