alarm api: rename counter_name to meter_name

We already have a really poor naming convention the metering API, and we
decided to remove the counter term from everywhere. We can't fix the
metering API since we relesed it, so let's fix the alarming one before
it gets released and we have to handle a lot of complicated
compatibility. :-(

Change-Id: I3e3219d2eae0b72ad4a898630cacfd334e9390cc
This commit is contained in:
Julien Danjou 2013-08-29 16:18:54 +02:00
parent 54465d8e7e
commit 7851969319
12 changed files with 62 additions and 29 deletions

View File

@ -119,7 +119,7 @@ class Evaluator(object):
"""Retrieve statistics over the current window."""
LOG.debug(_('stats query %s') % query)
try:
return self._client.statistics.list(alarm.counter_name,
return self._client.statistics.list(alarm.meter_name,
q=query,
period=alarm.period)
except Exception:

View File

@ -834,8 +834,8 @@ class Alarm(_Base):
description = wtypes.text
"The description of the alarm"
counter_name = wtypes.text
"The name of counter"
meter_name = wtypes.text
"The name of meter"
project_id = wtypes.text
"The ID of the project or tenant that owns the alarm"
@ -893,7 +893,7 @@ class Alarm(_Base):
return cls(alarm_id=None,
name="SwiftObjectAlarm",
description="An alarm",
counter_name="storage.objects",
meter_name="storage.objects",
comparison_operator="gt",
threshold=200,
statistic="avg",

View File

@ -543,7 +543,7 @@ class Connection(base.Connection):
name=row.name,
description=row.description,
timestamp=row.timestamp,
counter_name=row.counter_name,
meter_name=row.meter_name,
user_id=row.user_id,
project_id=row.project_id,
comparison_operator=row.comparison_operator,

View File

@ -258,7 +258,7 @@ class Alarm(Model):
:param description: User friendly description of the alarm
:param enabled: Is the alarm enabled
:param state: Alarm state (alarm/nodata/ok)
:param counter_name: The counter that the alarm is based on
:param meter_name: The counter that the alarm is based on
:param comparison_operator: How to compare the samples and the threshold
:param threshold: the value to compare to the samples
:param statistic: the function from Statistic (min/max/avg/count)
@ -277,7 +277,7 @@ class Alarm(Model):
:param repeat_actions: Is the actions should be triggered on each
alarm evaluation.
"""
def __init__(self, alarm_id, name, counter_name,
def __init__(self, alarm_id, name, meter_name,
comparison_operator, threshold, statistic,
user_id, project_id,
evaluation_periods=1,
@ -296,7 +296,7 @@ class Alarm(Model):
if not description:
# make a nice user friendly description by default
description = 'Alarm when %s is %s a %s of %s over %s seconds' % (
counter_name, comparison_operator,
meter_name, comparison_operator,
statistic, threshold, period)
Model.__init__(
@ -306,7 +306,7 @@ class Alarm(Model):
name=name,
description=description,
timestamp=timestamp,
counter_name=counter_name,
meter_name=meter_name,
user_id=user_id,
project_id=project_id,
comparison_operator=comparison_operator,

View File

@ -0,0 +1,33 @@
# -*- encoding: utf-8 -*-
#
# Copyright © 2013 eNovance <licensing@enovance.com>
#
# Author: Julien Danjou <julien@danjou.info>
#
# 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.
from sqlalchemy import MetaData, Table
meta = MetaData()
def upgrade(migrate_engine):
meta.bind = migrate_engine
alarm = Table('alarm', meta, autoload=True)
alarm.c.counter_name.alter(name='meter_name')
def downgrade(migrate_engine):
meta.bind = migrate_engine
alarm = Table('alarm', meta, autoload=True)
alarm.c.meter_name.alter(name='counter_name')

View File

@ -175,14 +175,14 @@ class Alarm(Base):
__table_args__ = (
Index('ix_alarm_user_id', 'user_id'),
Index('ix_alarm_project_id', 'project_id'),
Index('ix_alarm_counter_name', 'counter_name'),
Index('ix_alarm_meter_name', 'meter_name'),
)
id = Column(String(255), primary_key=True)
enabled = Column(Boolean)
name = Column(Text)
description = Column(Text)
timestamp = Column(DateTime, default=timeutils.utcnow)
counter_name = Column(String(255))
meter_name = Column(String(255))
user_id = Column(String(255), ForeignKey('user.id'))
project_id = Column(String(255), ForeignKey('project.id'))

View File

@ -40,7 +40,7 @@ class TestRPCAlarmNotifier(base.TestCase):
self.alarms = [
AlarmClient(None, info={
'name': 'instance_running_hot',
'counter_name': 'cpu_util',
'meter_name': 'cpu_util',
'comparison_operator': 'gt',
'threshold': 80.0,
'evaluation_periods': 5,
@ -56,7 +56,7 @@ class TestRPCAlarmNotifier(base.TestCase):
}),
AlarmClient(None, info={
'name': 'group_running_idle',
'counter_name': 'cpu_util',
'meter_name': 'cpu_util',
'comparison_operator': 'le',
'threshold': 10.0,
'statistic': 'max',

View File

@ -63,7 +63,7 @@ class TestSingletonAlarmService(base.TestCase):
def test_evaluation_cycle(self):
alarms = [
models.Alarm(name='instance_running_hot',
counter_name='cpu_util',
meter_name='cpu_util',
comparison_operator='gt',
threshold=80.0,
evaluation_periods=5,

View File

@ -36,7 +36,7 @@ class TestEvaluate(base.TestCase):
self.notifier = mock.MagicMock()
self.alarms = [
models.Alarm(name='instance_running_hot',
counter_name='cpu_util',
meter_name='cpu_util',
comparison_operator='gt',
threshold=80.0,
evaluation_periods=5,
@ -48,7 +48,7 @@ class TestEvaluate(base.TestCase):
matching_metadata={'resource_id':
'my_instance'}),
models.Alarm(name='group_running_idle',
counter_name='cpu_util',
meter_name='cpu_util',
comparison_operator='le',
threshold=10.0,
statistic='max',

View File

@ -56,7 +56,7 @@ class TestAlarms(FunctionalTest,
'X-Project-Id': str(uuid.uuid4())}
for alarm in [Alarm(name='name1',
alarm_id='a',
counter_name='meter.test',
meter_name='meter.test',
comparison_operator='gt', threshold=2.0,
statistic='avg',
repeat_actions=True,
@ -64,14 +64,14 @@ class TestAlarms(FunctionalTest,
project_id=self.auth_headers['X-Project-Id']),
Alarm(name='name2',
alarm_id='b',
counter_name='meter.mine',
meter_name='meter.mine',
comparison_operator='gt', threshold=2.0,
statistic='avg',
user_id=self.auth_headers['X-User-Id'],
project_id=self.auth_headers['X-Project-Id']),
Alarm(name='name3',
alarm_id='c',
counter_name='meter.test',
meter_name='meter.test',
comparison_operator='gt', threshold=2.0,
statistic='avg',
user_id=self.auth_headers['X-User-Id'],
@ -83,7 +83,7 @@ class TestAlarms(FunctionalTest,
self.assertEqual(3, len(data))
self.assertEqual(set(r['name'] for r in data),
set(['name1', 'name2', 'name3']))
self.assertEqual(set(r['counter_name'] for r in data),
self.assertEqual(set(r['meter_name'] for r in data),
set(['meter.test', 'meter.mine']))
def test_get_alarm(self):
@ -94,18 +94,18 @@ class TestAlarms(FunctionalTest,
for a in alarms:
print('%s: %s' % (a['name'], a['alarm_id']))
self.assertEqual(alarms[0]['name'], 'name1')
self.assertEqual(alarms[0]['counter_name'], 'meter.test')
self.assertEqual(alarms[0]['meter_name'], 'meter.test')
one = self.get_json('/alarms/%s' % alarms[0]['alarm_id'])
self.assertEqual(one['name'], 'name1')
self.assertEqual(one['counter_name'], 'meter.test')
self.assertEqual(one['meter_name'], 'meter.test')
self.assertEqual(one['alarm_id'], alarms[0]['alarm_id'])
self.assertEqual(one['repeat_actions'], alarms[0]['repeat_actions'])
def test_post_invalid_alarm(self):
json = {
'name': 'added_alarm',
'counter_name': 'ameter',
'meter_name': 'ameter',
'comparison_operator': 'gt',
'threshold': 2.0,
'statistic': 'magic',
@ -118,7 +118,7 @@ class TestAlarms(FunctionalTest,
def test_post_alarm(self):
json = {
'name': 'added_alarm',
'counter_name': 'ameter',
'meter_name': 'ameter',
'comparison_operator': 'gt',
'threshold': 2.0,
'statistic': 'avg',
@ -218,7 +218,7 @@ class TestAlarms(FunctionalTest,
def test_get_recorded_alarm_history_on_create(self):
new_alarm = dict(name='new_alarm',
counter_name='other_meter',
meter_name='other_meter',
comparison_operator='le',
threshold=42.0,
statistic='max')

View File

@ -224,7 +224,7 @@ class AlarmTestPagination(test_storage_scenarios.AlarmTestBase,
marker_pairs = {'name': 'red-alert'}
ret = impl_mongodb.Connection._get_marker(self.conn.db.alarm,
marker_pairs=marker_pairs)
self.assertEqual(ret['counter_name'], 'test.one')
self.assertEqual(ret['meter_name'], 'test.one')
def test_alarm_get_marker_None(self):
self.add_some_alarms()
@ -232,7 +232,7 @@ class AlarmTestPagination(test_storage_scenarios.AlarmTestBase,
marker_pairs = {'name': 'user-id-foo'}
ret = impl_mongodb.Connection._get_marker(self.conn.db.alarm,
marker_pairs)
self.assertEqual(ret['counter_name'], 'counter_name-foo')
self.assertEqual(ret['meter_name'], 'meter_name-foo')
except NoResultFound:
self.assertTrue(True)
@ -242,6 +242,6 @@ class AlarmTestPagination(test_storage_scenarios.AlarmTestBase,
marker_pairs = {'user_id': 'me'}
ret = impl_mongodb.Connection._get_marker(self.conn.db.alarm,
marker_pairs)
self.assertEqual(ret['counter_name'], 'counter-name-foo')
self.assertEqual(ret['meter_name'], 'counter-name-foo')
except MultipleResultsFound:
self.assertTrue(True)

View File

@ -1594,7 +1594,7 @@ class AlarmTest(AlarmTestBase,
def test_update_llu(self):
llu = models.Alarm('llu', 'llu',
'counter_name', 'lt', 34, 'max',
'meter_name', 'lt', 34, 'max',
'bla', 'ffo')
updated = self.conn.update_alarm(llu)
updated.state = models.Alarm.ALARM_OK