influxdb_setup 0.3.0 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4471496a08494e71b0e21ef15489732db87238bf
4
- data.tar.gz: 9860d614165a6b8afddf1743309d2e6cb89a9056
3
+ metadata.gz: af774bd0bda065750d0b284e4bfb5dbcba4e6e44
4
+ data.tar.gz: d28478b3420de3ed667969acd98f6644cd3714ed
5
5
  SHA512:
6
- metadata.gz: 10068472722032acf450895cc5331a26362ae4180c439739f249d4a0b279b5e241a12ed18ece490c1eabd71b5fa17ea34f53610ca3c64da684c712cc9a89985c
7
- data.tar.gz: a78a8c0f9c49d84737ec6ffdf2defa4f155fdefd6718aece8ac6dfadbbaf9d1d2f563009a841c43a0d6bfb459cfadf27405734368db34b630a859fff01152a03
6
+ metadata.gz: c287d4135601d44847afd6d98617054778600097e6ee68606a44239832516986de78bb4fd077aab66236ce112add87db143ff5e6bf47c98124b2acbb2b228a26
7
+ data.tar.gz: d67ffd8c67f5221ccba1633370e0ec471707de5047941fa567d1e48e63227cc92bb2250108e0cd90280ea12713c5502227aa40c9682c878775e7e6a90b126ea9
data/CHANGELOG.md ADDED
@@ -0,0 +1,14 @@
1
+ # Change Log
2
+ All notable changes to this project will be documented in this file.
3
+ This project adheres to [Semantic Versioning](http://semver.org/).
4
+ CHANGELOG inspiration from http://keepachangelog.com/.
5
+
6
+ ## Unreleased
7
+
8
+ ## [0.5.0] - March 17, 2016
9
+ * Update influxdb_queries.yml and LoadQueries for InfluxDB 0.10
10
+
11
+ ## [0.4.1] - March 4, 2016
12
+ * Skip loading continuous queries if influxdb_queries.yml file doesn't exist.
13
+ * Use a real logger object, this will cause timestamps to be printed, and makes
14
+ testing easier.
data/README.md CHANGED
@@ -1,19 +1,14 @@
1
1
  # InfluxdbSetup
2
2
 
3
- For configuring the influxdb database, shard spaces, and continuous queries.
4
-
5
- **Warning**: Only works with InfluxDB 0.8.x
6
-
7
- I wanted configuring influxdb to be as easy as database migrations with Rails.
8
- This gem provides rake tasks to create the database and user, setup 2 default
9
- shard spaces (one for a week of fine grained detail, and another for archiving
10
- a year of data), and for creating/removing/updating continuous queries.
3
+ For configuring the influxdb database, and continuous queries.
11
4
 
12
5
  ## Installation
13
6
 
14
7
  Add these lines to your application's Gemfile:
15
8
 
16
9
  ```ruby
10
+ source 'http://gems.corp.avvo.com'
11
+
17
12
  gem 'influxdb_setup'
18
13
  ```
19
14
 
@@ -26,10 +21,9 @@ And then execute:
26
21
  To have the task run on deploy, add `require "influxdb_setup/capistrano"` to
27
22
  your `config/deploy.rb`.
28
23
 
29
- This will run the setup on deploy (creating database, shard spaces, and
24
+ This will run the setup on deploy (creating database, user, and
30
25
  continuous queries). It will also mark the deploy in the "deploys" table in
31
- your influxdb. See the example `db/influxdb_queries.yml` below for the archive
32
- queries.
26
+ your influxdb. See the example `influxdb_queries.yml` for the archive queries.
33
27
 
34
28
  ## Usage
35
29
 
@@ -52,18 +46,29 @@ default: &default
52
46
 
53
47
  development:
54
48
  <<: *default
55
- hosts: ["192.168.59.103"] # boot2docker default ip
49
+ hosts: ["192.168.59.103"]
56
50
  async: false
57
51
  enabled: true
58
52
  retry: false
59
53
 
54
+ ec2:
55
+ <<: *default
56
+
60
57
  test:
61
58
  <<: *default
62
59
 
60
+ stag:
61
+ <<: *default
62
+ hosts: ["fs2wad.prod.avvo.com"]
63
+ enabled: true
64
+
63
65
  production:
64
66
  <<: *default
65
- hosts: ["localhost"]
67
+ hosts: ["fs2wad.prod.avvo.com"]
66
68
  enabled: true
69
+
70
+ docker:
71
+ <<: *default
67
72
  ```
68
73
 
69
74
  To add continuous queries, just add them to the `db/influxdb_queries.yml`, for
@@ -71,10 +76,14 @@ example:
71
76
 
72
77
  ```yaml
73
78
  ---
74
- - select * from "response_times" into response_times.[rails_env]
75
- - select mean(value),count(value),percentile(value,95.0) as 95th,percentile(value,99.0) as 99th from "response_times.production" group by time(1h) into archive.response_times.1h
76
- - select * from "deploys" into deploys.[rails_env]
77
- - select * from "deploys.production" into archive.deploys
79
+ stag_times:
80
+ select median(value) as median,mean(value) as mean,count(value) as count into one_hour_stag_response_times from "response_times" where rails_env='stag' group by time(1h)
81
+ prod_times:
82
+ select median(value) as median,mean(value) as mean,count(value) as count into one_hour_prod_response_times from "response_times" where rails_env='production' group by time(1h)
83
+ prod_deploys:
84
+ select count(commit) as deploys into prod_deploys_per_hour from "deploys" where rails_env='production' group by time(1h)
85
+ stag_deploys:
86
+ select count(commit) as deploys into stag_deploys_per_hour from "deploys" where rails_env='stag' group by time(1h)
78
87
  ```
79
88
 
80
89
  Make sure your queries match what the server coerces them into (no spaces
@@ -86,10 +95,6 @@ If there's queries to update the task will not do anything.
86
95
  `rake influxdb:create_db`
87
96
  Creates the database for the service if it doesn't already exist.
88
97
 
89
- `rake influxdb:setup_shard_spaces`
90
- Creates or updates the default and archives shard spaces. If they don't exist,
91
- it creates them. If they do exist but they are not correct, it updates them.
92
-
93
98
  `rake influxdb:create_user`
94
99
  Creates the user for the service if it doesn't already exist.
95
100
 
@@ -100,16 +105,42 @@ in the `db/influxdb_queries.yml` file.
100
105
  `rake influxdb:setup`
101
106
  Runs all the above rake tasks.
102
107
 
108
+ ## Tests
109
+
110
+ To run the tests, you need an influxdb host setup. If you're not running it on
111
+ `localhost:8086`, you can specify where it's running with the `INFLUXDB_HOSTS`
112
+ and `INFLUXDB_PORT` environmental variables.
113
+
103
114
  ## Development
104
115
 
105
116
  After checking out the repo, run `bin/setup` to install dependencies. Then, run
106
117
  `rake spec` to run the tests. You can also run `bin/console` for an interactive
107
118
  prompt that will allow you to experiment.
108
119
 
120
+ To install this gem onto your local machine, run `bundle exec rake install`. To
121
+ release a new version, update the version number in `version.rb`, and then run
122
+ `bundle exec rake release`, which will create a git tag for the version, push
123
+ git commits and tags, and push the `.gem` file to
124
+ [rubygems.org](https://rubygems.org).
125
+
126
+ To cut a gem:
127
+
128
+ 1. Bump the version in `lib/influxdb_setup/version.rb`
129
+ 2. Build the gem `gem_push=no rake release`
130
+ 3. Push to geminabox `gem inabox pkg/influxdb_setup-0.1.0.gem` (or whatever
131
+ version you just cut.)
132
+
109
133
  ## Contributing
110
134
 
111
- Bug reports and pull requests are welcome on Github at
112
- https://github.com/dplummer/influxdb_setup
135
+ Bug reports and pull requests are welcome on GitLab at
136
+ https://github.com/avvo/influxdb_setup.
137
+
138
+ ## Changelog
139
+
140
+ v0.4.0 - Upgrade influxdb gem to handle InfluxDB v0.9.x and greater and remove shard space setup support
141
+ v0.3.1 - automatically skip influxdb setup on a rollback
142
+ v0.3.0 - added the ability to skip influxdb setup by setting the capistrano variable skip_influx_setup
143
+
113
144
 
114
145
  ## License
115
146
 
@@ -7,10 +7,10 @@ Gem::Specification.new do |spec|
7
7
  spec.name = "influxdb_setup"
8
8
  spec.version = InfluxdbSetup::VERSION
9
9
  spec.authors = ["Donald Plummer"]
10
- spec.email = ["donald.plummer@gmail.com"]
10
+ spec.email = ["dplummer@avvo.com"]
11
11
 
12
12
  spec.summary = %q{Rake task for setting up an influxdb database and queries}
13
- spec.homepage = "https://github.com/dplummer/influxdb_setup"
13
+ spec.homepage = "https://github.com/avvo/influxdb_setup"
14
14
  spec.license = "MIT"
15
15
 
16
16
  spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
@@ -18,9 +18,10 @@ Gem::Specification.new do |spec|
18
18
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
19
19
  spec.require_paths = ["lib"]
20
20
 
21
- spec.add_dependency "influxdb", "~> 0.1.9"
21
+ spec.add_dependency "influxdb", "~> 0.2.3"
22
22
 
23
23
  spec.add_development_dependency "bundler", "~> 1.10"
24
24
  spec.add_development_dependency "rake", "~> 10.0"
25
25
  spec.add_development_dependency "rspec"
26
+ spec.add_development_dependency "pry"
26
27
  end
@@ -1,15 +1,23 @@
1
1
  namespace :deploy do
2
+ # on rollback, repo_path is not set or is not present, so we can't do
3
+ # the influxdb_setup task below
4
+ before :rollback, :skip_influxdb do
5
+ set :skip_influxdb_setup, true
6
+ end
7
+
2
8
  before :restart, :influxdb_setup do
3
9
  on roles(:db) do
4
- within release_path do
5
- revision = fetch(:current_revision) do
6
- within(repo_path) do
7
- capture("cd #{repo_path} && git rev-parse --short HEAD")
10
+ unless fetch(:skip_influxdb_setup)
11
+ within current_path do
12
+ revision = fetch(:current_revision) do
13
+ within(repo_path) do
14
+ capture("cd #{repo_path} && git rev-parse --short HEAD")
15
+ end
8
16
  end
9
- end
10
17
 
11
- with rails_env: fetch(:rails_env) do
12
- execute :rake, "influxdb:setup influxdb:mark_deploy[#{revision}]"
18
+ with rails_env: fetch(:rails_env), newrelic_agent_enabled: false do
19
+ execute :rake, "influxdb:setup influxdb:mark_deploy[#{revision}]"
20
+ end
13
21
  end
14
22
  end
15
23
  end
@@ -7,7 +7,7 @@ module InfluxdbSetup
7
7
  end
8
8
 
9
9
  def log(message)
10
- puts "[InfluxdbSetup] #{message}"
10
+ @config.logger.info "[InfluxdbSetup] #{message}"
11
11
  end
12
12
  end
13
13
  end
@@ -8,7 +8,6 @@ module InfluxdbSetup
8
8
 
9
9
  {
10
10
  create_db: CreateDb,
11
- setup_shard_spaces: SetupShardSpaces,
12
11
  create_user: CreateUser,
13
12
  load_queries: LoadQueries,
14
13
  mark_deploy: MarkDeploy,
@@ -1,5 +1,6 @@
1
1
  require 'yaml'
2
2
  require 'erb'
3
+ require 'influxdb'
3
4
 
4
5
  module InfluxdbSetup
5
6
  class Config
@@ -11,8 +12,11 @@ module InfluxdbSetup
11
12
  @config ||= YAML.load(ERB.new(File.read("config/influxdb.yml")).result)[env]
12
13
  end
13
14
 
14
- def initialize
15
- @config = self.class.config
15
+ attr_accessor :logger
16
+
17
+ def initialize(config: self.class.config, logger: Logger.new(STDOUT))
18
+ @config = config
19
+ @logger = logger
16
20
  end
17
21
 
18
22
  def env
@@ -3,7 +3,7 @@ module InfluxdbSetup
3
3
  def call
4
4
  db = @config.db_name
5
5
  root = @config.build_client
6
- databases = root.get_database_list.map { |row| row["name"] }
6
+ databases = root.list_databases.map { |row| row["name"] }
7
7
 
8
8
  unless databases.include?(db)
9
9
  root.create_database(db)
@@ -6,9 +6,9 @@ module InfluxdbSetup
6
6
  pass = @config.password
7
7
 
8
8
  root = @config.build_client
9
- users = root.get_database_user_list(db).map { |row| row["name"] }
9
+ users = root.list_users.map{|user_hash| user_hash["username"]}
10
10
 
11
- unless users.include?(db)
11
+ unless users.include?(user)
12
12
  root.create_database_user(db, user, pass)
13
13
  else
14
14
  log "Influxdb user '#{user}'@'#{db}' already exists"
@@ -1,33 +1,52 @@
1
1
  module InfluxdbSetup
2
2
  class LoadQueries < Command
3
- def call
4
- db = @config.db_name
5
- root = @config.build_client(db)
6
- url = root.send :full_url, "/cluster/configuration"
7
- configuration = root.send :get, url
3
+ class Query
4
+ attr_reader :raw_name, :query
8
5
 
9
- existing_queries = configuration["ContinuousQueries"].fetch(db, {}).each_with_object({}) do |row, acc|
10
- acc[row['Id']] = row['Query']
6
+ def initialize(raw_name, query)
7
+ @raw_name = raw_name
8
+ @query = query
11
9
  end
12
- expected_queries = YAML.load_file("db/influxdb_queries.yml")
13
-
14
- no_change = 0
15
- expected_queries.each do |query|
16
- unless existing_queries.values.include?(query)
17
- log "Adding '#{query}'"
18
- root.query query
19
- else
20
- no_change += 1
21
- end
10
+
11
+ def name
12
+ "influxdb_setup_#{raw_name}"
22
13
  end
14
+ end
15
+
16
+ FileFormatError = Class.new(StandardError)
23
17
 
24
- log "There were #{no_change} continuous queries that required no updates"
18
+ def call
19
+ queries_file = Pathname.new("db/influxdb_queries.yml")
20
+
21
+ if queries_file.exist?
22
+ db = @config.db_name
23
+ root = @config.build_client(db)
24
+ existing_queries = root.list_continuous_queries(db)
25
+ raw = YAML.load(ERB.new(queries_file.read).result) || {}
26
+ raise FileFormatError, "expected influxdb_queries.yml to be a hash, was a #{raw.class.name}" unless raw.is_a?(Hash)
27
+
28
+ expected_queries = raw.map do |name, query|
29
+ Query.new(name, query)
30
+ end
31
+
32
+ # Delete first in case an old name is getting overwritten
33
+ existing_queries.each do |query|
34
+ if expected_queries.none? {|expected| expected.name == query["name"]}
35
+ log "Removing '#{query['name']}', was: '#{query['query']}'"
36
+ root.delete_continuous_query(query["name"], db)
37
+ end
38
+ end
25
39
 
26
- existing_queries.each do |(id, query)|
27
- unless expected_queries.include?(query)
28
- log "Removing '#{query}'"
29
- root.query "drop continuous query #{id}"
40
+ expected_queries.each do |expected|
41
+ if existing_queries.any? {|hash| hash["name"] == expected.name}
42
+ log "Skipping '#{expected.raw_name}', a query by that name already exists"
43
+ else
44
+ log "Adding '#{expected.raw_name}': '#{expected.query}'"
45
+ root.create_continuous_query(expected.name, db, expected.query)
46
+ end
30
47
  end
48
+ else
49
+ log "No influxdb_queries.yml file found, skipping continuous queries setup"
31
50
  end
32
51
  end
33
52
  end
@@ -4,7 +4,7 @@ module InfluxdbSetup
4
4
  db = @config.db_name
5
5
  root = @config.build_client(db)
6
6
 
7
- root.write_point("deploys", {
7
+ root.write_point("deploys", values: {
8
8
  rails_env: config.env,
9
9
  commit: commit
10
10
  })
@@ -1,3 +1,3 @@
1
1
  module InfluxdbSetup
2
- VERSION = "0.3.0"
2
+ VERSION = "1.0.0"
3
3
  end
@@ -8,7 +8,6 @@ module InfluxdbSetup
8
8
  autoload :CreateUser, "influxdb_setup/create_user"
9
9
  autoload :LoadQueries, "influxdb_setup/load_queries"
10
10
  autoload :MarkDeploy, "influxdb_setup/mark_deploy"
11
- autoload :SetupShardSpaces, "influxdb_setup/setup_shard_spaces"
12
11
 
13
12
  def self.config
14
13
  InfluxdbSetup::Config.config
@@ -8,11 +8,6 @@ namespace :influxdb do
8
8
  @influxdb_setup.create_db
9
9
  end
10
10
 
11
- desc "Setup the default and archives shard spaces"
12
- task :setup_shard_spaces => [:config] do
13
- @influxdb_setup.setup_shard_spaces
14
- end
15
-
16
11
  desc "Creates the service's user if it doesn't exist"
17
12
  task :create_user => [:config] do
18
13
  @influxdb_setup.create_user
@@ -30,7 +25,6 @@ namespace :influxdb do
30
25
 
31
26
  desc "Run all the tasks to setup influxdb for the service"
32
27
  task :setup => [:create_db,
33
- :setup_shard_spaces,
34
28
  :create_user,
35
29
  :load_queries]
36
30
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: influxdb_setup
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Donald Plummer
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-10-08 00:00:00.000000000 Z
11
+ date: 2016-04-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: influxdb
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 0.1.9
19
+ version: 0.2.3
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: 0.1.9
26
+ version: 0.2.3
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: bundler
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -66,9 +66,23 @@ dependencies:
66
66
  - - ">="
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: pry
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
69
83
  description:
70
84
  email:
71
- - donald.plummer@gmail.com
85
+ - dplummer@avvo.com
72
86
  executables: []
73
87
  extensions: []
74
88
  extra_rdoc_files: []
@@ -76,6 +90,7 @@ files:
76
90
  - ".gitignore"
77
91
  - ".rspec"
78
92
  - ".travis.yml"
93
+ - CHANGELOG.md
79
94
  - Gemfile
80
95
  - LICENSE.txt
81
96
  - README.md
@@ -93,10 +108,9 @@ files:
93
108
  - lib/influxdb_setup/load_queries.rb
94
109
  - lib/influxdb_setup/mark_deploy.rb
95
110
  - lib/influxdb_setup/railtie.rb
96
- - lib/influxdb_setup/setup_shard_spaces.rb
97
111
  - lib/influxdb_setup/version.rb
98
112
  - lib/tasks/influxdb_setup.rake
99
- homepage: https://github.com/dplummer/influxdb_setup
113
+ homepage: https://github.com/avvo/influxdb_setup
100
114
  licenses:
101
115
  - MIT
102
116
  metadata: {}
@@ -116,7 +130,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
116
130
  version: '0'
117
131
  requirements: []
118
132
  rubyforge_project:
119
- rubygems_version: 2.4.5.1
133
+ rubygems_version: 2.5.1
120
134
  signing_key:
121
135
  specification_version: 4
122
136
  summary: Rake task for setting up an influxdb database and queries
@@ -1,51 +0,0 @@
1
- module InfluxdbSetup
2
- class SetupShardSpaces < Command
3
- def call
4
- db = @config.db_name
5
- root = @config.build_client
6
-
7
- expected_default_config = {
8
- "name" => "default",
9
- "database" => db,
10
- "regex" => "/.*/",
11
- "retentionPolicy" => "7d",
12
- "shardDuration" => "1h",
13
- "replicationFactor" => 1,
14
- "split" => 1
15
- }
16
-
17
- expected_archive_config = {
18
- "name" => "archives",
19
- "database" => db,
20
- "regex" => "/archive.*/",
21
- "retentionPolicy" => "365d",
22
- "shardDuration" => "7d",
23
- "replicationFactor" => 1,
24
- "split" => 1
25
- }
26
-
27
- actual_default_shard = root.get_shard_space(db, "default")
28
- actual_archive_shard = root.get_shard_space(db, "archives")
29
-
30
- if actual_default_shard.nil?
31
- log "Creating default shard space"
32
- root.create_shard_space(db, expected_default_config.except("database"))
33
- elsif actual_default_shard != expected_default_config
34
- log "Updating default shard space"
35
- root.update_shard_space(db, "default", expected_default_config.except("database"))
36
- else
37
- log "Shard default up to date"
38
- end
39
-
40
- if actual_archive_shard.nil?
41
- log "Creating archives shard space"
42
- root.create_shard_space(db, expected_archive_config.except("database"))
43
- elsif actual_archive_shard != expected_archive_config
44
- log "Updating archives shard space"
45
- root.update_shard_space(db, "archives", expected_archive_config.except("database"))
46
- else
47
- log "Shard archives up to date"
48
- end
49
- end
50
- end
51
- end