Remove send_cluster_metrics

This period job has been deprecated since Change
I3ca0f2e96fe63870406cc5323f08fa018ac6e8be in Rocky/Stein.

As it defaults to disabled, it causes logs like the following to be sent
over and over again.

 Running periodic task MagnumPeriodicTasks._send_cluster_metrics
 Skip sending cluster metrics _send_cluster_metrics

Remove the code totally as it has basically been a noop for a few
cycles.

Change-Id: Ib9142ab17d562b1d7ccf1409a9e0d934585a094d
This commit is contained in:
Jake Yip 2022-11-12 00:42:43 +11:00 committed by Jake Yip
parent d363622bf9
commit 6cdb367cfc
4 changed files with 5 additions and 204 deletions

View File

@ -30,13 +30,6 @@ drivers_opts = [
default="",
help='Path to the OpenStack CA-bundle file to pass and '
'install in all cluster nodes.'),
cfg.BoolOpt('send_cluster_metrics',
default=False,
deprecated_for_removal=True,
deprecated_reason='It does not make sense only collecting '
'metrics from the "default" namespcae.',
help='Allow periodic tasks to pull COE data and send to '
'ceilometer.'),
cfg.ListOpt('disabled_drivers',
default=[],
help='Disabled driver entry points. The default value is []. '

View File

@ -16,7 +16,6 @@
import functools
from oslo_log import log
from oslo_log.versionutils import deprecated
from oslo_service import loopingcall
from oslo_service import periodic_task
@ -227,56 +226,6 @@ class MagnumPeriodicTasks(periodic_task.PeriodicTasks):
"Ignore error [%s] when syncing up cluster status.",
e, exc_info=True)
@periodic_task.periodic_task(run_immediately=True)
@set_context
@deprecated(as_of=deprecated.ROCKY)
def _send_cluster_metrics(self, ctx):
if not CONF.drivers.send_cluster_metrics:
LOG.debug('Skip sending cluster metrics')
return
LOG.debug('Starting to send cluster metrics')
for cluster in objects.Cluster.list(ctx):
if cluster.status not in (
objects.fields.ClusterStatus.CREATE_COMPLETE,
objects.fields.ClusterStatus.UPDATE_COMPLETE):
continue
monitor = monitors.create_monitor(ctx, cluster)
if monitor is None:
continue
try:
monitor.pull_data()
except Exception as e:
LOG.warning(
"Skip pulling data from cluster %(cluster)s due to "
"error: %(e)s",
{'e': e, 'cluster': cluster.uuid}, exc_info=True)
continue
metrics = list()
for name in monitor.get_metric_names():
try:
metric = {
'name': name,
'value': monitor.compute_metric_value(name),
'unit': monitor.get_metric_unit(name),
}
metrics.append(metric)
except Exception as e:
LOG.warning("Skip adding metric %(name)s due to "
"error: %(e)s",
{'e': e, 'name': name}, exc_info=True)
message = dict(metrics=metrics,
user_id=cluster.user_id,
project_id=cluster.project_id,
resource_id=cluster.uuid)
LOG.debug("About to send notification: '%s'", message)
self.notifier.info(ctx, "magnum.cluster.metrics.update",
message)
def setup(conf, tg):
pt = MagnumPeriodicTasks(conf)

View File

