From f8410a78782909ac495821b702f34db7390e2699 Mon Sep 17 00:00:00 2001 From: michel-laterman Date: Mon, 13 Sep 2021 14:54:19 -0700 Subject: [PATCH] Elastic-agent snapshot lookup will use proxy settings 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. --- 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 bb20b592edc..9bcda5fe195 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 }