Skip to content

Commit e4b254b

Browse files
committed
Add influxer
1 parent 11ee1af commit e4b254b

File tree

6 files changed

+59
-1
lines changed

6 files changed

+59
-1
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ latest.dump
4040
/public/packs-test
4141
/node_modules
4242
config/database.yml
43+
config/influxdb.yml
4344

4445
# Ignore storybook static site generation
4546
storybook-static/
@@ -52,4 +53,4 @@ package-lock.json
5253
.idea/
5354

5455
#sitemap
55-
/public/sitemap.xml.gz
56+
/public/sitemap.xml.gz

Gemfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ group :development, :test do
139139
gem "rubocop-rspec", "~> 1.31"
140140
gem "spring", "~> 2.0"
141141
gem "spring-commands-rspec", "~> 1.0"
142+
gem "tty-command", "~> 0.10"
142143
gem "vcr", "~> 4.0"
143144
end
144145

@@ -148,6 +149,7 @@ group :test do
148149
gem "database_cleaner", "~> 1.7"
149150
gem "factory_bot_rails", "~> 4.11"
150151
gem "fake_stripe", "~> 0.2"
152+
gem "influxer", "~> 1.4"
151153
gem "launchy", "~> 2.4"
152154
gem "pundit-matchers", "~> 1.6"
153155
gem "rails-controller-testing", "~> 1.0"

Gemfile.lock

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,8 @@ GEM
112112
json (~> 1.8)
113113
ancestry (3.0.5)
114114
activerecord (>= 3.2.0)
115+
anyway_config (2.5.4)
116+
ruby-next-core (>= 0.14.0)
115117
approvals (0.0.24)
116118
nokogiri (~> 1.6)
117119
thor (~> 0.18)
@@ -541,6 +543,11 @@ GEM
541543
concurrent-ruby (~> 1.0)
542544
ice_nine (0.11.2)
543545
inflecto (0.0.2)
546+
influxdb (0.8.1)
547+
influxer (1.4.0)
548+
activemodel (>= 3.2.0)
549+
anyway_config (>= 2.0)
550+
influxdb (~> 0.8)
544551
inline_svg (1.3.1)
545552
activesupport (>= 3.0)
546553
nokogiri (>= 1.6)
@@ -655,6 +662,8 @@ GEM
655662
parallel
656663
parser (2.6.0.0)
657664
ast (~> 2.4.0)
665+
pastel (0.8.0)
666+
tty-color (~> 0.5)
658667
pg (1.1.4)
659668
powerpack (0.1.2)
660669
prometheus_exporter (2.0.8)
@@ -793,6 +802,7 @@ GEM
793802
unicode-display_width (~> 1.4.0)
794803
rubocop-rspec (1.31.0)
795804
rubocop (>= 0.60.0)
805+
ruby-next-core (0.15.3)
796806
ruby-prof (0.17.0)
797807
ruby-progressbar (1.10.0)
798808
ruby_dep (1.5.0)
@@ -892,6 +902,9 @@ GEM
892902
msgpack (~> 1.0)
893903
timecop (0.9.1)
894904
trollop (2.1.2)
905+
tty-color (0.6.0)
906+
tty-command (0.10.1)
907+
pastel (~> 0.8)
895908
twilio-ruby (5.21.0)
896909
faraday (~> 0.9)
897910
jwt (>= 1.5, <= 2.5)
@@ -1017,6 +1030,7 @@ DEPENDENCIES
10171030
honeycomb-rails
10181031
html_truncator (~> 0.4)
10191032
httparty (~> 0.16)
1033+
influxer (~> 1.4)
10201034
inline_svg (~> 1.3)
10211035
jbuilder (~> 2.8)
10221036
jquery-rails (~> 4.3)
@@ -1087,6 +1101,7 @@ DEPENDENCIES
10871101
test-prof (~> 0.7)
10881102
timber (~> 2.6)
10891103
timecop (~> 0.9)
1104+
tty-command (~> 0.10)
10901105
twilio-ruby (~> 5.21)
10911106
twitter (~> 6.2)
10921107
uglifier (~> 4.1)
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
class TestDurationMetric < Influxer::Metrics
2+
set_series :test
3+
4+
tags :user
5+
6+
attributes :run_time_seconds
7+
8+
validates :user, :run_time_seconds, presence: true
9+
validates :run_time_seconds, numericality: true
10+
end

config/application.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ class Application < Rails::Application
3030
config.autoload_paths += Dir["#{config.root}/app/black_box/"]
3131
config.autoload_paths += Dir["#{config.root}/app/sanitizers"]
3232
config.autoload_paths += Dir["#{config.root}/lib/"]
33+
config.autoload_paths += Dir["#{config.root}/app/metrics"]
3334

3435
config.active_record.observers = :article_observer, :reaction_observer, :comment_observer
3536
config.active_job.queue_adapter = :delayed_job

lib/tasks/test.rake

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
namespace :test do
2+
desc "run"
3+
task run: :environment do
4+
abort 'InfluxDB not running!' unless influx_running?
5+
6+
cmd = 'rspec'
7+
puts "Running rspec via `#{cmd}`"
8+
command = TTY::Command.new(printer: :quiet, color: true)
9+
10+
start = Time.now
11+
begin
12+
command.run(cmd)
13+
rescue TTY::Command::ExitError
14+
puts 'TEST FAILED SAFELY'
15+
end
16+
finish = Time.now
17+
18+
puts 'SENDING METRIC TO INFLUXDB'
19+
TestDurationMetric.write(user: 'IgorArkhipov', run_time_seconds: (finish - start).to_i)
20+
end
21+
22+
def influx_running?
23+
influx_endpoint = ENV['INFLUX_ENDPOINT'] || 'http://localhost:8086'
24+
puts "Check InfluxDB on #{influx_endpoint}..."
25+
26+
command = TTY::Command.new(printer: :null)
27+
command.run!("curl #{influx_endpoint}/ping").success?
28+
end
29+
end

0 commit comments

Comments
 (0)