diff --git a/CHANGELOG.md b/CHANGELOG.md index e532812bb40c..ab30936cc866 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -34,6 +34,8 @@ Main (unreleased) - Added links between compatible components in the documentation to make it easier to discover them. (@thampiotr) + +- Allow defining `HTTPClientConfig` for `discovery.ec2`. (@cmbrad) ### Bugfixes diff --git a/component/discovery/aws/ec2.go b/component/discovery/aws/ec2.go index 566527d2f67e..7672165e05e0 100644 --- a/component/discovery/aws/ec2.go +++ b/component/discovery/aws/ec2.go @@ -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" @@ -42,18 +43,21 @@ type EC2Arguments struct { RefreshInterval time.Duration `river:"refresh_interval,attr,optional"` Port int `river:"port,attr,optional"` Filters []*EC2Filter `river:"filter,block,optional"` + + HTTPClientConfig config.HTTPClientConfig `river:",squash"` } func (args EC2Arguments) Convert() *promaws.EC2SDConfig { cfg := &promaws.EC2SDConfig{ - 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(), } for _, f := range args.Filters { cfg.Filters = append(cfg.Filters, &promaws.EC2Filter{ diff --git a/component/discovery/aws/ec2_test.go b/component/discovery/aws/ec2_test.go new file mode 100644 index 000000000000..7696d750a4ff --- /dev/null +++ b/component/discovery/aws/ec2_test.go @@ -0,0 +1,29 @@ +package aws + +import ( + "net/url" + "testing" + + "github.com/grafana/agent/component/common/config" + "github.com/stretchr/testify/require" + "gotest.tools/assert" +) + +func TestConvert(t *testing.T) { + // parse example proxy + u, err := url.Parse("http://example:8080") + require.NoError(t, err) + httpClientConfig := config.DefaultHTTPClientConfig + httpClientConfig.ProxyURL = config.URL{URL: u} + + // example configuration + riverArgs := EC2Arguments{ + Region: "us-east-1", + HTTPClientConfig: httpClientConfig, + } + + // ensure values are set + promArgs := riverArgs.Convert() + assert.Equal(t, "us-east-1", promArgs.Region) + assert.Equal(t, "http://example:8080", promArgs.HTTPClientConfig.ProxyURL.String()) +} diff --git a/docs/sources/flow/reference/components/discovery.ec2.md b/docs/sources/flow/reference/components/discovery.ec2.md index 98f8b033b873..e2964d2df0a3 100644 --- a/docs/sources/flow/reference/components/discovery.ec2.md +++ b/docs/sources/flow/reference/components/discovery.ec2.md @@ -36,6 +36,9 @@ Name | Type | Description | Default | Required `role_arn` | `string` | AWS Role Amazon Resource Name (ARN), an alternative to using AWS API keys. | | no `refresh_interval` | `string` | Refresh interval to re-read the instance list. | 60s | no `port` | `int` | The port to scrape metrics from. If using the public IP address, this must instead be specified in the relabeling rule. | 80 | no +`proxy_url` | `string` | HTTP proxy to proxy requests through. | | no +`follow_redirects` | `bool` | Whether redirects returned by the server should be followed. | `true` | no +`enable_http2` | `bool` | Whether HTTP2 is supported for requests. | `true` | no ## Blocks