Skip to content

Commit

Permalink
Fixes for Elastic Agent v2 changes (#9681) (#9682)
Browse files Browse the repository at this point in the history
* internal/beater: set fallback fleet.hosts

If fleet.hosts isn't set in ESS, assume Fleet Server
is co-located and use "https://localhost:8220".

* internal/beatcmd: improve logging on runner exit

If the runner exits prematurely, log the error;
don't wait for the runner to be reloaded before
logging the error.

(cherry picked from commit fc31a49)

Co-authored-by: Andrew Wilkins <[email protected]>
  • Loading branch information
mergify[bot] and axw authored Nov 28, 2022
1 parent 808638e commit 8631a49
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 10 deletions.
12 changes: 8 additions & 4 deletions internal/beatcmd/reloader.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,17 +201,21 @@ func (r *Reloader) reload(inputConfig, outputConfig *config.C) error {
// Start the new runner.
var g errgroup.Group
ctx, cancel := context.WithCancel(context.Background())
g.Go(func() error { return newRunner.Run(ctx) })
g.Go(func() error {
if err := newRunner.Run(ctx); err != nil && !errors.Is(err, context.Canceled) {
r.logger.With(logp.Error(err)).Error("runner returned with an error")
return err
}
return nil
})
stopRunner := func() error {
cancel()
return g.Wait()
}

// Stop any existing runner.
if r.runner != nil {
if err := r.stopRunner(); err != nil && !errors.Is(err, context.Canceled) {
r.logger.With(logp.Error(err)).Error("on reload, old runner stopped with an error")
}
_ = r.stopRunner() // logged above
}
r.runner = newRunner
r.stopRunner = stopRunner
Expand Down
19 changes: 13 additions & 6 deletions internal/beater/beater.go
Original file line number Diff line number Diff line change
Expand Up @@ -226,12 +226,19 @@ func (s *Runner) Run(ctx context.Context) error {

// ELASTIC_AGENT_CLOUD is set when running in Elastic Cloud.
inElasticCloud := os.Getenv("ELASTIC_AGENT_CLOUD") != ""
if inElasticCloud && s.config.Kibana.Enabled {
go func() {
if err := kibana.SendConfig(ctx, kibanaClient, (*ucfg.Config)(s.rawConfig)); err != nil {
s.logger.Infof("failed to upload config to kibana: %v", err)
}
}()
if inElasticCloud {
if s.config.Kibana.Enabled {
go func() {
if err := kibana.SendConfig(ctx, kibanaClient, (*ucfg.Config)(s.rawConfig)); err != nil {
s.logger.Infof("failed to upload config to kibana: %v", err)
}
}()
}

// BUG(axw) fleet.hosts isn't being sent to APM Server in ESS, so assume co-location.
if len(s.fleetConfig.Hosts) == 0 {
s.fleetConfig.Hosts = []string{"https://localhost:8220"}
}
}

if s.config.JavaAttacherConfig.Enabled {
Expand Down

0 comments on commit 8631a49

Please sign in to comment.