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

Release/3.0.0 #11

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
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
22 changes: 13 additions & 9 deletions .kitchen.docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,36 +3,40 @@ driver:
name: docker

platforms:
- name: debian-6
- name: debian-7
driver_config:
image: chef/debian-6
image: chef/debian-7
platform: debian
require_chef_omnibus: false
- name: debian-7
- name: debian-8
driver_config:
image: chef/debian-7
image: chef/debian-8
platform: debian
require_chef_omnibus: false
- name: ubuntu-12.04
- name: ubuntu-16.04
driver_config:
image: chef/ubuntu-12.04
image: chef/ubuntu-16.04
platform: ubuntu
require_chef_omnibus: false
- name: ubuntu-14.04
- name: ubuntu-18.04
driver_config:
image: chef/ubuntu-14.04
image: chef/ubuntu-18.04
platform: ubuntu
require_chef_omnibus: false
- name: centos-6.4
driver_config:
image: chef/centos-6
platform: centos
require_chef_omnibus: false
- name: centos-7.6
driver_config:
image: chef/centos-7
platform: centos
require_chef_omnibus: false

suites:
- name: docker
run_list:
- recipe[apt]
- recipe[blackfire::mock]
- recipe[blackfire]
attributes:
Expand Down
9 changes: 3 additions & 6 deletions .kitchen.vagrant.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,14 @@ driver:
name: vagrant

platforms:
- name: debian-7.6
driver_config:
box: chef/debian-7.6
- name: ubuntu-14.04
- name: centos-6.4
- name: debian-8.11
- name: ubuntu-18.04
- name: centos-7.6
- name: fedora-20

suites:
- name: default
run_list:
- recipe[apt]
- recipe[blackfire::mock]
- recipe[blackfire]
attributes:
Expand Down
70 changes: 43 additions & 27 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,10 @@ Requirements
------------

#### Platform
* Ubuntu (10.04/11.04/12.04/13.04/14.04)
* Debian (6.0/7.0)
* Ubuntu (12.04/13.04/14.04/16.06/18.04)
* Debian (7/8/9)
* RedHat Based (CentOS 6.4 and Fedora 20 tested, others should work)

#### cookbooks
- apt
- yum

Attributes
----------

Expand All @@ -29,15 +25,6 @@ The following attributes are available to affect the installation/configuration
* `node['blackfire']['agent']['log_file']` - Sets where the agent write logs. Default "stderr"
* `node['blackfire']['agent']['socket']` - Sets where the socket the agent will listen to. Default "unix:///var/run/blackfire/agent.sock"

