-
Notifications
You must be signed in to change notification settings - Fork 486
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove replace directive for golang.org/x/exp (#5972)
* Remove replace directive for golang.org/x/exp * Update pyroscope/ebpf from 0.4.0 to 0.4.1 * Fill in missing docs about HTTP client options. Fix missing defaults. Add an "unsupported" converter diagnostic for keep_dropped_targets. Add HTTP client options to AWS Lightsail SD. * Add discovery.ovhcloud * Add a converter for discovery.ovhcloud * Update cloudwatch_exporter docs * Fix converter tests * Mention Prometheus update in the changelog. --------- Co-authored-by: William Dumont <[email protected]>
- Loading branch information
Showing
59 changed files
with
822 additions
and
248 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
package ovhcloud | ||
|
||
import ( | ||
"fmt" | ||
"time" | ||
|
||
"github.com/grafana/agent/component" | ||
"github.com/grafana/agent/component/discovery" | ||
"github.com/grafana/river/rivertypes" | ||
"github.com/prometheus/common/config" | ||
"github.com/prometheus/common/model" | ||
prom_discovery "github.com/prometheus/prometheus/discovery/ovhcloud" | ||
) | ||
|
||
func init() { | ||
component.Register(component.Registration{ | ||
Name: "discovery.ovhcloud", | ||
Args: Arguments{}, | ||
Exports: discovery.Exports{}, | ||
|
||
Build: func(opts component.Options, args component.Arguments) (component.Component, error) { | ||
return New(opts, args.(Arguments)) | ||
}, | ||
}) | ||
} | ||
|
||
// Arguments configure the discovery.ovhcloud component. | ||
type Arguments struct { | ||
Endpoint string `river:"endpoint,attr,optional"` | ||
ApplicationKey string `river:"application_key,attr"` | ||
ApplicationSecret rivertypes.Secret `river:"application_secret,attr"` | ||
ConsumerKey rivertypes.Secret `river:"consumer_key,attr"` | ||
RefreshInterval time.Duration `river:"refresh_interval,attr,optional"` | ||
Service string `river:"service,attr"` | ||
} | ||
|
||
// DefaultArguments is used to initialize default values for Arguments. | ||
var DefaultArguments = Arguments{ | ||
Endpoint: "ovh-eu", | ||
RefreshInterval: 60 * time.Second, | ||
} | ||
|
||
// SetToDefault implements river.Defaulter. | ||
func (args *Arguments) SetToDefault() { | ||
*args = DefaultArguments | ||
} | ||
|
||
// Validate implements river.Validator. | ||
func (args *Arguments) Validate() error { | ||
if args.Endpoint == "" { | ||
return fmt.Errorf("endpoint cannot be empty") | ||
} | ||
|
||
if args.ApplicationKey == "" { | ||
return fmt.Errorf("application_key cannot be empty") | ||
} | ||
|
||
if args.ApplicationSecret == "" { | ||
return fmt.Errorf("application_secret cannot be empty") | ||
} | ||
|
||
if args.ConsumerKey == "" { | ||
return fmt.Errorf("consumer_key cannot be empty") | ||
} | ||
|
||
switch args.Service { | ||
case "dedicated_server", "vps": | ||
// Valid value - do nothing. | ||
default: | ||
return fmt.Errorf("unknown service: %v", args.Service) | ||
} | ||
|
||
return nil | ||
} | ||
|
||
// Convert returns the upstream configuration struct. | ||
func (args *Arguments) Convert() *prom_discovery.SDConfig { | ||
return &prom_discovery.SDConfig{ | ||
Endpoint: args.Endpoint, | ||
ApplicationKey: args.ApplicationKey, | ||
ApplicationSecret: config.Secret(args.ApplicationSecret), | ||
ConsumerKey: config.Secret(args.ConsumerKey), | ||
RefreshInterval: model.Duration(args.RefreshInterval), | ||
Service: args.Service, | ||
} | ||
} | ||
|
||
// New returns a new instance of a discovery.ovhcloud component. | ||
func New(opts component.Options, args Arguments) (*discovery.Component, error) { | ||
return discovery.New(opts, args, func(args component.Arguments) (discovery.Discoverer, error) { | ||
newArgs := args.(Arguments) | ||
return prom_discovery.NewDiscovery(newArgs.Convert(), opts.Logger) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,135 @@ | ||
package ovhcloud_test | ||
|
||
import ( | ||
"testing" | ||
"time" | ||
|
||
"github.com/grafana/agent/component/discovery/ovhcloud" | ||
"github.com/grafana/river" | ||
"github.com/prometheus/common/model" | ||
prom_ovh "github.com/prometheus/prometheus/discovery/ovhcloud" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestUnmarshal(t *testing.T) { | ||
tests := []struct { | ||
testName string | ||
cfg string | ||
expected *prom_ovh.SDConfig | ||
errorMsg string | ||
}{ | ||
{ | ||
testName: "defaults", | ||
cfg: ` | ||
application_key = "appkey" | ||
application_secret = "appsecret" | ||
consumer_key = "consumerkey" | ||
service = "dedicated_server" | ||
`, | ||
expected: &prom_ovh.SDConfig{ | ||
Endpoint: ovhcloud.DefaultArguments.Endpoint, | ||
ApplicationKey: "appkey", | ||
ApplicationSecret: "appsecret", | ||
ConsumerKey: "consumerkey", | ||
RefreshInterval: model.Duration(ovhcloud.DefaultArguments.RefreshInterval), | ||
Service: "dedicated_server", | ||
}, | ||
}, | ||
{ | ||
testName: "explicit", | ||
cfg: ` | ||
endpoint = "custom-endpoint" | ||
refresh_interval = "11m" | ||
application_key = "appkey" | ||
application_secret = "appsecret" | ||
consumer_key = "consumerkey" | ||
service = "vps" | ||
`, | ||
expected: &prom_ovh.SDConfig{ | ||
Endpoint: "custom-endpoint", | ||
ApplicationKey: "appkey", | ||
ApplicationSecret: "appsecret", | ||
ConsumerKey: "consumerkey", | ||
RefreshInterval: model.Duration(11 * time.Minute), | ||
Service: "vps", | ||
}, | ||
}, | ||
{ | ||
testName: "empty application key", | ||
cfg: ` | ||
endpoint = "custom-endpoint" | ||
refresh_interval = "11m" | ||
application_key = "" | ||
application_secret = "appsecret" | ||
consumer_key = "consumerkey" | ||
service = "vps" | ||
`, | ||
errorMsg: "application_key cannot be empty", | ||
}, | ||
{ | ||
testName: "empty application secret", | ||
cfg: ` | ||
endpoint = "custom-endpoint" | ||
refresh_interval = "11m" | ||
application_key = "appkey" | ||
application_secret = "" | ||
consumer_key = "consumerkey" | ||
service = "vps" | ||
`, | ||
errorMsg: "application_secret cannot be empty", | ||
}, | ||
{ | ||
testName: "empty consumer key", | ||
cfg: ` | ||
endpoint = "custom-endpoint" | ||
refresh_interval = "11m" | ||
application_key = "appkey" | ||
application_secret = "appsecret" | ||
consumer_key = "" | ||
service = "vps" | ||
`, | ||
errorMsg: "consumer_key cannot be empty", | ||
}, | ||
{ | ||
testName: "empty endpoint", | ||
cfg: ` | ||
endpoint = "" | ||
refresh_interval = "11m" | ||
application_key = "appkey" | ||
application_secret = "appsecret" | ||
consumer_key = "consumerkey" | ||
service = "vps" | ||
`, | ||
errorMsg: "endpoint cannot be empty", | ||
}, | ||
{ | ||
testName: "unknown service", | ||
cfg: ` | ||
endpoint = "custom-endpoint" | ||
refresh_interval = "11m" | ||
application_key = "appkey" | ||
application_secret = "appsecret" | ||
consumer_key = "consumerkey" | ||
service = "asdf" | ||
`, | ||
errorMsg: "unknown service: asdf", | ||
}, | ||
} | ||
|
||
for _, tc := range tests { | ||
t.Run(tc.testName, func(t *testing.T) { | ||
var args ovhcloud.Arguments | ||
err := river.Unmarshal([]byte(tc.cfg), &args) | ||
if tc.errorMsg != "" { | ||
require.ErrorContains(t, err, tc.errorMsg) | ||
return | ||
} | ||
|
||
require.NoError(t, err) | ||
|
||
promArgs := args.Convert() | ||
|
||
require.Equal(t, tc.expected, promArgs) | ||
}) | ||
} | ||
} |
Oops, something went wrong.