From f91d83a56eb3e3901d043ce06456da9d04853aa5 Mon Sep 17 00:00:00 2001
From: Annie Lezil <annie.lezil@gmail.com>
Date: Tue, 27 Sep 2016 18:17:58 +0000
Subject: [PATCH] Adding Timing metrics for DRAC drivers.

This change adds timing metrics for method in the bios, deploy, inspect, management,
power, raid, vendor_passthru modules

Change-Id: Ib301f203badecf4834dae5bba35175d13c4545cf
Closes-Bug: #1611555
---
 ironic/drivers/modules/drac/deploy.py                | 5 +++++
 ironic/drivers/modules/drac/inspect.py               | 5 +++++
 ironic/drivers/modules/drac/management.py            | 8 ++++++++
 ironic/drivers/modules/drac/power.py                 | 7 +++++++
 ironic/drivers/modules/drac/raid.py                  | 8 ++++++++
 ironic/drivers/modules/drac/vendor_passthru.py       | 9 +++++++++
 releasenotes/notes/bug-1611555-de1ec64ba46982ec.yaml | 4 ++++
 7 files changed, 46 insertions(+)
 create mode 100644 releasenotes/notes/bug-1611555-de1ec64ba46982ec.yaml

diff --git a/ironic/drivers/modules/drac/deploy.py b/ironic/drivers/modules/drac/deploy.py
index eed3f14573..722fa944e4 100644
--- a/ironic/drivers/modules/drac/deploy.py
+++ b/ironic/drivers/modules/drac/deploy.py
@@ -15,6 +15,8 @@
 DRAC deploy interface
 """
 
+from ironic_lib import metrics_utils
+
 from ironic.drivers.modules import deploy_utils
 from ironic.drivers.modules import iscsi_deploy
 
@@ -23,9 +25,12 @@ _OOB_CLEAN_STEPS = [
     {'interface': 'raid', 'step': 'delete_configuration'}
 ]
 
+METRICS = metrics_utils.get_metrics_logger(__name__)
+
 
 class DracDeploy(iscsi_deploy.ISCSIDeploy):
 
+    @METRICS.timer('DracDeploy.prepare_cleaning')
     def prepare_cleaning(self, task):
         """Prepare environment for cleaning
 
diff --git a/ironic/drivers/modules/drac/inspect.py b/ironic/drivers/modules/drac/inspect.py
index 679873a529..c4c42ab5e9 100644
--- a/ironic/drivers/modules/drac/inspect.py
+++ b/ironic/drivers/modules/drac/inspect.py
@@ -15,6 +15,7 @@
 DRAC inspection interface
 """
 
+from ironic_lib import metrics_utils
 from oslo_log import log as logging
 from oslo_utils import importutils
 from oslo_utils import units
@@ -33,6 +34,8 @@ drac_exceptions = importutils.try_import('dracclient.exceptions')
 
 LOG = logging.getLogger(__name__)
 
+METRICS = metrics_utils.get_metrics_logger(__name__)
+
 
 class DracInspect(base.InspectInterface):
 
@@ -43,6 +46,7 @@ class DracInspect(base.InspectInterface):
         """
         return drac_common.COMMON_PROPERTIES
 
+    @METRICS.timer('DracInspect.validate')
     def validate(self, task):
         """Validate the driver-specific info supplied.
 
@@ -57,6 +61,7 @@ class DracInspect(base.InspectInterface):
         """
         return drac_common.parse_driver_info(task.node)
 
+    @METRICS.timer('DracInspect.inspect_hardware')
     def inspect_hardware(self, task):
         """Inspect hardware.
 
diff --git a/ironic/drivers/modules/drac/management.py b/ironic/drivers/modules/drac/management.py
index f1159ae1b4..7439c2fda8 100644
--- a/ironic/drivers/modules/drac/management.py
+++ b/ironic/drivers/modules/drac/management.py
@@ -19,6 +19,7 @@
 DRAC management interface
 """
 
+from ironic_lib import metrics_utils
 from oslo_log import log as logging
 from oslo_utils import importutils
 
@@ -34,6 +35,8 @@ drac_exceptions = importutils.try_import('dracclient.exceptions')
 
 LOG = logging.getLogger(__name__)
 