#### blackfire::php
* `node['blackfire']['php']['version']` - Sets which version of the PHP extension will be installed. Default last version.
* `node['blackfire']['php']['agent_timeout']` - Sets the PHP extension timeout when communicating with the agent. Default '0.25'
* `node['blackfire']['php']['log_level']` - Sets the logging level for the PHP extension.
* `node['blackfire']['php']['log_file']` - Sets where the PHP extension write logs.
* `node['blackfire']['php']['ini_path']` - Sets where the PHP configuration will be written.
* `node['blackfire']['php']['server_id']` - Sets the Server ID to use for probe fine-grained configuration (See https://blackfire.io/doc/configuration#probe-configuration)
* `node['blackfire']['php']['server_token']` - Sets the Server Token to use for probe fine-grained configuration (See https://blackfire.io/doc/configuration#probe-configuration)

Usage
-----
#### blackfire::default
Expand Down Expand Up @@ -73,26 +60,55 @@ This cookbook makes no assumption about the webserver you use.
Therefore this is *your* responsability to write a wrapper and notify your
webserver (ie. Apache or php5-fpm) for reload/restart or subscribe the good
resources.
To do that, you can use `blackfire_php` resource to manage blackfire.ini and
notify PHP service according to PHP version. It's very usefull if you have
many PHP version on the same server.

You can obtain futher informations on wrapper cookbooks here:
https://www.getchef.com/blog/2013/12/03/doing-wrapper-cookbooks-right/
https://blog.chef.io/2017/02/14/writing-wrapper-cookbooks/

Resources
---------

### 'blackfire_php'

Manage blackfire.ini for a specific version of PHP

One way to do that (maybe the best to avoid disturbing logs messages):
#### Actions

- `create` - (default) Create blackfire.ini file

#### Properties

Name | Types | Description | Default
-------------- | ------ | ---------------------------------------------------------------------------------------------------------------------------------- | ----------------
`version` | String | Define version of PHP | <resource_name>
`cookbook` | String | Cookbook name of blackfire.ini template | 'blackfire'
`ini_path` | String | Path of blackfire.ini. Autodetected if not specified | ''
`agent_timeout | String | Sets the PHP extension timeout when communicating with the agent | '0.25'
`log_file` | String | Sets where the PHP extension write logs |
`log_level` | String | Sets the logging level for the PHP extension |
`socket` | String | Sets where the socket the agent will listen to | 'unix:///var/run/blackfire/agent.sock'
`server_id` | String | Sets the Server ID to use for probe fine-grained configuration (See https://blackfire.io/doc/configuration#probe-configuration) |
`server_token` | String | Sets the Server Token to use for probe fine-grained configuration (See https://blackfire.io/doc/configuration#probe-configuration) |

#### Examples

In a wrapper cookbook:
```ruby
include_recipe "blackfire"

begin
r = resources(:ruby_block => "blackfire-php-restart-webserver")
r.block do
end
r.notifies :reload, "service[php5-fpm]"
rescue Chef::Exceptions::ResourceNotFound
Chef::Log.warn 'could not find resource "ruby_block[blackfire-php-restart-webserver]" to override!'
include_recipe 'blackfire'

blackfire_php '7.1' do
agent_timeout '0.75'
log_file '/var/log/php/7.1/blackfire.log'
server_id 'foo'
server_token 'bar'
notifies :reload, 'service[php7.0-fpm]'
end

```

NOTE: Notify HTTP/PHP service means that you've installed these services before.

Contributing
------------

Expand Down
2 changes: 2 additions & 0 deletions attributes/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,5 @@
default['blackfire']['agent']['log_file'] = 'stderr'
default['blackfire']['agent']['socket'] = 'unix:///var/run/blackfire/agent.sock'
default['blackfire']['agent']['restart_mode'] = :delayed

default['blackfire']['php']['version'] = nil
23 changes: 0 additions & 23 deletions attributes/php.rb

This file was deleted.

4 changes: 2 additions & 2 deletions libraries/blackfire_versions_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ def self.fetch_versions(node = nil)
def self.fetch_releases(node = nil)
uri = URI.parse("#{get_endpoint(node)}/api/v1/releases")
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = 'https' == uri.scheme
http.use_ssl = uri.scheme == 'https'
response = http.get(uri.request_uri)

raise 'Impossible to fetch Blackfire versions' unless '200' == response.code
raise 'Unable to fetch Blackfire versions' unless response.code == '200'

response.body
end
Expand Down
7 changes: 4 additions & 3 deletions metadata.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
license 'MIT'
description 'Installs and configures Blackfire.io stack'
long_description IO.read(File.join(File.dirname(__FILE__), 'README.md'))
version '2.1.0'
version '3.0.0'
chef_version '>= 12.14' if respond_to?(:chef_version)

recipe 'default', 'Installs blackfire-php & blackfire-agent.'
recipe 'php', 'Installs only blackfire-php'
Expand All @@ -18,5 +19,5 @@
supports 'centos'
supports 'amazon'

depends 'apt'
depends 'yum'
issues_url 'https://github.com/blackfireio/blackfire-cookbook/issues'
source_url 'https://github.com/blackfireio/blackfire-cookbook'
14 changes: 0 additions & 14 deletions recipes/php.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,23 +19,9 @@
end

probe_version = node[cookbook_name]['php']['version'] ? node[cookbook_name]['php']['version'] : Blackfire::Versions.probe(node)

probe_version << '-1' if platform_family?('rhel', 'fedora', 'amazon')

package 'blackfire-php' do
version probe_version
notifies :run, 'ruby_block[blackfire-php-restart-webserver]'
end

template node[cookbook_name]['php']['ini_path'] do
source 'blackfire.ini.erb'
variables(
'agent_timeout' => node[cookbook_name]['php']['agent_timeout'],
'log_file' => node[cookbook_name]['php']['log_file'],
'log_level' => node[cookbook_name]['php']['log_level'],
'socket' => node[cookbook_name]['agent']['socket'],
'server_id' => node[cookbook_name]['php']['server_id'],
'server_token' => node[cookbook_name]['php']['server_token']
)
notifies :run, 'ruby_block[blackfire-php-restart-webserver]', :immediately
end
55 changes: 55 additions & 0 deletions resources/php.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# frozen_string_literal: true
#
# Cookbook:: blackfire
# Resource:: php
#
# Copyright 2014-2018, SensioLabs
# See LICENSE file
#

property :version, String, name_property: true
property :cookbook, String, default: 'blackfire'
property :ini_path, String, default: ''
property :agent_timeout, String, default: '0.25'
property :log_file, String
property :log_level, String
property :socket, String, default: 'unix:///var/run/blackfire/agent.sock'
property :server_id, String
property :server_token, String

action :create do
local_ini_path = new_resource.ini_path

if new_resource.ini_path.empty?
version = new_resource.version
v = version.to_i < 7 ? version.chr : version
mods_path = version.to_i < 7 ? "/etc/php#{v}/mods-available" : "/etc/php/#{v}/mods-available"

local_ini_path = if platform_family?('rhel', 'fedora', 'amazon')
'/etc/php.d/zz-blackfire.ini'
elsif platform?('debian') && node['platform_version'].to_f < 7.0
'/etc/php5/conf.d/blackfire.ini'
elsif platform?('ubuntu') && node['platform_version'].to_f <= 13.04
'/etc/php5/conf.d/blackfire.ini'
else
"#{mods_path}/blackfire.ini"
end
end

template local_ini_path do
cookbook new_resource.cookbook
source 'blackfire.ini.erb'
variables(
agent_timeout: new_resource.agent_timeout,
log_file: new_resource.log_file,
log_level: new_resource.log_level,
socket: new_resource.socket,
server_id: new_resource.server_id,
server_token: new_resource.server_token
)
end

execute 'phpenmod -v ALL blackfire' do
only_if 'which phpenmod'
end
end
7 changes: 5 additions & 2 deletions spec/default_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@

describe 'blackfire::default' do
let(:chef_run) do
ChefSpec::SoloRunner.converge('blackfire::default')
ChefSpec::SoloRunner.new do |node|
node.normal['blackfire']['agent']['server_id'] = 'foo'
node.normal['blackfire']['agent']['server_token'] = 'bar'
end.converge('blackfire::default')
end

it 'Install blackfire repository' do
Expand All @@ -32,7 +35,7 @@
describe 'blackfire::default without repository installation' do
let(:chef_run) do
ChefSpec::SoloRunner.new do |node|
node.set['blackfire']['install_repository'] = false
node.normal['blackfire']['install_repository'] = false
end.converge('blackfire::default')
end

Expand Down