From 0af224916f085166d5ccd104e90cbc680039063d Mon Sep 17 00:00:00 2001 From: Emilien Macchi Date: Wed, 4 Dec 2013 01:04:42 +0100 Subject: [PATCH] TTL mechanism support with expirer service 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 --- examples/site.pp | 5 +- manifests/expirer.pp | 74 +++++++++++++++++++++ manifests/params.pp | 6 +- spec/classes/ceilometer_expirer_spec.rb | 87 +++++++++++++++++++++++++ 4 files changed, 168 insertions(+), 4 deletions(-) create mode 100644 manifests/expirer.pp create mode 100644 spec/classes/ceilometer_expirer_spec.rb diff --git a/examples/site.pp b/examples/site.pp index 9cea299b5..32cbe25b2 100644 --- a/examples/site.pp +++ b/examples/site.pp @@ -58,6 +58,9 @@ class { 'ceilometer::alarm::evaluator': } - + # Purge 1 month old meters + class { 'ceilometer::expirer': + time_to_live => '2592000' + } } diff --git a/manifests/expirer.pp b/manifests/expirer.pp new file mode 100644 index 000000000..597b09cb4 --- /dev/null +++ b/manifests/expirer.pp @@ -0,0 +1,74 @@ +# +# Copyright (C) 2013 eNovance SAS +# +# Author: Emilien Macchi +# +# 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 + } + + +} diff --git a/manifests/params.pp b/manifests/params.pp index d0d00ad5b..b0d2adcd2 100644 --- a/manifests/params.pp +++ b/manifests/params.pp @@ -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': { diff --git a/spec/classes/ceilometer_expirer_spec.rb b/spec/classes/ceilometer_expirer_spec.rb new file mode 100644 index 000000000..bf9371028 --- /dev/null +++ b/spec/classes/ceilometer_expirer_spec.rb @@ -0,0 +1,87 @@ +# +# Copyright (C) 2013 eNovance SAS +# +# Author: Emilien Macchi +# +# 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