Skip to content
This repository has been archived by the owner on Nov 28, 2023. It is now read-only.

Commit

Permalink
Merge pull request bdangit#45 from mistsys/rberger/influxdb-0.9.x
Browse files Browse the repository at this point in the history
Added changes to support Influxdb version 0.9.x
  • Loading branch information
jakedavis committed May 11, 2015
2 parents 68a843c + 9470a27 commit c598fb3
Show file tree
Hide file tree
Showing 10 changed files with 221 additions and 25 deletions.
9 changes: 9 additions & 0 deletions .kitchen.yml
Expand Up @@ -16,3 +16,12 @@ suites:
- recipe[apt::default]
- recipe[influxdb::default]
attributes:
influxdb:
version: "0.8.8"
- name: zero_nine
run_list:
- recipe[apt::default]
- recipe[influxdb::default]
attributes:
influxdb:
version: "0.9.0-rc27"
2 changes: 1 addition & 1 deletion Berksfile
@@ -1,4 +1,4 @@
source 'http://api.berkshelf.com'
source "https://supermarket.getchef.com"

metadata

Expand Down
1 change: 1 addition & 0 deletions Gemfile
Expand Up @@ -12,4 +12,5 @@ group :test do
gem 'rubocop'
gem 'rake'
gem 'foodcritic'
gem 'serverspec'
end
11 changes: 9 additions & 2 deletions README.md
@@ -1,12 +1,19 @@
# InfluxDB
Chef cookbook to install and configure InfluxDB.

Now supports Influxdb versions before and after 0.9.x

## Usage and Resources
The InfluxDB cookbook comes with a Vagrantfile. Test using `vagrant up`. Simply
running the `default` recipe should be sufficient. Real tests coming soon!

For rendering the config, set the parameter under `node[:influxdb][:config]`:
For rendering the config

* For Influxdb versions before 0.9.x:
set the parameter under `node[:influxdb][:config]`
* For versions 0.9.x and greater:
set the parameter under `node[:influxdb][:zero_nine[:config]`

`default[:influxdb][:config]['MyParameter'] = 'val'`

The following gems are used by the `InfluxDB::Helpers` module:
Expand All @@ -24,7 +31,7 @@ This resource installs and configures InfluxDB based on `node[:influxdb][:config
influxdb 'main' do
source node[:influxdb][:source]
checksum node[:influxdb][:checksum]
config node[:influxdb][:config]
config node[:influxdb][:config] # Or if >= 0.9.x it will use node[:influxdb][:zero_nine[:config]
action :create
end
```
Expand Down
147 changes: 147 additions & 0 deletions attributes/default.rb
Expand Up @@ -32,7 +32,19 @@
default[:influxdb][:client][:ruby][:version] = nil
default[:influxdb][:handler][:version] = '0.1.4'

# For influxdb versions >= 0.9.x
default[:influxdb][:install_root_dir] = "/opt/influxdb"
default[:influxdb][:log_dir] = "/var/log/influxdb"
default[:influxdb][:data_root_dir] = "/var/opt/influxdb"
default[:influxdb][:config_root_dir] = "/etc/opt/influxdb"
default[:influxdb][:config_file_path] = "#{node[:influxdb][:config_root_dir]}/influxdb.conf"

# Parameters to configure InfluxDB
# For versions < 0.9.x set default[:influxdb][:config] immediately following this.
# For versions >= 0.9.x set default[:influxdb][:zero_nine][:config] later in the file.


# For influxdb versions < 0.9.x
# Based on https://github.com/influxdb/influxdb/blob/v0.8.5/config.sample.toml
default[:influxdb][:config] = {
'bind-address' => '0.0.0.0',
Expand Down Expand Up @@ -104,3 +116,138 @@
'requests-per-logfile' => 10_000
}
}

