influxdb_setup 1.0.1 → 1.1.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: 292b9c53f779444476e2eadee7f3ebf6f7a211d7
4
- data.tar.gz: e044cd782119b717f838ae936ac86c8784d7033d
3
+ metadata.gz: 3f8f561855ababe643437b7264f70405452ada8f
4
+ data.tar.gz: 0f678a8b91a45b3417eb5da6fb6ca9847c995002
5
5
  SHA512:
6
- metadata.gz: c470a19810295c2054edf8e73d1e12b57816b081612e7022903faecb387312f07470fee78ad2eded4c4188fb269aef604059079ade032831fdf1057b610e8379
7
- data.tar.gz: 7f9d34ab5a87195f8f1600adb190cd4296db22c95afc067c4a1a768413600d57960a990ac7ee62807d770f588a3bd5d919b427d23bb8215b7f11814ff841c6cd
6
+ metadata.gz: e0cc6b05a40dc0970d44af0b4cf158f20f8651874fe421f4599027d54005a98a2a88a43d3ddea560b3343e7c978e1b9a448ee016495824fc07b702417b429a64
7
+ data.tar.gz: 820639ba9e660591ae6f069e34b33bde93575e6dafd5200b19e9d449db8d284e762af3dbbeb9f7a75b52f82a2defb56f4c6133f6d79a3fb791c2049dc3100669
data/CHANGELOG.md CHANGED
@@ -5,6 +5,11 @@ CHANGELOG inspiration from http://keepachangelog.com/.
5
5
 
6
6
  ## Unreleased
7
7
 
8
+ ## [1.1.0] - August 8, 2016
9
+ * Support configuration of retention policies
10
+ * Support specifying config file instead of using the default one
11
+ * Fix crash in create_user task when not specifing user in config
12
+
8
13
  ## [1.0.1] - May 20, 2016
9
14
  * Fix Config.env method to be class, so that Config.config works if you don't set it first.
10
15
 
data/README.md CHANGED
@@ -26,7 +26,9 @@ your influxdb. See the example `influxdb_queries.yml` for the archive queries.
26
26
  ## Usage
27
27
 
28
28
  This library expects your influxdb config to be located in the
