From e9dd23941534f4fec2265f18013bfc6e0d0fca32 Mon Sep 17 00:00:00 2001 From: "mergify[bot]" <37929162+mergify[bot]@users.noreply.github.com> Date: Tue, 14 Sep 2021 15:44:19 -0700 Subject: [PATCH] Elastic-agent snapshot lookup will use proxy settings (#27904) (#27927) Change the HTTP client from the standard library client to one built from the http settings supplied to the artifact downloader (`agent.download` in fleet.yml) so that proxy settings are used for the initial request to find the artifact location as well as the subsequent download. (cherry picked from commit 0ee910f4df6653dc9557090946b392533621c2a3) Co-authored-by: Michel Laterman <82832767+michel-laterman@users.noreply.github.com> --- x-pack/elastic-agent/CHANGELOG.next.asciidoc | 1 + .../pkg/artifact/download/snapshot/downloader.go | 13 +++++++++---- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/x-pack/elastic-agent/CHANGELOG.next.asciidoc b/x-pack/elastic-agent/CHANGELOG.next.asciidoc index 5672a680ee4..392179b29c8 100644 --- a/x-pack/elastic-agent/CHANGELOG.next.asciidoc +++ b/x-pack/elastic-agent/CHANGELOG.next.asciidoc @@ -86,6 +86,7 @@ - Migrate state on upgrade {pull}27825[27825] - Add "_monitoring" suffix to monitoring instance names to remove ambiguity with the status command. {issue}25449[25449] - Ignore ErrNotExists when fixing permissions. {issue}27836[27836] {pull}27846[27846] +- Snapshot artifact lookup will use agent.download proxy settings. {issue}27903[27903] {pull}27904[27904] ==== New features diff --git a/x-pack/elastic-agent/pkg/artifact/download/snapshot/downloader.go b/x-pack/elastic-agent/pkg/artifact/download/snapshot/downloader.go index acf6b32328f..a08295ba49b 100644 --- a/x-pack/elastic-agent/pkg/artifact/download/snapshot/downloader.go +++ b/x-pack/elastic-agent/pkg/artifact/download/snapshot/downloader.go @@ -7,9 +7,9 @@ package snapshot import ( "encoding/json" "fmt" - gohttp "net/http" "strings" + "github.com/elastic/beats/v7/libbeat/common/transport/httpcommon" "github.com/elastic/beats/v7/x-pack/elastic-agent/pkg/artifact" "github.com/elastic/beats/v7/x-pack/elastic-agent/pkg/artifact/download" "github.com/elastic/beats/v7/x-pack/elastic-agent/pkg/artifact/download/http" @@ -27,7 +27,7 @@ func NewDownloader(config *artifact.Config, versionOverride string) (download.Do } func snapshotConfig(config *artifact.Config, versionOverride string) (*artifact.Config, error) { - snapshotURI, err := snapshotURI(versionOverride) + snapshotURI, err := snapshotURI(versionOverride, config) if err != nil { return nil, fmt.Errorf("failed to detect remote snapshot repo, proceeding with configured: %v", err) } @@ -43,7 +43,7 @@ func snapshotConfig(config *artifact.Config, versionOverride string) (*artifact. }, nil } -func snapshotURI(versionOverride string) (string, error) { +func snapshotURI(versionOverride string, config *artifact.Config) (string, error) { version := release.Version() if versionOverride != "" { if strings.HasSuffix(versionOverride, "-SNAPSHOT") { @@ -52,8 +52,13 @@ func snapshotURI(versionOverride string) (string, error) { version = versionOverride } + client, err := config.HTTPTransportSettings.Client(httpcommon.WithAPMHTTPInstrumentation()) + if err != nil { + return "", err + } + artifactsURI := fmt.Sprintf("https://artifacts-api.elastic.co/v1/search/%s-SNAPSHOT/elastic-agent", version) - resp, err := gohttp.Get(artifactsURI) + resp, err := client.Get(artifactsURI) if err != nil { return "", err }