Skip to content

Commit

Permalink
TTL mechanism support with expirer service
Browse files Browse the repository at this point in the history
Aims to support a TTL mechanism for data entering Ceilometer
collector database.
TTL is very useful to configure when getting a lot of meters.

implement blueprint ttl-support
Change-Id: I9d98e8b833ad94fd79722dee7226e7f4f03aaa2e
Signed-off-by: Emilien Macchi <[email protected]>
  • Loading branch information
Emilien Macchi committed Dec 7, 2013
1 parent 0fb3b8f commit 0af2249
Show file tree
Hide file tree
Showing 4 changed files with 168 additions and 4 deletions.
5 changes: 4 additions & 1 deletion examples/site.pp
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@
class { 'ceilometer::alarm::evaluator':
}


# Purge 1 month old meters
class { 'ceilometer::expirer':
time_to_live => '2592000'
}

}
74 changes: 74 additions & 0 deletions manifests/expirer.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
#
# Copyright (C) 2013 eNovance SAS <[email protected]>
#
# Author: Emilien Macchi <[email protected]>
#
# 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, 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.
#
# == Class: ceilometer::expirer
#
# Setups Ceilometer Expirer service to enable TTL feature.
#
# === Parameters
#
# [*time_to_live*]
# (optional) Number of seconds that samples are kept in the database.
# Should be a valid integer
# Defaults to '-1' to disable TTL and keep forever the datas.
#
# [*minute*]
# (optional) Defaults to '1'.
#
# [*hour*]
# (optional) Defaults to '0'.
#
# [*monthday*]
# (optional) Defaults to '*'.
#
# [*month*]
# (optional) Defaults to '*'.
#
# [*weekday*]
# (optional) Defaults to '*'.
#

class ceilometer::expirer (
$time_to_live = '-1',
$minute = 1,
$hour = 0,
$monthday = '*',
$month = '*',
$weekday = '*',
) {

include ceilometer::params

Package<| title == 'ceilometer-common' |> -> Class['ceilometer::expirer']

ceilometer_config {
'database/time_to_live': value => $time_to_live;
}

cron { 'ceilometer-expirer':
command => $ceilometer::params::expirer_command,
environment => 'PATH=/bin:/usr/bin:/usr/sbin',
user => 'ceilometer',
minute => $minute,
hour => $hour,
monthday => $monthday,
month => $month,
weekday => $weekday
}


}
6 changes: 3 additions & 3 deletions manifests/params.pp
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
#
class ceilometer::params {

$dbsync_command =
'ceilometer-dbsync --config-file=/etc/ceilometer/ceilometer.conf'
$log_dir = '/var/log/ceilometer'
$dbsync_command = 'ceilometer-dbsync --config-file=/etc/ceilometer/ceilometer.conf'
$log_dir = '/var/log/ceilometer'
$expirer_command = 'ceilometer-expirer'

case $::osfamily {
'RedHat': {
Expand Down
87 changes: 87 additions & 0 deletions spec/classes/ceilometer_expirer_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
#
# Copyright (C) 2013 eNovance SAS <[email protected]>
#
# Author: Emilien Macchi <[email protected]>
#
# 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, 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.
#
# Unit tests for ceilometer::expirer
#

require 'spec_helper'

describe 'ceilometer::expirer' do

let :pre_condition do
"class { 'ceilometer': metering_secret => 's3cr3t' }"
end

let :params do
{ :time_to_live => '-1' }
end

shared_examples_for 'ceilometer-expirer' do

it { should include_class('ceilometer::params') }

it 'installs ceilometer common package' do
should contain_package('ceilometer-common').with(
:ensure => 'present',
:name => platform_params[:common_package_name]
)
end

it 'configures a cron' do
should contain_cron('ceilometer-expirer').with(
:command => 'ceilometer-expirer',
:environment => 'PATH=/bin:/usr/bin:/usr/sbin',
:user => 'ceilometer',
:minute => 1,
:hour => 0,
:monthday => '*',
:month => '*',
:weekday => '*'
)
end

it 'configures database section in ceilometer.conf' do
should contain_ceilometer_config('database/time_to_live').with_value( params[:time_to_live] )
end

end

context 'on Debian platforms' do
let :facts do
{ :osfamily => 'Debian' }
end

let :platform_params do
{ :common_package_name => 'ceilometer-common' }
end

it_configures 'ceilometer-expirer'
end

context 'on RedHat platforms' do
let :facts do
{ :osfamily => 'RedHat' }
end

let :platform_params do
{ :common_package_name => 'openstack-ceilometer-common' }
end

it_configures 'ceilometer-expirer'
end

end

0 comments on commit 0af2249

Please sign in to comment.