-
Notifications
You must be signed in to change notification settings - Fork 145
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Elastic-Agent] Added source uri reloading #686
Merged
michalpristas
merged 11 commits into
elastic:main
from
michalpristas:feat/dynamic-source-uri
Jul 26, 2022
Merged
Changes from 10 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
f1d98a0
added source uri reloading
michalpristas 319bd63
typo
michalpristas 78cd614
typo
michalpristas 19082fc
typo
michalpristas 635f75b
typo
michalpristas 3b89b2b
use reloadable
michalpristas 48aa387
use reloadable
michalpristas 0649adf
use reloadable
michalpristas 5d08d67
fleet compatibility
michalpristas 10fa7b2
typo
michalpristas 58e2b4a
wrap error
michalpristas File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,12 +11,16 @@ import ( | |
|
||
"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/config" | ||
"github.com/elastic/elastic-agent/pkg/core/logger" | ||
) | ||
|
||
const ( | ||
darwin = "darwin" | ||
linux = "linux" | ||
windows = "windows" | ||
|
||
defaultSourceURI = "https://artifacts.elastic.co/downloads/" | ||
) | ||
|
||
// Config is a configuration used for verifier and downloader | ||
|
@@ -46,6 +50,52 @@ type Config struct { | |
httpcommon.HTTPTransportSettings `config:",inline" yaml:",inline"` // Note: use anonymous struct for json inline | ||
} | ||
|
||
type Reloader struct { | ||
log *logger.Logger | ||
cfg *Config | ||
} | ||
|
||
func NewReloader(cfg *Config, log *logger.Logger) *Reloader { | ||
return &Reloader{ | ||
cfg: cfg, | ||
log: log, | ||
} | ||
} | ||
|
||
func (r *Reloader) Reload(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"` | ||
|
||
// FleetSourceURI: source of the artifacts, e.g https://artifacts.elastic.co/downloads/ coming from fleet which uses | ||
// different naming. | ||
FleetSourceURI string `json:"agent.download.source_uri" config:"agent.download.source_uri"` | ||
} | ||
cfg := &reloadConfig{} | ||
if err := rawConfig.Unpack(&cfg); err != nil { | ||
return err | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [Suggestion] |
||
} | ||
|
||
var newSourceURI string | ||
if cfg.FleetSourceURI != "" { | ||
// fleet configuration takes precedence | ||
newSourceURI = cfg.FleetSourceURI | ||
} else if cfg.SourceURI != "" { | ||
newSourceURI = cfg.SourceURI | ||
} | ||
|
||
if newSourceURI != "" { | ||
r.log.Infof("Source URI changed from %q to %q", r.cfg.SourceURI, newSourceURI) | ||
r.cfg.SourceURI = newSourceURI | ||
} else { | ||
// source uri unset, reset to default | ||
r.log.Infof("Source URI reset from %q to %q", r.cfg.SourceURI, defaultSourceURI) | ||
r.cfg.SourceURI = defaultSourceURI | ||
} | ||
Comment on lines
+88
to
+95
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
|
||
return nil | ||
} | ||
|
||
// DefaultConfig creates a config with pre-set default values. | ||
func DefaultConfig() *Config { | ||
transport := httpcommon.DefaultHTTPTransportSettings() | ||
|
@@ -56,7 +106,7 @@ func DefaultConfig() *Config { | |
transport.Timeout = 10 * time.Minute | ||
|
||
return &Config{ | ||
SourceURI: "https://artifacts.elastic.co/downloads/", | ||
SourceURI: defaultSourceURI, | ||
TargetDirectory: paths.Downloads(), | ||
InstallPath: paths.Install(), | ||
HTTPTransportSettings: transport, | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