Skip to content
This repository has been archived by the owner on Jan 1, 2024. It is now read-only.

Vanity failing to access database on Heroku #251

Closed
raphaelpflieger opened this issue Mar 29, 2015 · 5 comments
Closed

Vanity failing to access database on Heroku #251

raphaelpflieger opened this issue Mar 29, 2015 · 5 comments

Comments

@raphaelpflieger
Copy link

Hey there,

Thanks for your work on this incredibly useful gem. I've played with it a lot on my localhost, but it failed to work while on production on Heroku. I get the following error while trying to access the main report page:

ActionView::Template::Error (could not translate host name "ec2-XX-XXX-XXX-XXX.eu-west-1.compute.amazonaws.com:5642" to address: Name or service not known )

(XXs in ec2 path were added by me)

Here is the rest of the logs:

6:       Vanity.metric("#{vanity_h(id)}")
7:         .plot([{
8:           label:"#{vanity_h(metric.name)}",
9:           data: [#{Vanity::Metric.data(metric).map { |date,value| "['#{date.to_time.httpdate}',#{value}]" }.join(",")}]
10:         }])
11:     })
12:     </script>}
app/views/vanity/_metric.erb:9:in `_app_views_vanity__metric_erb__400322292071622517_70194567122580'
app/views/vanity/_metrics.erb:4:in `block in _app_views_vanity__metrics_erb__533107748726636358_70194566826760'
app/views/vanity/_metrics.erb:2:in `each'
app/views/vanity/_metrics.erb:2:in `_app_views_vanity__metrics_erb__533107748726636358_70194566826760'
app/views/vanity/_report.erb:49:in `_app_views_vanity__report_erb___4325486560256375919_70194565783140'
@phillbaker
Copy link
Collaborator

Thanks for using vanity! Can you post an (annonymized) version of your
config/vanity.yml ?

On Sunday, March 29, 2015, Raphaël Pflieger notifications@github.com
wrote:

Hey there,

Thanks for your work on this incredibly useful gem. I've played with it a
lot on my localhost, but it failed to work while on production on Heroku. I
get the following error while trying to access the main report page:

ActionView::Template::Error (could not translate host name "
ec2-XX-XXX-XXX-XXX.eu-west-1.compute.amazonaws.com:5642" to address: Name
or service not known )

(XXs in ec2 path were added by me)

Here is the rest of the logs:

6: Vanity.metric("#{vanity_h(id)}")
7: .plot([{
8: label:"#{vanity_h(metric.name)}",
9: data: [#{Vanity::Metric.data(metric).map { |date,value| "['#{date.to_time.httpdate}',#{value}]" }.join(",")}]
10: }])
11: })
12: </script>}
app/views/vanity/_metric.erb:9:in _app_views_vanity__metric_erb__400322292071622517_70194567122580' app/views/vanity/_metrics.erb:4:inblock in _app_views_vanity__metrics_erb__533107748726636358_70194566826760'
app/views/vanity/_metrics.erb:2:in each' app/views/vanity/_metrics.erb:2:in_app_views_vanity__metrics_erb__533107748726636358_70194566826760'
app/views/vanity/_report.erb:49:in `_app_views_vanity__report_erb___4325486560256375919_70194565783140'


Reply to this email directly or view it on GitHub
#251.

@phillbaker
Copy link
Collaborator

Also, as a reference, here's a repo of vanity running in rails on Heroku: https://github.com/phillbaker/vanity-rails3-demo, available at http://vanity-rails3-demo.herokuapp.com, and visit the dashboard.

@raphaelpflieger
Copy link
Author

Sure, here's the part used in production (and thank you so much for reacting so quickly):

adapter: active_record
active_record_adapter: postgresql
<% unless ENV['DATABASE_URL'].nil? %>
<% username, password, host, database = ENV['DATABASE_URL'].scan(%r{//(.*):(.*)@(.*)/(.*)}).first %>
host:     <%= host %>
username: <%= username %>
password: <%= password %>
database: <%= database %>
<% end %>
pool: 5

This configuration came from this blog post : http://www.jonathankirst.com/2012/06/rails-ab-testing-with-vanity.html

What is kinda weird is that if I use metrics based on ActiveRecord models everything works fine. This error is only throwed when trying to call metrics recorded with the track! method...

I must add I'm using Postgis, do you think it has any impact on this ?

@phillbaker
Copy link
Collaborator

@raphaelpflieger two thoughts:

  • as the error says, you're not separating the host from the port: "ec2-XX-XXX-XXX-XXX.eu-west-1.compute.amazonaws.com:5642" has the port appended to it, I think you'll need to separate that into a port attribute
  • if you want to re-use the existing ActiveRecord connection and avoid the duplicate between database.yml and vanity.yml, you could use a config like:
adapter: active_record
active_record_adapter: default

@raphaelpflieger
Copy link
Author

Using active_record_adapter: default and removing Vanity.playground.establish_connection from the after_fork block in the unicorn server config file did the trick, everything is working smoothly now. Thanks again for your help !

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants