Merge "Use removeprefix instead of replace in ironic.py"

This commit is contained in:
Zuul
2025-12-09 18:53:46 +00:00
committed by Gerrit Code Review

View File

@@ -47,12 +47,8 @@ def category_registry(message, metrics_registry):
if key.startswith('ironic.drivers.modules'): if key.startswith('ironic.drivers.modules'):
# Deconstruct driver entries/counters to be more sane and attach # Deconstruct driver entries/counters to be more sane and attach
# labeling to them. # labeling to them.
formatted_key = 'ironic.' + key.removeprefix(
# TODO(TheJulia): Once the minimum python version is 3.9, change 'ironic.drivers.modules.')
# to str.removeprefix.
formatted_key = key.replace(
'ironic.drivers.modules.',
'ironic.')
for driver_label in ['ipmi', 'redfish', 'agent', 'pxe', for driver_label in ['ipmi', 'redfish', 'agent', 'pxe',
'ilo', 'drac', 'irmc', 'inspector', 'ansible', 'ilo', 'drac', 'irmc', 'inspector', 'ansible',
@@ -95,11 +91,10 @@ def category_registry(message, metrics_registry):
# Catches entries from: # Catches entries from:
# - ironic.conductor.manager # - ironic.conductor.manager
# - ironic.conductor.deployments # - ironic.conductor.deployments
# TODO(TheJulia): Once the minimum python version is 3.9, change
# to str.removeprefix.
labels['component'] = 'conductor' labels['component'] = 'conductor'
formatted_key = key.replace('ironic.conductor.manager.', 'ironic_') formatted_key = 'ironic_' + key.removeprefix(
'ironic.conductor.manager.')
for filename in ['manager', 'deployments', 'allocations']: for filename in ['manager', 'deployments', 'allocations']:
if filename in key: if filename in key:
formatted_key = key.replace(f'conductor.{filename}', '') formatted_key = key.replace(f'conductor.{filename}', '')