Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support for instances and http_host #299

Merged
merged 4 commits into from
Mar 10, 2017
Merged
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
15 changes: 14 additions & 1 deletion manifests/integrations/php_fpm.pp
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,25 @@
#

class datadog_agent::integrations::php_fpm(
$http_host = undef,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Small nit (since all parameters are essentially optional, it doesn't make much of a difference), we probably want to http_host to be placed after ping_url, just to resemble the YAML structure and the fact that it really can be undef whereas the other two are a must.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No worries, it's such a small change I don't want to bother you with it. I'll take care of it! Thanks!

$status_url = 'http://localhost/status',
$ping_url = 'http://localhost/ping',
$tags = []
$tags = [],
$instances = undef
) inherits datadog_agent::params {
include datadog_agent

if !$instances {
$_instances = [{
'http_host' => $http_host,
'status_url' => $status_url,
'ping_url' => $ping_url,
'tags' => $tags,
}]
} else {
$_instances = $instances
}

file { "${datadog_agent::params::conf_dir}/php_fpm.yaml":
ensure => file,
owner => $datadog_agent::params::dd_user,
Expand Down
30 changes: 30 additions & 0 deletions spec/classes/datadog_agent_integrations_php_fpm_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,34 @@
it { should contain_file(conf_file).with_content(/status_url: http:\/\/localhost\/fpm_status/) }
it { should contain_file(conf_file).with_content(/ping_url: http:\/\/localhost\/fpm_ping/) }
end

context 'with http_host set' do
let(:params) {{
status_url: 'http://localhost/fpm_status',
ping_url: 'http://localhost/fpm_ping',
http_host: 'php_fpm_server',
}}
it { should contain_file(conf_file).with_content(/http_host: php_fpm_server/) }
it { should contain_file(conf_file).with_content(/status_url: http:\/\/localhost\/fpm_status/) }
it { should contain_file(conf_file).with_content(/ping_url: http:\/\/localhost\/fpm_ping/) }
end

context 'with instances set' do
let(:params) {{
instances: [
{
'status_url' => 'http://localhost/a/fpm_status',
'ping_url' => 'http://localhost/a/fpm_ping',
},
{
'status_url' => 'http://localhost/b/fpm_status',
'ping_url' => 'http://localhost/b/fpm_ping',
},
]
}}
it { should contain_file(conf_file).with_content(/status_url: http:\/\/localhost\/a\/fpm_status/) }
it { should contain_file(conf_file).with_content(/ping_url: http:\/\/localhost\/a\/fpm_ping/) }
it { should contain_file(conf_file).with_content(/status_url: http:\/\/localhost\/b\/fpm_status/) }
it { should contain_file(conf_file).with_content(/ping_url: http:\/\/localhost\/b\/fpm_ping/) }
end
end
16 changes: 11 additions & 5 deletions templates/agent-conf.d/php_fpm.yaml.erb
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,17 @@
init_config:

instances:
<%- (Array(@_instances)).each do |instance| -%>
- # Get metrics from your FPM pool with this URL
status_url: <%= @status_url %>
status_url: <%= instance['status_url'] %>
# Get a reliable service check of your FPM pool with that one
ping_url: <%= @ping_url %>
ping_url: <%= instance['ping_url'] %>
# Set the expected reply to the ping.
ping_reply: pong
<%- if instance['http_host'] -%>
# Set http host header
http_host: <%= instance['http_host'] %>
<%- end -%>
# These 2 URLs should follow the options from your FPM pool
# See http://php.net/manual/en/install.fpm.configuration.php
# * pm.status_path
Expand All @@ -19,11 +24,12 @@ instances:
# you want to monitor (FPM `listen` directive in the config, usually
# a UNIX socket or TCP socket.
#
<% if @tags and !@tags.empty? -%>
<%- if instance['tags'] and !instance['tags'].empty? -%>
# Array of custom tags
# By default metrics and service check will be tagged by pool and host
tags:
<% @tags.each do |tag| -%>
<%- instance['tags'].each do |tag| -%>
- <%= tag %>
<% end -%>
<%- end -%>
<%- end -%>
<% end -%>