@ -323,152 +323,6 @@ class PeriodicTestCase(base.TestCase):
notifications = fake_notifier.NOTIFICATIONS
self.assertEqual(5, len(notifications))
@mock.patch('magnum.conductor.monitors.create_monitor')
@mock.patch('magnum.objects.Cluster.list')
@mock.patch('magnum.common.rpc.get_notifier')
@mock.patch('magnum.common.context.make_admin_context')
def test_send_cluster_metrics(self, mock_make_admin_context,
mock_get_notifier, mock_cluster_list,
mock_create_monitor):
"""Test if RPC notifier receives the expected message"""
CONF.set_override('send_cluster_metrics', True, group='drivers')
mock_make_admin_context.return_value = self.context
notifier = mock.MagicMock()
mock_get_notifier.return_value = notifier
mock_cluster_list.return_value = [self.cluster1, self.cluster2,
self.cluster3, self.cluster4]
self.cluster4.status = cluster_status.CREATE_COMPLETE
monitor = mock.MagicMock()
monitor.get_metric_names.return_value = ['metric1', 'metric2']
monitor.compute_metric_value.return_value = 30
monitor.get_metric_unit.return_value = '%'
mock_create_monitor.return_value = monitor
periodic.MagnumPeriodicTasks(CONF)._send_cluster_metrics(self.context)
expected_event_type = 'magnum.cluster.metrics.update'
expected_metrics = [
{
'name': 'metric1',
'value': 30,
'unit': '%',
},
{
'name': 'metric2',
'value': 30,
'unit': '%',
},
]
expected_msg = {
'user_id': self.cluster4.user_id,
'project_id': self.cluster4.project_id,
'resource_id': self.cluster4.uuid,
'metrics': expected_metrics
}
self.assertEqual(1, mock_create_monitor.call_count)
notifier.info.assert_called_once_with(
self.context, expected_event_type, expected_msg)
@mock.patch('magnum.conductor.monitors.create_monitor')
@mock.patch('magnum.objects.Cluster.list')
@mock.patch('magnum.common.rpc.get_notifier')
@mock.patch('magnum.common.context.make_admin_context')
def test_send_cluster_metrics_compute_metric_raise(
self, mock_make_admin_context, mock_get_notifier,
mock_cluster_list, mock_create_monitor):
CONF.set_override('send_cluster_metrics', True, group='drivers')
mock_make_admin_context.return_value = self.context
notifier = mock.MagicMock()
mock_get_notifier.return_value = notifier
mock_cluster_list.return_value = [self.cluster4]
self.cluster4.status = cluster_status.CREATE_COMPLETE
monitor = mock.MagicMock()
monitor.get_metric_names.return_value = ['metric1', 'metric2']
monitor.compute_metric_value.side_effect = Exception(
"error on computing metric")
mock_create_monitor.return_value = monitor
periodic.MagnumPeriodicTasks(CONF)._send_cluster_metrics(self.context)
expected_event_type = 'magnum.cluster.metrics.update'
expected_msg = {
'user_id': self.cluster4.user_id,
'project_id': self.cluster4.project_id,
'resource_id': self.cluster4.uuid,
'metrics': []
}
self.assertEqual(1, mock_create_monitor.call_count)
notifier.info.assert_called_once_with(
self.context, expected_event_type, expected_msg)
@mock.patch('magnum.conductor.monitors.create_monitor')
@mock.patch('magnum.objects.Cluster.list')
@mock.patch('magnum.common.rpc.get_notifier')
@mock.patch('magnum.common.context.make_admin_context')
def test_send_cluster_metrics_pull_data_raise(
self, mock_make_admin_context, mock_get_notifier,
mock_cluster_list, mock_create_monitor):
CONF.set_override('send_cluster_metrics', True, group='drivers')
mock_make_admin_context.return_value = self.context
notifier = mock.MagicMock()
mock_get_notifier.return_value = notifier
mock_cluster_list.return_value = [self.cluster4]
self.cluster4.status = cluster_status.CREATE_COMPLETE
monitor = mock.MagicMock()
monitor.pull_data.side_effect = Exception("error on pulling data")
mock_create_monitor.return_value = monitor
periodic.MagnumPeriodicTasks(CONF)._send_cluster_metrics(self.context)
self.assertEqual(1, mock_create_monitor.call_count)
self.assertEqual(0, notifier.info.call_count)
@mock.patch('magnum.conductor.monitors.create_monitor')
@mock.patch('magnum.objects.Cluster.list')
@mock.patch('magnum.common.rpc.get_notifier')
@mock.patch('magnum.common.context.make_admin_context')
def test_send_cluster_metrics_monitor_none(
self, mock_make_admin_context, mock_get_notifier,
mock_cluster_list, mock_create_monitor):
CONF.set_override('send_cluster_metrics', True, group='drivers')
mock_make_admin_context.return_value = self.context
notifier = mock.MagicMock()
mock_get_notifier.return_value = notifier
mock_cluster_list.return_value = [self.cluster4]
self.cluster4.status = cluster_status.CREATE_COMPLETE
mock_create_monitor.return_value = None
periodic.MagnumPeriodicTasks(CONF)._send_cluster_metrics(self.context)
self.assertEqual(1, mock_create_monitor.call_count)
self.assertEqual(0, notifier.info.call_count)
@mock.patch('magnum.conductor.monitors.create_monitor')
@mock.patch('magnum.objects.Cluster.list')
@mock.patch('magnum.common.rpc.get_notifier')
@mock.patch('magnum.common.context.make_admin_context')
def test_send_cluster_metrics_disable_pull_data(
self, mock_make_admin_context, mock_get_notifier,
mock_cluster_list, mock_create_monitor):
mock_make_admin_context.return_value = self.context
notifier = mock.MagicMock()
mock_get_notifier.return_value = notifier
mock_cluster_list.return_value = [self.cluster1, self.cluster2,
self.cluster3, self.cluster4]
self.cluster4.status = cluster_status.CREATE_COMPLETE
monitor = mock.MagicMock()
monitor.get_metric_names.return_value = ['metric1', 'metric2']
monitor.compute_metric_value.return_value = 30
monitor.get_metric_unit.return_value = '%'
mock_create_monitor.return_value = monitor
periodic.MagnumPeriodicTasks(CONF)._send_cluster_metrics(self.context)
self.assertEqual(0, mock_create_monitor.call_count)
self.assertEqual(0, notifier.info.call_count)
@mock.patch('oslo_service.loopingcall.FixedIntervalLoopingCall',
new=fakes.FakeLoopingCall)
@mock.patch('magnum.conductor.monitors.create_monitor')

View File

@ -0,0 +1,5 @@
---
deprecations:
- |
Remove period job send_cluster_metrics. This job has been deprecated since
Rocky.