# For influxdb versions >= 0.9.x
default[:influxdb][:zero_nine][:config] = {
# If hostname (on the OS) doesn't return a name that can be resolved by the other
# systems in the cluster, you'll have to set the hostname to an IP or something
# that can be resolved here.
hostname: "",

'bind-address' => '0.0.0.0',

# The default cluster and API port
port: 8086,

# Once every 24 hours InfluxDB will report anonymous data to m.influxdb.com
# The data includes raft id (random 8 bytes), os, arch and version
# We don't track ip addresses of servers reporting. This is only used
# to track the number of instances running and the versions, which
# is very helpful for us.
# Change this option to true to disable reporting.
'reporting-disabled' => false,

# Controls settings for initial start-up. Once a node is successfully started,
# these settings are ignored. If a node is started with the -join flag,
# these settings are ignored.
# The first (seed) node should not be included in the join-urls list
initialization: {
'join-urls' => "", # Comma-delimited URLs, in the form http://host:port, for joining another cluster.
},


# Control authentication
# If not set authetication is DISABLED. Be sure to explicitly set this flag to
# true if you want authentication.
authentication: {
enabled: false
},

# Configure the admin server
admin: {
enabled: true,
port: 8083,
},

# Configure the HTTP API endpoint. All time-series data and queries uses this endpoint.
api: {
'bind-address' => '0.0.0.0',
'ssl-port' => nil, # SSL support is enabled if you set a port and cert
'ssl-cert' => nil,
port: 8086,
'read-timeout' => '5s'
},
graphite: [
{
enabled: false,
protocol: "", # Set to "tcp" or "udp"
'bind-address' => "0.0.0.0", # If not set, is actually set to bind-address.
port: 2003,
'name-position' => "last",
'name-separator' => "-",
database: "" # store graphite data in this database
}
],
collectd: {
enabled: false,
'bind-address' => "0.0.0.0",
port: 25827,
database: "collectd_database",
typesdb: "types.db"
},
opentsdb: {
enabled: false,
'bind-address' => "0.0.0.0",
port: 4242,
database: "opentsdb_database"
},
udp: {
enabled: false,
'bind-address' => "0.0.0.0",
port: 4444
},

# Broker configuration. Brokers are nodes which participate in distributed
# consensus.
broker: {
enabled: true,
# Where the Raft logs are stored. The user running InfluxDB will need read/write access.
dir: "#{node[:influxdb][:data_root_dir]}/raft",
'truncation-interval' => "10m",
'max-topic-size' => 1073741824,
'max-segment-size' => 10485760
},

# Raft configuration. Controls the distributed consensus system.
raft: {
'apply-interval' => "10ms",
'election-timeout' => "1s",
'heartbeat-interval' => "100ms",
'reconnect-timeout' => "10ms"
},

# Data node configuration. Data nodes are where the time-series data, in the form of
# shards, is stored.
data: {
enabled: true,
dir: "#{node[:influxdb][:data_root_dir]}/db",

# Auto-create a retention policy when a database is created. Defaults to true.
'retention-auto-create' => true,

# Control whether retention policies are enforced and how long the system waits between
# enforcing those policies.
'retention-check-enabled' => true,
'retention-check-period' => "10m"
},

# Configuration for snapshot endpoint.
snapshot: {
enabled: true # Enabled by default if not set.
},

logging: {
'write-tracing' => false, # If true, enables detailed logging of the write system.
'raft-tracing' => false, # If true, enables detailed logging of Raft consensus.
'http-access' => true, # If true, logs each HTTP access to the system.
file: "#{node[:influxdb][:log_dir]}/influxd.log"
},

# InfluxDB can store statistical and diagnostic information about itself. This is useful for
# monitoring purposes. This feature is disabled by default, but if enabled, these data can be
# queried like any other data.
monitoring: {
enabled: false,
'write-interval' => "1m" # Period between writing the data.
}
}
10 changes: 4 additions & 6 deletions libraries/default.rb
Expand Up @@ -25,19 +25,17 @@
module InfluxDB
# Some helpers to interact with InfluxDB
module Helpers
INFLUXDB_CONFIG = '/opt/influxdb/shared/config.toml'

