Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 4 additions & 9 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,22 +1,17 @@
.idea/

.vagrant
Berksfile.lock
*~
*#
.#*
\#*#
.*.sw[a-z]
*.un~
pkg/

# Berkshelf
.vagrant
/cookbooks
Berksfile.lock

# Bundler
Gemfile.lock
bin/*
.bundle/*

.kitchen/
.kitchen.local.yml

.idea
39 changes: 21 additions & 18 deletions attributes/default.rb
Original file line number Diff line number Diff line change
@@ -1,27 +1,30 @@
default["td_agent"]["api_key"] = ''
default['td_agent']['api_key'] = ''

default["td_agent"]["plugins"] = []
# Enable td-agent Prometheus monitoring
default['td_agent']['enable_prometheus'] = false

default["td_agent"]["uid"] = nil
default["td_agent"]["gid"] = nil
default['td_agent']['plugins'] = []

default["td_agent"]["user"] = 'td-agent'
default["td_agent"]["group"] = 'td-agent'
default['td_agent']['uid'] = nil
default['td_agent']['gid'] = nil

default["td_agent"]["includes"] = false
default["td_agent"]["default_config"] = true
default["td_agent"]["template_cookbook"] = 'td-agent'
default["td_agent"]["in_http"]["enable_api"] = true
default["td_agent"]["version"] = "2.2.0"
default["td_agent"]["pinning_version"] = false
default["td_agent"]["apt_arch"] = 'amd64'
default["td_agent"]["in_forward"] = {
default['td_agent']['user'] = 'td-agent'
default['td_agent']['group'] = 'td-agent'

default['td_agent']['includes'] = true
default['td_agent']['default_config'] = true
default['td_agent']['template_cookbook'] = 'td-agent'
default['td_agent']['in_http']['enable_api'] = true
default['td_agent']['version'] = '3.1.1'
default['td_agent']['pinning_version'] = false
default['td_agent']['apt_arch'] = 'amd64'
default['td_agent']['in_forward'] = {
port: 24224,
bind: '0.0.0.0'
bind: '0.0.0.0',
}
default["td_agent"]["in_http"] = {
default['td_agent']['in_http'] = {
port: 8888,
bind: '0.0.0.0'
bind: '0.0.0.0',
}
default["td_agent"]["yum_amazon_releasever"] = "$releasever"
default['td_agent']['yum_amazon_releasever'] = '$releasever'
default['td_agent']['skip_repository'] = false
16 changes: 7 additions & 9 deletions libraries/helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,11 @@ def self.params_to_text(parameters)
body += params_to_text(param_value)
body += "</#{param_key}>\n"
elsif param_value.is_a?(Array)
if param_value.all? { |array_value| array_value.is_a?(Hash) }
body += param_value.map { |array_value|
"<#{param_key}>\n#{params_to_text(array_value)}</#{param_key}>\n"
}.join
else
body += "#{param_key} [#{param_value.map { |array_value| array_value.to_s.dump }.join(", ")}]\n"
end
body += if param_value.all? { |array_value| array_value.is_a?(Hash) }
param_value.map { |array_value| "<#{param_key}>\n#{params_to_text(array_value)}</#{param_key}>\n" }.join
else
"#{param_key} [#{param_value.map { |array_value| array_value.to_s.dump }.join(', ')}]\n"
end
else
body += "#{param_key} #{param_value}\n"
end
Expand All @@ -24,13 +22,13 @@ def self.params_to_text(parameters)
body.each_line.map { |line| "#{indent}#{line}" }.join
end

def self.apply_params_kludge?()
def self.apply_params_kludge?
if ::Chef::Config[:treat_deprecation_warnings_as_errors]
# Skip setting up backward compatibility code for `params` (#112)
false
else
# Workaround for backward compatibility for Chef pre-13 (#99)
chef_major_version = ::Chef::VERSION.split(".").first.to_i
chef_major_version = ::Chef::VERSION.split('.').first.to_i
chef_major_version < 13
end
end
Expand Down
9 changes: 7 additions & 2 deletions libraries/matchers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,42 +2,47 @@
def install_td_agent_gem(resource_name)
ChefSpec::Matchers::ResourceMatcher.new(:td_agent_gem, :install, resource_name)
end

def upgrade_td_agent_gem(resource_name)
ChefSpec::Matchers::ResourceMatcher.new(:td_agent_gem, :upgrade, resource_name)
end

def remove_td_agent_gem(resource_name)
ChefSpec::Matchers::ResourceMatcher.new(:td_agent_gem, :remove, resource_name)
end

def purge_td_agent_gem(resource_name)
ChefSpec::Matchers::ResourceMatcher.new(:td_agent_gem, :purge, resource_name)
end


def create_td_agent_source(resource_name)
ChefSpec::Matchers::ResourceMatcher.new(:td_agent_source, :create, resource_name)
end

def delete_td_agent_source(resource_name)
ChefSpec::Matchers::ResourceMatcher.new(:td_agent_source, :delete, resource_name)
end


def create_td_agent_match(resource_name)
ChefSpec::Matchers::ResourceMatcher.new(:td_agent_match, :create, resource_name)
end

def delete_td_agent_match(resource_name)
ChefSpec::Matchers::ResourceMatcher.new(:td_agent_match, :delete, resource_name)
end

def create_td_agent_filter(resource_name)
ChefSpec::Matchers::ResourceMatcher.new(:td_agent_filter, :create, resource_name)
end

def delete_td_agent_filter(resource_name)
ChefSpec::Matchers::ResourceMatcher.new(:td_agent_filter, :delete, resource_name)
end

def create_td_agent_plugin(resource_name)
ChefSpec::Matchers::ResourceMatcher.new(:td_agent_plugin, :create, resource_name)
end

def delete_td_agent_plugin(resource_name)
ChefSpec::Matchers::ResourceMatcher.new(:td_agent_plugin, :delete, resource_name)
end
Expand Down
15 changes: 7 additions & 8 deletions libraries/provider_td_rubygems.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@
#
# Copyright 2013, Treasure Data, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# Licensed under the Apache License, Version 2.0 (the 'License');
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# distributed under the License is distributed on an 'AS IS' BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
Expand All @@ -23,32 +23,31 @@ class Chef
class Provider
class Package
class TdRubygems < Chef::Provider::Package::Rubygems

class TdGemEnvironment < AlternateGemEnvironment
end

def initialize(new_resource, run_context = nil)
super
gem_binary_path = new_resource.gem_binary.empty? ? td_gem_binary_path : new_resource.gem_binary
gem_binary_path = new_resource.gem_binary.empty? ? td_gem_binary_path : new_resource.gem_binary
@new_resource.gem_binary gem_binary_path
@new_resource.package_name td_plugin_name if @new_resource.plugin
@gem_env = TdGemEnvironment.new(gem_binary_path)
Chef::Log.debug("#{@new_resource} using gem '#{gem_binary_path}'")
end

def td_plugin_name
"fluent-plugin-#{@new_resource.package_name}"
"fluent-plugin-#{@new_resource.package_name}"
end

def td_gem_binary_path
if major && major != '1'
# td-agent 2.x or later works with /opt
'/usr/sbin/td-agent-gem'
elsif node['platform_family'] == "rhel" && node["kernel"]["machine"] == "x86_64"
"/usr/lib64/fluent/ruby/bin/fluent-gem"
elsif node['platform_family'] == 'rhel' && node['kernel']['machine'] == 'x86_64'
'/usr/lib64/fluent/ruby/bin/fluent-gem'
else
# older Ubuntu/Debian works with /usr/lib
"/usr/lib/fluent/ruby/bin/fluent-gem"
'/usr/lib/fluent/ruby/bin/fluent-gem'
end
end
end
Expand Down
10 changes: 5 additions & 5 deletions libraries/resource_td_agent_gem.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ def initialize(*args)
@provider = Chef::Provider::Package::TdRubygems

@plugin = false
@gem_binary = ""
@gem_binary = ''
end

def response_file(arg=nil)
set_or_return(:response_file, arg, :kind_of => String)
def response_file(arg = nil)
set_or_return(:response_file, arg, kind_of: String)
end

def plugin(arg=nil)
set_or_return(:plugin, arg, :kind_of => [ TrueClass, FalseClass ])
def plugin(arg = nil)
set_or_return(:plugin, arg, kind_of: [TrueClass, FalseClass])
end
end
end
Expand Down
14 changes: 7 additions & 7 deletions libraries/version.rb
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
require "rubygems"
require 'rubygems'

module TdAgent
module Version
def major
unless @major
version = node["td_agent"]["version"]
version = node['td_agent']['version']
@major = version.nil? ? nil : version.to_s.split('.').first
end
@major
end

def reload_available?
case node["platform_family"]
when "debian"
case node['platform_family']
when 'debian'
# td-agent's init script for debian starts supporting reload starting from 2.1.4
if node["td_agent"]["version"]
::Gem::Version.new("2.1.4") <= ::Gem::Version.new(node["td_agent"]["version"].to_s)
if node['td_agent']['version']
::Gem::Version.new('2.1.4') <= ::Gem::Version.new(node['td_agent']['version'].to_s)
else
false
end
when "rhel"
when 'rhel'
# td-agent's init script for redhat is supporting reload
true
else
Expand Down
22 changes: 11 additions & 11 deletions metadata.rb
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
name "td-agent"
maintainer "Treasure Data, Inc."
maintainer_email "k@treasure-data.com"
license "Apache 2.0"
description "Installs/Configures td-agent"
name 'td-agent'
maintainer 'Treasure Data, Inc.'
maintainer_email 'k@treasure-data.com'
license 'Apache 2.0'
description 'Installs/Configures td-agent'
long_description IO.read(File.join(File.dirname(__FILE__), 'README.md'))
version "3.1.0"
recipe "td-agent", "td-agent configuration"
version '3.1.0'
recipe 'td-agent', 'td-agent configuration'

chef_version ">= 12" if respond_to?(:chef_version)
issues_url "https://github.com/treasure-data/chef-td-agent/issues" if respond_to?(:issues_url)
source_url "https://github.com/treasure-data/chef-td-agent" if respond_to?(:source_url)
chef_version '>= 12' if respond_to?(:chef_version)
issues_url 'https://github.com/treasure-data/chef-td-agent/issues' if respond_to?(:issues_url)
source_url 'https://github.com/treasure-data/chef-td-agent' if respond_to?(:source_url)

%w{redhat centos debian ubuntu}.each do |os|
%w[redhat centos debian ubuntu].each do |os|
supports os
end

Expand Down
16 changes: 10 additions & 6 deletions providers/filter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,12 @@

include ::TdAgent::Version

provides :fluentd_filter

use_inline_resources

action :create do
fail 'You should set the node[:td_agent][:includes] attribute to true to use this resource.' unless node['td_agent']['includes']
raise 'You should set the node[:td_agent][:includes] attribute to true to use this resource.' unless node['td_agent']['includes']

template "/etc/td-agent/conf.d/#{new_resource.filter_name}.conf" do
source 'filter.conf.erb'
Expand All @@ -32,7 +36,7 @@

# Workaround for backward compatibility for Chef pre-13 (#99)
if TdAgent::Helpers.apply_params_kludge?
::Chef::Log.warn("chef-td-agent: property `params` has been renamed to `parameters` since `params` is reserved in Chef 13+. The `params` will not be supported anymore with future release of chef-td-agent")
::Chef::Log.warn('chef-td-agent: property `params` has been renamed to `parameters` since `params` is reserved in Chef 13+. The `params` will not be supported anymore with future release of chef-td-agent')
parameters = Hash(new_resource.params).merge(Hash(new_resource.parameters))
else
parameters = new_resource.parameters
Expand All @@ -42,10 +46,10 @@
parameters: TdAgent::Helpers.params_to_text(parameters),
tag: new_resource.tag)
cookbook 'td-agent'
notifies reload_action, 'service[td-agent]'
notifies reload_action, 'service[td-agent]', :delayed
end

new_resource.updated_by_last_action(true)
converge_by('created') {}
end

action :delete do
Expand All @@ -55,13 +59,13 @@
notifies reload_action, 'service[td-agent]'
end

new_resource.updated_by_last_action(true)
converge_by('deleted') {}
end

def reload_action
if reload_available?
:reload
else
else
:restart
end
end
14 changes: 9 additions & 5 deletions providers/match.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,12 @@

include ::TdAgent::Version

provides :fluentd_match

use_inline_resources

action :create do
fail 'You should set the node[:td_agent][:includes] attribute to true to use this resource.' unless node['td_agent']['includes']
raise 'You should set the node[:td_agent][:includes] attribute to true to use this resource.' unless node['td_agent']['includes']

template "/etc/td-agent/conf.d/#{new_resource.match_name}.conf" do
source 'match.conf.erb'
Expand All @@ -32,7 +36,7 @@

# Workaround for backward compatibility for Chef pre-13 (#99)
if TdAgent::Helpers.apply_params_kludge?
::Chef::Log.warn("chef-td-agent: property `params` has been renamed to `parameters` since `params` is reserved in Chef 13+. The `params` will not be supported anymore with future release of chef-td-agent")
::Chef::Log.warn('chef-td-agent: property `params` has been renamed to `parameters` since `params` is reserved in Chef 13+. The `params` will not be supported anymore with future release of chef-td-agent')
parameters = Hash(new_resource.params).merge(Hash(new_resource.parameters))
else
parameters = new_resource.parameters
Expand All @@ -42,10 +46,10 @@
parameters: TdAgent::Helpers.params_to_text(parameters),
tag: new_resource.tag)
cookbook 'td-agent'
notifies reload_action, 'service[td-agent]'
notifies reload_action, 'service[td-agent]', :delayed
end

new_resource.updated_by_last_action(true)
converge_by('created') {}
end

action :delete do
Expand All @@ -55,7 +59,7 @@
notifies reload_action, 'service[td-agent]'
end

new_resource.updated_by_last_action(true)
converge_by('deleted') {}
end

def reload_action
Expand Down
Loading