From 0c367b4fedecbc0242d6bd3c217bc33e92ab5a1d Mon Sep 17 00:00:00 2001 From: Omer Date: Tue, 8 Aug 2023 18:46:44 +0200 Subject: [PATCH] Provide Amphora stats for Octavia no-op drivers So far, when Octavia was running with noop drivers, there were no amphora statistics data provided and 404 was returned as the AmphoraStatistics object was not created, and therefore not found. This patch adds fake statistics to amphora noop driver. Closes-Bug: #2030774 Change-Id: Ib65e459bcd10a5ab877c0cf6f234d634d25d1e55 --- .../amphorae/drivers/noop_driver/driver.py | 19 +++++++++++++++++++ .../drivers/noop_driver/test_driver.py | 3 ++- ...d-noop-amphora-stats-2cc64717f85eb9a8.yaml | 5 +++++ 3 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 releasenotes/notes/add-noop-amphora-stats-2cc64717f85eb9a8.yaml diff --git a/octavia/amphorae/drivers/noop_driver/driver.py b/octavia/amphorae/drivers/noop_driver/driver.py index f007fa8d17..df3648d38a 100644 --- a/octavia/amphorae/drivers/noop_driver/driver.py +++ b/octavia/amphorae/drivers/noop_driver/driver.py @@ -11,10 +11,14 @@ # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. +import random from oslo_log import log as logging from octavia.amphorae.drivers import driver_base +from octavia.common import data_models +from octavia.db import api as db_apis +from octavia.db import repositories LOG = logging.getLogger(__name__) @@ -34,6 +38,21 @@ class NoopManager(object): self.amphoraconfig[(listener.id, amphora_id)] = ( listener, amphora_id, timeout_dict, "update_amp") + # Add some dummy stats to the DB when using noop driver + listener_stats_repo = repositories.ListenerStatisticsRepository() + stats_obj = data_models.ListenerStatistics( + listener_id=listener.id, + amphora_id=amphora.id, + bytes_in=random.randrange(1000000000), + bytes_out=random.randrange(1000000000), + active_connections=random.randrange(1000000000), + total_connections=random.randrange(1000000000), + request_errors=random.randrange(1000000000), + received_time=float(random.randrange(1000000000)), + ) + listener_stats_repo.replace(session=db_apis.get_session(), + stats_obj=stats_obj) + def update(self, loadbalancer): LOG.debug("Amphora %s no-op, update listener %s, vip %s", self.__class__.__name__, diff --git a/octavia/tests/unit/amphorae/drivers/noop_driver/test_driver.py b/octavia/tests/unit/amphorae/drivers/noop_driver/test_driver.py index da0058414f..548224bf9b 100644 --- a/octavia/tests/unit/amphorae/drivers/noop_driver/test_driver.py +++ b/octavia/tests/unit/amphorae/drivers/noop_driver/test_driver.py @@ -57,7 +57,8 @@ class TestNoopAmphoraLoadBalancerDriver(base.TestCase): constants.CONN_MAX_RETRIES: 3, constants.CONN_RETRY_INTERVAL: 4} - def test_update_amphora_listeners(self): + @mock.patch('octavia.db.api.get_session') + def test_update_amphora_listeners(self, mock_session): self.driver.update_amphora_listeners(self.load_balancer, self.amphora, self.timeout_dict) self.assertEqual((self.listener, self.amphora.id, self.timeout_dict, diff --git a/releasenotes/notes/add-noop-amphora-stats-2cc64717f85eb9a8.yaml b/releasenotes/notes/add-noop-amphora-stats-2cc64717f85eb9a8.yaml new file mode 100644 index 0000000000..88aca6aeb1 --- /dev/null +++ b/releasenotes/notes/add-noop-amphora-stats-2cc64717f85eb9a8.yaml @@ -0,0 +1,5 @@ +--- +other: + - | + Add fake Amphora stats for when Octavia runs in noop mode / using + noop drivers.