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

🔊 Add better logging when loading the Shoryuken environment #691

Merged
merged 4 commits into from
Jan 8, 2022

Conversation

danielvdao
Copy link
Contributor

@danielvdao danielvdao commented Jan 6, 2022

Context

When running shoryuken, we ran into an issue where the queue didn't exist. In theory this is true because we don't have permission to access the queue, but the suggestion to create a queue was a bit mis-leading.

More of a suggestion if anything since I noticed we were struggling and maybe it could help others as well! Ultimately the solution was stumbled upon in a SO post and some prior knowledge / experience.

Issue link: #692

@danielvdao
Copy link
Contributor Author

danielvdao commented Jan 7, 2022

@cjlarose thanks for triggering the job. I tried to change the HEREDOC to match, apparently it doesn't like the ~ for that version of Rails? Having trouble reproducing it locally even though I tried running bundle exec appraisal rails_4_2 rake rails:spec, so maybe it's my ruby version.

@danielvdao danielvdao marked this pull request as ready for review January 7, 2022 18:42
@danielvdao
Copy link
Contributor Author

Yeah, I'm running ruby 3 locally. Having trouble trying to drop down to ruby 2.2.10 which is what's being used to run, but my suspicion is that the HEREDOC syntax must've changed based on these docs.

@cjlarose
Copy link
Collaborator

cjlarose commented Jan 7, 2022

That makes sense. I think the "sqiggly" heredoc was introduced in Ruby 2.3.

I like this change; my own Ops team is constantly reassuring our devs that their queues exist when they get this error message; it's almost always a permissions problem.

I think the error message is formatted a little weird though.

In master,

/Users/chris.larose/workspace/ruby-shoryuken/shoryuken/lib/shoryuken/environment_loader.rb:163:in `validate_queues': The specified queue(s) dev_cjlarose_accounts_receivable.fifo do not exist. (ArgumentError)
Try 'shoryuken sqs create QUEUE-NAME' for creating a queue with default settings

This branch:

/Users/chris.larose/workspace/ruby-shoryuken/shoryuken/lib/shoryuken/environment_loader.rb:169:in `validate_queues':         "The specified queue(s) dev_cjlarose_accounts_receivable.fifo do not exist. (ArgumentError)
         Try 'shoryuken sqs create QUEUE-NAME' for creating a queue with default settings.
         It's also possible that you don't have permission to access the specified queues."

It'd be great to omit the quotes and remove the leading whitespace. Also, if you could add a test to spec/shoryuken/environment_loader_spec.rb to assert that this error message is raised, that'd be awesome!

@danielvdao
Copy link
Contributor Author

@cjlarose you got it, let me take care of that - I feel like an archaeologist trying to figure out how the squiggly works.

@cjlarose
Copy link
Collaborator

cjlarose commented Jan 7, 2022

Haha yeah. Sorry about the old Ruby support! Ruby 2.4 and older are actually EOL already according to https://www.ruby-lang.org/en/downloads/branches/

I think in the next major shoryuken version, we'll drop support for some of the older versions to make maintenance easier.

@danielvdao
Copy link
Contributor Author

danielvdao commented Jan 7, 2022

@cjlarose

Sorry about the old Ruby support!

Not at all :), thank you for maintaining this gem - the effort is much appreciated.

As for the tests, I believe I've added them, but let me know. It took a bit of reverse-engineering as I'm not too familiar with the nitty gritty of what's going on. Let me know if there's things I can do better to conform with the repo style.

Apologies for the delay, was working on some of my day job stuff as well and hopping back <> forth.

specify do
expect { subject.load }.to raise_error(
ArgumentError,
<<-MSG.gsub(/^\s+/, '')
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ha, the ~ operator is actually used to deal with indentation. The suggested / cleanest solution I could find was to use #gsub. I know it can be expensive though (since it's re-creating string objects), but this doesn't seem like a potential blocker since this command is invoked on load versus runtime.

Copy link
Collaborator

Choose a reason for hiding this comment

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

This solution looks good! Like you said, this isn't a hot path, so the performance won't matter much.

Comment on lines +11 to +14
allow(Shoryuken::Client)
.to receive(:queues)
.with('stubbed_queue')
.and_raise(Aws::SQS::Errors::NonExistentQueue.new(nil, nil))
Copy link
Contributor Author

@danielvdao danielvdao Jan 7, 2022

Choose a reason for hiding this comment

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

I guess looking at this, I can do something else similar to - https://stackoverflow.com/a/54314792. It could be better to not depend on an underlying API which is susceptible to change in the specs, otherwise if AWS SDK changes number of parameters, etc. to the Aws::ServiceError class, this test would break. WDYT? @cjlarose

Copy link
Collaborator

Choose a reason for hiding this comment

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

I didn't know about stub_const but it looks like it might be worth trying here!

@cjlarose
Copy link
Collaborator

cjlarose commented Jan 8, 2022

Changes look good! Lemme know if you wanna try the stub_const approach.

@danielvdao
Copy link
Contributor Author

danielvdao commented Jan 8, 2022

@cjlarose haha I'm not too married to it and I think this solution is good enough (gave it a shot and it seemed a little trickier than I thought). Unfortunately I have other things to attend to as well so don't want to spend too much time on this 😞 Thank you for taking a look at this!

Copy link
Collaborator

@cjlarose cjlarose left a comment

Choose a reason for hiding this comment

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

Awesome. Thanks for adding this!

@cjlarose cjlarose merged commit a5b31ea into ruby-shoryuken:master Jan 8, 2022
@danielvdao danielvdao deleted the dvd-better-logging branch January 8, 2022 01:04
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