Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Development #4

Open
wants to merge 15 commits into
base: main
Choose a base branch
from
8 changes: 8 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,11 @@ Layout/HashAlignment:

RSpec/MultipleExpectations:
Enabled: false

RSpec/AnyInstance:
Enabled: false

Metrics/MethodLength:
Exclude:
- lib/generators/ez/status/install_generator.rb
- lib/generators/ez/status/migrations_generator.rb
2 changes: 2 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ GEM
parallel (1.20.1)
parser (3.0.1.1)
ast (~> 2.4.1)
pg (1.2.3)
pry (0.14.1)
coderay (~> 1.1)
method_source (~> 1.0)
Expand Down Expand Up @@ -296,6 +297,7 @@ DEPENDENCIES
generator_spec
guard-rspec
launchy
pg
pry-rails
rails-controller-testing
redis
Expand Down
62 changes: 62 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,53 @@ Ez::Status.configure do |config|
# Ez::Status::Providers::Sidekiq,
# MyCustomProvider
]

# config.ui_custom_css_map = {
# 'ez-status-index-container' => 'your_css_class',
# 'ez-status-index-inner-container' => 'your_css_class',
# # heder
# 'ez-status-index-inner-header' => 'your_css_class',
# 'ez-status-index-inner-title' => 'your_css_class',
# 'ez-status-index-inner-title-span' => 'your_css_class',
# # monitors
# 'ez-status-index-monitors-collection' => 'your_css_class',
# # monitor
# 'ez-status-index-status' => 'your_css_class',
# 'ez-status-index-failed' => 'your_css_class',
#
# 'ez-status-index-check-message' => 'your_css_class',
# 'ez-status-index-check-message-span' => 'your_css_class',
#
# 'ez-status-index-check-value' => 'your_css_class',
# 'ez-status-index-check-value-span' => 'your_css_class',
#
# 'ez-status-index-check-result' => 'your_css_class',
# 'ez-status-index-check-result-span' => 'your_css_class',
#
# 'ez-status-index-check-name' => 'your_css_class',
# 'ez-status-index-check-name-span' => 'your_css_class'
# }
end
```

### ActiveRecord migrations:

**If you want save data to DataBase, please change configuration first**

config/initializers/ez_status.rb
```ruby
# Backend adapter to store all status
config.backend = Ez::Status::Store.new
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

# We need a method for capturing current monitor metrics
Ez::Status.capture! # => insert_all metrics monitors
# + add readme

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

