Skip to content

Commit

Permalink
integrate blzer
Browse files Browse the repository at this point in the history
  • Loading branch information
epugh committed Nov 11, 2024
1 parent 64ef7c1 commit 05156f7
Show file tree
Hide file tree
Showing 7 changed files with 244 additions and 5 deletions.
2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -98,3 +98,5 @@ end
gem 'geocoder', '~> 1.8'

gem 'geoip', '~> 1.6'

gem 'blazer', '~> 3.1'
8 changes: 8 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,12 @@ GEM
bigdecimal (3.1.8)
bindata (2.5.0)
bindex (0.8.1)
blazer (3.1.0)
activerecord (>= 6.1)
chartkick (>= 5)
csv
railties (>= 7)
safely_block (>= 0.4)
bootsnap (1.18.4)
msgpack (~> 1.2)
builder (3.3.0)
Expand All @@ -135,6 +141,7 @@ GEM
rack-test (>= 0.6.3)
regexp_parser (>= 1.5, < 3.0)
xpath (~> 3.2)
chartkick (5.1.2)
childprocess (5.1.0)
logger (~> 1.5)
choice (0.2.0)
Expand Down Expand Up @@ -557,6 +564,7 @@ DEPENDENCIES
annotaterb (~> 4.13)
apipie-rails (~> 1.2)
bcrypt (~> 3.1.7)
blazer (~> 3.1)
bootsnap
bullet!
cal-heatmap-rails (~> 3.6)
Expand Down
11 changes: 11 additions & 0 deletions app/views/admin/home/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,17 @@
</div>
</div>
<p/>
<div class="card" style="">
<div class="card-body">
<h5 class="card-title">Analytics</h5>
<p class="card-text">Dig into the data being collected by users.</p>

<ul class="list-group list-group-flush">
<li class="list-group-item"><%= link_to 'SQL Analytics', blazer_path %>
</ul>
</div>
</div>
<p/>
<div class="card" style="">
<div class="card-body">
<h5 class="card-title">Background Jobs</h5>
Expand Down
81 changes: 81 additions & 0 deletions config/blazer.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
# see https://github.com/ankane/blazer for more info

data_sources:
main:
url: <%= ENV["BLAZER_DATABASE_URL"] %>

# statement timeout, in seconds
# none by default
# timeout: 15

# caching settings
# can greatly improve speed
# off by default
# cache:
# mode: slow # or all
# expires_in: 60 # min
# slow_threshold: 15 # sec, only used in slow mode

# wrap queries in a transaction for safety
# not necessary if you use a read-only user
# true by default
# use_transaction: false

smart_variables:
# zone_id: "SELECT id, name FROM zones ORDER BY name ASC"
# period: ["day", "week", "month"]
# status: {0: "Active", 1: "Archived"}

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 current user
# user_method: current_user

# method name for the display name
# user_name: name

# custom before_action to use for auth
# before_action_method: require_admin

# email to send checks from
# from_email: [email protected]

# webhook for Slack
# slack_webhook_url: <%= ENV["BLAZER_SLACK_WEBHOOK_URL"] %>

check_schedules:
- "1 day"
- "1 hour"
- "5 minutes"

# enable anomaly detection
# note: with trend, time series are sent to https://trendapi.org
# anomaly_checks: prophet / trend / anomaly_detection
anomaly_checks: prophet

# enable forecasting
# note: with trend, time series are sent to https://trendapi.org
# forecasting: prophet / trend
forecasting: prophet

# enable map
# mapbox_access_token: <%= ENV["MAPBOX_ACCESS_TOKEN"] %>

# enable uploads
# uploads:
# url: <%= ENV["BLAZER_UPLOADS_URL"] %>
# schema: uploads
# data_source: main
42 changes: 38 additions & 4 deletions config/routes.rb
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
# frozen_string_literal: true

