Skip to content

queue_storage: allow defining Resque configuration without sentinels#41

Merged
bors[bot] merged 1 commit intomasterfrom
change/allow-resque-without-sentinels
Jun 29, 2018
Merged

queue_storage: allow defining Resque configuration without sentinels#41
bors[bot] merged 1 commit intomasterfrom
change/allow-resque-without-sentinels

Conversation

@miguelsorianod
Copy link
Copy Markdown
Contributor

@miguelsorianod miguelsorianod commented Jun 29, 2018

This allows to configure a Redis Resque without defining sentinels.
This is the case for example when Redis ElastiCache is used.

While at it also allow picking up the configuration in dev/test modes.

@unleashed
Copy link
Copy Markdown
Contributor

@miguelsorianod IIRC you can still run the queues storage without sentinels if you set the value to an empty array

@unleashed
Copy link
Copy Markdown
Contributor

@miguelsorianod can you please check whether this valid_cfg? method makes sense at all given that the client for this storage is now created by the same code for the client for the main storage, which should already error out if there is an inconsistent configuration?

@miguelsorianod
Copy link
Copy Markdown
Contributor Author

About the possibility of using an empty array, that's possible because the cfg_sentinels_handler in storage.rb sees empty as not using sentinels:

return options if sentinels.nil? || sentinels.empty?

However I'd prefer not having to specify an empty array in the configuration file, which seems ugly to me.

About seeing if the valid_cfg? methods makes sense let me take a look 👍

@miguelsorianod
Copy link
Copy Markdown
Contributor Author

Both Resque and Storage end calling the methods in storage.rb but the initialization for resque is a specific one in queue_storage.rb. There, it configures some parameters depending on the introduced configuration, which are different than the one for storage (for example, the 'default_url' redis parameter) , or renames the master_name parameter to 'url', which is indeed a Redis config-related parameter,and then indeed calls some storage helpers to generate a configuration.

I still see it makes sense having this method because it references several sublevels of configuration: cfg.queues.master_name and we would not want to receive a NoMethodError.

@unleashed
Copy link
Copy Markdown
Contributor

unleashed commented Jun 29, 2018

I just took a look and we could actually do:

def self.connection(_env, cfg)
  init_params = {
    url: cfg.queues && cfg.queues.master_name,
    default_url: '127.0.0.1:6379'
  }
# [...]

...for removing the branching on env and the different configurations. I was about to tell you not to worry about it, as it's not important, but then I remembered these comments which would be nice to fix.

@miguelsorianod
Copy link
Copy Markdown
Contributor Author

I agree. As we discussed I now pushed a change that allows dev/test environments to specify a non-localhost URL.

Furthermore, we now do not crash the program on the storage_queue.rb file anymore but we let the storage.rb to do the crashing. I've updated the tests accordingly.

Comment thread lib/3scale/backend/queue_storage.rb Outdated
raise 'Configuration must have a valid queues section' unless valid_cfg? cfg
init_params[:url] = cfg.queues.master_name
else
init_params = { url: cfg.queues && cfg.queues.master_name}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

typo space between identifier and }?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

fixed

Comment thread spec/unit/queue_storage_spec.rb Outdated
context 'with a invalid configuration' do
it 'returns an exception' do
expect { conn }.to raise_error RuntimeError
expect { conn }.to raise_error
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This has been changed because the RuntimeError is not raised anymore after the changes that have been done in the program.

We know that it should crash but without specifying any specific error now

Copy link
Copy Markdown
Contributor

@unleashed unleashed left a comment

Choose a reason for hiding this comment

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

fix styling issue and 👍

@miguelsorianod miguelsorianod force-pushed the change/allow-resque-without-sentinels branch from 09c09a3 to 09dd45c Compare June 29, 2018 15:42
@unleashed unleashed changed the title backend/queue_storage: Allow defining resque configuration without sentinels queue_storage: allow defining Resque configuration without sentinels Jun 29, 2018
@miguelsorianod miguelsorianod force-pushed the change/allow-resque-without-sentinels branch from 09dd45c to eef305e Compare June 29, 2018 15:56
@miguelsorianod
Copy link
Copy Markdown
Contributor Author

commits have been squashed

…nels

This commit allows resque to be configured without sentinels while
also allowing the dev/test environments to specify a non-localhost
resque configuration.
@miguelsorianod miguelsorianod force-pushed the change/allow-resque-without-sentinels branch from eef305e to d450e80 Compare June 29, 2018 16:07
@miguelsorianod
Copy link
Copy Markdown
Contributor Author

bors r=@unleashed,@eguzki

bors Bot added a commit that referenced this pull request Jun 29, 2018
41: queue_storage: allow defining Resque configuration without sentinels r=unleashed,eguzki a=miguelsorianod

This allows to configure a Redis Resque without defining sentinels.
This is the case for example when Redis ElastiCache is used.

While at it also allow picking up the configuration in dev/test modes.

Co-authored-by: Miguel Soriano <msoriano@redhat.com>
@bors
Copy link
Copy Markdown
Contributor

bors Bot commented Jun 29, 2018

Build succeeded

@bors bors Bot merged commit d450e80 into master Jun 29, 2018
@bors bors Bot deleted the change/allow-resque-without-sentinels branch June 29, 2018 16:13
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.

3 participants