+METRICS = metrics_utils.get_metrics_logger(__name__)
+
 _BOOT_DEVICES_MAP = {
     boot_devices.DISK: 'HardDisk',
     boot_devices.PXE: 'NIC',
@@ -123,6 +126,7 @@ class DracManagement(base.ManagementInterface):
         """Return the properties of the interface."""
         return drac_common.COMMON_PROPERTIES
 
+    @METRICS.timer('DracManagement.validate')
     def validate(self, task):
         """Validate the driver-specific info supplied.
 
@@ -137,6 +141,7 @@ class DracManagement(base.ManagementInterface):
         """
         return drac_common.parse_driver_info(task.node)
 
+    @METRICS.timer('DracManagement.get_supported_boot_devices')
     def get_supported_boot_devices(self, task):
         """Get a list of the supported boot devices.
 
@@ -147,6 +152,7 @@ class DracManagement(base.ManagementInterface):
         """
         return list(_BOOT_DEVICES_MAP.keys())
 
+    @METRICS.timer('DracManagement.get_boot_device')
     def get_boot_device(self, task):
         """Get the current boot device for a node.
 
@@ -169,6 +175,7 @@ class DracManagement(base.ManagementInterface):
 
         return _get_boot_device(node)
 
+    @METRICS.timer('DracManagement.set_boot_device')
     @task_manager.require_exclusive_lock
     def set_boot_device(self, task, device, persistent=False):
         """Set the boot device for a node.
@@ -205,6 +212,7 @@ class DracManagement(base.ManagementInterface):
         node.driver_internal_info = driver_internal_info
         node.save()
 
+    @METRICS.timer('DracManagement.get_sensors_data')
     def get_sensors_data(self, task):
         """Get sensors data.
 
diff --git a/ironic/drivers/modules/drac/power.py b/ironic/drivers/modules/drac/power.py
index 2596e827b2..6a4c6becb6 100644
--- a/ironic/drivers/modules/drac/power.py
+++ b/ironic/drivers/modules/drac/power.py
@@ -15,6 +15,7 @@
 DRAC power interface
 """
 
+from ironic_lib import metrics_utils
 from oslo_log import log as logging
 from oslo_utils import importutils
 
@@ -31,6 +32,8 @@ drac_exceptions = importutils.try_import('dracclient.exceptions')
 
 LOG = logging.getLogger(__name__)
 
+METRICS = metrics_utils.get_metrics_logger(__name__)
+
 if drac_constants:
     POWER_STATES = {
         drac_constants.POWER_ON: states.POWER_ON,
@@ -119,6 +122,7 @@ class DracPower(base.PowerInterface):
         """Return the properties of the interface."""
         return drac_common.COMMON_PROPERTIES
 
+    @METRICS.timer('DracPower.validate')
     def validate(self, task):
         """Validate the driver-specific Node power info.
 
@@ -132,6 +136,7 @@ class DracPower(base.PowerInterface):
         """
         return drac_common.parse_driver_info(task.node)
 
+    @METRICS.timer('DracPower.get_power_state')
     def get_power_state(self, task):
         """Return the power state of the node.
 
@@ -143,6 +148,7 @@ class DracPower(base.PowerInterface):
         """
         return _get_power_state(task.node)
 
+    @METRICS.timer('DracPower.set_power_state')
     @task_manager.require_exclusive_lock
     def set_power_state(self, task, power_state):
         """Set the power state of the node.
@@ -155,6 +161,7 @@ class DracPower(base.PowerInterface):
         """
         _set_power_state(task.node, power_state)
 
+    @METRICS.timer('DracPower.reboot')
     @task_manager.require_exclusive_lock
     def reboot(self, task):
         """Perform a reboot of the task's node.
diff --git a/ironic/drivers/modules/drac/raid.py b/ironic/drivers/modules/drac/raid.py
index 58bd9093a2..00c8be33fc 100644
--- a/ironic/drivers/modules/drac/raid.py
+++ b/ironic/drivers/modules/drac/raid.py
@@ -18,6 +18,7 @@ DRAC RAID specific methods
 import math
 
 from futurist import periodics
+from ironic_lib import metrics_utils
 from oslo_log import log as logging
 from oslo_utils import importutils
 from oslo_utils import units
@@ -37,6 +38,8 @@ drac_exceptions = importutils.try_import('dracclient.exceptions')
 
 LOG = logging.getLogger(__name__)
 
+METRICS = metrics_utils.get_metrics_logger(__name__)
+
 RAID_LEVELS = {
     '0': {
         'min_disks': 1,
@@ -663,6 +666,7 @@ class DracRAID(base.RAIDInterface):
         """Return the properties of the interface."""
         return drac_common.COMMON_PROPERTIES
 
+    @METRICS.timer('DracRAID.create_configuration')
     @base.clean_step(priority=0, abortable=False, argsinfo={
         'create_root_volume': {
             'description': (
@@ -740,6 +744,7 @@ class DracRAID(base.RAIDInterface):
 
         return _commit_to_controllers(node, list(controllers))
 
+    @METRICS.timer('DracRAID.delete_configuration')
     @base.clean_step(priority=0)
     def delete_configuration(self, task):
         """Delete the RAID configuration.
@@ -758,6 +763,7 @@ class DracRAID(base.RAIDInterface):
 
         return _commit_to_controllers(node, list(controllers))
 
+    @METRICS.timer('DracRAID.get_logical_disks')
     def get_logical_disks(self, task):
         """Get the RAID configuration of the node.
 
@@ -783,6 +789,7 @@ class DracRAID(base.RAIDInterface):
 
         return {'logical_disks': logical_disks}
 
+    @METRICS.timer('DracRAID._query_raid_config_job_status')
     @periodics.periodic(
         spacing=CONF.drac.query_raid_config_job_status_interval)
     def _query_raid_config_job_status(self, manager, context):
@@ -816,6 +823,7 @@ class DracRAID(base.RAIDInterface):
                              "%(node)s was already locked by another process. "
                              "Skip."), {'node': node_uuid})
 
+    @METRICS.timer('DracRAID._check_node_raid_jobs')
     def _check_node_raid_jobs(self, task):
         """Check the progress of running RAID config jobs of a node."""
 
diff --git a/ironic/drivers/modules/drac/vendor_passthru.py b/ironic/drivers/modules/drac/vendor_passthru.py
index bb4665f111..07b08135ed 100644
--- a/ironic/drivers/modules/drac/vendor_passthru.py
+++ b/ironic/drivers/modules/drac/vendor_passthru.py
@@ -15,6 +15,8 @@
 DRAC vendor-passthru interface
 """
 
+from ironic_lib import metrics_utils
+
 from ironic.common.i18n import _
 from ironic.conductor import task_manager
 from ironic.drivers import base
@@ -22,6 +24,8 @@ from ironic.drivers.modules.drac import bios as drac_bios
 from ironic.drivers.modules.drac import common as drac_common
 from ironic.drivers.modules.drac import job as drac_job
 
+METRICS = metrics_utils.get_metrics_logger(__name__)
+
 
 class DracVendorPassthru(base.VendorInterface):
     """Interface for DRAC specific methods."""
@@ -30,6 +34,7 @@ class DracVendorPassthru(base.VendorInterface):
         """Return the properties of the interface."""
         return drac_common.COMMON_PROPERTIES
 
+    @METRICS.timer('DracVendorPassthru.validate')
     def validate(self, task, **kwargs):
         """Validate the driver-specific info supplied.
 
@@ -44,6 +49,7 @@ class DracVendorPassthru(base.VendorInterface):
         """
         return drac_common.parse_driver_info(task.node)
 
+    @METRICS.timer('DracVendorPassthru.get_bios_config')
     @base.passthru(['GET'], async=False,
                    description=_("Returns a dictionary containing the BIOS "
                                  "settings from a node."))
@@ -65,6 +71,7 @@ class DracVendorPassthru(base.VendorInterface):
 
         return bios_attrs
 
+    @METRICS.timer('DracVendorPassthru.set_bios_config')
     @base.passthru(['POST'], async=False,
                    description=_("Change the BIOS configuration on a node. "
                                  "Required argument : a dictionary of "
@@ -88,6 +95,7 @@ class DracVendorPassthru(base.VendorInterface):
         """
         return drac_bios.set_config(task, **kwargs)
 
+    @METRICS.timer('DracVendorPassthru.commit_bios_config')
     @base.passthru(['POST'], async=False,
                    description=_("Commit a BIOS configuration job submitted "
                                  "through set_bios_config(). Required "
@@ -119,6 +127,7 @@ class DracVendorPassthru(base.VendorInterface):
         job_id = drac_bios.commit_config(task, reboot=reboot)
         return {'job_id': job_id, 'reboot_required': not reboot}
 
+    @METRICS.timer('DracVendorPassthru.abandon_bios_config')
     @base.passthru(['DELETE'], async=False,
                    description=_("Abandon a BIOS configuration job previously "
                                  "submitted through set_bios_config()."))
diff --git a/releasenotes/notes/bug-1611555-de1ec64ba46982ec.yaml b/releasenotes/notes/bug-1611555-de1ec64ba46982ec.yaml
new file mode 100644
index 0000000000..dabda95d9a
--- /dev/null
+++ b/releasenotes/notes/bug-1611555-de1ec64ba46982ec.yaml
@@ -0,0 +1,4 @@
+---
+features:
+  - Adds timing metrics to DRAC drivers.
+