-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #872 from instedd/feature/telemetry-accounts-metric
Feature/telemetry accounts metric
- Loading branch information
Showing
8 changed files
with
156 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
module Telemetry::AccountsCollector | ||
|
||
def self.collect_stats(period) | ||
{ | ||
"counters" => [{ | ||
"metric" => "accounts", | ||
"key" => { }, | ||
"value" => User.where("created_at < ?", period.end).count, | ||
}] | ||
} | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
version: '2.0' | ||
|
||
services: | ||
rails: | ||
image: instedd/nginx-rails:2.1 | ||
environment: | ||
RAILS_ENV: development | ||
ELASTICSEARCH_URL: 'elasticsearch:9200' | ||
REDIS_URL: 'redis://redis:6379' | ||
DATABASE_URL: 'mysql2://root@db' | ||
POIROT_ENABLED: 'false' | ||
volumes: | ||
- .:/app | ||
- bundle:/usr/local/bundle |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
version: '2.0' | ||
|
||
services: | ||
db: | ||
image: mysql:5.6 | ||
environment: | ||
MYSQL_ALLOW_EMPTY_PASSWORD: 'yes' | ||
volumes: | ||
- db:/var/lib/mysql | ||
|
||
elasticsearch: | ||
image: elasticsearch:1.7 | ||
command: elasticsearch -Des.network.host=0.0.0.0 | ||
volumes: | ||
- elastic:/usr/share/elasticsearch/data | ||
|
||
redis: | ||
image: redis | ||
|
||
web: | ||
extends: | ||
file: docker-compose-base.yml | ||
service: rails | ||
command: bundle exec rails server -b 0.0.0.0 | ||
links: | ||
- db | ||
- elasticsearch | ||
- redis | ||
ports: | ||
- 3000:3000 | ||
|
||
resque: | ||
extends: | ||
file: docker-compose-base.yml | ||
service: rails | ||
command: bundle exec rake resque:work TERM_CHILD=1 FORK_PER_JOB=false | ||
links: | ||
- db | ||
- elasticsearch | ||
- redis | ||
|
||
resque_scheduler: | ||
extends: | ||
file: docker-compose-base.yml | ||
service: rails | ||
command: bundle exec rake resque:scheduler | ||
links: | ||
- db | ||
- elasticsearch | ||
- redis | ||
|
||
volumes: | ||
db: | ||
elastic: | ||
redis: | ||
bundle: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
#!/bin/sh | ||
docker-compose run --rm web "$@" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
require 'spec_helper' | ||
|
||
describe Telemetry::AccountsCollector do | ||
|
||
it "counts accounts for current period" do | ||
3.times { User.make } | ||
period = InsteddTelemetry::Period.current | ||
|
||
stats = Telemetry::AccountsCollector.collect_stats(period) | ||
|
||
assert_equal stats, { | ||
"counters" => [ | ||
{ | ||
"metric" => "accounts", | ||
"key" => {}, | ||
"value" => 3 | ||
} | ||
] | ||
} | ||
end | ||
|
||
it "takes into account period date" do | ||
Timecop.freeze(Time.now) | ||
3.times { User.make } | ||
p0 = InsteddTelemetry::Period.current | ||
|
||
Timecop.freeze(Time.now + InsteddTelemetry::Period.span) | ||
2.times { User.make } | ||
p1 = InsteddTelemetry::Period.current | ||
|
||
assert_equal Telemetry::AccountsCollector.collect_stats(p0), { | ||
"counters" => [{ | ||
"metric" => "accounts", | ||
"key" => {}, | ||
"value" => 3 | ||
}] | ||
} | ||
|
||
assert_equal Telemetry::AccountsCollector.collect_stats(p1), { | ||
"counters" => [{ | ||
"metric" => "accounts", | ||
"key" => {}, | ||
"value" => 5 | ||
}] | ||
} | ||
end | ||
|
||
end |