From 73c0d1e87752af347cdbf9c39b34b8859a0a90b0 Mon Sep 17 00:00:00 2001 From: Chris Bradley Date: Tue, 14 Nov 2023 21:54:09 +1100 Subject: [PATCH 1/3] Add HTTPClientConfig to discovery.ec2 and add a simple test --- CHANGELOG.md | 2 ++ component/discovery/aws/ec2.go | 20 ++++++++++++-------- component/discovery/aws/ec2_test.go | 29 +++++++++++++++++++++++++++++ 3 files changed, 43 insertions(+), 8 deletions(-) create mode 100644 component/discovery/aws/ec2_test.go diff --git a/CHANGELOG.md b/CHANGELOG.md index 92b37f905438..587f325129dd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -101,6 +101,8 @@ Main (unreleased) - Improved resilience of graph evaluation in presence of slow components. (@thampiotr) +- Allow overriding `HTTPClientConfig` fields such as `proxy_url` in `discovery.ec2`. (@cmbrad) + ### Bugfixes - Set exit code 1 on grafana-agentctl non-runnable command. (@fgouteroux) 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()) +} From 86a413b94ef716e1b22dc105ef679e45b20c6747 Mon Sep 17 00:00:00 2001 From: Chris Bradley Date: Wed, 15 Nov 2023 20:54:00 +1100 Subject: [PATCH 2/3] Update docs for HTTPClientConfig options --- docs/sources/flow/reference/components/discovery.ec2.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/docs/sources/flow/reference/components/discovery.ec2.md b/docs/sources/flow/reference/components/discovery.ec2.md index 63a4cfc802f4..7847f9bbec20 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 From 8f2563e4f492d432bebd3656f30ca82e91fddff4 Mon Sep 17 00:00:00 2001 From: Paschalis Tsilias Date: Fri, 8 Dec 2023 16:21:07 +0200 Subject: [PATCH 3/3] Bring back accidentally removed code Signed-off-by: Paschalis Tsilias --- CHANGELOG.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index d275707682b2..ab30936cc866 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -169,6 +169,12 @@ v0.38.0 (2023-11-21) - Improved resilience of graph evaluation in presence of slow components. (@thampiotr) +- Updated windows exporter to use prometheus-community/windows_exporter commit 1836cd1. (@mattdurham) + +- Allow agent to start with `module.git` config if cached before. (@hainenber) + +- Adds new optional config parameter `query_config` to `mssql` integration to allow for custom metrics (@StefanKurek) + ### Bugfixes - Set exit code 1 on grafana-agentctl non-runnable command. (@fgouteroux)