From d1c8550894f036e568c0523e0fc51614fb30554a Mon Sep 17 00:00:00 2001 From: Julien Pivotto Date: Fri, 12 Mar 2021 01:03:27 +0100 Subject: [PATCH 1/2] Scaleway SD: Add more labels to the instance role Signed-off-by: Julien Pivotto --- discovery/scaleway/instance.go | 67 ++++++++++++++++++++--------- discovery/scaleway/instance_test.go | 64 ++++++++++++++++++--------- docs/configuration/configuration.md | 49 +++++++++++++-------- 3 files changed, 119 insertions(+), 61 deletions(-) diff --git a/discovery/scaleway/instance.go b/discovery/scaleway/instance.go index 6a62730ef..b67296541 100644 --- a/discovery/scaleway/instance.go +++ b/discovery/scaleway/instance.go @@ -34,17 +34,28 @@ import ( const ( instanceLabelPrefix = metaLabelPrefix + "instance_" - instanceIDLabel = instanceLabelPrefix + "id" - instancePrivateIPv4 = instanceLabelPrefix + "private_ipv4" - instancePublicIPv4 = instanceLabelPrefix + "public_ipv4" - instancePublicIPv6 = instanceLabelPrefix + "public_ipv6" - instanceImageNameLabel = instanceLabelPrefix + "image_name" - instanceNameLabel = instanceLabelPrefix + "name" - instanceProjectLabel = instanceLabelPrefix + "project_id" - instanceStateLabel = instanceLabelPrefix + "status" - instanceTagsLabel = instanceLabelPrefix + "tags" - instanceTypeLabel = instanceLabelPrefix + "type" - instanceZoneLabel = instanceLabelPrefix + "zone" + instanceBootTypeLabel = instanceLabelPrefix + "boot_type" + instanceHostnameLabel = instanceLabelPrefix + "hostname" + instanceIDLabel = instanceLabelPrefix + "id" + instanceImageArchLabel = instanceLabelPrefix + "image_arch" + instanceImageIDLabel = instanceLabelPrefix + "image_id" + instanceImageNameLabel = instanceLabelPrefix + "image_name" + instanceLocationClusterID = instanceLabelPrefix + "location_cluster_id" + instanceLocationHypervisorID = instanceLabelPrefix + "location_hypervisor_id" + instanceLocationNodeID = instanceLabelPrefix + "location_node_id" + instanceNameLabel = instanceLabelPrefix + "name" + instanceOrganizationLabel = instanceLabelPrefix + "organization" + instancePrivateIPv4Label = instanceLabelPrefix + "private_ipv4" + instanceProjectLabel = instanceLabelPrefix + "project_id" + instancePublicIPv4Label = instanceLabelPrefix + "public_ipv4" + instancePublicIPv6Label = instanceLabelPrefix + "public_ipv6" + instanceSecurityGroupIDLabel = instanceLabelPrefix + "security_group_id" + instanceSecurityGroupNameLabel = instanceLabelPrefix + "security_group_name" + instanceStateLabel = instanceLabelPrefix + "status" + instanceTagsLabel = instanceLabelPrefix + "tags" + instanceTypeLabel = instanceLabelPrefix + "type" + instanceZoneLabel = instanceLabelPrefix + "zone" + instanceRegionLabel = instanceLabelPrefix + "region" ) type instanceDiscovery struct { @@ -116,13 +127,27 @@ func (d *instanceDiscovery) refresh(ctx context.Context) ([]*targetgroup.Group, var targets []model.LabelSet for _, server := range servers.Servers { labels := model.LabelSet{ - instanceIDLabel: model.LabelValue(server.ID), - instanceImageNameLabel: model.LabelValue(server.Image.Name), - instanceNameLabel: model.LabelValue(server.Name), - instanceProjectLabel: model.LabelValue(server.Project), - instanceStateLabel: model.LabelValue(server.State), - instanceTypeLabel: model.LabelValue(server.CommercialType), - instanceZoneLabel: model.LabelValue(server.Zone.String()), + instanceBootTypeLabel: model.LabelValue(server.BootType), + instanceHostnameLabel: model.LabelValue(server.Hostname), + instanceIDLabel: model.LabelValue(server.ID), + instanceImageArchLabel: model.LabelValue(server.Image.Arch), + instanceImageIDLabel: model.LabelValue(server.Image.ID), + instanceImageNameLabel: model.LabelValue(server.Image.Name), + instanceLocationClusterID: model.LabelValue(server.Location.ClusterID), + instanceLocationHypervisorID: model.LabelValue(server.Location.HypervisorID), + instanceLocationNodeID: model.LabelValue(server.Location.NodeID), + instanceNameLabel: model.LabelValue(server.Name), + instanceOrganizationLabel: model.LabelValue(server.Organization), + instanceProjectLabel: model.LabelValue(server.Project), + instanceSecurityGroupIDLabel: model.LabelValue(server.SecurityGroup.ID), + instanceSecurityGroupNameLabel: model.LabelValue(server.SecurityGroup.Name), + instanceStateLabel: model.LabelValue(server.State), + instanceTypeLabel: model.LabelValue(server.CommercialType), + instanceZoneLabel: model.LabelValue(server.Zone.String()), + } + + if region, err := server.Zone.Region(); err == nil { + labels[instanceRegionLabel] = model.LabelValue(region.String()) } if len(server.Tags) > 0 { @@ -133,15 +158,15 @@ func (d *instanceDiscovery) refresh(ctx context.Context) ([]*targetgroup.Group, } if server.IPv6 != nil { - labels[instancePublicIPv6] = model.LabelValue(server.IPv6.Address.String()) + labels[instancePublicIPv6Label] = model.LabelValue(server.IPv6.Address.String()) } if server.PublicIP != nil { - labels[instancePublicIPv4] = model.LabelValue(server.PublicIP.Address.String()) + labels[instancePublicIPv4Label] = model.LabelValue(server.PublicIP.Address.String()) } if server.PrivateIP != nil { - labels[instancePrivateIPv4] = model.LabelValue(*server.PrivateIP) + labels[instancePrivateIPv4Label] = model.LabelValue(*server.PrivateIP) addr := net.JoinHostPort(*server.PrivateIP, strconv.FormatUint(uint64(d.port), 10)) labels[model.AddressLabel] = model.LabelValue(addr) diff --git a/discovery/scaleway/instance_test.go b/discovery/scaleway/instance_test.go index b920e2baf..15fdb495e 100644 --- a/discovery/scaleway/instance_test.go +++ b/discovery/scaleway/instance_test.go @@ -63,29 +63,51 @@ api_url: %s for i, lbls := range []model.LabelSet{ { - "__address__": "10.70.60.57:80", - "__meta_scaleway_instance_id": "93c18a61-b681-49d0-a1cc-62b43883ae89", - "__meta_scaleway_instance_image_name": "Ubuntu 18.04 Bionic Beaver", - "__meta_scaleway_instance_name": "scw-nervous-shirley", - "__meta_scaleway_instance_private_ipv4": "10.70.60.57", - "__meta_scaleway_instance_project_id": "cb334986-b054-4725-9d5a-30850fdc6015", - "__meta_scaleway_instance_public_ipv6": "2001:bc8:630:1e1c::1", - "__meta_scaleway_instance_status": "running", - "__meta_scaleway_instance_type": "DEV1-S", - "__meta_scaleway_instance_zone": "fr-par-1", + "__address__": "10.70.60.57:80", + "__meta_scaleway_instance_boot_type": "local", + "__meta_scaleway_instance_hostname": "scw-nervous-shirley", + "__meta_scaleway_instance_id": "93c18a61-b681-49d0-a1cc-62b43883ae89", + "__meta_scaleway_instance_image_arch": "x86_64", + "__meta_scaleway_instance_image_id": "45a86b35-eca6-4055-9b34-ca69845da146", + "__meta_scaleway_instance_image_name": "Ubuntu 18.04 Bionic Beaver", + "__meta_scaleway_instance_location_cluster_id": "40", + "__meta_scaleway_instance_location_hypervisor_id": "1601", + "__meta_scaleway_instance_location_node_id": "29", + "__meta_scaleway_instance_name": "scw-nervous-shirley", + "__meta_scaleway_instance_organization": "cb334986-b054-4725-9d3a-40850fdc6015", + "__meta_scaleway_instance_private_ipv4": "10.70.60.57", + "__meta_scaleway_instance_project_id": "cb334986-b054-4725-9d5a-30850fdc6015", + "__meta_scaleway_instance_public_ipv6": "2001:bc8:630:1e1c::1", + "__meta_scaleway_instance_region": "fr-par", + "__meta_scaleway_instance_security_group_id": "a6a794b7-c05b-4b20-b9fe-e17a9bb85cf0", + "__meta_scaleway_instance_security_group_name": "Default security group", + "__meta_scaleway_instance_status": "running", + "__meta_scaleway_instance_type": "DEV1-S", + "__meta_scaleway_instance_zone": "fr-par-1", }, { - "__address__": "10.193.162.9:80", - "__meta_scaleway_instance_id": "5b6198b4-c677-41b5-9c05-04557264ae1f", - "__meta_scaleway_instance_image_name": "Debian Buster", - "__meta_scaleway_instance_name": "scw-quizzical-feistel", - "__meta_scaleway_instance_private_ipv4": "10.193.162.9", - "__meta_scaleway_instance_project_id": "cb334986-b054-4725-9d5a-30850fdc6015", - "__meta_scaleway_instance_public_ipv4": "151.115.45.127", - "__meta_scaleway_instance_public_ipv6": "2001:bc8:1e00:6204::1", - "__meta_scaleway_instance_status": "running", - "__meta_scaleway_instance_type": "DEV1-S", - "__meta_scaleway_instance_zone": "fr-par-1", + "__address__": "10.193.162.9:80", + "__meta_scaleway_instance_boot_type": "local", + "__meta_scaleway_instance_hostname": "scw-quizzical-feistel", + "__meta_scaleway_instance_id": "5b6198b4-c677-41b5-9c05-04557264ae1f", + "__meta_scaleway_instance_image_arch": "x86_64", + "__meta_scaleway_instance_image_id": "71733b74-260f-4d0d-8f18-f37dcfa56d6f", + "__meta_scaleway_instance_image_name": "Debian Buster", + "__meta_scaleway_instance_location_cluster_id": "4", + "__meta_scaleway_instance_location_hypervisor_id": "201", + "__meta_scaleway_instance_location_node_id": "5", + "__meta_scaleway_instance_name": "scw-quizzical-feistel", + "__meta_scaleway_instance_organization": "cb334986-b054-4725-9d3a-40850fdc6015", + "__meta_scaleway_instance_private_ipv4": "10.193.162.9", + "__meta_scaleway_instance_project_id": "cb334986-b054-4725-9d5a-30850fdc6015", + "__meta_scaleway_instance_public_ipv4": "151.115.45.127", + "__meta_scaleway_instance_public_ipv6": "2001:bc8:1e00:6204::1", + "__meta_scaleway_instance_region": "fr-par", + "__meta_scaleway_instance_security_group_id": "d35dd210-8392-44dc-8854-121e419a0f56", + "__meta_scaleway_instance_security_group_name": "Default security group", + "__meta_scaleway_instance_status": "running", + "__meta_scaleway_instance_type": "DEV1-S", + "__meta_scaleway_instance_zone": "fr-par-1", }, } { t.Run(fmt.Sprintf("item %d", i), func(t *testing.T) { diff --git a/docs/configuration/configuration.md b/docs/configuration/configuration.md index 8f5073d31..30acedc85 100644 --- a/docs/configuration/configuration.md +++ b/docs/configuration/configuration.md @@ -1535,17 +1535,29 @@ The following meta labels are available on targets during [relabeling](#relabel_ #### Instance role -* `__meta_scaleway_instance_id`: the id of the instance -* `__meta_scaleway_instance_private_ipv4`: the private ipv4 address of the instance -* `__meta_scaleway_instance_public_ipv4`: the public ipv4 address of the instance -* `__meta_scaleway_instance_public_ipv6`: the public ipv6 address of the instance -* `__meta_scaleway_instance_image_name`: name of the server image + +* `__meta_scaleway_instance_boot_type`: the boot type of the server +* `__meta_scaleway_instance_hostname`: the hostname of the server +* `__meta_scaleway_instance_id`: the ID of the server +* `__meta_scaleway_instance_image_arch`: the arch of the server image +* `__meta_scaleway_instance_image_id`: the ID of the server image +* `__meta_scaleway_instance_image_name`: the name of the server image +* `__meta_scaleway_instance_location_cluster_id`: the cluster ID of the server location +* `__meta_scaleway_instance_location_hypervisor_id`: the hypervisor ID of the server location +* `__meta_scaleway_instance_location_node_id`: the node ID of the server location * `__meta_scaleway_instance_name`: name of the server +* `__meta_scaleway_instance_organization`: the organization of the server +* `__meta_scaleway_instance_private_ipv4`: the private IPv4 address of the server * `__meta_scaleway_instance_project_id`: project id of the server +* `__meta_scaleway_instance_public_ipv4`: the public IPv4 address of the server +* `__meta_scaleway_instance_public_ipv6`: the public IPv6 address of the server +* `__meta_scaleway_instance_region`: the region of the server +* `__meta_scaleway_instance_security_group_id`: the ID of the security group of the server +* `__meta_scaleway_instance_security_group_name`: the name of the security group of the server * `__meta_scaleway_instance_status`: status of the server -* `__meta_scaleway_instance_tags`: the list of tags of the target joined by the tag separator +* `__meta_scaleway_instance_tags`: the list of tags of the server joined by the tag separator * `__meta_scaleway_instance_type`: commercial type of the server -* `__meta_scaleway_instance_zone`: zone of the instance (ex: `fr-par-1`, complete list on ) +* `__meta_scaleway_instance_zone`: the zone of the server (ex: `fr-par-1`, complete list [here](https://developers.scaleway.com/en/products/instance/api/#introduction)) This role uses the private IPv4 address by default. This can be changed with relabelling, as demonstrated in [the Prometheus scaleway-sd @@ -1553,18 +1565,17 @@ configuration file](/documentation/examples/prometheus-scaleway.yml). #### Baremetal role -* `__meta_scaleway_baremetal_id`: the id of the server -* `__meta_scaleway_baremetal_public_ipv4`: the public ipv4 address of the server -* `__meta_scaleway_baremetal_public_ipv6`: the public ipv6 address of the server -* `__meta_scaleway_baremetal_ipaddress_order`: zero-based order of the address in the server -* `__meta_scaleway_baremetal_name`: name of the server -* `__meta_scaleway_baremetal_os_name`: name of the os used -* `__meta_scaleway_baremetal_os_version`: version of the os used -* `__meta_scaleway_baremetal_project_id`: project id of the server -* `__meta_scaleway_baremetal_status`: status of the server -* `__meta_scaleway_baremetal_tags`: tag list of the server -* `__meta_scaleway_baremetal_type`: commercial type of the server -* `__meta_scaleway_baremetal_zone`: zone of the server (ex: `fr-par-1`, complete list on ) +* `__meta_scaleway_baremetal_id`: the ID of the server +* `__meta_scaleway_baremetal_public_ipv4`: the public IPv4 address of the server +* `__meta_scaleway_baremetal_public_ipv6`: the public IPv6 address of the server +* `__meta_scaleway_baremetal_name`: the name of the server +* `__meta_scaleway_baremetal_os_name`: the name of the operating system of the server +* `__meta_scaleway_baremetal_os_version`: the version of the operating system of the server +* `__meta_scaleway_baremetal_project_id`: the project ID of the server +* `__meta_scaleway_baremetal_status`: the status of the server +* `__meta_scaleway_baremetal_tags`: the list of tags of the server joined by the tag separator +* `__meta_scaleway_baremetal_type`: the commercial type of the server +* `__meta_scaleway_baremetal_zone`: the zone of the server (ex: `fr-par-1`, complete list [here](https://developers.scaleway.com/en/products/instance/api/#introduction)) This role uses the public IPv4 address by default. This can be changed with relabelling, as demonstrated in [the Prometheus scaleway-sd From bab0fb81ef03981ca8ebdb72e8fb4840aae4b4fa Mon Sep 17 00:00:00 2001 From: Julien Pivotto Date: Fri, 12 Mar 2021 23:53:08 +0100 Subject: [PATCH 2/2] Rename to or ID Signed-off-by: Julien Pivotto --- discovery/scaleway/instance.go | 2 +- discovery/scaleway/instance_test.go | 4 ++-- docs/configuration/configuration.md | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/discovery/scaleway/instance.go b/discovery/scaleway/instance.go index b67296541..2dae98d68 100644 --- a/discovery/scaleway/instance.go +++ b/discovery/scaleway/instance.go @@ -44,7 +44,7 @@ const ( instanceLocationHypervisorID = instanceLabelPrefix + "location_hypervisor_id" instanceLocationNodeID = instanceLabelPrefix + "location_node_id" instanceNameLabel = instanceLabelPrefix + "name" - instanceOrganizationLabel = instanceLabelPrefix + "organization" + instanceOrganizationLabel = instanceLabelPrefix + "organization_id" instancePrivateIPv4Label = instanceLabelPrefix + "private_ipv4" instanceProjectLabel = instanceLabelPrefix + "project_id" instancePublicIPv4Label = instanceLabelPrefix + "public_ipv4" diff --git a/discovery/scaleway/instance_test.go b/discovery/scaleway/instance_test.go index 15fdb495e..3c07de35f 100644 --- a/discovery/scaleway/instance_test.go +++ b/discovery/scaleway/instance_test.go @@ -74,7 +74,7 @@ api_url: %s "__meta_scaleway_instance_location_hypervisor_id": "1601", "__meta_scaleway_instance_location_node_id": "29", "__meta_scaleway_instance_name": "scw-nervous-shirley", - "__meta_scaleway_instance_organization": "cb334986-b054-4725-9d3a-40850fdc6015", + "__meta_scaleway_instance_organization_id": "cb334986-b054-4725-9d3a-40850fdc6015", "__meta_scaleway_instance_private_ipv4": "10.70.60.57", "__meta_scaleway_instance_project_id": "cb334986-b054-4725-9d5a-30850fdc6015", "__meta_scaleway_instance_public_ipv6": "2001:bc8:630:1e1c::1", @@ -97,7 +97,7 @@ api_url: %s "__meta_scaleway_instance_location_hypervisor_id": "201", "__meta_scaleway_instance_location_node_id": "5", "__meta_scaleway_instance_name": "scw-quizzical-feistel", - "__meta_scaleway_instance_organization": "cb334986-b054-4725-9d3a-40850fdc6015", + "__meta_scaleway_instance_organization_id": "cb334986-b054-4725-9d3a-40850fdc6015", "__meta_scaleway_instance_private_ipv4": "10.193.162.9", "__meta_scaleway_instance_project_id": "cb334986-b054-4725-9d5a-30850fdc6015", "__meta_scaleway_instance_public_ipv4": "151.115.45.127", diff --git a/docs/configuration/configuration.md b/docs/configuration/configuration.md index 30acedc85..3173279a2 100644 --- a/docs/configuration/configuration.md +++ b/docs/configuration/configuration.md @@ -1546,7 +1546,7 @@ The following meta labels are available on targets during [relabeling](#relabel_ * `__meta_scaleway_instance_location_hypervisor_id`: the hypervisor ID of the server location * `__meta_scaleway_instance_location_node_id`: the node ID of the server location * `__meta_scaleway_instance_name`: name of the server -* `__meta_scaleway_instance_organization`: the organization of the server +* `__meta_scaleway_instance_organization_id`: the organization of the server * `__meta_scaleway_instance_private_ipv4`: the private IPv4 address of the server * `__meta_scaleway_instance_project_id`: project id of the server * `__meta_scaleway_instance_public_ipv4`: the public IPv4 address of the server