Code Monkey home page Code Monkey logo

librato-sidekiq's Introduction

librato-sidekiq

librato-sidekiq is a simple gem to stick Sidekiq stats and granular processing counts/times into Librato Metrics

Requirements and Compatibility

Gems:

  • sidekiq
  • librato-rails OR librato-rack

Compatibility (tested):

  • Ruby 2.0.0
  • Ruby 2.1.0

(if you can confirm another version of Ruby, email me at [email protected])

Usage with Rails 3.x

In your Gemfile:

gem 'librato-sidekiq'

In config/environments/librato_sidekiq.rb:

# only needed for fine-tuning, gem will enable all metrics by default
Librato::Sidekiq::Middleware.configure do |c|
  # only enable for production
  c.enabled = Rails.env.production?

  # only allow these 3 queues
  c.whitelist_queues = %w(default cron notifications)

  # ignore these worker classes
  c.blacklist_classes = %w(CronSchedulerWorker NotificationCheckerWorker)
end

Configuration

Librato::Sidekiq accepts the following options.

enabled: Boolean, true by default

whitelist_queues: Array, list of queue names that will be the only ones sent to Librato (optional)

blacklist_queues: Array, list of queue names that will not be sent to Librato (optional)

whitelist_classes: Array, list of worker classes that will be the only ones sent to Librato (optional)

blacklist_classes: Array, list of worker classes that will not be sent to Librato (optional)

Contributing

If you have a fix you wish to provide, please fork the code, fix in your local project and then send a pull request on github. Please ensure that you include a test which verifies your fix and update History.md with a one sentence description of your fix so you get credit as a contributor.

Thanks

Mike Perham - for creating Sidekiq, a fantastic contribution to the ruby world

Librato - for a great metrics service

Author

Scott Klein, [email protected], statuspage.io, If you like and use this project, please check out the StatusPage.io service for your project or company

Copyright

Copyright (c) 2013 Scott Klein. See LICENSE for details.

librato-sidekiq's People

Contributors

olemchls avatar pboling avatar scootklein avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

librato-sidekiq's Issues

Missing `cattr_accessor` method when using only librato-metrics

I'm using librato-sidekiq outside of a rails/rack app and activesupport deps is required.

librato-sidekiq should add activesupport gem as a dependency and add require 'active_support/core_ext/class/attribute_accessors'

In the meantime I added gem 'activesupport', require: 'active_support/core_ext/class/attribute_accessors' in my Gemfile.

Thanks for the gem!

Tests?

hey,

I was checking out the repo and wanted to add some little thing I missed. The readme said I should write tests and there are also references to test frameworks in the gemspec but there is no tests folder. So where are the tests? Or should I just give it a head start?

cheers

undefined method `cattr_accessor' with this gem

I'm trying to use this gem in a non-rails project and when I do I get this error:

Gem Load Error is: undefined method `cattr_accessor' for Librato::Sidekiq::Middleware:Class
Did you mean?  attr_accessor
Backtrace for gem load error is:
/app/vendor/bundle/ruby/2.5.0/gems/librato-sidekiq-0.1.2/lib/librato-sidekiq/middleware.rb:4:in `<class:Middleware>'
/app/vendor/bundle/ruby/2.5.0/gems/librato-sidekiq-0.1.2/lib/librato-sidekiq/middleware.rb:3:in `<module:Sidekiq>'
/app/vendor/bundle/ruby/2.5.0/gems/librato-sidekiq-0.1.2/lib/librato-sidekiq/middleware.rb:2:in `<module:Librato>'
/app/vendor/bundle/ruby/2.5.0/gems/librato-sidekiq-0.1.2/lib/librato-sidekiq/middleware.rb:1:in `<top (required)>'
/app/vendor/bundle/ruby/2.5.0/gems/librato-sidekiq-0.1.2/lib/librato-sidekiq.rb:1:in `require'
/app/vendor/bundle/ruby/2.5.0/gems/librato-sidekiq-0.1.2/lib/librato-sidekiq.rb:1:in `<top (required)>'
/app/vendor/bundle/ruby/2.5.0/gems/bundler-1.15.2/lib/bundler/runtime.rb:82:in `require'
/app/vendor/bundle/ruby/2.5.0/gems/bundler-1.15.2/lib/bundler/runtime.rb:82:in `block (2 levels) in require'
/app/vendor/bundle/ruby/2.5.0/gems/bundler-1.15.2/lib/bundler/runtime.rb:77:in `each'
/app/vendor/bundle/ruby/2.5.0/gems/bundler-1.15.2/lib/bundler/runtime.rb:77:in `block in require'
/app/vendor/bundle/ruby/2.5.0/gems/bundler-1.15.2/lib/bundler/runtime.rb:66:in `each'
/app/vendor/bundle/ruby/2.5.0/gems/bundler-1.15.2/lib/bundler/runtime.rb:66:in `require'
/app/vendor/bundle/ruby/2.5.0/gems/bundler-1.15.2/lib/bundler.rb:108:in `require'

It looks like maybe you're expecting cattr_accessor to be available from some other gem perhaps active support? You need to find it and add it to the gemspec.

Dependencies improvement

Hey there. I was trying to get this up and running outside of rack/rails and hit the following problem. Apparently your code uses Librato.group which is nowhere to be found. Then I read in the README that one is supposed to include either librato-rack or librato-rails by hand. So this Librato.group must be defined in one of those soft dependencies.

It turns out that librato-rack defines this and that librato-rails depends upon librato-rack. Thus it would be a good thing for this gem to depend on librato-rack directly. This will make it work out of the box in plain ruby.

librato-sidekiq drops other middlewares

On the first job invoked by a sidekiq process, the librato-sidekiq middleware will drop (cause sidekiq not to execute) the middleware immediately after it in the chain. Here's why it happens:

When a job is ready to be invoked, Sidekiq.server_middleware.invoke is called with the relevant worker instance and arguments. #invoke maps over the middleware chain and instantiates new middleware objects of the correct classes (dups the chain, essentially).

Each time the librato-sidekiq middleware is initialized it "reconfigures" itself, which really means that it removes and re-adds itself to the middleware chain entries array. Array#each expects that the position of objects in the array will not change during iteration. Since the librato-sidekiq middleware removes an element of the entries array while the chain is mapping over that array, the entry immediately following ends up "skipped" (and the librato-sidekiq middleware runs twice).

Is there a reason why #reconfigure has to be run every time the middleware is instantiated? Can we move the method to the class and just run it once after .configure is run?

The offending code is here: https://github.com/StatusPage/librato-sidekiq/blob/master/lib/librato-sidekiq/middleware.rb#L46-54

For reference, here is the sidekiq class involved: https://github.com/mperham/sidekiq/blob/master/lib/sidekiq/middleware/chain.rb

And here is the logic for Array#each: http://www.ruby-doc.org/core-2.1.2/Array.html#method-i-each

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.