Skip to content

Commit 75abdb4

Browse files
committed
Vendor metrics library from Ironic-Lib & deprecate
We are phasing out use of ironic-lib, and as such are removing the metrics module from it. However, due to it's requirement of having a statsd instance on the same subnet as the agent and there being no support for prometheus exporting of metrics from IPA, these metrics are no longer valuable (in the agent). We are vendoring the module for the deprecation in order to facilitate its removal from ironic-lib. Change-Id: Ie50e078bc3f78d65cfa53680dc4116d1119ce155
1 parent d8d32d9 commit 75abdb4

13 files changed

Lines changed: 1189 additions & 14 deletions

File tree

doc/source/contributor/metrics.rst

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,26 +4,31 @@
44
Emitting metrics from Ironic-Python-Agent (IPA)
55
===============================================
66

7+
.. warning::
8+
IPA metrics are deprecated and scheduled for removal at or after the
9+
2026.1 OpenStack release cycle.
10+
711
This document describes how to emit metrics from IPA, including timers and
812
counters in code to directly emitting hardware metrics from a custom
913
HardwareManager.
1014

1115
Overview
1216
========
13-
IPA uses the metrics implementation from ironic-lib, with a few caveats due
14-
to the dynamic configuration done at lookup time. You cannot cache the metrics
15-
instance as the MetricsLogger returned will change after lookup if configs
16-
different than the default setting have been used. This also means that the
17-
method decorator supported by ironic-lib cannot be used in IPA.
17+
IPA uses a vendored version of the metrics implementation originally from
18+
ironic-lib, with a few caveats due to the dynamic configuration done at
19+
lookup time. You cannot cache the metrics instance as the MetricsLogger
20+
returned will change after lookup if configs different than the default
21+
setting have been used. This also means that the method decorator
22+
cannot be used in IPA.
1823

1924
Using a context manager
2025
=======================
2126
Using the context manager is the recommended way for sending metrics that time
2227
or count sections of code. However, given that you cannot cache the
2328
MetricsLogger, you have to explicitly call get_metrics_logger() from
24-
ironic-lib every time. For example::
29+
every time. For example::
2530

26-
from ironic_lib import metrics_utils
31+
from ironic_python_agent.metrics_lib import metrics_utils
2732

2833
def my_method():
2934
with metrics_utils.get_metrics_logger(__name__).timer('my_method'):
@@ -41,13 +46,9 @@ HardwareManagers is the ability to explicitly send metrics. For instance,
4146
you could add a cleaning step which would retrieve metrics about a device and
4247
ship them using the provided metrics library. For example::
4348

44-
from ironic_lib import metrics_utils
49+
from ironic_python_agent.metrics_lib import metrics_utils
4550

4651
def my_cleaning_step():
4752
for name, value in _get_smart_data():
4853
metrics_utils.get_metrics_logger(__name__).send_gauge(name, value)
4954

50-
References
51-
==========
52-
For more information, please read the source of the metrics module in
53-
`ironic-lib <https://opendev.org/openstack/ironic-lib/src/branch/master/ironic_lib>`_.

ironic_python_agent/api/app.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,14 @@
1414

1515
import json
1616

17-
from ironic_lib import metrics_utils
1817
from oslo_log import log
1918
from oslo_service import wsgi
2019
import werkzeug
2120
from werkzeug import exceptions as http_exc
2221
from werkzeug import routing
2322

2423
from ironic_python_agent import encoding
24+
from ironic_python_agent.metrics_lib import metrics_utils
2525

2626

2727
LOG = log.getLogger(__name__)

ironic_python_agent/config.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,12 @@
1515
from oslo_config import cfg
1616
from oslo_log import log as logging
1717

18+
from ironic_python_agent.metrics_lib.metrics_statsd import statsd_opts
19+
from ironic_python_agent.metrics_lib.metrics_utils import metrics_opts
1820
from ironic_python_agent import netutils
1921
from ironic_python_agent import utils
2022

23+
2124
LOG = logging.getLogger(__name__)
2225
CONF = cfg.CONF
2326

@@ -438,14 +441,18 @@
438441
def list_opts():
439442
return [('DEFAULT', cli_opts),
440443
('disk_utils', disk_utils_opts),
441-
('disk_partitioner', disk_part_opts)]
444+
('disk_partitioner', disk_part_opts),
445+
('metrics', metrics_opts),
446+
('metrics_statsd', statsd_opts)]
442447

443448

444449
def populate_config():
445450
"""Populate configuration. In a method so tests can easily utilize it."""
446451
CONF.register_cli_opts(cli_opts)
447452
CONF.register_opts(disk_utils_opts, group='disk_utils')
448453
CONF.register_opts(disk_part_opts, group='disk_partitioner')
454+
CONF.register_opts(metrics_opts, group='metrics')
455+
CONF.register_opts(statsd_opts, group='metrics_statsd')
449456

450457

451458
def override(params):

0 commit comments

Comments
 (0)