# and DB table name that you can change as well
config.active_record_table_name = :ez_status_store
```

And run
```bash
rails generate ez:status:migrations
```


### Basic Authentication

```ruby
Expand Down Expand Up @@ -154,6 +198,24 @@ class MyCustomProvider
end
```

## Creating a Custom Style

### Style for Semantic Ui

```ruby
config.ui_custom_css_map = {
'ez-status-index-container' => 'ui grid',
'ez-status-index-inner-container' => 'six wide column',
'ez-status-index-monitors-collection' => 'ui middle aligned divided list',
'ez-status-index-status' => 'item',
'ez-status-index-check-name' => 'content',
'ez-status-index-check-message' => 'right floated content',
'ez-status-index-check-value' => 'right floated content',
'ez-status-index-check-result' => 'right floated content',
'ez-status-index-check-name-span' => 'ui green label'
}
```

## TODO

-
Expand Down
11 changes: 5 additions & 6 deletions app/cells/ez/status/index/show.slim
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,24 @@
= div_for 'index-inner-container'
header class="#{css_for('index-header')}"
h1 class="#{css_for('index-title')}"
span class="#{css_for('index-top')}" = header
span class="#{css_for('index-bottom')}"
span class="#{css_for('index-title-span')}" = header

div class="#{css_for('index-monitors-collection')}"
- monitors.each do |monitor|
div class="#{css_for('index-status')} #{css_for('failed') if monitor[:result] == 'FAILURE'}" id=(monitor[:name].to_sym)
div class="#{css_for('index-status')} #{css_for('index-failed') if monitor[:result] == 'FAILURE'}" id=(monitor[:name].to_sym)

- if monitor[:msg]
div class="#{css_for('index-check-message')}"
span class="#{css_for('index-check-name-message')}"
span class="#{css_for('index-check-message-span')}"
= monitor[:msg]

- if monitor[:value]
div class="#{css_for('index-check-value')}"
span class="#{css_for('index-check-name-value')}"
span class="#{css_for('index-check-value-span')}"
= monitor[:value]

div class="#{css_for('index-check-result')}"
span class="#{css_for('index-check-name-result')}"
span class="#{css_for('index-check-result-span')}"
= monitor[:result]

div class="#{css_for('index-check-name')}"
Expand Down
9 changes: 9 additions & 0 deletions app/models/ez/status/application_record.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# frozen_string_literal: true

module Ez
module Status
class ApplicationRecord < ActiveRecord::Base
self.abstract_class = true
end
end
end
14 changes: 14 additions & 0 deletions app/models/ez/status/status.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# frozen_string_literal: true

module Ez
module Status
class Status < ApplicationRecord
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

class Record

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

self.table_name = Ez::Status.config.active_record_table_name

validates :name, presence: true
validates :result, presence: false
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove presence false

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove

validates :message, presence: false
validates :value, presence: false
end
end
end
1 change: 0 additions & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,3 @@
root to: 'status#index'
end
end

1 change: 1 addition & 0 deletions ez-status.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ Gem::Specification.new do |spec|
spec.add_development_dependency 'generator_spec'
spec.add_development_dependency 'guard-rspec'
spec.add_development_dependency 'launchy'
spec.add_development_dependency 'pg'
spec.add_development_dependency 'pry-rails'
spec.add_development_dependency 'rails-controller-testing'
spec.add_development_dependency 'redis'
Expand Down
4 changes: 4 additions & 0 deletions lib/ez/status.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,13 @@ module Status
configure do |config|
config.status_base_controller = nil
config.status_base_routes = nil

config.layout = nil

config.basic_auth_credentials = {}

config.active_record_table_name = nil
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

config.active_record_table_name = :ez_status_records

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done


config.monitors = []

config.ui_header = nil
Expand Down
28 changes: 26 additions & 2 deletions lib/generators/ez/status/install_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
module Ez
module Status
class InstallGenerator < Rails::Generators::Base
# rubocop:disable Metrics/MethodLength
def create_initializer_file
create_file 'config/initializers/ez_status.rb',
"require 'ez/status/providers/database'
Expand Down Expand Up @@ -51,10 +50,35 @@ def create_initializer_file
# Ez::Status::Providers::Sidekiq,
# MyCustomProvider
]

# config.ui_custom_css_map = {
# 'ez-status-index-container' => 'your_css_class',
# 'ez-status-index-inner-container' => 'your_css_class',
# # heder
# 'ez-status-index-inner-header' => 'your_css_class',
# 'ez-status-index-inner-title' => 'your_css_class',
# 'ez-status-index-inner-title-span' => 'your_css_class',
# # monitors
# 'ez-status-index-monitors-collection' => 'your_css_class',
# # monitor
# 'ez-status-index-status' => 'your_css_class',
# 'ez-status-index-failed' => 'your_css_class',
#
# 'ez-status-index-check-message' => 'your_css_class',
# 'ez-status-index-check-message-span' => 'your_css_class',
#
# 'ez-status-index-check-value' => 'your_css_class',
# 'ez-status-index-check-value-span' => 'your_css_class',
#
# 'ez-status-index-check-result' => 'your_css_class',
# 'ez-status-index-check-result-span' => 'your_css_class',
#
# 'ez-status-index-check-name' => 'your_css_class',
# 'ez-status-index-check-name-span' => 'your_css_class'
# }
end
"
end
# rubocop:enable Metrics/MethodLength
end
end
end
41 changes: 41 additions & 0 deletions lib/generators/ez/status/migrations_generator.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# frozen_string_literal: true

# rubocop:disable all
module Ez
module Status
class MigrationsGenerator < Rails::Generators::Base
def create_migration
create_file "db/migrate/#{current_time}_create_#{table_name.to_s.underscore}.rb",
"class Create#{table_name.to_s.classify} < ActiveRecord::Migration[#{ActiveRecord::Migration.current_version}]
def change
create_table :#{table_name.to_s.underscore} do |t|
t.string :name, null: false
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

t.string :monitor_name, null: false

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

t.string :result, null: true
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

t.boolean :result, null: true

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

t.string :message, null: true
t.string :value, null: true
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

t.bigint :value, null: true

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done


t.timestamps null: false
end
end
end
"
end

private

def config
Ez::Status.config
end

def table_name
raise 'You need setup active_record_table_name in config file' if config.active_record_table_name.blank?
config.active_record_table_name
end

def current_time
Time.now.strftime('%Y%m%d%H%M%S')
end

end
end
end
12 changes: 3 additions & 9 deletions spec/controllers/ez/status/status_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,12 @@

describe 'Application Layout' do
context 'when default layout' do
subject { get :index }

it 'renders page' do
expect(subject).to render_template('layouts/application')
expect(get(:index)).to render_template('layouts/application')
end
end

xcontext 'when custom layout: layouts/custom_application' do
subject { get :index }

around do |spec|
Ez::Status.config.layout = 'layouts/custom_application'
routes { Ez::Status::Engine.routes }
Expand All @@ -27,21 +23,19 @@
end

xit 'layout' do
expect(subject).not_to render_template(layout: :application)
expect(get(:index)).not_to render_template(layout: :application)
end
end

xcontext 'when missing template layouts/application_not_found' do
subject { get :index }

around do |spec|
Ez::Status.config.layout = 'layouts/application_not_found'
spec.run
Ez::Status.config.layout = nil
end

it 'renders page' do
expect(subject).to render_template('layouts/application_not_found')
expect(get(:index)).to render_template('layouts/application_not_found')
end
end
end
Expand Down
8 changes: 4 additions & 4 deletions spec/dummy/config/database.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,21 @@
# gem 'sqlite3'
#
default: &default
adapter: sqlite3
adapter: postgresql
pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
timeout: 5000

development:
<<: *default
database: db/development.sqlite3
database: ez_status_development

# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
test:
<<: *default
database: db/test.sqlite3
database: ez_status_test

production:
<<: *default
database: db/production.sqlite3
database: ez_status_production
Loading