# rubocop:disable Layout/LineLength:
# == Route Map
#
# Prefix Verb URI Pattern Controller#Action
# /cable #<ActionCable::Server::Base:0x00007f9d8a193ac8 @config=#<ActionCable::Server::Configuration:0x00007f9d8a1ea648 @log_tags=[:channel, :connection, :transmissions, :state_updates], @connection_class=#<Proc:0x00007f9d8a1daa90 /usr/local/bundle/gems/actioncable-8.0.0/lib/action_cable/engine.rb:55 (lambda)>, @worker_pool_size=4, @disable_request_forgery_protection=true, @allow_same_origin_as_host=true, @filter_parameters=[:passw, :email, :secret, :token, :_key, :crypt, :salt, :certificate, :otp, :ssn, :cvv, :cvc, :document_fields, "query_doc_pair.document_fields", "snapshot.docs", "snapshot_doc.explain", "snapshot_doc.fields"], @health_check_application=#<Proc:0x00007f9d8a1de3c0 /usr/local/bundle/gems/actioncable-8.0.0/lib/action_cable/engine.rb:31 (lambda)>, @logger=#<ActiveSupport::BroadcastLogger:0x00007f9d8c0067a8 @broadcasts=[#<ActiveSupport::Logger:0x00007f9d8c090610 @level=0, @progname=nil, @default_formatter=#<Logger::Formatter:0x00007f9d8bfc7508 @datetime_format=nil>, @formatter=#<TruncatingFormatter:0x00007f9d8c007130 @datetime_format=nil, @limit=5000>, @logdev=#<Logger::LogDevice:0x00007f9d8b200140 @shift_period_suffix="%Y%m%d", @shift_size=104857600, @shift_age=1, @filename="/srv/app/log/development.log", @dev=#<File:/srv/app/log/development.log>, @binmode=false, @reraise_write_errors=[], @mon_data=#<Monitor:0x00007f9d8bfc7490>, @mon_data_owner_object_id=7240>, @level_override={}>], @progname="Broadcast", @formatter=#<TruncatingFormatter:0x00007f9d8c007130 @datetime_format=nil, @limit=5000>>, @cable={"adapter"=>"solid_cable", "polling_interval"=>"0.1.seconds", "message_retention"=>"1.day", "silence_polling"=>true}, @mount_path="/cable", @precompile_assets=true, @allowed_request_origins="*", @url="/cable">, @mutex=#<Monitor:0x00007f9d8a1766a8>, @pubsub=nil, @worker_pool=nil, @event_loop=nil, @remote_connections=nil>
# /cable #<ActionCable::Server::Base:0x00007f0384ffcb28 @config=#<ActionCable::Server::Configuration:0x00007f0384d3f7a0 @log_tags=[:channel, :connection, :transmissions, :state_updates], @connection_class=#<Proc:0x00007f03839ee160 /usr/local/bundle/gems/actioncable-8.0.0/lib/action_cable/engine.rb:55 (lambda)>, @worker_pool_size=4, @disable_request_forgery_protection=true, @allow_same_origin_as_host=true, @filter_parameters=[:passw, :email, :secret, :token, :_key, :crypt, :salt, :certificate, :otp, :ssn, :cvv, :cvc, :document_fields, "query_doc_pair.document_fields", "snapshot.docs", "snapshot_doc.explain", "snapshot_doc.fields"], @health_check_application=#<Proc:0x00007f03837646b0 /usr/local/bundle/gems/actioncable-8.0.0/lib/action_cable/engine.rb:31 (lambda)>, @logger=#<ActiveSupport::BroadcastLogger:0x00007f0384324608 @broadcasts=[#<ActiveSupport::Logger:0x00007f0384365388 @level=0, @progname=nil, @default_formatter=#<Logger::Formatter:0x00007f0384326980 @datetime_format=nil>, @formatter=#<TruncatingFormatter:0x00007f03843249c8 @datetime_format=nil, @limit=5000>, @logdev=#<Logger::LogDevice:0x00007f0384312ef8 @shift_period_suffix="%Y%m%d", @shift_size=104857600, @shift_age=1, @filename="/srv/app/log/development.log", @dev=#<File:/srv/app/log/development.log>, @binmode=false, @reraise_write_errors=[], @mon_data=#<Monitor:0x00007f0384326908>, @mon_data_owner_object_id=7420>, @level_override={}>], @progname="Broadcast", @formatter=#<TruncatingFormatter:0x00007f03843249c8 @datetime_format=nil, @limit=5000>>, @cable={"adapter"=>"solid_cable", "polling_interval"=>"0.1.seconds", "message_retention"=>"1.day", "silence_polling"=>true}, @mount_path="/cable", @precompile_assets=true, @allowed_request_origins="*", @url="/cable">, @mutex=#<Monitor:0x00007f0383a4a9d8>, @pubsub=nil, @worker_pool=nil, @event_loop=nil, @remote_connections=nil>
# apipie_apipie_checksum GET /apipie/apipie_checksum(.:format) apipie/apipies#apipie_checksum {:format=>/json/}
# apipie_apipie GET /apipie(/:version)(/:resource)(/:method)(.:format) apipie/apipies#index {:version=>/[^\/]+/, :resource=>/[^\/]+/, :method=>/[^\/]+/}
# active_storage_db /active_storage_db ActiveStorageDB::Engine
# rails_health_check GET /healthcheck(.:format) rails/health#show
# mission_control_jobs /admin/jobs MissionControl::Jobs::Engine
# blazer /admin/blazer Blazer::Engine
# root GET / home#show
# home_sparklines GET /home/sparklines(.:format) home#sparklines
# home_case_prophet GET /home/case_prophet/:case_id(.:format) home#case_prophet
Expand Down Expand Up @@ -373,7 +373,41 @@
# job GET /jobs/:id(.:format) mission_control/jobs/jobs#show
# jobs GET /:status/jobs(.:format) mission_control/jobs/jobs#index
# root GET / mission_control/jobs/queues#index
#
# Routes for Blazer::Engine:
# run_queries POST /queries/run(.:format) blazer/queries#run
# cancel_queries POST /queries/cancel(.:format) blazer/queries#cancel
# refresh_query POST /queries/:id/refresh(.:format) blazer/queries#refresh
# tables_queries GET /queries/tables(.:format) blazer/queries#tables
# schema_queries GET /queries/schema(.:format) blazer/queries#schema
# docs_queries GET /queries/docs(.:format) blazer/queries#docs
# queries GET /queries(.:format) blazer/queries#index
# POST /queries(.:format) blazer/queries#create
# new_query GET /queries/new(.:format) blazer/queries#new
# edit_query GET /queries/:id/edit(.:format) blazer/queries#edit
# query GET /queries/:id(.:format) blazer/queries#show
# PATCH /queries/:id(.:format) blazer/queries#update
# PUT /queries/:id(.:format) blazer/queries#update
# DELETE /queries/:id(.:format) blazer/queries#destroy
# run_check GET /checks/:id/run(.:format) blazer/checks#run
# checks GET /checks(.:format) blazer/checks#index
# POST /checks(.:format) blazer/checks#create
# new_check GET /checks/new(.:format) blazer/checks#new
# edit_check GET /checks/:id/edit(.:format) blazer/checks#edit
# check PATCH /checks/:id(.:format) blazer/checks#update
# PUT /checks/:id(.:format) blazer/checks#update
# DELETE /checks/:id(.:format) blazer/checks#destroy
# refresh_dashboard POST /dashboards/:id/refresh(.:format) blazer/dashboards#refresh
# dashboards POST /dashboards(.:format) blazer/dashboards#create
# new_dashboard GET /dashboards/new(.:format) blazer/dashboards#new
# edit_dashboard GET /dashboards/:id/edit(.:format) blazer/dashboards#edit
# dashboard GET /dashboards/:id(.:format) blazer/dashboards#show
# PATCH /dashboards/:id(.:format) blazer/dashboards#update
# PUT /dashboards/:id(.:format) blazer/dashboards#update
# DELETE /dashboards/:id(.:format) blazer/dashboards#destroy
# root GET / blazer/queries#home

# rubocop:disable Layout/LineLength:
# rubocop:disable Metrics/BlockLength
Rails.application.routes.draw do
# Define your application routes per the DSL in https://guides.rubyonrails.org/routing.html
Expand All @@ -385,18 +419,18 @@
mount ActionCable.server => '/cable'
apipie
mount ActiveStorageDB::Engine => '/active_storage_db'
get 'healthcheck' => 'rails/health#show', as: :rails_health_check

# Render dynamic PWA files from app/views/pwa/*
# get 'service-worker' => 'rails/pwa#service_worker', as: :pwa_service_worker
# get 'manifest' => 'rails/pwa#manifest', as: :pwa_manifest

# Reveal health status on /up that returns 200 if the app boots with no exceptions, otherwise 500.
# Can be used by load balancers and uptime monitors to verify that the app is live.
# get 'up' => 'rails/health#show', as: :rails_health_check
get 'healthcheck' => 'rails/health#show', as: :rails_health_check

constraints(AdminConstraint) do
mount MissionControl::Jobs::Engine, at: 'admin/jobs'
mount Blazer::Engine, at: 'admin/blazer'
end

root 'home#show'
Expand Down
47 changes: 47 additions & 0 deletions db/migrate/20241110123336_install_blazer.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
class InstallBlazer < ActiveRecord::Migration[8.0]
def change
create_table :blazer_queries do |t|
t.references :creator
t.string :name
t.text :description
t.text :statement
t.string :data_source
t.string :status
t.timestamps null: false
end

create_table :blazer_audits do |t|
t.references :user
t.references :query
t.text :statement
t.string :data_source
t.datetime :created_at
end

create_table :blazer_dashboards do |t|
t.references :creator
t.string :name
t.timestamps null: false
end

create_table :blazer_dashboard_queries do |t|
t.references :dashboard
t.references :query
t.integer :position
t.timestamps null: false
end

create_table :blazer_checks do |t|
t.references :creator
t.references :query
t.string :state
t.string :schedule
t.text :emails
t.text :slack_channels
t.string :check_type
t.text :message
t.datetime :last_run_at
t.timestamps null: false
end
end
end
58 changes: 57 additions & 1 deletion db/schema.rb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 05156f7

Please sign in to comment.