Skip to content

Commit

Permalink
Elastic-agent snapshot lookup will use proxy settings (#27904) (#27927)
Browse files Browse the repository at this point in the history
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 0ee910f)

Co-authored-by: Michel Laterman <[email protected]>
  • Loading branch information
mergify[bot] and michel-laterman authored Sep 14, 2021
1 parent e3b05c4 commit e9dd239
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
1 change: 1 addition & 0 deletions x-pack/elastic-agent/CHANGELOG.next.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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)
}
Expand All @@ -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") {
Expand All @@ -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
}
Expand Down

0 comments on commit e9dd239

Please sign in to comment.