diff --git a/x-pack/elastic-agent/CHANGELOG.asciidoc b/x-pack/elastic-agent/CHANGELOG.asciidoc index cc0d31f0f10..cbec5f316db 100644 --- a/x-pack/elastic-agent/CHANGELOG.asciidoc +++ b/x-pack/elastic-agent/CHANGELOG.asciidoc @@ -32,6 +32,7 @@ - Fix make sure the collected logs or metrics include streams information. {pull}18261[18261] - Fix version to 7.8 {pull}18286[18286] - Fix an issue where the checkin_frequency, jitter, and backoff options where not configurable. {pull}17843[17843] +- Stop monitoring on config change {pull}18284[18284] ==== New features diff --git a/x-pack/elastic-agent/pkg/agent/operation/monitoring.go b/x-pack/elastic-agent/pkg/agent/operation/monitoring.go index 5487dcddbf6..daa3b6d0d08 100644 --- a/x-pack/elastic-agent/pkg/agent/operation/monitoring.go +++ b/x-pack/elastic-agent/pkg/agent/operation/monitoring.go @@ -32,7 +32,7 @@ func (o *Operator) handleStartSidecar(s configrequest.Step) (result error) { o.isMonitoring = true - for _, step := range o.getMonitoringSteps(s) { + for _, step := range o.getMonitoringSteps(s, o.monitor.WatchLogs(), o.monitor.WatchMetrics()) { p, cfg, err := getProgramFromStepWithTags(step, o.config.DownloadConfig, monitoringTags()) if err != nil { return errors.New(err, @@ -57,7 +57,7 @@ func (o *Operator) handleStartSidecar(s configrequest.Step) (result error) { } func (o *Operator) handleStopSidecar(s configrequest.Step) (result error) { - for _, step := range o.getMonitoringSteps(s) { + for _, step := range o.getMonitoringSteps(s, true, true) { p, _, err := getProgramFromStepWithTags(step, o.config.DownloadConfig, monitoringTags()) if err != nil { return errors.New(err, @@ -66,6 +66,7 @@ func (o *Operator) handleStopSidecar(s configrequest.Step) (result error) { "operator.handleStopSidecar failed to create program") } + o.logger.Debugf("stopping program %v", p) if err := o.stop(p); err != nil { result = multierror.Append(err, err) } @@ -86,7 +87,7 @@ func monitoringTags() map[app.Tag]string { } } -func (o *Operator) getMonitoringSteps(step configrequest.Step) []configrequest.Step { +func (o *Operator) getMonitoringSteps(step configrequest.Step, watchLogs, watchMetrics bool) []configrequest.Step { // get output config, err := getConfigFromStep(step) if err != nil { @@ -112,13 +113,13 @@ func (o *Operator) getMonitoringSteps(step configrequest.Step) []configrequest.S return nil } - return o.generateMonitoringSteps(step.Version, output) + return o.generateMonitoringSteps(step.Version, output, watchLogs, watchMetrics) } -func (o *Operator) generateMonitoringSteps(version string, output interface{}) []configrequest.Step { +func (o *Operator) generateMonitoringSteps(version string, output interface{}, watchLogs, watchMetrics bool) []configrequest.Step { var steps []configrequest.Step - if o.monitor.WatchLogs() { + if watchLogs { fbConfig, any := o.getMonitoringFilebeatConfig(output) stepID := configrequest.StepRun if !any { @@ -136,7 +137,7 @@ func (o *Operator) generateMonitoringSteps(version string, output interface{}) [ steps = append(steps, filebeatStep) } - if o.monitor.WatchMetrics() { + if watchMetrics { mbConfig, any := o.getMonitoringMetricbeatConfig(output) stepID := configrequest.StepRun if !any { diff --git a/x-pack/elastic-agent/pkg/agent/operation/monitoring_test.go b/x-pack/elastic-agent/pkg/agent/operation/monitoring_test.go index 826e5bbd03d..e313a1a07b9 100644 --- a/x-pack/elastic-agent/pkg/agent/operation/monitoring_test.go +++ b/x-pack/elastic-agent/pkg/agent/operation/monitoring_test.go @@ -43,7 +43,7 @@ func TestGenerateSteps(t *testing.T) { t.Run(tc.Name, func(t *testing.T) { m := &testMonitor{monitorLogs: tc.Config.MonitorLogs, monitorMetrics: tc.Config.MonitorMetrics} operator, _ := getMonitorableTestOperator(t, "tests/scripts", m) - steps := operator.generateMonitoringSteps("8.0", sampleOutput) + steps := operator.generateMonitoringSteps("8.0", sampleOutput, tc.Config.MonitorLogs, tc.Config.MonitorMetrics) if actualSteps := len(steps); actualSteps != tc.ExpectedSteps { t.Fatalf("invalid number of steps, expected %v, got %v", tc.ExpectedSteps, actualSteps) } diff --git a/x-pack/elastic-agent/pkg/agent/operation/operator.go b/x-pack/elastic-agent/pkg/agent/operation/operator.go index 89734e38fe7..e8ce81f2c40 100644 --- a/x-pack/elastic-agent/pkg/agent/operation/operator.go +++ b/x-pack/elastic-agent/pkg/agent/operation/operator.go @@ -228,6 +228,7 @@ func (o *Operator) getApp(p Descriptor) (Application, error) { id := p.ID() + o.logger.Debugf("operator is looking for %s in app collection: %v", p.ID(), o.apps) if a, ok := o.apps[id]; ok { return a, nil } diff --git a/x-pack/elastic-agent/pkg/agent/operation/operator_handlers.go b/x-pack/elastic-agent/pkg/agent/operation/operator_handlers.go index 3e7d796f7a3..cab5d10bab1 100644 --- a/x-pack/elastic-agent/pkg/agent/operation/operator_handlers.go +++ b/x-pack/elastic-agent/pkg/agent/operation/operator_handlers.go @@ -42,6 +42,7 @@ func (o *Operator) handleRun(step configrequest.Step) error { } func (o *Operator) handleRemove(step configrequest.Step) error { + o.logger.Debugf("stopping process %s: %s", step.Process, step.ID) if step.Process == monitoringName { return o.handleStopSidecar(step) } diff --git a/x-pack/elastic-agent/pkg/core/plugin/app/configure.go b/x-pack/elastic-agent/pkg/core/plugin/app/configure.go index 84869f027b7..0613d53ba9b 100644 --- a/x-pack/elastic-agent/pkg/core/plugin/app/configure.go +++ b/x-pack/elastic-agent/pkg/core/plugin/app/configure.go @@ -68,6 +68,7 @@ func (a *Application) Configure(ctx context.Context, config map[string]interface return errors.New(ErrClientNotConfigurable, errors.TypeApplication) } + a.logger.Debugf("configuring application %s: %s", a.Name(), string(rawYaml)) err = configClient.Config(ctx, string(rawYaml)) if netErr, ok := err.(net.Error); ok && (netErr.Timeout() || netErr.Temporary()) {