discovery/vultr: upgrade govultr from v2 to v3 (#18347)

* discovery/vultr: upgrade govultr from v2 to v3

The govultr/v2 library is no longer actively maintained. Upgrade to
govultr/v3 (v3.28.1) which receives regular updates and security
patches.

The v3 library is API-compatible with v2 for the Instance.List
method used by the Vultr SD, with the only change being an
additional *http.Response return value.

Signed-off-by: Pierluigi Lenoci <pierluigi.lenoci@gmail.com>

* discovery/vultr: check HTTP response status code

Validate that the Vultr API returns a 2xx status code after listing
instances, as the *http.Response from govultr v3 is now available.

Signed-off-by: Pierluigi Lenoci <pierluigi.lenoci@gmail.com>

* discovery/vultr: fix linter error in error string capitalization

Error strings should not be capitalized per Go conventions (ST1005).

Signed-off-by: Pierluigi Lenoci <pierluigi.lenoci@gmail.com>

---------

Signed-off-by: Pierluigi Lenoci <pierluigi.lenoci@gmail.com>
This commit is contained in:
Pierluigi Lenoci
2026-03-26 09:42:25 +01:00
committed by GitHub
parent dd19e08663
commit 73902efbd0
3 changed files with 12 additions and 8 deletions

View File

@@ -16,6 +16,7 @@ package vultr
import (
"context"
"errors"
"fmt"
"net"
"net/http"
"strconv"
@@ -26,7 +27,7 @@ import (
"github.com/prometheus/common/config"
"github.com/prometheus/common/model"
"github.com/prometheus/common/version"
"github.com/vultr/govultr/v2"
"github.com/vultr/govultr/v3"
"github.com/prometheus/prometheus/discovery"
"github.com/prometheus/prometheus/discovery/refresh"
@@ -206,10 +207,13 @@ func (d *Discovery) listInstances(ctx context.Context) ([]govultr.Instance, erro
}
for {
pagedInstances, meta, err := d.client.Instance.List(ctx, listOptions)
pagedInstances, meta, resp, err := d.client.Instance.List(ctx, listOptions)
if err != nil {
return nil, err
}
if resp != nil && resp.StatusCode/100 != 2 {
return nil, fmt.Errorf("vultr API returned unexpected status %d", resp.StatusCode)
}
instances = append(instances, pagedInstances...)
if meta.Links.Next == "" {

4
go.mod
View File

@@ -72,7 +72,7 @@ require (
github.com/shurcooL/httpfs v0.0.0-20230704072500-f1e31cf0ba5c
github.com/stackitcloud/stackit-sdk-go/core v0.21.1
github.com/stretchr/testify v1.11.1
github.com/vultr/govultr/v2 v2.17.2
github.com/vultr/govultr/v3 v3.28.1
go.opentelemetry.io/collector/component v1.51.0
go.opentelemetry.io/collector/consumer v1.51.0
go.opentelemetry.io/collector/pdata v1.51.0
@@ -193,7 +193,7 @@ require (
github.com/hashicorp/go-hclog v1.6.3 // indirect
github.com/hashicorp/go-immutable-radix v1.3.1 // indirect
github.com/hashicorp/go-multierror v1.1.1 // indirect
github.com/hashicorp/go-retryablehttp v0.7.7 // indirect
github.com/hashicorp/go-retryablehttp v0.7.8 // indirect
github.com/hashicorp/go-rootcerts v1.0.2 // indirect
github.com/hashicorp/go-version v1.8.0 // indirect
github.com/hashicorp/golang-lru v0.6.0 // indirect

8
go.sum
View File

@@ -311,8 +311,8 @@ github.com/hashicorp/go-multierror v1.1.0/go.mod h1:spPvp8C1qA32ftKqdAHm4hHTbPw+
github.com/hashicorp/go-multierror v1.1.1 h1:H5DkEtf6CXdFp0N0Em5UCwQpXMWke8IA0+lD48awMYo=
github.com/hashicorp/go-multierror v1.1.1/go.mod h1:iw975J/qwKPdAO1clOe2L8331t/9/fmwbPZ6JB6eMoM=
github.com/hashicorp/go-retryablehttp v0.5.3/go.mod h1:9B5zBasrRhHXnJnui7y6sL7es7NDiJgTc6Er0maI1Xs=
github.com/hashicorp/go-retryablehttp v0.7.7 h1:C8hUCYzor8PIfXHa4UrZkU4VvK8o9ISHxT2Q8+VepXU=
github.com/hashicorp/go-retryablehttp v0.7.7/go.mod h1:pkQpWZeYWskR+D1tR2O5OcBFOxfA7DoAO6xtkuQnHTk=
github.com/hashicorp/go-retryablehttp v0.7.8 h1:ylXZWnqa7Lhqpk0L1P1LzDtGcCR0rPVUrx/c8Unxc48=
github.com/hashicorp/go-retryablehttp v0.7.8/go.mod h1:rjiScheydd+CxvumBsIrFKlx3iS0jrZ7LvzFGFmuKbw=
github.com/hashicorp/go-rootcerts v1.0.2 h1:jzhAVGtqPKbwpyCPELlgNWhE1znq+qwJtW5Oi2viEzc=
github.com/hashicorp/go-rootcerts v1.0.2/go.mod h1:pqUvnprVnM5bf7AOirdbb01K4ccR319Vf4pU3K5EGc8=
github.com/hashicorp/go-sockaddr v1.0.0/go.mod h1:7Xibr9yA9JjQq1JpNB2Vw7kxv8xerXegt+ozgdvDeDU=
@@ -567,8 +567,8 @@ github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8
github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U=
github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U=
github.com/tv42/httpunix v0.0.0-20150427012821-b75d8614f926/go.mod h1:9ESjWnEqriFuLhtthL60Sar/7RFoluCcXsuvEwTV5KM=
github.com/vultr/govultr/v2 v2.17.2 h1:gej/rwr91Puc/tgh+j33p/BLR16UrIPnSr+AIwYWZQs=
github.com/vultr/govultr/v2 v2.17.2/go.mod h1:ZFOKGWmgjytfyjeyAdhQlSWwTjh2ig+X49cAp50dzXI=
github.com/vultr/govultr/v3 v3.28.1 h1:KR3LhppYARlBujY7+dcrE7YKL0Yo9qXL+msxykKQrLI=
github.com/vultr/govultr/v3 v3.28.1/go.mod h1:2zyUw9yADQaGwKnwDesmIOlBNLrm7edsCfWHFJpWKf8=
github.com/x448/float16 v0.8.4 h1:qLwI1I70+NjRFUR3zs1JPUCgaCXSh3SW62uAKT1mSBM=
github.com/x448/float16 v0.8.4/go.mod h1:14CWIYCyZA/cWjXOioeEpHeN/83MdbZDRQHoFcYsOfg=
github.com/xhit/go-str2duration/v2 v2.1.0 h1:lxklc02Drh6ynqX+DdPyp5pCKLUQpRT8bp8Ydu2Bstc=