From faac031a9b6893963375674f031e28a8c486c2a8 Mon Sep 17 00:00:00 2001
From: Julien Danjou <julien@danjou.info>
Date: Thu, 23 Nov 2017 10:41:03 +0100
Subject: [PATCH] Remove shuffle_time_before_polling_task option

The problem that shuffle_time_before_polling_task tries to solve is the startup
of a horde of Ceilometer instances that would start polling the same thing at
the same time.

It's actually unlikely they would all start at the same right second, and the
correct fix would be to do that each time.

Related-Bug: #1734898

Change-Id: If8141f6b48657c06e8e782eeef9b209dabb2097c
---
 ceilometer/polling/manager.py                 | 20 +------------------
 ceilometer/tests/unit/polling/test_manager.py |  5 -----
 ..._polling_task-option-05a4d225236c64b1.yaml |  5 +++++
 3 files changed, 6 insertions(+), 24 deletions(-)
 create mode 100644 releasenotes/notes/remove-shuffle_time_before_polling_task-option-05a4d225236c64b1.yaml

diff --git a/ceilometer/polling/manager.py b/ceilometer/polling/manager.py
index ad653e191e..ee47275276 100644
--- a/ceilometer/polling/manager.py
+++ b/ceilometer/polling/manager.py
@@ -17,8 +17,6 @@
 import collections
 import itertools
 import logging
-import random
-import time
 import uuid
 
 from concurrent import futures
@@ -49,12 +47,6 @@ OPTS = [
                 help='To reduce polling agent load, samples are sent to the '
                      'notification agent in a batch. To gain higher '
                      'throughput at the cost of load set this to False.'),
-    cfg.FloatOpt('shuffle_time_before_polling_task',
-                 min=0,
-                 default=10,
-                 help='To reduce large requests at same time to Nova or other '
-                 'components from different compute agents, shuffle '
-                 'start time of polling task.'),
 ]
 
 POLLING_OPTS = [
@@ -363,16 +355,7 @@ class AgentManager(cotyledon.Service):
     def construct_group_id(self, discovery_group_id):
         return '%s-%s' % (self.group_prefix, discovery_group_id)
 
-    @staticmethod
-    def _delayed(delay, target, *args, **kwargs):
-        time.sleep(delay)
-        return target(*args, **kwargs)
-
     def start_polling_tasks(self):
-        # set shuffle time before polling task if necessary
-        delay_polling_time = random.randint(
-            0, self.conf.shuffle_time_before_polling_task)
-
         data = self.setup_polling_tasks()
 
         # Don't start useless threads if no task will run
@@ -390,8 +373,7 @@ class AgentManager(cotyledon.Service):
             def task(running_task):
                 self.interval_task(running_task)
 
-            utils.spawn_thread(self._delayed, delay_polling_time,
-                               self.polling_periodics.add, task, polling_task)
+            self.polling_periodics.add(task, polling_task)
 
         utils.spawn_thread(self.polling_periodics.start, allow_empty=True)
 
diff --git a/ceilometer/tests/unit/polling/test_manager.py b/ceilometer/tests/unit/polling/test_manager.py
index 6bd6e7480a..fbdde6351d 100644
--- a/ceilometer/tests/unit/polling/test_manager.py
+++ b/ceilometer/tests/unit/polling/test_manager.py
@@ -33,10 +33,6 @@ from ceilometer import service
 from ceilometer.tests import base
 
 
-def fakedelayed(delay, target, *args, **kwargs):
-    return target(*args, **kwargs)
-
-
 def default_test_data(name='test'):
     return sample.Sample(
         name=name,
@@ -823,7 +819,6 @@ class TestPollingAgent(BaseAgent):
                 'publishers': ["test"]}]
         }
         self.setup_polling(poll_cfg)
-        self.mgr._delayed = fakedelayed
         polling_task = list(self.mgr.setup_polling_tasks().values())[0]
 
         self.mgr.interval_task(polling_task)
diff --git a/releasenotes/notes/remove-shuffle_time_before_polling_task-option-05a4d225236c64b1.yaml b/releasenotes/notes/remove-shuffle_time_before_polling_task-option-05a4d225236c64b1.yaml
new file mode 100644
index 0000000000..4874a993e4
--- /dev/null
+++ b/releasenotes/notes/remove-shuffle_time_before_polling_task-option-05a4d225236c64b1.yaml
@@ -0,0 +1,5 @@
+---
+deprecations:
+  - |
+    The `shuffle_time_before_polling_task` option has been removed. This option
+    never worked in the way it was originally intended too.