# TODO : Configurable administrator creds
def self.client(user = 'root', pass = 'root', run_context)
install_influxdb(run_context)
require_influxdb
InfluxDB::Client.new(username: user, password: pass)
end

def self.render_config(hash, run_context)
def self.render_config(hash, run_context, config_file)
install_toml(run_context)
require_toml
config_file(hash, run_context)
config_file(hash, run_context, config_file)
end

def self.install_toml(run_context)
Expand All @@ -58,8 +56,8 @@ def self.require_influxdb
require 'influxdb'
end

def self.config_file(hash, run_context)
f = Chef::Resource::File.new(INFLUXDB_CONFIG, run_context)
def self.config_file(hash, run_context, config_file)
f = Chef::Resource::File.new(config_file, run_context)
f.owner 'root'
f.mode 00644
f.content TOML::Generator.new(hash).body
Expand Down
3 changes: 1 addition & 2 deletions providers/default.rb
Expand Up @@ -48,7 +48,6 @@ def install_influxdb
remote.source(@source) if @source
remote.checksum(@checksum) if @checksum
remote.run_action(:create)

pkg = Chef::Resource::Package.new(path, @run_context)
pkg.provider(Chef::Provider::Package::Dpkg)
pkg.run_action(:install)
Expand All @@ -60,7 +59,7 @@ def influxdb_service(action)
end

def create_config
InfluxDB::Helpers.render_config(@config, @run_context)
InfluxDB::Helpers.render_config(@config, @run_context, node[:influxdb][:config_file_path])
end

def touch_logfile
Expand Down
23 changes: 22 additions & 1 deletion recipes/default.rb
Expand Up @@ -19,12 +19,33 @@
#
# Installs InfluxDB

require 'pp'

ver = node[:influxdb][:version]
arch = /x86_64/.match(node[:kernel][:machine]) ? 'amd64' : 'i686'
node.default[:influxdb][:source] = "http://s3.amazonaws.com/influxdb/influxdb_#{ver}_#{arch}.deb"

if (ver =~ /^0\.9\./)
influxdb_config = node[:influxdb][:zero_nine][:config]
dirs = [node[:influxdb][:data_root_dir], influxdb_config[:data][:dir], influxdb_config[:broker][:dir]]
else
node.set[:influxdb][:config_file_path] = "#{node[:influxdb][:install_root_dir]}/shared/config.toml"
influxdb_config = node[:influxdb][:config]
dirs = [node[:influxdb][:data_root_dir]]
end

pp_influxdb = PP.pp(node[:influxdb], '')
Chef::Log.info "++++ influxdb:\n#{pp_influxdb}"

directory node[:influxdb][:data_root_dir] do
mode "0755"
owner "influxdb"
group "influxdb"
recursive true
end

influxdb 'main' do
source node[:influxdb][:source]
config node[:influxdb][:config]
config influxdb_config
action node[:influxdb][:action]
end
39 changes: 26 additions & 13 deletions test/integration/default/serverspec/install_spec.rb
@@ -1,20 +1,33 @@
require 'serverspec'

include Serverspec::Helper::Exec
include Serverspec::Helper::DetectOS
# Required by serverspec
set :backend, :exec

describe user('influxdb') do
it { should exist }
end
# include Serverspec::Helper::Exec
# include Serverspec::Helper::DetectOS
Serverspec.describe "influxdb" do
before(:all) do
status = `service influxdb status`
unless status =~ /OK/
puts "STARTING INFLUXDB: "
puts `service influxdb start`
sleep 1
end
end

describe service('influxdb') do
it { should be_running }
end
describe user('influxdb') do
it { should exist }
end

describe port(8083) do
it { should be_listening }
end
describe service('influxdb') do
it { should be_running }
end

describe port(8083) do
it { should be_listening }
end

describe port(8086) do
it { should be_listening }
describe port(8086) do
it { should be_listening }
end
end
1 change: 1 addition & 0 deletions test/integration/zero_nine

0 comments on commit c598fb3

Please sign in to comment.