|
9 years ago | |
---|---|---|
app | 9 years ago | |
config | 9 years ago | |
lib | 9 years ago | |
.gitignore | 10 years ago | |
CHANGELOG.md | 9 years ago | |
Gemfile | 10 years ago | |
LICENSE.txt | 10 years ago | |
README.md | 9 years ago | |
Rakefile | 10 years ago | |
blazer.gemspec | 10 years ago |
Explore your data. Easily create charts and dashboards, and share the results with your team.
:tangerine: Battle-tested at Instacart
Blazer 1.0 was recently released! See the instructions for upgrading
[demo]
Create queries with variables
SELECT COUNT(*) FROM users WHERE gender = {gender}
[demo]
Supposed you have this query
SELECT COUNT(*) FROM users WHERE city_id = {city_id}
Instead of remembering each city’s id, users can select cities by name.
Add a smart variable with:
smart_variables:
city_id: "SELECT id, name FROM cities ORDER BY name ASC"
The first column is the value of the variable, and the second column is the label.
[demo]
Link results to other pages in your apps or around the web. Specify a column name and where it should link to. You can use the value of the result with {value}
.
linked_columns:
user_id: "/admin/users/{value}"
ip_address: "http://www.infosniper.net/index.php?ip_address={value}"
[demo]
SELECT name, city_id FROM users
See which city the user belongs to without a join.
smart_columns:
city_id: "SELECT id, name FROM cities WHERE id IN {value}"
Blazer will automatically generate charts based on the types of the columns returned in your query.
There are two ways to generate line charts.
2+ columns - timestamp, numeric(s) [demo]
SELECT gd_week(created_at), COUNT(*) FROM users GROUP BY 1
3 columns - timestamp, string, numeric [demo]
SELECT gd_week(created_at), gender, AVG(age) FROM users GROUP BY 1, 2
2 columns - string, numeric [demo]
SELECT gender, COUNT(*) FROM users GROUP BY 1
Each query run creates a Blazer::Audit
.
[demo]
Combine multiple queries into a dashboard.
If the query has a chart, the chart is shown. Otherwise, you’ll see a table.
If any queries have variables, they will show up on the dashboard.
[demo]
Checks give you a centralized place to see the health of your data.
Create a query to identify bad rows.
SELECT * FROM events WHERE started_at > ended_at
Then create check with optional emails if you want to be notified.
Add this line to your application’s Gemfile:
gem 'blazer'
Run:
rails g blazer:install
rake db:migrate
And mount the dashboard in your config/routes.rb
:
mount Blazer::Engine, at: "blazer"
For production, specify your database:
ENV["BLAZER_DATABASE_URL"] = "postgres://user:password@hostname:5432/database"
Blazer tries to protect against queries which modify data (by running each query in a transaction and rolling it back), but a safer approach is to use a read only user. See how to create one.
Be sure to set a host in config/environments/production.rb
for emails to work.
config.action_mailer.default_url_options = {host: "blazerme.herokuapp.com"}
Schedule checks to run every hour (with cron, Heroku Scheduler, etc).
rake blazer:run_checks
You can also set up failing checks to be sent once a day (or whatever you prefer).
rake blazer:send_failing_checks
Create a user with read only permissions:
BEGIN;
CREATE ROLE blazer LOGIN PASSWORD 'secret123';
GRANT CONNECT ON DATABASE database_name TO blazer;
GRANT USAGE ON SCHEMA public TO blazer;
GRANT SELECT ON ALL TABLES IN SCHEMA public TO blazer;
ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT SELECT ON TABLES TO blazer;
COMMIT;
Create a user with read only permissions:
GRANT SELECT, SHOW VIEW ON database_name.* TO blazer@’127.0.0.1′ IDENTIFIED BY ‘secret123‘;
FLUSH PRIVILEGES;
To protect sensitive info like password hashes and access tokens, use views. Documentation coming soon.
Don’t forget to protect the dashboard in production.
Set the following variables in your environment or an initializer.
ENV["BLAZER_USERNAME"] = "andrew"
ENV["BLAZER_PASSWORD"] = "secret"
authenticate :user, lambda { |user| user.admin? } do
mount Blazer::Engine, at: "blazer"
end
For an easy way to group by day, week, month, and more with correct time zones, check out Groupdate.
Add activerecord4-redshift-adapter to your Gemfile and set:
ENV["BLAZER_DATABASE_URL"] = "redshift://user:password@hostname:5439/database"
Blazer 1.0 brings a number of new features:
To upgrade, run
bundle update blazer
Create a migration
rails g migration upgrade_blazer_to_1_0
with
add_column :blazer_queries, :data_source, :string
add_column :blazer_audits, :data_source, :string
create_table :blazer_dashboards do |t|
t.text :name
t.timestamps
end
create_table :blazer_dashboard_queries do |t|
t.references :dashboard
t.references :query
t.integer :position
t.timestamps
end
create_table :blazer_checks do |t|
t.references :query
t.string :state
t.text :emails
t.timestamps
end
And run
rake db:migrate
Update config/blazer.yml
with
# see https://github.com/ankane/blazer for more info
# data sources
data_sources:
main:
url: <%%= ENV["BLAZER_DATABASE_URL"] %>
timeout: 15
smart_variables:
# zone_id: "SELECT id, name FROM zones ORDER BY name ASC"
linked_columns:
# user_id: "/admin/users/{value}"
smart_columns:
# user_id: "SELECT id, name FROM users WHERE id IN {value}"
# create audits
audit: true
# change the time zone
# time_zone: "Pacific Time (US & Canada)"
# class name of the user model
# user_class: User
# method name for the user model
# user_name: name
View the changelog
Blazer uses a number of awesome, open source projects.
Demo data from MovieLens.
Everyone is encouraged to help improve this project. Here are a few ways you can help: