From 4677f90bb2de8fd11a82264befe92b97a54c13d9 Mon Sep 17 00:00:00 2001 From: Maki Date: Mon, 26 Jul 2021 15:58:30 -0300 Subject: [PATCH] blazer --- Gemfile | 2 + Gemfile.lock | 10 +++ config/blazer.yml | 79 +++++++++++++++++++++ config/routes.rb | 1 + db/migrate/20210726182544_install_blazer.rb | 47 ++++++++++++ db/schema.rb | 58 ++++++++++++++- 6 files changed, 196 insertions(+), 1 deletion(-) create mode 100644 config/blazer.yml create mode 100644 db/migrate/20210726182544_install_blazer.rb diff --git a/Gemfile b/Gemfile index 82827f1..1b5edbd 100644 --- a/Gemfile +++ b/Gemfile @@ -3,6 +3,8 @@ git_source(:github) { |repo| "https://github.com/#{repo}.git" } ruby '2.7.3' +# Blazer: 'blazer', github: https://github.com/ankane/blazer +gem 'blazer' # Bundle edge Rails instead: gem 'rails', github: 'rails/rails', branch: 'main' gem 'rails', '~> 6.1.4' # Use postgresql as the database for Active Record diff --git a/Gemfile.lock b/Gemfile.lock index 5e3d277..c7e74e8 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -65,6 +65,11 @@ GEM ast (2.4.2) bcrypt (3.1.16-x86_64-linux-musl) bindex (0.8.1-x86_64-linux-musl) + blazer (2.4.2) + activerecord (>= 5) + chartkick (>= 3.2) + railties (>= 5) + safely_block (>= 0.1.1) bootsnap (1.7.5-x86_64-linux-musl) msgpack (~> 1.0) brakeman (5.0.4) @@ -78,6 +83,7 @@ GEM rack-test (>= 0.6.3) regexp_parser (>= 1.5, < 3.0) xpath (~> 3.2) + chartkick (4.0.3) childprocess (3.0.0) concurrent-ruby (1.1.9) crass (1.0.6) @@ -89,6 +95,7 @@ GEM warden (~> 1.2.3) devise-i18n (1.10.0) devise (>= 4.8.0) + errbase (0.2.1) erubi (1.10.0) ffi (1.15.3-x86_64-linux-musl) globalid (0.4.2) @@ -178,6 +185,8 @@ GEM parser (>= 3.0.1.1) ruby-progressbar (1.11.0) rubyzip (2.3.2) + safely_block (0.3.0) + errbase (>= 0.1.1) sass-rails (6.0.0) sassc-rails (~> 2.1, >= 2.1.1) sassc (2.4.0-x86_64-linux-musl) @@ -235,6 +244,7 @@ PLATFORMS x86_64-linux-musl DEPENDENCIES + blazer bootsnap (>= 1.4.4) brakeman byebug diff --git a/config/blazer.yml b/config/blazer.yml new file mode 100644 index 0000000..2ec4180 --- /dev/null +++ b/config/blazer.yml @@ -0,0 +1,79 @@ +# 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: true + + 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: <%= ENV["TIME_ZONE"] %> + +# 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: email + +# custom before_action to use for auth +before_action_method: require_user + +# email to send checks from +from_email: <%= ENV["DEFAULT_FROM"] %> + +# 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: trend / r + +# enable forecasting +# note: with trend, time series are sent to https://trendapi.org +# forecasting: trend / prophet + +# enable map +# mapbox_access_token: <%= ENV["MAPBOX_ACCESS_TOKEN"] %> + +# enable uploads +# uploads: +# url: <%= ENV["BLAZER_UPLOADS_URL"] %> +# schema: uploads +# data_source: main diff --git a/config/routes.rb b/config/routes.rb index 43bdc02..be7de5c 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -4,4 +4,5 @@ Rails.application.routes.draw do resources :sensors, only: [] do resources :measurements, only: [:create] end + mount Blazer::Engine, at: 'blazer' end diff --git a/db/migrate/20210726182544_install_blazer.rb b/db/migrate/20210726182544_install_blazer.rb new file mode 100644 index 0000000..b55a18a --- /dev/null +++ b/db/migrate/20210726182544_install_blazer.rb @@ -0,0 +1,47 @@ +class InstallBlazer < ActiveRecord::Migration[6.1] + 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 diff --git a/db/schema.rb b/db/schema.rb index 5191b5b..a101244 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,11 +10,67 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 2021_07_26_174833) do +ActiveRecord::Schema.define(version: 2021_07_26_182544) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" + create_table "blazer_audits", force: :cascade do |t| + t.bigint "user_id" + t.bigint "query_id" + t.text "statement" + t.string "data_source" + t.datetime "created_at" + t.index ["query_id"], name: "index_blazer_audits_on_query_id" + t.index ["user_id"], name: "index_blazer_audits_on_user_id" + end + + create_table "blazer_checks", force: :cascade do |t| + t.bigint "creator_id" + t.bigint "query_id" + 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.datetime "created_at", precision: 6, null: false + t.datetime "updated_at", precision: 6, null: false + t.index ["creator_id"], name: "index_blazer_checks_on_creator_id" + t.index ["query_id"], name: "index_blazer_checks_on_query_id" + end + + create_table "blazer_dashboard_queries", force: :cascade do |t| + t.bigint "dashboard_id" + t.bigint "query_id" + t.integer "position" + t.datetime "created_at", precision: 6, null: false + t.datetime "updated_at", precision: 6, null: false + t.index ["dashboard_id"], name: "index_blazer_dashboard_queries_on_dashboard_id" + t.index ["query_id"], name: "index_blazer_dashboard_queries_on_query_id" + end + + create_table "blazer_dashboards", force: :cascade do |t| + t.bigint "creator_id" + t.string "name" + t.datetime "created_at", precision: 6, null: false + t.datetime "updated_at", precision: 6, null: false + t.index ["creator_id"], name: "index_blazer_dashboards_on_creator_id" + end + + create_table "blazer_queries", force: :cascade do |t| + t.bigint "creator_id" + t.string "name" + t.text "description" + t.text "statement" + t.string "data_source" + t.string "status" + t.datetime "created_at", precision: 6, null: false + t.datetime "updated_at", precision: 6, null: false + t.index ["creator_id"], name: "index_blazer_queries_on_creator_id" + end + create_table "measurements", force: :cascade do |t| t.decimal "temperature" t.decimal "level"