From 02d06719b491830d1856ffe05433151744ee0556 Mon Sep 17 00:00:00 2001 From: Rain Sun Date: Sun, 14 Feb 2021 11:26:43 +0800 Subject: [PATCH] User server supported microversion when nova list services (#160) * User server supported microversion when nova list services When nova cell enabled, we have two nova-conductor service, one is nova-conductor and another is super nova-super-conductor, they have same name in different databases (nova_cell0 & nova_cell1). The only difference for the agent_state metrics is the service ID, but service ID is actually a db seqNo, they can be same in different tables. In our cases, we met two nova-conductors have the same label, that will cause metrics failed to store. For nova apiversion bigger than 2.53, it will return uuid for service id, so add microversion for nova client. * User server supported microversion when nova list services When nova cell enabled, we have two nova-conductor service, one is nova-conductor and another is super nova-super-conductor, they have same name in different databases (nova_cell0 & nova_cell1). The only difference for the agent_state metrics is the service ID, but service ID is actually a db seqNo, they can be same in different tables. In our cases, we met two nova-conductors have the same label, that will cause metrics failed to store. For nova apiversion bigger than 2.53, it will return uuid for service id, so add microversion for nova client. * User server supported microversion when nova list services When nova cell enabled, we have two nova-conductor service, one is nova-conductor and another is super nova-super-conductor, they have same name in different databases (nova_cell0 & nova_cell1). The only difference for the agent_state metrics is the service ID, but service ID is actually a db seqNo, they can be same in different tables. In our cases, we met two nova-conductors have the same label, that will cause metrics failed to store. For nova apiversion bigger than 2.53, it will return uuid for service id, so add microversion for nova client. * Use server supported microversion when nova list services When nova cell enabled, we have two nova-conductor service, one is nova-conductor and another is super nova-super-conductor, they have same name in different databases (nova_cell0 & nova_cell1). The only difference for the agent_state metrics is the service ID, but service ID is actually a db seqNo, they can be same in different tables. In our cases, we met two nova-conductors have the same label, that will cause metrics failed to store. For nova apiversion bigger than 2.53, it will return uuid for service id, so add microversion for nova client. * Use server supported microversion when nova list services When nova cell enabled, we have two nova-conductor service, one is nova-conductor and another is super nova-super-conductor, they have same name in different databases (nova_cell0 & nova_cell1). The only difference for the agent_state metrics is the service ID, but service ID is actually a db seqNo, they can be same in different tables. In our cases, we met two nova-conductors have the same label, that will cause metrics failed to store. For nova apiversion bigger than 2.53, it will return uuid for service id, so add microversion for nova client. * Update exporter_test.go * Update exporter_test.go Co-authored-by: minsu Co-authored-by: Jorge Niedbalski --- exporters/exporter_test.go | 17 +++++++++-------- exporters/fixtures/nova_api_v2.1.json | 27 +++++++++++++++++++++++++++ exporters/nova.go | 5 +++++ 3 files changed, 41 insertions(+), 8 deletions(-) create mode 100644 exporters/fixtures/nova_api_v2.1.json diff --git a/exporters/exporter_test.go b/exporters/exporter_test.go index dfd5bb4..fe74c1d 100644 --- a/exporters/exporter_test.go +++ b/exporters/exporter_test.go @@ -51,14 +51,15 @@ func (suite *BaseOpenStackTestSuite) FixturePath(name string) string { } var fixtures map[string]string = map[string]string{ - "/container-infra/clusters": "container_infra_clusters", - "/compute/": "nova_api_discovery", - "/compute/os-services": "nova_os_services", - "/compute/os-hypervisors/detail": "nova_os_hypervisors", - "/compute/flavors/detail": "nova_os_flavors", - "/compute/os-availability-zone": "nova_os_availability_zones", - "/compute/os-security-groups": "nova_os_security_groups", - "/compute/os-aggregates": "nova_os_aggregates", + "/container-infra/clusters": "container_infra_clusters", + "/compute/": "nova_api_discovery", + "/compute/v2.1/": "nova_api_v2.1", + "/compute/os-services": "nova_os_services", + "/compute/os-hypervisors/detail": "nova_os_hypervisors", + "/compute/flavors/detail": "nova_os_flavors", + "/compute/os-availability-zone": "nova_os_availability_zones", + "/compute/os-security-groups": "nova_os_security_groups", + "/compute/os-aggregates": "nova_os_aggregates", "/compute/limits?tenant_id=0c4e939acacf4376bdcd1129f1a054ad": "nova_os_limits", "/compute/limits?tenant_id=0cbd49cbf76d405d9c86562e1d579bd3": "nova_os_limits", "/compute/limits?tenant_id=2db68fed84324f29bb73130c6c2094fb": "nova_os_limits", diff --git a/exporters/fixtures/nova_api_v2.1.json b/exporters/fixtures/nova_api_v2.1.json new file mode 100644 index 0000000..c050bef --- /dev/null +++ b/exporters/fixtures/nova_api_v2.1.json @@ -0,0 +1,27 @@ +{ + "versions": + { + "id": "v2.1", + "status": "CURRENT", + "version": "2.87", + "min_version": "2.1", + "updated": "2013-07-23T11:33:21Z", + "links": [ + { + "rel": "self", + "href": "http://test.cloud:8774/v2.1/" + }, + { + "rel": "describedby", + "type": "text/html", + "href": "http://docs.openstack.org/" + } + ], + "media-types": [ + { + "base": "application/json", + "type": "application/vnd.openstack.compute+json;version=2.1" + } + ] + } +} \ No newline at end of file diff --git a/exporters/nova.go b/exporters/nova.go index 59f002d..8b4c6b2 100644 --- a/exporters/nova.go +++ b/exporters/nova.go @@ -7,6 +7,7 @@ import ( "github.com/gophercloud/gophercloud" "github.com/gophercloud/gophercloud/openstack" + "github.com/gophercloud/gophercloud/openstack/compute/apiversions" "github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/aggregates" "github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/availabilityzones" "github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/extendedserverattributes" @@ -96,6 +97,10 @@ func NewNovaExporter(config *ExporterConfig) (*NovaExporter, error) { exporter.AddMetric(metric.Name, metric.Fn, metric.Labels, nil) } } + microversion, err := apiversions.Get(config.Client, "v2.1").Extract() + if err == nil { + exporter.Client.Microversion = microversion.Version + } return &exporter, nil }