Skip to content

Commit

Permalink
Fix missing nova metrics from openstack-exporter (#30)
Browse files Browse the repository at this point in the history
Previously this error was seen in the logs:

  ts=2024-04-03T23:09:00.715Z caller=exporter.go:126 level=error err="Failed to collect metric for exporter" exporter=nova error="failed to collect metric: running_vms, error: CPUInfo has unexpected type: <nil>"

Causing `openstack_nova_running_vms` and a selection of other hypervisor related metrics to be missing from the output.

This applies the workaround noted in openstack-exporter/openstack-exporter#268
  • Loading branch information
samuelallan72 committed Apr 5, 2024
1 parent 0211f46 commit 31fb589
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions src/service.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""Utility module to help manage the snap service with guarding functions."""

import os
from logging import getLogger
from typing import Any, Optional

Expand Down Expand Up @@ -48,8 +49,11 @@ def configure(self, snap_config: dict[str, Any]) -> None:
self.snap_client.set(snap_config, typed=True)


def snap_install(resource: str) -> Optional[SnapService]:
"""Install or refresh the snap, and return the snap service."""
def snap_install(resource: str) -> SnapService:
"""Install or refresh the snap, and return the snap service.
Raises an exception on error.
"""
try:
logger.debug("installing snap.")
logger.debug("fetching from resource.")
Expand All @@ -59,6 +63,7 @@ def snap_install(resource: str) -> Optional[SnapService]:
raise e # need to crash on_install event if it's not okay
else:
logger.info("installed %s snap.", snap_client.name)
workaround_bug_268()
return SnapService(snap_client)


Expand All @@ -75,3 +80,15 @@ def get_installed_snap_service(snap_name: str) -> Optional[SnapService]:
return None

return SnapService(snap_client)


def workaround_bug_268() -> None:
"""Workaround for a bug that blocks some nova metrics.
https://github.com/openstack-exporter/openstack-exporter/issues/268
"""
logger.info("Adding service override to workaround bug 268")
dir = "/etc/systemd/system/snap.golang-openstack-exporter.service.service.d"
os.makedirs(dir, exist_ok=True)
with open(f"{dir}/bug_268.conf", "w") as f:
f.write("[Service]\nEnvironment=OS_COMPUTE_API_VERSION=2.87\n")

0 comments on commit 31fb589

Please sign in to comment.