Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/main'
Browse files Browse the repository at this point in the history
  • Loading branch information
ph committed Aug 1, 2022
2 parents d513cfc + 74ce2ba commit fd1a95a
Show file tree
Hide file tree
Showing 8 changed files with 344 additions and 17 deletions.
4 changes: 2 additions & 2 deletions NOTICE.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8227,11 +8227,11 @@ Contents of probable licence file $GOMODCACHE/github.com/docker/go-connections@v

--------------------------------------------------------------------------------
Dependency : github.com/elastic/go-structform
Version: v0.0.9
Version: v0.0.10
Licence type (autodetected): Apache-2.0
--------------------------------------------------------------------------------

Contents of probable licence file $GOMODCACHE/github.com/elastic/[email protected].9/LICENSE:
Contents of probable licence file $GOMODCACHE/github.com/elastic/[email protected].10/LICENSE:

Apache License
Version 2.0, January 2004
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ require (
github.com/docker/distribution v2.8.1+incompatible // indirect
github.com/docker/docker v20.10.12+incompatible // indirect
github.com/docker/go-connections v0.4.0 // indirect
github.com/elastic/go-structform v0.0.9 // indirect
github.com/elastic/go-structform v0.0.10 // indirect
github.com/elastic/go-windows v1.0.1 // indirect
github.com/elastic/gosigar v0.14.2 // indirect
github.com/evanphx/json-patch v4.12.0+incompatible // indirect
Expand Down
3 changes: 2 additions & 1 deletion go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -397,8 +397,9 @@ github.com/elastic/go-elasticsearch/v8 v8.0.0-20210317102009-a9d74cec0186/go.mod
github.com/elastic/go-licenser v0.3.1/go.mod h1:D8eNQk70FOCVBl3smCGQt/lv7meBeQno2eI1S5apiHQ=
github.com/elastic/go-licenser v0.4.0 h1:jLq6A5SilDS/Iz1ABRkO6BHy91B9jBora8FwGRsDqUI=
github.com/elastic/go-licenser v0.4.0/go.mod h1:V56wHMpmdURfibNBggaSBfqgPxyT1Tldns1i87iTEvU=
github.com/elastic/go-structform v0.0.9 h1:HpcS7xljL4kSyUfDJ8cXTJC6rU5ChL1wYb6cx3HLD+o=
github.com/elastic/go-structform v0.0.9/go.mod h1:CZWf9aIRYY5SuKSmOhtXScE5uQiLZNqAFnwKR4OrIM4=
github.com/elastic/go-structform v0.0.10 h1:oy08o/Ih2hHTkNcRY/1HhaYvIp5z6t8si8gnCJPDo1w=
github.com/elastic/go-structform v0.0.10/go.mod h1:CZWf9aIRYY5SuKSmOhtXScE5uQiLZNqAFnwKR4OrIM4=
github.com/elastic/go-sysinfo v1.1.1/go.mod h1:i1ZYdU10oLNfRzq4vq62BEwD2fH8KaWh6eh0ikPT9F0=
github.com/elastic/go-sysinfo v1.7.1 h1:Wx4DSARcKLllpKT2TnFVdSUJOsybqMYCNQZq1/wO+s0=
github.com/elastic/go-sysinfo v1.7.1/go.mod h1:i1ZYdU10oLNfRzq4vq62BEwD2fH8KaWh6eh0ikPT9F0=
Expand Down
4 changes: 3 additions & 1 deletion internal/pkg/agent/application/local_mode.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"github.com/elastic/elastic-agent/internal/pkg/agent/configuration"
"github.com/elastic/elastic-agent/internal/pkg/agent/errors"
"github.com/elastic/elastic-agent/internal/pkg/agent/operation"
"github.com/elastic/elastic-agent/internal/pkg/artifact"
"github.com/elastic/elastic-agent/internal/pkg/capabilities"
"github.com/elastic/elastic-agent/internal/pkg/composable"
"github.com/elastic/elastic-agent/internal/pkg/config"
Expand Down Expand Up @@ -131,6 +132,7 @@ func newLocal(
},
caps,
monitor,
artifact.NewReloader(cfg.Settings.DownloadConfig, log),
)
if err != nil {
return nil, err
Expand Down Expand Up @@ -203,7 +205,7 @@ func (l *Local) AgentInfo() *info.AgentInfo {
}

func discoverer(patterns ...string) discoverFunc {
var p []string
p := make([]string, 0, len(patterns))
for _, newP := range patterns {
if len(newP) == 0 {
continue
Expand Down
84 changes: 80 additions & 4 deletions internal/pkg/artifact/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"strings"
"time"

c "github.com/elastic/elastic-agent-libs/config"
"github.com/elastic/elastic-agent-libs/transport/httpcommon"
"github.com/elastic/elastic-agent/internal/pkg/agent/application/paths"
"github.com/elastic/elastic-agent/internal/pkg/agent/errors"
Expand Down Expand Up @@ -64,6 +65,42 @@ func NewReloader(cfg *Config, log *logger.Logger) *Reloader {
}

func (r *Reloader) Reload(rawConfig *config.Config) error {
if err := r.reloadConfig(rawConfig); err != nil {
return errors.New(err, "failed to reload config")
}

if err := r.reloadSourceURI(rawConfig); err != nil {
return errors.New(err, "failed to reload source URI")
}

return nil
}

func (r *Reloader) reloadConfig(rawConfig *config.Config) error {
type reloadConfig struct {
C *Config `json:"agent.download" config:"agent.download"`
}
tmp := &reloadConfig{
C: DefaultConfig(),
}
if err := rawConfig.Unpack(&tmp); err != nil {
return err
}

*(r.cfg) = Config{
OperatingSystem: tmp.C.OperatingSystem,
Architecture: tmp.C.Architecture,
SourceURI: tmp.C.SourceURI,
TargetDirectory: tmp.C.TargetDirectory,
InstallPath: tmp.C.InstallPath,
DropPath: tmp.C.DropPath,
HTTPTransportSettings: tmp.C.HTTPTransportSettings,
}

return nil
}

func (r *Reloader) reloadSourceURI(rawConfig *config.Config) error {
type reloadConfig struct {
// SourceURI: source of the artifacts, e.g https://artifacts.elastic.co/downloads/
SourceURI string `json:"agent.download.sourceURI" config:"agent.download.sourceURI"`
Expand All @@ -78,11 +115,11 @@ func (r *Reloader) Reload(rawConfig *config.Config) error {
}

var newSourceURI string
if cfg.FleetSourceURI != "" {
if fleetURI := strings.TrimSpace(cfg.FleetSourceURI); fleetURI != "" {
// fleet configuration takes precedence
newSourceURI = cfg.FleetSourceURI
} else if cfg.SourceURI != "" {
newSourceURI = cfg.SourceURI
newSourceURI = fleetURI
} else if sourceURI := strings.TrimSpace(cfg.SourceURI); sourceURI != "" {
newSourceURI = sourceURI
}

if newSourceURI != "" {
Expand Down Expand Up @@ -148,3 +185,42 @@ func (c *Config) Arch() string {
c.Architecture = arch
return c.Architecture
}

// Unpack reads a config object into the settings.
func (c *Config) Unpack(cfg *c.C) error {
tmp := struct {
OperatingSystem string `json:"-" config:",ignore"`
Architecture string `json:"-" config:",ignore"`
SourceURI string `json:"sourceURI" config:"sourceURI"`
TargetDirectory string `json:"targetDirectory" config:"target_directory"`
InstallPath string `yaml:"installPath" config:"install_path"`
DropPath string `yaml:"dropPath" config:"drop_path"`
}{
OperatingSystem: c.OperatingSystem,
Architecture: c.Architecture,
SourceURI: c.SourceURI,
TargetDirectory: c.TargetDirectory,
InstallPath: c.InstallPath,
DropPath: c.DropPath,
}

if err := cfg.Unpack(&tmp); err != nil {
return err
}

transport := DefaultConfig().HTTPTransportSettings
if err := cfg.Unpack(&transport); err != nil {
return err
}

*c = Config{
OperatingSystem: tmp.OperatingSystem,
Architecture: tmp.Architecture,
SourceURI: tmp.SourceURI,
TargetDirectory: tmp.TargetDirectory,
InstallPath: tmp.InstallPath,
DropPath: tmp.DropPath,
HTTPTransportSettings: transport,
}
return nil
}
Loading

0 comments on commit fd1a95a

Please sign in to comment.