From fd874652e3558cc2f9a3512f0c7b4e2f4170ec22 Mon Sep 17 00:00:00 2001 From: Josh Gachnang Date: Mon, 8 Sep 2014 20:26:51 -0700 Subject: Add metrics support to IPA This utilizes the new metrics support in ironic-lib to allow the agent to report timing metrics for agent API methods as configured in ironic-lib. Additionally, this adds developer docs on how to use metrics in IPA, including some caveats specific to ironic-lib.metrics use in IPA. Co-Authored-By: Jay Faulkner Co-Authored-By: Alex Weeks Change-Id: Ic08d4ff78b6fb614b474b956a32eac352a14262a Partial-bug: #1526219 --- ironic_python_agent/api/controllers/v1/command.py | 42 +++++++++++++---------- 1 file changed, 23 insertions(+), 19 deletions(-) (limited to 'ironic_python_agent/api/controllers/v1/command.py') diff --git a/ironic_python_agent/api/controllers/v1/command.py b/ironic_python_agent/api/controllers/v1/command.py index e4483e29..b6971fa7 100644 --- a/ironic_python_agent/api/controllers/v1/command.py +++ b/ironic_python_agent/api/controllers/v1/command.py @@ -13,6 +13,7 @@ # License for the specific language governing permissions and limitations # under the License. +from ironic_lib import metrics_utils import pecan from pecan import rest from wsme import types @@ -78,9 +79,10 @@ class CommandController(rest.RestController): @wsme_pecan.wsexpose(CommandResultList) def get_all(self): """Get all command results.""" - agent = pecan.request.agent - results = agent.list_command_results() - return CommandResultList.from_results(results) + with metrics_utils.get_metrics_logger(__name__).timer('get_all'): + agent = pecan.request.agent + results = agent.list_command_results() + return CommandResultList.from_results(results) @wsme_pecan.wsexpose(CommandResult, types.text, types.text) def get_one(self, result_id, wait=None): @@ -91,13 +93,14 @@ class CommandController(rest.RestController): :returns: a :class:`ironic_python_agent.api.controller.v1.command. CommandResult` object. """ - agent = pecan.request.agent - result = agent.get_command_result(result_id) + with metrics_utils.get_metrics_logger(__name__).timer('get_one'): + agent = pecan.request.agent + result = agent.get_command_result(result_id) - if wait and wait.lower() == 'true': - result.join() + if wait and wait.lower() == 'true': + result.join() - return CommandResult.from_result(result) + return CommandResult.from_result(result) @wsme_pecan.wsexpose(CommandResult, types.text, body=Command) def post(self, wait=None, command=None): @@ -109,14 +112,15 @@ class CommandController(rest.RestController): :returns: a :class:`ironic_python_agent.api.controller.v1.command. CommandResult` object. """ - # the POST body is always the last arg, - # so command must be a kwarg here - if command is None: - command = Command() - agent = pecan.request.agent - result = agent.execute_command(command.name, **command.params) - - if wait and wait.lower() == 'true': - result.join() - - return result + with metrics_utils.get_metrics_logger(__name__).timer('post'): + # the POST body is always the last arg, + # so command must be a kwarg here + if command is None: + command = Command() + agent = pecan.request.agent + result = agent.execute_command(command.name, **command.params) + + if wait and wait.lower() == 'true': + result.join() + + return result -- cgit v1.2.1