29
- `config/influxdb.yml` file. For example (change *myapp* to your application
29
+ `config/influxdb.yml` file. You can also specify a config file
30
+ by using the INFLUXDB_CONFIG_FILE environment variable. For example (change
31
+ *myapp* to your application
30
32
  name):
31
33
 
32
34
  ```yaml
@@ -40,7 +42,13 @@ default: &default
40
42
  retry: <%= ENV.fetch('INFLUXDB_RETRY', 'true') == "true" %> # default true
41
43
  use_ssl: <%= ENV.fetch('INFLUXDB_USE_SSL', 'false') == "true" %> # default false
42
44
  enabled: <%= ENV.fetch('INFLUXDB_ENABLED', 'false') == "true" %> # default false
43
-
45
+ retention_policies:
46
+ - name: 'default'
47
+ duration: '4w'
48
+ replication: 1
49
+ - name: 'archive'
50
+ duration: 'INF'
51
+ replication: 1
44
52
 
45
53
  development:
46
54
  <<: *default
@@ -48,6 +56,13 @@ development:
48
56
  async: false
49
57
  enabled: true
50
58
  retry: false
59
+ retention_policies:
60
+ - name: 'default'
61
+ duration: '4w'
62
+ replication: 1
63
+ - name: 'archive'
64
+ duration: 'INF'
65
+ replication: 1
51
66
 
52
67
  ec2:
53
68
  <<: *default
@@ -57,12 +72,12 @@ test:
57
72
 
58
73
  stag:
59
74
  <<: *default
60
- hosts: ["fs2wad.prod.avvo.com"]
75
+ hosts: ["your-local-influx-host"]
61
76
  enabled: true
62
77
 
63
78
  production:
64
79
  <<: *default
65
- hosts: ["fs2wad.prod.avvo.com"]
80
+ hosts: ["your-local-influx-host"]
66
81
  enabled: true
67
82
 
68
83
  docker:
@@ -107,6 +122,9 @@ Creates the database for the service if it doesn't already exist.
107
122
  `rake influxdb:create_user`
108
123
  Creates the user for the service if it doesn't already exist.
109
124
 
125
+ `rake influxdb:create_retention_policy`
126
+ Creates retention policies if they don't exist and alters retention policies if they already exist.
127
+
110
128
  `rake influxdb:load_queries`
111
129
  Creates any continuous queries that are missing. Removes queries that are not
112
130
  in the `db/influxdb_queries.yml` file.
@@ -114,6 +132,9 @@ in the `db/influxdb_queries.yml` file.
114
132
  `rake influxdb:setup`
115
133
  Runs all the above rake tasks.
116
134
 
135
+ `INFLUXDB_CONFIG_FILE=/your/config/file/path rake influxdb:setup`
136
+ Use specified config file. Here ```setup``` could be any other tasks supported.
137
+
117
138
  ## Tests
118
139
 
119
140
  To run the tests, you need an influxdb host setup. If you're not running it on
@@ -9,6 +9,7 @@ module InfluxdbSetup
9
9
  {
10
10
  create_db: CreateDb,
11
11
  create_user: CreateUser,
12
+ create_retention_policy: CreateRetentionPolicy,
12
13
  load_queries: LoadQueries,
13
14
  mark_deploy: MarkDeploy,
14
15
  }.each do |cmd, klass|
@@ -9,7 +9,8 @@ module InfluxdbSetup
9
9
  end
10
10
 
11
11
  def self.config
12
- @config ||= YAML.load(ERB.new(File.read("config/influxdb.yml")).result)[env]
12
+ config_file = ENV.fetch('INFLUXDB_CONFIG_FILE', 'config/influxdb.yml')
13
+ @config ||= YAML.load(ERB.new(File.read(config_file)).result)[env]
13
14
  end
14
15
 
15
16
  def self.env
@@ -39,15 +40,19 @@ module InfluxdbSetup
39
40
  @config['password']
40
41
  end
41
42
 
43
+ def retention_policies
44
+ @config['retention_policies']
45
+ end
46
+
42
47
  def build_client(database = "", options = {})
43
48
  InfluxDB::Client.new(database,
44
49
  {
45
- username: "root",
46
- password: "root",
47
- hosts: @config["hosts"],
48
- port: @config.fetch("port", 8086),
49
- async: false,
50
- use_ssl: @config.fetch("use_ssl", false),
50
+ username: @config.fetch('username', 'root'),
51
+ password: @config.fetch('password', 'root'),
52
+ hosts: @config['hosts'],
53
+ port: @config.fetch('port', 8086),
54
+ async: @config.fetch('async', false),
55
+ use_ssl: @config.fetch('use_ssl', false),
51
56
  retry: false,
52
57
  }.merge(options))
53
58
  end
@@ -0,0 +1,19 @@
1
+ module InfluxdbSetup
2
+ class CreateRetentionPolicy < Command
3
+ def call
4
+ db = @config.db_name
5
+ retention_policies = @config.retention_policies
6
+
7
+ root = @config.build_client
8
+ rcs = root.list_retention_policies(db).map { |row| row["name"] }
9
+
10
+ retention_policies.each do |rc|
11
+ if rcs.include? rc['name']
12
+ root.alter_retention_policy(rc['name'], db, rc['duration'], rc['replication'])
13
+ else
14
+ root.create_retention_policy(rc['name'], db, rc['duration'], rc['replication'])
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -8,10 +8,12 @@ module InfluxdbSetup
8
8
  root = @config.build_client
9
9
  users = root.list_users.map{|user_hash| user_hash["username"]}
10
10
 
11
- unless users.include?(user)
12
- root.create_database_user(db, user, pass)
13
- else
11
+ if user.nil?
12
+ log "Influxdb user not specified, using the default one..."
13
+ elsif users.include?(user)
14
14
  log "Influxdb user '#{user}'@'#{db}' already exists"
15
+ else
16
+ root.create_database_user(db, user, pass)
15
17
  end
16
18
  end
17
19
  end
@@ -1,3 +1,3 @@
1
1
  module InfluxdbSetup
2
- VERSION = "1.0.1"
2
+ VERSION = "1.1.0"
3
3
  end
@@ -6,6 +6,7 @@ module InfluxdbSetup
6
6
  autoload :Config, "influxdb_setup/config"
7
7
  autoload :CreateDb, "influxdb_setup/create_db"
8
8
  autoload :CreateUser, "influxdb_setup/create_user"
9
+ autoload :CreateRetentionPolicy, "influxdb_setup/create_retention_policy"
9
10
  autoload :LoadQueries, "influxdb_setup/load_queries"
10
11
  autoload :MarkDeploy, "influxdb_setup/mark_deploy"
11
12
 
@@ -13,6 +13,11 @@ namespace :influxdb do
13
13
  @influxdb_setup.create_user
14
14
  end
15
15
 
16
+ desc "Create the retention policies"
17
+ task :create_retention_policy => [:config] do
18
+ @influxdb_setup.create_retention_policy
19
+ end
20
+
16
21
  desc "Loads the continuous queries from db/influxdb_queries.yml"
17
22
  task :load_queries => [:config] do
18
23
  @influxdb_setup.load_queries
@@ -26,5 +31,6 @@ namespace :influxdb do
26
31
  desc "Run all the tasks to setup influxdb for the service"
27
32
  task :setup => [:create_db,
28
33
  :create_user,
34
+ :create_retention_policy,
29
35
  :load_queries]
30
36
  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: 1.0.1
4
+ version: 1.1.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: 2016-05-20 00:00:00.000000000 Z
11
+ date: 2016-08-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: influxdb
@@ -104,6 +104,7 @@ files:
104
104
  - lib/influxdb_setup/commands.rb
105
105
  - lib/influxdb_setup/config.rb
106
106
  - lib/influxdb_setup/create_db.rb
107
+ - lib/influxdb_setup/create_retention_policy.rb
107
108
  - lib/influxdb_setup/create_user.rb
108
109
  - lib/influxdb_setup/load_queries.rb
109
110
  - lib/influxdb_setup/mark_deploy.rb
@@ -130,7 +131,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
130
131
  version: '0'
131
132
  requirements: []
132
133
  rubyforge_project:
133
- rubygems_version: 2.5.1
134
+ rubygems_version: 2.4.8
134
135
  signing_key:
135
136
  specification_version: 4
136
137
  summary: Rake task for setting up an influxdb database and queries