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:
parent
1e5f830fe7
commit
5893f401e3
@ -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)
|
||||
|
||||
|
||||
|
@ -358,22 +358,25 @@ class Connection(base.Connection):
|
||||
rows = sample_q.delete()
|
||||
LOG.info(_("%d samples removed from database"), rows)
|
||||
|
||||
# remove Meter definitions with no matching samples
|
||||
(session.query(models.Meter)
|
||||
.filter(~models.Meter.samples.any())
|
||||
.delete(synchronize_session=False))
|
||||
|
||||
# remove resources with no matching samples
|
||||
resource_q = (session.query(models.Resource.internal_id)
|
||||
.filter(~models.Resource.samples.any()))
|
||||
resource_subq = resource_q.subquery()
|
||||
# remove metadata of cleaned resources
|
||||
for table in [models.MetaText, models.MetaBigInt,
|
||||
models.MetaFloat, models.MetaBool]:
|
||||
(session.query(table)
|
||||
.filter(table.id.in_(resource_subq))
|
||||
if not cfg.CONF.sql_expire_samples_only:
|
||||
# remove Meter definitions with no matching samples
|
||||
(session.query(models.Meter)
|
||||
.filter(~models.Meter.samples.any())
|
||||
.delete(synchronize_session=False))
|
||||
resource_q.delete(synchronize_session=False)
|
||||
|
||||
# remove resources with no matching samples
|
||||
resource_q = (session.query(models.Resource.internal_id)
|
||||
.filter(~models.Resource.samples.any()))
|
||||
resource_subq = resource_q.subquery()
|
||||
# remove metadata of cleaned resources
|
||||
for table in [models.MetaText, models.MetaBigInt,
|
||||
models.MetaFloat, models.MetaBool]:
|
||||
(session.query(table)
|
||||
.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,
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user