Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PLINT-366] Adding glance image up and size metrics #17454

Merged
merged 9 commits into from
Apr 29, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@
from datadog_checks.openstack_controller.components.component import Component
from datadog_checks.openstack_controller.metrics import (
GLANCE_IMAGE_COUNT,
GLANCE_IMAGE_METRICS,
GLANCE_IMAGE_PREFIX,
GLANCE_IMAGE_TAGS,
GLANCE_METRICS_PREFIX,
GLANCE_RESPONSE_TIME,
GLANCE_SERVICE_CHECK,
get_metrics_and_tags,
Expand Down Expand Up @@ -40,8 +41,18 @@ def _report_images(self, config, tags):
image = get_metrics_and_tags(
item,
tags=GLANCE_IMAGE_TAGS,
prefix=GLANCE_METRICS_PREFIX,
metrics=[GLANCE_IMAGE_COUNT],
prefix=GLANCE_IMAGE_PREFIX,
metrics=GLANCE_IMAGE_METRICS,
lambda_name=lambda key: 'up' if key == 'status' else 'bytes' if key == 'name' else key,
lambda_value=lambda key, value, item=item: (
item['status'] == 'active'
if key == 'status'
else len(bytes(str(item), 'utf-8'))
if key == 'name'
else value
),
)
self.check.log.debug("image: %s", image)
self.check.gauge(GLANCE_IMAGE_COUNT, 1, tags=tags + image['tags'])
for metric, value in image['metrics'].items():
self.check.gauge(metric, value, tags=tags + image['tags'])
Original file line number Diff line number Diff line change
Expand Up @@ -535,7 +535,9 @@
GLANCE_METRICS_PREFIX = "openstack.glance"
GLANCE_SERVICE_CHECK = f"{GLANCE_METRICS_PREFIX}.api.up"
GLANCE_RESPONSE_TIME = f"{GLANCE_METRICS_PREFIX}.response_time"
GLANCE_IMAGE_COUNT = f"{GLANCE_METRICS_PREFIX}.image.count"
GLANCE_IMAGE_PREFIX = f"{GLANCE_METRICS_PREFIX}.image"
GLANCE_IMAGE_COUNT = f"{GLANCE_IMAGE_PREFIX}.count"
GLANCE_IMAGE_METRICS = {f"{GLANCE_IMAGE_PREFIX}.up": {}, f"{GLANCE_IMAGE_PREFIX}.bytes": {}}
GLANCE_IMAGE_TAGS = {
'name': 'image_name',
'status': 'status',
Expand Down
2 changes: 2 additions & 0 deletions openstack_controller/metadata.csv
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
metric_name,metric_type,interval,unit_name,per_unit_name,description,orientation,integration,short_name,curated_metric
openstack.cinder.response_time,gauge,,millisecond,,Duration that an HTTP request takes to complete when making a request to cinder endpoint,0,openstack_controller,cinder response time,
openstack.glance.image.bytes,gauge,,,,Number of bytes in a glance image response body,0,openstack_controller,glance image bytes,
openstack.glance.image.count,gauge,,,,Number of public virtual machine images,0,openstack_controller,glance image ct,
openstack.glance.image.up,gauge,,,,Whether a glance image is up,0,openstack_controller,glance image up,
openstack.glance.response_time,gauge,,millisecond,,Duration that an HTTP request takes to complete when making a request to glance endpoint,0,openstack_controller,glance response time,
openstack.ironic.conductor.count,gauge,,,,Number of ironic conductors,0,openstack_controller,ironic conductor ct,
openstack.ironic.conductor.up,gauge,,,,Whether an ironic conductor is up,0,openstack_controller,ironic conductor up,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
{
"images": [
{
"hw_rng_model": "virtio",
"owner_specified.openstack.md5": "",
"owner_specified.openstack.object": "images/cirros-0.5.2-x86_64-disk",
"owner_specified.openstack.object": "images/cirros-1.5.2-x86_64-disk",
"owner_specified.openstack.sha256": "",
"name": "cirros-0.5.2-x86_64-disk",
"owner_specified.openstack.md5": "",
"hw_rng_model": "virtio",
"name": "cirros-1.5.2-x86_64-disk",
"disk_format": "qcow2",
"container_format": "bare",
"visibility": "public",
"size": 16300544,
"virtual_size": 117440512,
"size": 46310543,
"virtual_size": 217940522,
"status": "active",
"checksum": "b874c39491a2377b8490f5f1e89761a4",
"checksum": "b873c39491a1377c8490f5f1e89261a9",
"protected": false,
"min_ram": 0,
"min_disk": 0,
"owner": "c09ccb52462d49c89595d2194a367198",
"owner": "c09ccb52463d49c89595d2194a367298",
"os_hidden": false,
"os_hash_algo": "sha512",
"os_hash_value": "6b813aa46bb90b4da216a4d19376593fa3f4fc7e617f03a92b7fe11e9a3981cbe8f0959dbebe36225e5f53dc4492341a4863cac4ed1ee0909f3fc78ef9c3e869",
"os_hash_value": "7b813aa46bb90b4da216a4d19376593fa3f3fc7e617f03a92b7fe11e9a3981cbe9f0959dbebe36225e5f53dc4492341a4863cac4ed1ee0909f3fc78ef9c3e861",
"id": "a4dcf3f7-e4d6-45d5-be2b-a939f2bbedfc",
"created_at": "2023-10-18T15:03:09Z",
"updated_at": "2023-10-18T15:03:10Z",
"created_at": "2023-10-28T15:03:09Z",
"updated_at": "2023-10-28T15:03:10Z",
"tags": [],
"self": "/v2/images/a4dcf3f7-e4d6-45d5-be2b-a939f2bbedfc",
"file": "/v2/images/a4dcf3f7-e4d6-45d5-be2b-a939f2bbedfc/file",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,27 +1,31 @@
{
"images": [
{
"name": "cirros-1.5.2-x86_64-disk",
"owner_specified.openstack.object": "images/cirros-0.5.2-x86_64-disk",
"owner_specified.openstack.sha256": "",
"owner_specified.openstack.md5": "",
"hw_rng_model": "virtio",
"name": "cirros-0.5.2-x86_64-disk",
"disk_format": "qcow2",
"container_format": "bare",
"visibility": "public",
"size": 16338944,
"size": 16300544,
"virtual_size": 117440512,
"status": "active",
"checksum": "1d3062cd89af34e419f7100277f38b2b",
"checksum": "b874c39491a2377b8490f5f1e89761a4",
"protected": false,
"min_ram": 0,
"min_disk": 0,
"owner": "29b43a58176646e3870a9ea0b60fb7ad",
"owner": "c09ccb52462d49c89595d2194a367198",
"os_hidden": false,
"os_hash_algo": "sha512",
"os_hash_value": "553d220ed58cfee7dafe003c446a9f197ab5edf8ffc09396c74187cf83873c877e7ae041cb80f3b91489acf687183adcd689b53b38e3ddd22e627e7f98a09c46",
"os_hash_value": "6b813aa46bb90b4da216a4d19376593fa3f4fc7e617f03a92b7fe11e9a3981cbe8f0959dbebe36225e5f53dc4492341a4863cac4ed1ee0909f3fc78ef9c3e869",
"id": "28c293db-48c5-4c8b-a711-09b2c11fa8e5",
"created_at": "2024-02-28T20:31:08Z",
"updated_at": "2024-02-28T20:31:09Z",
"created_at": "2023-10-18T15:03:09Z",
"updated_at": "2023-10-18T15:03:10Z",
"tags": [],
"self": "/v2/images/28c293db-48c5-4c8b-a711-09b2c11fa8e5",
"file": "/v2/images/28c293db-48c5-4c8b-a711-09b2c11fa8e5/file",
"self": "/v2/images/a4dcf3f7-e4d6-45d5-be2b-a939f2bbedfc",
"file": "/v2/images/a4dcf3f7-e4d6-45d5-be2b-a939f2bbedfc/file",
"schema": "/v2/schemas/image"
}
],
Expand Down
Original file line number Diff line number Diff line change
@@ -1,27 +1,31 @@
{
"images": [
{
"owner_specified.openstack.object": "images/cirros-1.5.2-x86_64-disk",
"owner_specified.openstack.sha256": "",
"owner_specified.openstack.md5": "",
"hw_rng_model": "virtio",
"name": "cirros-1.5.2-x86_64-disk",
"disk_format": "qcow2",
"container_format": "bare",
"visibility": "public",
"size": 16338944,
"virtual_size": 117440512,
"size": 46310543,
"virtual_size": 217940522,
"status": "active",
"checksum": "1d3062cd89af34e419f7100277f38b2b",
"checksum": "b873c39491a1377c8490f5f1e89261a9",
"protected": false,
"min_ram": 0,
"min_disk": 0,
"owner": "29b43a58176646e3870a9ea0b60fb7ad",
"owner": "c09ccb52463d49c89595d2194a367298",
"os_hidden": false,
"os_hash_algo": "sha512",
"os_hash_value": "553d220ed58cfee7dafe003c446a9f197ab5edf8ffc09396c74187cf83873c877e7ae041cb80f3b91489acf687183adcd689b53b38e3ddd22e627e7f98a09c46",
"id": "28c293db-48c5-4c8b-a711-09b2c11fa8e5",
"created_at": "2024-02-28T20:31:08Z",
"updated_at": "2024-02-28T20:31:09Z",
"os_hash_value": "7b813aa46bb90b4da216a4d19376593fa3f3fc7e617f03a92b7fe11e9a3981cbe9f0959dbebe36225e5f53dc4492341a4863cac4ed1ee0909f3fc78ef9c3e861",
"id": "a4dcf3f7-e4d6-45d5-be2b-a939f2bbedfc",
"created_at": "2023-10-28T15:03:09Z",
"updated_at": "2023-10-28T15:03:10Z",
"tags": [],
"self": "/v2/images/28c293db-48c5-4c8b-a711-09b2c11fa8e5",
"file": "/v2/images/28c293db-48c5-4c8b-a711-09b2c11fa8e5/file",
"self": "/v2/images/a4dcf3f7-e4d6-45d5-be2b-a939f2bbedfc",
"file": "/v2/images/a4dcf3f7-e4d6-45d5-be2b-a939f2bbedfc/file",
"schema": "/v2/schemas/image"
},
{
Expand All @@ -44,7 +48,7 @@
"os_hidden": false,
"os_hash_algo": "sha512",
"os_hash_value": "6b813aa46bb90b4da216a4d19376593fa3f4fc7e617f03a92b7fe11e9a3981cbe8f0959dbebe36225e5f53dc4492341a4863cac4ed1ee0909f3fc78ef9c3e869",
"id": "a4dcf3f7-e4d6-45d5-be2b-a939f2bbedfc",
"id": "28c293db-48c5-4c8b-a711-09b2c11fa8e5",
"created_at": "2023-10-18T15:03:09Z",
"updated_at": "2023-10-18T15:03:10Z",
"tags": [],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,34 @@
"self": "/v2/images/a4dcf3f7-e4d6-45d5-be2b-a939f2bbedfc",
"file": "/v2/images/a4dcf3f7-e4d6-45d5-be2b-a939f2bbedfc/file",
"schema": "/v2/schemas/image"
},
{
"owner_specified.openstack.object": "images/cirros-0.5.2-x86_64-disk",
"owner_specified.openstack.sha256": "",
"owner_specified.openstack.md5": "",
"hw_rng_model": "virtio",
"name": "cirros-0.5.2-x86_64-disk",
"disk_format": "qcow2",
"container_format": "bare",
"visibility": "public",
"size": 16300544,
"virtual_size": 117440512,
"status": "active",
"checksum": "b874c39491a2377b8490f5f1e89761a4",
"protected": false,
"min_ram": 0,
"min_disk": 0,
"owner": "c09ccb52462d49c89595d2194a367198",
"os_hidden": false,
"os_hash_algo": "sha512",
"os_hash_value": "6b813aa46bb90b4da216a4d19376593fa3f4fc7e617f03a92b7fe11e9a3981cbe8f0959dbebe36225e5f53dc4492341a4863cac4ed1ee0909f3fc78ef9c3e869",
"id": "28c293db-48c5-4c8b-a711-09b2c11fa8e5",
"created_at": "2023-10-18T15:03:09Z",
"updated_at": "2023-10-18T15:03:10Z",
"tags": [],
"self": "/v2/images/a4dcf3f7-e4d6-45d5-be2b-a939f2bbedfc",
"file": "/v2/images/a4dcf3f7-e4d6-45d5-be2b-a939f2bbedfc/file",
"schema": "/v2/schemas/image"
}
],
"first": "/v2/images",
Expand Down
60 changes: 60 additions & 0 deletions openstack_controller/tests/metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -4548,6 +4548,18 @@


IMAGES_METRICS_GLANCE = [
{
'name': 'openstack.glance.image.bytes',
'count': 1,
'value': 976,
rahulkaukuntla marked this conversation as resolved.
Show resolved Hide resolved
'hostname': '',
'tags': [
'container_format:bare',
'image_name:cirros-1.5.2-x86_64-disk',
'status:active',
'keystone_server:http://127.0.0.1:8080/identity',
],
},
{
'name': 'openstack.glance.image.count',
'count': 1,
Expand All @@ -4560,4 +4572,52 @@
'keystone_server:http://127.0.0.1:8080/identity',
],
},
{
'name': 'openstack.glance.image.up',
'count': 1,
'value': 1,
'hostname': '',
'tags': [
'container_format:bare',
'image_name:cirros-1.5.2-x86_64-disk',
'status:active',
'keystone_server:http://127.0.0.1:8080/identity',
],
},
{
'name': 'openstack.glance.image.bytes',
'count': 1,
'value': 976,
'hostname': '',
'tags': [
'container_format:bare',
'image_name:cirros-0.5.2-x86_64-disk',
'status:active',
'keystone_server:http://127.0.0.1:8080/identity',
],
},
{
'name': 'openstack.glance.image.count',
'count': 1,
'value': 1,
'hostname': '',
'tags': [
'container_format:bare',
'image_name:cirros-0.5.2-x86_64-disk',
'status:active',
'keystone_server:http://127.0.0.1:8080/identity',
],
},
{
'name': 'openstack.glance.image.up',
'count': 1,
'value': 1,
'hostname': '',
'tags': [
'container_format:bare',
'image_name:cirros-0.5.2-x86_64-disk',
'status:active',
'keystone_server:http://127.0.0.1:8080/identity',
],
},
]
29 changes: 29 additions & 0 deletions openstack_controller/tests/test_unit_glance.py
Original file line number Diff line number Diff line change
Expand Up @@ -334,3 +334,32 @@ def test_images_pagination(
tags=metric['tags'],
hostname=metric.get('hostname'),
)


@pytest.mark.parametrize(
('instance'),
[
pytest.param(
configs.REST,
id='api rest no microversion',
),
pytest.param(
configs.SDK,
id='api sdk no microversion',
),
],
)
@pytest.mark.usefixtures('mock_http_get', 'mock_http_post', 'openstack_connection')
def test_disable_glance_image_metrics(aggregator, dd_run_check, instance, openstack_controller_check):
instance = instance | {
"components": {
"image": {
"images": False,
},
},
}
check = openstack_controller_check(instance)
dd_run_check(check)
for metric in aggregator.metric_names:
assert not metric.startswith('openstack.cinder.image.count')
rahulkaukuntla marked this conversation as resolved.
Show resolved Hide resolved
assert not metric.startswith('openstack.cinder.image.up')