From 7a67a728a852e4f76c9f7ca35ff9ba3b43333596 Mon Sep 17 00:00:00 2001 From: Julien Pivotto Date: Thu, 3 Nov 2022 15:04:19 +0100 Subject: [PATCH] Followup on OVHCloud merge (#11529) Signed-off-by: Julien Pivotto Signed-off-by: Julien Pivotto --- discovery/ovhcloud/dedicated_server.go | 34 ++++++------ discovery/ovhcloud/dedicated_server_test.go | 26 ++++----- discovery/ovhcloud/ovhcloud.go | 12 ++--- discovery/ovhcloud/vps.go | 45 ++++++++-------- discovery/ovhcloud/vps_test.go | 42 +++++++-------- docs/configuration/configuration.md | 58 ++++++++++----------- 6 files changed, 109 insertions(+), 108 deletions(-) diff --git a/discovery/ovhcloud/dedicated_server.go b/discovery/ovhcloud/dedicated_server.go index db205cc83..aeb4eccbb 100644 --- a/discovery/ovhcloud/dedicated_server.go +++ b/discovery/ovhcloud/dedicated_server.go @@ -32,9 +32,11 @@ import ( const ( dedicatedServerAPIPath = "/dedicated/server" - dedicatedServerLabelPrefix = metaLabelPrefix + "dedicatedServer_" + dedicatedServerLabelPrefix = metaLabelPrefix + "dedicated_server_" ) +// dedicatedServer struct from API. Also contains IP addresses that are fetched +// independently. type dedicatedServer struct { State string `json:"state"` ips []netip.Addr @@ -138,21 +140,21 @@ func (d *dedicatedServerDiscovery) refresh(ctx context.Context) ([]*targetgroup. defaultIP = ipv6 } labels := model.LabelSet{ - model.AddressLabel: model.LabelValue(defaultIP), - model.InstanceLabel: model.LabelValue(server.Name), - dedicatedServerLabelPrefix + "state": model.LabelValue(server.State), - dedicatedServerLabelPrefix + "commercialRange": model.LabelValue(server.CommercialRange), - dedicatedServerLabelPrefix + "linkSpeed": model.LabelValue(fmt.Sprintf("%d", server.LinkSpeed)), - dedicatedServerLabelPrefix + "rack": model.LabelValue(server.Rack), - dedicatedServerLabelPrefix + "noIntervention": model.LabelValue(strconv.FormatBool(server.NoIntervention)), - dedicatedServerLabelPrefix + "os": model.LabelValue(server.Os), - dedicatedServerLabelPrefix + "supportLevel": model.LabelValue(server.SupportLevel), - dedicatedServerLabelPrefix + "serverId": model.LabelValue(fmt.Sprintf("%d", server.ServerID)), - dedicatedServerLabelPrefix + "reverse": model.LabelValue(server.Reverse), - dedicatedServerLabelPrefix + "datacenter": model.LabelValue(server.Datacenter), - dedicatedServerLabelPrefix + "name": model.LabelValue(server.Name), - dedicatedServerLabelPrefix + "ipv4": model.LabelValue(ipv4), - dedicatedServerLabelPrefix + "ipv6": model.LabelValue(ipv6), + model.AddressLabel: model.LabelValue(defaultIP), + model.InstanceLabel: model.LabelValue(server.Name), + dedicatedServerLabelPrefix + "state": model.LabelValue(server.State), + dedicatedServerLabelPrefix + "commercial_range": model.LabelValue(server.CommercialRange), + dedicatedServerLabelPrefix + "link_speed": model.LabelValue(fmt.Sprintf("%d", server.LinkSpeed)), + dedicatedServerLabelPrefix + "rack": model.LabelValue(server.Rack), + dedicatedServerLabelPrefix + "no_intervention": model.LabelValue(strconv.FormatBool(server.NoIntervention)), + dedicatedServerLabelPrefix + "os": model.LabelValue(server.Os), + dedicatedServerLabelPrefix + "support_level": model.LabelValue(server.SupportLevel), + dedicatedServerLabelPrefix + "server_id": model.LabelValue(fmt.Sprintf("%d", server.ServerID)), + dedicatedServerLabelPrefix + "reverse": model.LabelValue(server.Reverse), + dedicatedServerLabelPrefix + "datacenter": model.LabelValue(server.Datacenter), + dedicatedServerLabelPrefix + "name": model.LabelValue(server.Name), + dedicatedServerLabelPrefix + "ipv4": model.LabelValue(ipv4), + dedicatedServerLabelPrefix + "ipv6": model.LabelValue(ipv6), } targets = append(targets, labels) } diff --git a/discovery/ovhcloud/dedicated_server_test.go b/discovery/ovhcloud/dedicated_server_test.go index 280cd2631..03a01005a 100644 --- a/discovery/ovhcloud/dedicated_server_test.go +++ b/discovery/ovhcloud/dedicated_server_test.go @@ -56,19 +56,19 @@ consumer_key: %s`, mock.URL, ovhcloudApplicationKeyTest, ovhcloudApplicationSecr for i, lbls := range []model.LabelSet{ { "__address__": "1.2.3.4", - "__meta_ovhcloud_dedicatedServer_commercialRange": "Advance-1 Gen 2", - "__meta_ovhcloud_dedicatedServer_datacenter": "gra3", - "__meta_ovhcloud_dedicatedServer_ipv4": "1.2.3.4", - "__meta_ovhcloud_dedicatedServer_ipv6": "", - "__meta_ovhcloud_dedicatedServer_linkSpeed": "123", - "__meta_ovhcloud_dedicatedServer_name": "abcde", - "__meta_ovhcloud_dedicatedServer_noIntervention": "false", - "__meta_ovhcloud_dedicatedServer_os": "debian11_64", - "__meta_ovhcloud_dedicatedServer_rack": "TESTRACK", - "__meta_ovhcloud_dedicatedServer_reverse": "abcde-rev", - "__meta_ovhcloud_dedicatedServer_serverId": "1234", - "__meta_ovhcloud_dedicatedServer_state": "test", - "__meta_ovhcloud_dedicatedServer_supportLevel": "pro", + "__meta_ovhcloud_dedicated_server_commercial_range": "Advance-1 Gen 2", + "__meta_ovhcloud_dedicated_server_datacenter": "gra3", + "__meta_ovhcloud_dedicated_server_ipv4": "1.2.3.4", + "__meta_ovhcloud_dedicated_server_ipv6": "", + "__meta_ovhcloud_dedicated_server_link_speed": "123", + "__meta_ovhcloud_dedicated_server_name": "abcde", + "__meta_ovhcloud_dedicated_server_no_intervention": "false", + "__meta_ovhcloud_dedicated_server_os": "debian11_64", + "__meta_ovhcloud_dedicated_server_rack": "TESTRACK", + "__meta_ovhcloud_dedicated_server_reverse": "abcde-rev", + "__meta_ovhcloud_dedicated_server_server_id": "1234", + "__meta_ovhcloud_dedicated_server_state": "test", + "__meta_ovhcloud_dedicated_server_support_level": "pro", "instance": "abcde", }, } { diff --git a/discovery/ovhcloud/ovhcloud.go b/discovery/ovhcloud/ovhcloud.go index 9ac857542..535ade4df 100644 --- a/discovery/ovhcloud/ovhcloud.go +++ b/discovery/ovhcloud/ovhcloud.go @@ -91,7 +91,7 @@ func createClient(config *SDConfig) (*ovh.Client, error) { return ovh.NewClient(config.Endpoint, config.ApplicationKey, string(config.ApplicationSecret), string(config.ConsumerKey)) } -// NewDiscoverer new discoverer +// NewDiscoverer returns a Discoverer for the Config. func (c *SDConfig) NewDiscoverer(options discovery.DiscovererOptions) (discovery.Discoverer, error) { return NewDiscovery(c, options.Logger) } @@ -102,7 +102,7 @@ func init() { // ParseIPList parses ip list as they can have different formats. func parseIPList(ipList []string) ([]netip.Addr, error) { - var IPs []netip.Addr + var ipAddresses []netip.Addr for _, ip := range ipList { ipAddr, err := netip.ParseAddr(ip) if err != nil { @@ -119,14 +119,14 @@ func parseIPList(ipList []string) ([]netip.Addr, error) { } } if ipAddr.IsValid() && !ipAddr.IsUnspecified() { - IPs = append(IPs, ipAddr) + ipAddresses = append(ipAddresses, ipAddr) } } - if len(IPs) < 1 { + if len(ipAddresses) == 0 { return nil, errors.New("could not parse IP addresses from list") } - return IPs, nil + return ipAddresses, nil } func newRefresher(conf *SDConfig, logger log.Logger) (refresher, error) { @@ -139,7 +139,7 @@ func newRefresher(conf *SDConfig, logger log.Logger) (refresher, error) { return nil, fmt.Errorf("unknown OVHcloud discovery service '%s'", conf.Service) } -// NewDiscovery returns a new Ovhcloud Discoverer which periodically refreshes its targets. +// NewDiscovery returns a new OVHcloud Discoverer which periodically refreshes its targets. func NewDiscovery(conf *SDConfig, logger log.Logger) (*refresh.Discovery, error) { r, err := newRefresher(conf, logger) if err != nil { diff --git a/discovery/ovhcloud/vps.go b/discovery/ovhcloud/vps.go index 414d0ac92..705b42b65 100644 --- a/discovery/ovhcloud/vps.go +++ b/discovery/ovhcloud/vps.go @@ -46,7 +46,8 @@ type vpsModel struct { Memory int `json:"memory"` } -// VPS struct from API. +// VPS struct from API. Also contains IP addresses that are fetched +// independently. type virtualPrivateServer struct { ips []netip.Addr Keymap []string `json:"keymap"` @@ -156,27 +157,27 @@ func (d *vpsDiscovery) refresh(ctx context.Context) ([]*targetgroup.Group, error defaultIP = ipv6 } labels := model.LabelSet{ - model.AddressLabel: model.LabelValue(defaultIP), - model.InstanceLabel: model.LabelValue(server.Name), - vpsLabelPrefix + "offer": model.LabelValue(server.Model.Offer), - vpsLabelPrefix + "datacenter": model.LabelValue(fmt.Sprintf("%+v", server.Model.Datacenter)), - vpsLabelPrefix + "model_vcore": model.LabelValue(fmt.Sprintf("%d", server.Model.Vcore)), - vpsLabelPrefix + "maximumAdditionalIp": model.LabelValue(fmt.Sprintf("%d", server.Model.MaximumAdditionalIP)), - vpsLabelPrefix + "version": model.LabelValue(server.Model.Version), - vpsLabelPrefix + "model_name": model.LabelValue(server.Model.Name), - vpsLabelPrefix + "disk": model.LabelValue(fmt.Sprintf("%d", server.Model.Disk)), - vpsLabelPrefix + "memory": model.LabelValue(fmt.Sprintf("%d", server.Model.Memory)), - vpsLabelPrefix + "zone": model.LabelValue(server.Zone), - vpsLabelPrefix + "displayName": model.LabelValue(server.DisplayName), - vpsLabelPrefix + "cluster": model.LabelValue(server.Cluster), - vpsLabelPrefix + "state": model.LabelValue(server.State), - vpsLabelPrefix + "name": model.LabelValue(server.Name), - vpsLabelPrefix + "netbootMode": model.LabelValue(server.NetbootMode), - vpsLabelPrefix + "memoryLimit": model.LabelValue(fmt.Sprintf("%d", server.MemoryLimit)), - vpsLabelPrefix + "offerType": model.LabelValue(server.OfferType), - vpsLabelPrefix + "vcore": model.LabelValue(fmt.Sprintf("%d", server.Vcore)), - vpsLabelPrefix + "ipv4": model.LabelValue(ipv4), - vpsLabelPrefix + "ipv6": model.LabelValue(ipv6), + model.AddressLabel: model.LabelValue(defaultIP), + model.InstanceLabel: model.LabelValue(server.Name), + vpsLabelPrefix + "offer": model.LabelValue(server.Model.Offer), + vpsLabelPrefix + "datacenter": model.LabelValue(fmt.Sprintf("%+v", server.Model.Datacenter)), + vpsLabelPrefix + "model_vcore": model.LabelValue(fmt.Sprintf("%d", server.Model.Vcore)), + vpsLabelPrefix + "maximum_additional_ip": model.LabelValue(fmt.Sprintf("%d", server.Model.MaximumAdditionalIP)), + vpsLabelPrefix + "version": model.LabelValue(server.Model.Version), + vpsLabelPrefix + "model_name": model.LabelValue(server.Model.Name), + vpsLabelPrefix + "disk": model.LabelValue(fmt.Sprintf("%d", server.Model.Disk)), + vpsLabelPrefix + "memory": model.LabelValue(fmt.Sprintf("%d", server.Model.Memory)), + vpsLabelPrefix + "zone": model.LabelValue(server.Zone), + vpsLabelPrefix + "display_name": model.LabelValue(server.DisplayName), + vpsLabelPrefix + "cluster": model.LabelValue(server.Cluster), + vpsLabelPrefix + "state": model.LabelValue(server.State), + vpsLabelPrefix + "name": model.LabelValue(server.Name), + vpsLabelPrefix + "netboot_mode": model.LabelValue(server.NetbootMode), + vpsLabelPrefix + "memory_limit": model.LabelValue(fmt.Sprintf("%d", server.MemoryLimit)), + vpsLabelPrefix + "offer_type": model.LabelValue(server.OfferType), + vpsLabelPrefix + "vcore": model.LabelValue(fmt.Sprintf("%d", server.Vcore)), + vpsLabelPrefix + "ipv4": model.LabelValue(ipv4), + vpsLabelPrefix + "ipv6": model.LabelValue(ipv6), } targets = append(targets, labels) diff --git a/discovery/ovhcloud/vps_test.go b/discovery/ovhcloud/vps_test.go index 3bbb42e33..31b30fdfc 100644 --- a/discovery/ovhcloud/vps_test.go +++ b/discovery/ovhcloud/vps_test.go @@ -56,27 +56,27 @@ consumer_key: %s`, mock.URL, ovhcloudApplicationKeyTest, ovhcloudApplicationSecr require.Equal(t, 1, len(targetGroup.Targets)) for i, lbls := range []model.LabelSet{ { - "__address__": "192.0.2.1", - "__meta_ovhcloud_vps_ipv4": "192.0.2.1", - "__meta_ovhcloud_vps_ipv6": "", - "__meta_ovhcloud_vps_cluster": "cluster_test", - "__meta_ovhcloud_vps_datacenter": "[]", - "__meta_ovhcloud_vps_disk": "40", - "__meta_ovhcloud_vps_displayName": "abc", - "__meta_ovhcloud_vps_maximumAdditionalIp": "16", - "__meta_ovhcloud_vps_memory": "2048", - "__meta_ovhcloud_vps_memoryLimit": "2048", - "__meta_ovhcloud_vps_model_name": "vps-value-1-2-40", - "__meta_ovhcloud_vps_name": "abc", - "__meta_ovhcloud_vps_netbootMode": "local", - "__meta_ovhcloud_vps_offer": "VPS abc", - "__meta_ovhcloud_vps_offerType": "ssd", - "__meta_ovhcloud_vps_state": "running", - "__meta_ovhcloud_vps_vcore": "1", - "__meta_ovhcloud_vps_model_vcore": "1", - "__meta_ovhcloud_vps_version": "2019v1", - "__meta_ovhcloud_vps_zone": "zone", - "instance": "abc", + "__address__": "192.0.2.1", + "__meta_ovhcloud_vps_ipv4": "192.0.2.1", + "__meta_ovhcloud_vps_ipv6": "", + "__meta_ovhcloud_vps_cluster": "cluster_test", + "__meta_ovhcloud_vps_datacenter": "[]", + "__meta_ovhcloud_vps_disk": "40", + "__meta_ovhcloud_vps_display_name": "abc", + "__meta_ovhcloud_vps_maximum_additional_ip": "16", + "__meta_ovhcloud_vps_memory": "2048", + "__meta_ovhcloud_vps_memory_limit": "2048", + "__meta_ovhcloud_vps_model_name": "vps-value-1-2-40", + "__meta_ovhcloud_vps_name": "abc", + "__meta_ovhcloud_vps_netboot_mode": "local", + "__meta_ovhcloud_vps_offer": "VPS abc", + "__meta_ovhcloud_vps_offer_type": "ssd", + "__meta_ovhcloud_vps_state": "running", + "__meta_ovhcloud_vps_vcore": "1", + "__meta_ovhcloud_vps_model_vcore": "1", + "__meta_ovhcloud_vps_version": "2019v1", + "__meta_ovhcloud_vps_zone": "zone", + "instance": "abc", }, } { t.Run(fmt.Sprintf("item %d", i), func(t *testing.T) { diff --git a/docs/configuration/configuration.md b/docs/configuration/configuration.md index 23de16fbf..de495eaec 100644 --- a/docs/configuration/configuration.md +++ b/docs/configuration/configuration.md @@ -1190,42 +1190,40 @@ For OVHcloud's [public cloud instances](https://www.ovhcloud.com/en/public-cloud #### VPS -* `__meta_ovhcloud_vps_ipv4`: the ipv4 of the server -* `__meta_ovhcloud_vps_ipv6`: the ipv6 of the server -* `__meta_ovhcloud_vps_keymap`: the KVM keyboard layout on VPS Cloud -* `__meta_ovhcloud_vps_zone`: the zone of the server -* `__meta_ovhcloud_vps_maximumAdditionalIp`: the maximumAdditionalIp of the server -* `__meta_ovhcloud_vps_offer`: the offer of the server -* `__meta_ovhcloud_vps_datacenter`: the datacenter of the server -* `__meta_ovhcloud_vps_vcore`: the vcore of the server -* `__meta_ovhcloud_vps_version`: the version of the server -* `__meta_ovhcloud_vps_name`: the name of the server -* `__meta_ovhcloud_vps_disk`: the disk of the server -* `__meta_ovhcloud_vps_memory`: the memory of the server -* `__meta_ovhcloud_vps_displayName`: the name displayed in ManagerV6 for your VPS -* `__meta_ovhcloud_vps_monitoringIpBlocks`: the Ip blocks for OVH monitoring servers * `__meta_ovhcloud_vps_cluster`: the cluster of the server -* `__meta_ovhcloud_vps_state`: the state of the server +* `__meta_ovhcloud_vps_datacenter`: the datacenter of the server +* `__meta_ovhcloud_vps_disk`: the disk of the server +* `__meta_ovhcloud_vps_display_name`: the display name of the server +* `__meta_ovhcloud_vps_ipv4`: the IPv4 of the server +* `__meta_ovhcloud_vps_ipv6`: the IPv6 of the server +* `__meta_ovhcloud_vps_keymap`: the KVM keyboard layout of the server +* `__meta_ovhcloud_vps_maximum_additional_ip`: the maximum additional IPs of the server +* `__meta_ovhcloud_vps_memory_limit`: the memory limit of the server +* `__meta_ovhcloud_vps_memory`: the memory of the server +* `__meta_ovhcloud_vps_monitoring_ip_blocks`: the monitoring IP blocks of the server * `__meta_ovhcloud_vps_name`: the name of the server -* `__meta_ovhcloud_vps_netbootMode`: the netbootMode of the server -* `__meta_ovhcloud_vps_memoryLimit`: the memoryLimit of the server -* `__meta_ovhcloud_vps_offerType`: the offerType of the server -* `__meta_ovhcloud_vps_vcore`: the vcore of the server +* `__meta_ovhcloud_vps_netboot_mode`: the netboot mode of the server +* `__meta_ovhcloud_vps_offer_type`: the offer type of the server +* `__meta_ovhcloud_vps_offer`: the offer of the server +* `__meta_ovhcloud_vps_state`: the state of the server +* `__meta_ovhcloud_vps_vcore`: the number of virtual cores of the server +* `__meta_ovhcloud_vps_version`: the version of the server +* `__meta_ovhcloud_vps_zone`: the zone of the server #### Dedicated servers -* `__meta_ovhcloud_dedicated_server_state`: the state of the server -* `__meta_ovhcloud_dedicated_server_ipv4`: the ipv4 of the server -* `__meta_ovhcloud_dedicated_server_ipv6`: the ipv6 of the server -* `__meta_ovhcloud_dedicated_server_commercialRange`: the dedicated server commercial range -* `__meta_ovhcloud_dedicated_server_linkSpeed`: the linkSpeed of the server +* `__meta_ovhcloud_dedicated_server_commercial_range`: the commercial range of the server +* `__meta_ovhcloud_dedicated_server_datacenter`: the datacenter of the server +* `__meta_ovhcloud_dedicated_server_ipv4`: the IPv4 of the server +* `__meta_ovhcloud_dedicated_server_ipv6`: the IPv6 of the server +* `__meta_ovhcloud_dedicated_server_link_speed`: the link speed of the server +* `__meta_ovhcloud_dedicated_server_name`: the name of the server +* `__meta_ovhcloud_dedicated_server_os`: the operating system of the server * `__meta_ovhcloud_dedicated_server_rack`: the rack of the server -* `__meta_ovhcloud_dedicated_server_os`: operating system -* `__meta_ovhcloud_dedicated_server_supportLevel`: the supportLevel of the server -* `__meta_ovhcloud_dedicated_server_serverId`: your server id -* `__meta_ovhcloud_dedicated_server_reverse`: dedicated server reverse -* `__meta_ovhcloud_dedicated_server_datacenter`: the dedicated datacenter localisation -* `__meta_ovhcloud_dedicated_server_name`: the dedicated server name +* `__meta_ovhcloud_dedicated_server_reverse`: the reverse DNS name of the server +* `__meta_ovhcloud_dedicated_server_server_id`: the ID of the server +* `__meta_ovhcloud_dedicated_server_state`: the state of the server +* `__meta_ovhcloud_dedicated_server_support_level`: the support level of the server See below for the configuration options for OVHcloud discovery: