discovery: add support for gathering flavor name in Openstack discovery (#14312)

* feat: add support for gathering flavor name in Openstack discovery

Signed-off-by: Paulo Dias <paulodias.gm@gmail.com>

* Update instance.go

Co-authored-by: Ayoub Mrini <ayoubmrini424@gmail.com>
Signed-off-by: Paulo Dias <44772900+paulojmdias@users.noreply.github.com>

* Update configuration.md

Co-authored-by: Ayoub Mrini <ayoubmrini424@gmail.com>
Signed-off-by: Paulo Dias <44772900+paulojmdias@users.noreply.github.com>

* fix: fix linting

Signed-off-by: Paulo Dias <paulodias.gm@gmail.com>

* fix: fix instance type

Signed-off-by: Paulo Dias <paulodias.gm@gmail.com>

* Update docs/configuration/configuration.md

Co-authored-by: Simon Pasquier <spasquie@redhat.com>
Signed-off-by: Paulo Dias <44772900+paulojmdias@users.noreply.github.com>

---------

Signed-off-by: Paulo Dias <paulodias.gm@gmail.com>
Signed-off-by: Paulo Dias <44772900+paulojmdias@users.noreply.github.com>
Co-authored-by: Ayoub Mrini <ayoubmrini424@gmail.com>
Co-authored-by: Simon Pasquier <spasquie@redhat.com>
pull/14369/head^2
Paulo Dias 5 months ago committed by GitHub
parent 675d02cd0b
commit f4b1fcb73e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -146,12 +146,18 @@ func (i *InstanceDiscovery) refresh(ctx context.Context) ([]*targetgroup.Group,
openstackLabelUserID: model.LabelValue(s.UserID),
}
flavorID, ok := s.Flavor["id"].(string)
if !ok {
level.Warn(i.logger).Log("msg", "Invalid type for flavor id, expected string")
continue
flavorName, nameOk := s.Flavor["original_name"].(string)
// "original_name" is only available for microversion >= 2.47. It was added in favor of "id".
if !nameOk {
flavorID, idOk := s.Flavor["id"].(string)
if !idOk {
level.Warn(i.logger).Log("msg", "Invalid type for both flavor original_name and flavor id, expected string")
continue
}
labels[openstackLabelInstanceFlavor] = model.LabelValue(flavorID)
} else {
labels[openstackLabelInstanceFlavor] = model.LabelValue(flavorName)
}
labels[openstackLabelInstanceFlavor] = model.LabelValue(flavorID)
imageID, ok := s.Image["id"].(string)
if ok {

@ -84,7 +84,7 @@ func TestOpenstackSDInstanceRefresh(t *testing.T) {
},
{
"__address__": model.LabelValue("10.0.0.31:0"),
"__meta_openstack_instance_flavor": model.LabelValue("1"),
"__meta_openstack_instance_flavor": model.LabelValue("m1.medium"),
"__meta_openstack_instance_id": model.LabelValue("9e5476bd-a4ec-4653-93d6-72c93aa682ba"),
"__meta_openstack_instance_image": model.LabelValue("f90f6034-2570-4974-8351-6b49732ef2eb"),
"__meta_openstack_instance_status": model.LabelValue("ACTIVE"),
@ -96,7 +96,7 @@ func TestOpenstackSDInstanceRefresh(t *testing.T) {
},
{
"__address__": model.LabelValue("10.0.0.33:0"),
"__meta_openstack_instance_flavor": model.LabelValue("4"),
"__meta_openstack_instance_flavor": model.LabelValue("m1.small"),
"__meta_openstack_instance_id": model.LabelValue("9e5476bd-a4ec-4653-93d6-72c93aa682bb"),
"__meta_openstack_instance_status": model.LabelValue("ACTIVE"),
"__meta_openstack_instance_name": model.LabelValue("merp"),
@ -108,7 +108,7 @@ func TestOpenstackSDInstanceRefresh(t *testing.T) {
},
{
"__address__": model.LabelValue("10.0.0.34:0"),
"__meta_openstack_instance_flavor": model.LabelValue("4"),
"__meta_openstack_instance_flavor": model.LabelValue("m1.small"),
"__meta_openstack_instance_id": model.LabelValue("9e5476bd-a4ec-4653-93d6-72c93aa682bb"),
"__meta_openstack_instance_status": model.LabelValue("ACTIVE"),
"__meta_openstack_instance_name": model.LabelValue("merp"),

@ -427,13 +427,17 @@ const serverListBody = `
"OS-SRV-USG:launched_at": "2014-09-25T13:04:49.000000",
"OS-EXT-SRV-ATTR:hypervisor_hostname": "devstack",
"flavor": {
"id": "1",
"links": [
{
"href": "http://104.130.131.164:8774/fcad67a6189847c4aecfa3c81a05783b/flavors/1",
"rel": "bookmark"
}
]
"vcpus": 2,
"ram": 4096,
"disk": 0,
"ephemeral": 0,
"swap": 0,
"original_name": "m1.medium",
"extra_specs": {
"aggregate_instance_extra_specs:general": "true",
"hw:mem_page_size": "large",
"hw:vif_multiqueue_enabled": "true"
}
},
"id": "9e5476bd-a4ec-4653-93d6-72c93aa682ba",
"security_groups": [
@ -498,13 +502,17 @@ const serverListBody = `
"OS-SRV-USG:launched_at": "2014-09-25T13:04:49.000000",
"OS-EXT-SRV-ATTR:hypervisor_hostname": "devstack",
"flavor": {
"id": "4",
"links": [
{
"href": "http://104.130.131.164:8774/fcad67a6189847c4aecfa3c81a05783b/flavors/1",
"rel": "bookmark"
}
]
"vcpus": 2,
"ram": 4096,
"disk": 0,
"ephemeral": 0,
"swap": 0,
"original_name": "m1.small",
"extra_specs": {
"aggregate_instance_extra_specs:general": "true",
"hw:mem_page_size": "large",
"hw:vif_multiqueue_enabled": "true"
}
},
"id": "9e5476bd-a4ec-4653-93d6-72c93aa682bb",
"security_groups": [

@ -1363,7 +1363,7 @@ interface.
The following meta labels are available on targets during [relabeling](#relabel_config):
* `__meta_openstack_address_pool`: the pool of the private IP.
* `__meta_openstack_instance_flavor`: the flavor ID of the OpenStack instance.
* `__meta_openstack_instance_flavor`: the flavor name of the OpenStack instance, or the flavor ID if the flavor name isn't available.
* `__meta_openstack_instance_id`: the OpenStack instance ID.
* `__meta_openstack_instance_image`: the ID of the image the OpenStack instance is using.
* `__meta_openstack_instance_name`: the OpenStack instance name.

Loading…
Cancel
Save