danmayer / coverband

Ruby production code coverage collection and reporting (line of code usage)
https://github.com/danmayer/coverband
MIT License
2.5k stars 161 forks source link

Coverband Reports web View returning 500 errror unable to connect to redis #492

Closed tesssie closed 11 months ago

tesssie commented 11 months ago

Describe the bug I am using coverband 5.2.1 with rails 4.2. I have configured coverband redis.

Coverband.configure do |config|
  ENV['COVERBAND_REDIS_URL'] = "redis://#{CONFIG[:redis_host]}"
  config.logger = Rails.logger

  # config options false, true. (defaults to false)
  # true and debug can give helpful and interesting code usage information
  # and is safe to use if one is investigating issues in production, but it will slightly
  # hit perf.
  # default false. button at the top of the web interface which clears all data
  config.web_enable_clear = true

  # default false. Experimental support for tracking view layer tracking.
  # Does not track line-level usage, only indicates if an entire file
  # is used or not.
  config.track_views = true
end

\nRedis::CannotConnectError (Error connecting to Redis on 127.0.0.1:6379 (Errno::ECONNREFUSED)):\n redis (3.3.5) lib/redis/client.rb:345:in rescue in establish_connection'\n redis (3.3.5) lib/redis/client.rb:330:inestablish_connection'\n redis (3.3.5) lib/redis/client.rb:101:in block in connect'\n redis (3.3.5) lib/redis/client.rb:293:inwith_reconnect'\n redis (3.3.5) lib/redis/client.rb:100:in connect'\n redis (3.3.5) lib/redis/client.rb:364:inensure_connected'\n redis



I have tried hardcoding the redis url and everything and even then the same issue is persisting.
danmayer commented 11 months ago

We no longer support Rails 4.2 or Redis 3.0, I am guessing the issues is related to the version of the redis gem and the interface for setting up redis... but can't really help on the out of support versions.

check and ensure your redis is up and running on the port you export... it looks like you are trying to connect to 127.0.0.1:6379 use Rails console to just see if you can establish a connection. If that is working the other thing to try is removing the prefix redis:// as we likely don't export or need that part of the url.

tesssie commented 11 months ago

Yes I was able to connect to the redis. Now I fixed once i started moving this to ENV['COVERBAND_REDIS_URL'] to application.rb

danmayer commented 11 months ago

if moving it to your application.rb fixed it that means the ENV wasn't set when the coverband initializer ran... I am guessing you are using something like figaro, or rails_dot_env to load your ENV vars which means they need to be loaded by the time coverband initializes... You might see some issues with a few files not being covered if you leave it in the application.rb due to load order issues... but it will mostly work. The better fix is to ensure your ENV vars are loaded before coverband.

See this section of the readme that talks about how to fix this env load ordering issue

https://github.com/danmayer/coverband#working-with-environment-variables