Skip to content

Commit

Permalink
Remove replace directive for golang.org/x/exp (#5972)
Browse files Browse the repository at this point in the history
* 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
ptodev and wildum authored Jan 5, 2024
1 parent 35b8039 commit 404423b
Show file tree
Hide file tree
Showing 59 changed files with 822 additions and 248 deletions.
11 changes: 10 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ Main (unreleased)
- This change will not break any existing configurations and you can opt in to validation via the `validate_dimensions` configuration option.
- Before this change, pulling metrics for azure resources with variable dimensions required one configuration per metric + dimension combination to avoid an error.
- After this change, you can include all metrics and dimensions in a single configuration and the Azure APIs will only return dimensions which are valid for the various metrics.

### Features

- A new `discovery.ovhcloud` component for discovering scrape targets on OVHcloud. (@ptodev)

### Enhancements

Expand Down Expand Up @@ -77,6 +81,7 @@ Main (unreleased)
- Add `max_cache_size` to `prometheus.relabel` to allow configurability instead of hard coded 100,000. (@mattdurham)

- Add support for `http_sd_config` within a `scrape_config` for prometheus to flow config conversion. (@erikbaranowski)
- `discovery.lightsail` now supports additional parameters for configuring HTTP client settings. (@ptodev)

### Bugfixes

Expand All @@ -100,7 +105,11 @@ Main (unreleased)

- Bump github.com/IBM/sarama from v1.41.2 to v1.42.1

- Attatch unique Agent ID header to remote-write requests. (@captncraig)
- Attach unique Agent ID header to remote-write requests. (@captncraig)

- Update to v2.48.1 of `github.com/prometheus/prometheus`.
Previously, a custom fork of v2.47.2 was used.
The custom fork of v2.47.2 also contained prometheus#12729 and prometheus#12677.

v0.38.1 (2023-11-30)
--------------------
Expand Down
1 change: 1 addition & 0 deletions component/all/all.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
_ "github.com/grafana/agent/component/discovery/nerve" // Import discovery.nerve
_ "github.com/grafana/agent/component/discovery/nomad" // Import discovery.nomad
_ "github.com/grafana/agent/component/discovery/openstack" // Import discovery.openstack
_ "github.com/grafana/agent/component/discovery/ovhcloud" // Import discovery.ovhcloud
_ "github.com/grafana/agent/component/discovery/puppetdb" // Import discovery.puppetdb
_ "github.com/grafana/agent/component/discovery/relabel" // Import discovery.relabel
_ "github.com/grafana/agent/component/discovery/scaleway" // Import discovery.scaleway
Expand Down
5 changes: 3 additions & 2 deletions component/discovery/aws/ec2.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,9 @@ func (args EC2Arguments) Convert() *promaws.EC2SDConfig {
}

var DefaultEC2SDConfig = EC2Arguments{
Port: 80,
RefreshInterval: 60 * time.Second,
Port: 80,
RefreshInterval: 60 * time.Second,
HTTPClientConfig: config.DefaultHTTPClientConfig,
}

// SetToDefault implements river.Defaulter.
Expand Down
40 changes: 22 additions & 18 deletions component/discovery/aws/lightsail.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"github.com/aws/aws-sdk-go/aws/ec2metadata"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/grafana/agent/component"
"github.com/grafana/agent/component/common/config"
"github.com/grafana/agent/component/discovery"
"github.com/grafana/river/rivertypes"
promcfg "github.com/prometheus/common/config"
Expand All @@ -27,34 +28,37 @@ func init() {

// LightsailArguments is the configuration for AWS Lightsail based service discovery.
type LightsailArguments struct {
Endpoint string `river:"endpoint,attr,optional"`
Region string `river:"region,attr,optional"`
AccessKey string `river:"access_key,attr,optional"`
SecretKey rivertypes.Secret `river:"secret_key,attr,optional"`
Profile string `river:"profile,attr,optional"`
RoleARN string `river:"role_arn,attr,optional"`
RefreshInterval time.Duration `river:"refresh_interval,attr,optional"`
Port int `river:"port,attr,optional"`
Endpoint string `river:"endpoint,attr,optional"`
Region string `river:"region,attr,optional"`
AccessKey string `river:"access_key,attr,optional"`
SecretKey rivertypes.Secret `river:"secret_key,attr,optional"`
Profile string `river:"profile,attr,optional"`
RoleARN string `river:"role_arn,attr,optional"`
RefreshInterval time.Duration `river:"refresh_interval,attr,optional"`
Port int `river:"port,attr,optional"`
HTTPClientConfig config.HTTPClientConfig `river:",squash"`
}

func (args LightsailArguments) Convert() *promaws.LightsailSDConfig {
cfg := &promaws.LightsailSDConfig{
Endpoint: args.Endpoint,
Region: args.Region,
AccessKey: args.AccessKey,
SecretKey: promcfg.Secret(args.SecretKey),
Profile: args.Profile,
RoleARN: args.RoleARN,
RefreshInterval: model.Duration(args.RefreshInterval),
Port: args.Port,
Endpoint: args.Endpoint,
Region: args.Region,
AccessKey: args.AccessKey,
SecretKey: promcfg.Secret(args.SecretKey),
Profile: args.Profile,
RoleARN: args.RoleARN,
RefreshInterval: model.Duration(args.RefreshInterval),
Port: args.Port,
HTTPClientConfig: *args.HTTPClientConfig.Convert(),
}
return cfg
}

// DefaultLightsailSDConfig is the default Lightsail SD configuration.
var DefaultLightsailSDConfig = LightsailArguments{
Port: 80,
RefreshInterval: 60 * time.Second,
Port: 80,
RefreshInterval: 60 * time.Second,
HTTPClientConfig: config.DefaultHTTPClientConfig,
}

// SetToDefault implements river.Defaulter.
Expand Down
2 changes: 2 additions & 0 deletions component/discovery/azure/azure.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ var DefaultArguments = Arguments{
Environment: azure.PublicCloud.Name,
Port: 80,
RefreshInterval: 5 * time.Minute,
FollowRedirects: true,
EnableHTTP2: true,
}

// SetToDefault implements river.Defaulter.
Expand Down
11 changes: 6 additions & 5 deletions component/discovery/consul/consul.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,12 @@ type Arguments struct {
}

var DefaultArguments = Arguments{
Server: "localhost:8500",
TagSeparator: ",",
Scheme: "http",
AllowStale: true,
RefreshInterval: 30 * time.Second,
Server: "localhost:8500",
TagSeparator: ",",
Scheme: "http",
AllowStale: true,
RefreshInterval: 30 * time.Second,
HTTPClientConfig: config.DefaultHTTPClientConfig,
}

// SetToDefault implements river.Defaulter.
Expand Down
2 changes: 2 additions & 0 deletions component/discovery/digitalocean/digitalocean.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ type Arguments struct {
var DefaultArguments = Arguments{
Port: 80,
RefreshInterval: time.Minute,
FollowRedirects: true,
EnableHTTP2: true,
}

// SetToDefault implements river.Defaulter.
Expand Down
94 changes: 94 additions & 0 deletions component/discovery/ovhcloud/ovhcloud.go
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)
})
}
135 changes: 135 additions & 0 deletions component/discovery/ovhcloud/ovhcloud_test.go
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)
})
}
}
Loading

0 comments on commit 404423b

Please sign in to comment.