Added option to allow sample expiration more frequently

Added a new CLI param - sql-expire-samples-only
to ceilometer-expirer. This will allow the
expirer to expire samples only, since samples
have more volume and velocity, thus allowing
sample expiration more frequently than other
metering data (meters, resources and metadata).

DocImpact

Closes-Bug: #1424871

Change-Id: I9b3081a3bcc1a24dd7ad7706e76a886af7185af4
This commit is contained in:
Rohit Jaiswal 2015-02-23 16:24:47 -08:00
parent 1e5f830fe7
commit 5893f401e3
3 changed files with 41 additions and 15 deletions

View File

@ -76,6 +76,17 @@ OPTS = [
cfg.CONF.register_opts(OPTS, group='database')
CLI_OPTS = [
cfg.BoolOpt('sql-expire-samples-only',
default=False,
help="Indicates if expirer expires only samples. If set true,"
" expired samples will be deleted, but residual"
" resource and meter definition data will remain.",
),
]
cfg.CONF.register_cli_opts(CLI_OPTS)
db_options.set_defaults(cfg.CONF)

View File

@ -358,6 +358,7 @@ class Connection(base.Connection):
rows = sample_q.delete()
LOG.info(_("%d samples removed from database"), rows)
if not cfg.CONF.sql_expire_samples_only:
# remove Meter definitions with no matching samples
(session.query(models.Meter)
.filter(~models.Meter.samples.any())
@ -374,6 +375,8 @@ class Connection(base.Connection):
.filter(table.id.in_(resource_subq))
.delete(synchronize_session=False))
resource_q.delete(synchronize_session=False)
LOG.info(_("Expired residual resource and"
" meter definition data"))
def get_resources(self, user=None, project=None, source=None,
start_timestamp=None, start_timestamp_op=None,

View File

@ -685,6 +685,18 @@ class RawSampleTest(DBTestBase,
results = list(self.conn.get_resources())
self.assertEqual(10, len(results))
@tests_db.run_with('sqlite', 'mysql', 'pgsql')
def test_clear_metering_data_expire_samples_only(self):
cfg.CONF.set_override('sql_expire_samples_only', True)
self.mock_utcnow.return_value = datetime.datetime(2012, 7, 2, 10, 45)
self.conn.clear_expired_metering_data(4 * 60)
f = storage.SampleFilter(meter='instance')
results = list(self.conn.get_samples(f))
self.assertEqual(7, len(results))
results = list(self.conn.get_resources())
self.assertEqual(6, len(results))
@tests_db.run_with('sqlite', 'mysql', 'pgsql', 'hbase', 'db2')
def test_clear_metering_data_with_alarms(self):
# NOTE(jd) Override this test in MongoDB because our code doesn't clear