Skip to content

Commit def3aa7

Browse files
jaymzhfacebook-github-bot
authored andcommitted
New cookbook: fb_influxdb (facebook#252)
Summary: This is a pretty simple one - just a package, config and service. Signed-off-by: Phil Dibowitz <phil@ipom.com> Pull Request resolved: facebook#252 Differential Revision: D69684408 fbshipit-source-id: 163d007307fc9adf30044c646b7546a59e800816
1 parent 6db3cb3 commit def3aa7

File tree

8 files changed

+190
-0
lines changed

8 files changed

+190
-0
lines changed

cookbooks/fb_influxdb/README.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
fb_influxdb Cookbook
2+
====================
3+
Installs and configures influxdb
4+
5+
Requirements
6+
------------
7+
This cookbook only works in Debian and Ubuntu since influxdb is not packaged
8+
in Fedora or EPEL.
9+
10+
Attributes
11+
----------
12+
* node['fb_influxdb']['manage_packages']
13+
* node['fb_influxdb']['config']
14+
15+
Usage
16+
-----
17+
NOTE: This cookbook currently assumes Influx 1.x.
18+
19+
### Packages
20+
21+
This cookbook will install both the server and client packages for you. If you
22+
want to manage packages yourself, set `node['fb_influxdb']['manage_packages']`
23+
to `false`.
24+
25+
### Configuration
26+
27+
A basic configuration is present in `node['fb_influxdb']['config']` which will
28+
allow a local influxdb instance to startup. It directly maps to the config
29+
format. All top-level sections are already created, add to them from your own
30+
cookbook like:
31+
32+
```ruby
33+
node.default['fb_influxdb']['config']['logging']['level'] = 'debug'
34+
```
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
default['fb_influxdb'] = {
2+
'manage_packages' => true,
3+
'config' => {
4+
'reporting-enabled' => false,
5+
'meta' => {
6+
'dir' => '/var/lib/influxdb/meta',
7+
},
8+
'data' => {
9+
'dir' => '/var/lib/influxdb/data',
10+
'wal-dir' => '/var/lib/influxdb/wal',
11+
},
12+
'coordinator' => {},
13+
'retention' => {},
14+
'shard-precreation' => {},
15+
'monitor' => {},
16+
'http' => {
17+
'bind-address' => 'localhost:8086',
18+
},
19+
'ifql' => {},
20+
'logging' => {},
21+
'subscriber' => {},
22+
# note a typo, some sections should be rendered as [[ ]]
23+
'[graphite]' => {},
24+
'[collectd]' => {
25+
'enabled' => true,
26+
'bind-address' => '127.0.0.1:25826',
27+
'database' => 'collectd',
28+
'typesdb' => '/usr/share/collectd',
29+
'security-level' => 'none',
30+
},
31+
'[opentsdb]' => {},
32+
'[udp]' => {},
33+
'continuous_queries' => {},
34+
'tls' => {},
35+
},
36+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
#
2+
# vim: syntax=ruby:expandtab:shiftwidth=2:softtabstop=2:tabstop=2
3+
#
4+
# Copyright (c) 2025-present, Meta Platforms, Inc.
5+
# Copyright (c) 2025-present, Phil Dibowitz
6+
# All rights reserved.
7+
#
8+
# Licensed under the Apache License, Version 2.0 (the "License");
9+
# you may not use this file except in compliance with the License.
10+
# You may obtain a copy of the License at
11+
#
12+
# http://www.apache.org/licenses/LICENSE-2.0
13+
#
14+
# Unless required by applicable law or agreed to in writing, software
15+
# distributed under the License is distributed on an "AS IS" BASIS,
16+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17+
# See the License for the specific language governing permissions and
18+
# limitations under the License.
19+
#
20+
21+
module FB
22+
class InfluxDB
23+
def self.indentstr(indent)
24+
' ' * indent
25+
end
26+
27+
def self.handle_raw_val(val)
28+
val.is_a?(String) ? "\"#{val}\"" : val.to_s
29+
end
30+
31+
def self.template_hash_helper(buf, indent, data)
32+
data.each do |key, val|
33+
buf << indentstr(indent + 1)
34+
case val
35+
when Array
36+
buf << "#{key} = [\n"
37+
val.each do |item|
38+
buf << indentstr(indent + 2)
39+
buf << "#{handle_raw_val(item)},\n"
40+
end
41+
buf << indentstr(indent + 1)
42+
buf << "]\n"
43+
when Hash
44+
template_hash_helper(buf, indent + 1, data)
45+
else
46+
buf << "#{key} = #{handle_raw_val(val)}\n"
47+
end
48+
end
49+
end
50+
end
51+
end

cookbooks/fb_influxdb/metadata.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
name 'fb_influxdb'
2+
maintainer 'Meta Platforms, Inc.'
3+
maintainer_email 'noreply@meta.com'
4+
license 'Apache-2.0'
5+
description 'Installs/Configures InfluxDB'
6+
version '0.1.0'
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
#
2+
# Cookbook:: fb_influxdb
3+
# Recipe:: default
4+
#
5+
# Copyright (c) 2025-present, Meta Platforms, Inc.
6+
# Copyright (c) 2025-present, Phil Dibowitz
7+
# All rights reserved.
8+
#
9+
# Licensed under the Apache License, Version 2.0 (the "License");
10+
# you may not use this file except in compliance with the License.
11+
# You may obtain a copy of the License at
12+
#
13+
# http://www.apache.org/licenses/LICENSE-2.0
14+
#
15+
# Unless required by applicable law or agreed to in writing, software
16+
# distributed under the License is distributed on an "AS IS" BASIS,
17+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18+
# See the License for the specific language governing permissions and
19+
# limitations under the License.
20+
#
21+
22+
unless node.debian? || node.ubuntu?
23+
fail 'fb_influxdb: not supported on this platform.'
24+
end
25+
26+
packages = %w{
27+
influxdb
28+
influxdb-client
29+
}
30+
31+
package 'influxdb packages' do
32+
only_if { node['fb_influxdb']['manage_packages'] }
33+
package_name packages
34+
action :upgrade
35+
notifies :restart, 'service[influxdb]'
36+
end
37+
38+
template '/etc/influxdb/influxdb.conf' do
39+
owner node.root_user
40+
group node.root_group
41+
mode '0644'
42+
notifies :restart, 'service[influxdb]'
43+
end
44+
45+
service 'influxdb' do
46+
action [:enable, :start]
47+
end
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# This file is controlled by Chef - do not modify!
2+
<% node['fb_influxdb']['config'].each do |section, config| %>
3+
<%
4+
# If the config isn't a has, then we're on global configs, process,
5+
# them manually, otherwise print the section header and pass the
6+
# hash to the hash handler.
7+
%>
8+
<% if config.is_a?(Hash) %>
9+
[<%= section %>]
10+
<% FB::InfluxDB.template_hash_helper(_buf, 0, config) %>
11+
<% else %>
12+
<%= section %> = <%= FB::InfluxDB.handle_raw_val(config) %>
13+
<% end %>
14+
<% end %>

cookbooks/test_services/metadata.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
depends 'fb_apache'
1111
depends 'fb_apt_cacher'
1212
depends 'fb_ejabberd'
13+
depends 'fb_influxdb'
1314
depends 'fb_reprepro'
1415
depends 'fb_smokeping'
1516
depends 'fb_spamassassin'

cookbooks/test_services/recipes/default.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
end
3535
node.default['fb_ejabberd']['config']['hosts'] << 'sample.com'
3636
include_recipe 'fb_ejabberd'
37+
include_recipe 'fb_influxdb'
3738
end
3839

3940
include_recipe 'fb_spamassassin'

0 commit comments

Comments
 (0)