diff --git a/changelog/fragments/1666611696-fix_service_stop_timeout.yaml b/changelog/fragments/1666611696-fix_service_stop_timeout.yaml new file mode 100644 index 00000000000..5125282618f --- /dev/null +++ b/changelog/fragments/1666611696-fix_service_stop_timeout.yaml @@ -0,0 +1,4 @@ +kind: bug-fix +summary: "Fix: Windows Agent Left Unhealthy After Removing Endpoint Integration" +pr: 1286 +issue: 1262 diff --git a/internal/pkg/agent/operation/monitoring.go b/internal/pkg/agent/operation/monitoring.go index f28c681e42a..d3f120da677 100644 --- a/internal/pkg/agent/operation/monitoring.go +++ b/internal/pkg/agent/operation/monitoring.go @@ -373,6 +373,7 @@ func (o *Operator) getMonitoringMetricbeatConfig(outputType string, output inter if len(hosts) == 0 { return nil, false } + //nolint:prealloc // false positive var modules []interface{} fixedAgentName := strings.ReplaceAll(agentName, "-", "_") @@ -668,7 +669,7 @@ func normalizeHTTPCopyRules(name string) []map[string]interface{} { return fromToMap } - for _, exportedMetric := range spec.ExprtedMetrics { + for _, exportedMetric := range spec.ExportedMetrics { fromToMap = append(fromToMap, map[string]interface{}{ "from": fmt.Sprintf("http.agent.%s", exportedMetric), "to": exportedMetric, diff --git a/internal/pkg/agent/operation/monitoring_test.go b/internal/pkg/agent/operation/monitoring_test.go index 06a9cfbe23b..55b18741dad 100644 --- a/internal/pkg/agent/operation/monitoring_test.go +++ b/internal/pkg/agent/operation/monitoring_test.go @@ -37,7 +37,7 @@ import ( func TestExportedMetrics(t *testing.T) { programName := "testing" expectedMetricsName := "metric_name" - program.SupportedMap[programName] = program.Spec{ExprtedMetrics: []string{expectedMetricsName}} + program.SupportedMap[programName] = program.Spec{ExportedMetrics: []string{expectedMetricsName}} exportedMetrics := normalizeHTTPCopyRules(programName) diff --git a/internal/pkg/agent/program/spec.go b/internal/pkg/agent/program/spec.go index 12f860a1e9a..41cf966aaed 100644 --- a/internal/pkg/agent/program/spec.go +++ b/internal/pkg/agent/program/spec.go @@ -8,6 +8,7 @@ import ( "fmt" "io/ioutil" "path/filepath" + "time" "gopkg.in/yaml.v2" @@ -40,7 +41,20 @@ type Spec struct { When string `yaml:"when"` Constraints string `yaml:"constraints"` RestartOnOutputChange bool `yaml:"restart_on_output_change,omitempty"` - ExprtedMetrics []string `yaml:"exported_metrics,omitempty"` + ExportedMetrics []string `yaml:"exported_metrics,omitempty"` + Process *ProcessSettings `yaml:"process,omitempty"` +} + +// ProcessSettings process specific settings +type ProcessSettings struct { + // Allows to override the agent stop timeout settings and specify a different stop timeout for Endpoint service + StopTimeout time.Duration `yaml:"stop_timeout"` +} + +// Service info +type ServiceInfo struct { + Name string `yaml:"name"` + Label string `yaml:"label"` } // ReadSpecs reads all the specs that match the provided globbing path. diff --git a/internal/pkg/agent/program/spec_test.go b/internal/pkg/agent/program/spec_test.go index 110dd92eb36..31985d3d6d7 100644 --- a/internal/pkg/agent/program/spec_test.go +++ b/internal/pkg/agent/program/spec_test.go @@ -5,13 +5,16 @@ package program import ( + "fmt" "io/ioutil" "os" "path/filepath" "regexp" "strings" "testing" + "time" + "github.com/google/go-cmp/cmp" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "gopkg.in/yaml.v2" @@ -147,3 +150,44 @@ func TestExport(t *testing.T) { require.NoError(t, err) } } + +func TestSerializationProcessSettings(t *testing.T) { + ymlTmpl := `name: "Foobar" +process: + stop_timeout: %v` + + tests := []struct { + name string + tonum int + to time.Duration + }{ + {"zero", 0, 0}, + {"180ns", 180, 0}, + {"180s", 0, 120 * time.Second}, + {"3m", 0, 3 * time.Minute}, + } + for _, tc := range tests { + t.Run(tc.name, func(t *testing.T) { + var ( + yml string + wantTimeout time.Duration + ) + if tc.to == 0 { + yml = fmt.Sprintf(ymlTmpl, tc.tonum) + wantTimeout = time.Duration(tc.tonum) + } else { + yml = fmt.Sprintf(ymlTmpl, tc.to) + wantTimeout = tc.to + } + var spec Spec + err := yaml.Unmarshal([]byte(yml), &spec) + if err != nil { + t.Fatal(err) + } + diff := cmp.Diff(wantTimeout, spec.Process.StopTimeout) + if diff != "" { + t.Fatal(diff) + } + }) + } +} diff --git a/internal/pkg/agent/program/supported.go b/internal/pkg/agent/program/supported.go index 52685137b97..0938fbff351 100644 --- a/internal/pkg/agent/program/supported.go +++ b/internal/pkg/agent/program/supported.go @@ -27,7 +27,7 @@ func init() { // internal/spec/metricbeat.yml // internal/spec/osquerybeat.yml // internal/spec/packetbeat.yml - unpacked := packer.MustUnpack("eJzce1mTo0h39v33M+b2s/2ylGoaR7wXgmo2qagRapGQd2SmCiQlSFMCSeDwf3dksggQqqVnPB77oiK6U5DLybM85zmH//hlk2brtzSk/zge1vgf4SH51+P67bR++7ciob/8+y8o0TP4Yx8tPNWZew7FKaQ4OmwRWDxahn5GS7GEvi1B35oFvi2EAMaBPPpbist9BM77yNKszF1aR0uzswBMYih5GQQTYZ54eQDsIwQLhZi2CJfWUdtMI2sj6tbmHFkJ2fqySnHiUJQuFNvM1NV38Yfr2cD17FdXUMxFub88P6mKFR2IlngP2FAKYng7XxIpMe1DID8/WvpxZmnTTeCr2dyvz7SxjhoVZjj1jtB/fmTrzpfqFsnqxJfdky9dDlhe8HFLm0aWQQUIhEfLgEcIPKEdN93Ty0Y9oFQVifk842PaNELS5DWQlBwml0Mln8kJyVP2e2YZYoyf9u2z2NCF8GkfweRCob+4jnf21ozNl2oBgXgiifcaSt7kJdq3v1V/6hv0d+w+toHklVhUYmxQ/uxPzWPatJIpzeG5+4wQ4cTLkAypL2V0/eN6nuaPz7tR2X3nZLrn78CEPviyI+DEi9GPfbSWhVom8IBMl2KqSAG4iL1zmw5FhrclhlKMybpeR1j7Kr2+A2NkehSXvX1lXE8X7V6OxPCK69nVEoILDWT3hNMbud+sW82niMRUxep8V9l07jKzDJqHibclurKHQN9B3y5fNuqvr4uDHBpe/rJRjxBMUmJEe9vM6nUcZbac/n/raRoFYLKzjDjGQkbXy2i3luo1TeFoaYQiQy+JQbdY8mKcOHu7OEe2bFNo0NIuzmwPaSjpSSh9T+faNEWGkmLZjbEUpbPF/p+//M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fCE9fkSBV0TQrUOOpp9wwum5SCeMnct4FxH6siapz2+yoKZ2wkyrNc57DZUkwSnl1llpftamLt5p5/lCn3d993W65GutPB+liqoWiiZsrNuF2o+dPuylG6Tnen3NnVTPJ2kdd9gf/bdK80Vw8b8r3Qf8O2o5CdcJISdTE73F13LBgHZ2Un39PQ7GBx+mjZYk3vNcI2UI0ZJl3uWzQmtss3SmH39z8T9dhv4sHV2XggROvt+i1rmD2770gtt4sI7/8fJwEV7+t/Xd22x5K6NqHtE2d28bXpcR3KZ8jV6qqM8ehn2v15TZMYRHFihmQVJzMqrHLU4MaHilK+2ef7BnvfPe4gfSgMO0wo+nDn+6373zHcwfmGMkRPrCGSy/RL7WCTH+1BRiz29+XE7o+cR8zDe05ejzj6Qj+762kcuHvdU9GSQshB7jc1bnH22tHPCDv0Fv9O7we756K8bon+peKPSLVb8z4kRUU0aBMxl2R/xAZ8SPU78f6Yz+UkeE8/Pd0/Vningonw87ILWSBD4j2Xb2c51+zfus6nD+aoef6Bz1TzRY3NsPj+dut/c7wWK3K6L55HBA25ou7476N/Diax3K0pocp6uiWwQDJmQYQZHd49CRctf+fofGH/gUpvfp5TCLzE27vr9BZWG8+/rLn2gMvrf+y7utP/lu+rZLq991xYPKRLONR802SPn8EGajQeM+ItvVWNrmBZibSPGlXtBocWdzZM2HK23QWJCjV4WpnwSM/JmbZz/8nkJIpZDNquf84z6q/rPvBorZex8sk/6Zfz518wdTJP3687vpkXMI3Tc0kif8P/bdwWf/B4HZL//5//4rAAD//5prDEo=") SupportedMap = make(map[string]Spec) for f, v := range unpacked { diff --git a/internal/pkg/core/plugin/service/app.go b/internal/pkg/core/plugin/service/app.go index 312ac8b592e..af553ac5ac8 100644 --- a/internal/pkg/core/plugin/service/app.go +++ b/internal/pkg/core/plugin/service/app.go @@ -165,8 +165,8 @@ func (a *Application) Start(ctx context.Context, _ app.Taggable, cfg map[string] // already started if a.srvState != nil { a.setState(state.Starting, "Starting", nil) - a.srvState.SetStatus(proto.StateObserved_STARTING, a.state.Message, a.state.Payload) - a.srvState.UpdateConfig(a.srvState.Config()) + _ = a.srvState.SetStatus(proto.StateObserved_STARTING, a.state.Message, a.state.Payload) + _ = a.srvState.UpdateConfig(a.srvState.Config()) } else { a.setState(state.Starting, "Starting", nil) a.srvState, err = a.srv.Register(a, string(cfgStr)) @@ -247,6 +247,13 @@ func (a *Application) Configure(ctx context.Context, config map[string]interface return err } +func (a *Application) getStopTimeout() time.Duration { + if a.desc.Spec().Process != nil && a.desc.Spec().Process.StopTimeout > 0 { + return a.desc.Spec().Process.StopTimeout + } + return a.processConfig.StopTimeout +} + // Stop stops the current application. func (a *Application) Stop() { a.appLock.Lock() @@ -257,21 +264,36 @@ func (a *Application) Stop() { return } - if err := srvState.Stop(a.processConfig.StopTimeout); err != nil { - a.appLock.Lock() - a.setState( - state.Failed, - fmt.Errorf("failed to stop after %s: %w", a.processConfig.StopTimeout, err).Error(), - nil) - } else { - a.appLock.Lock() - a.setState(state.Stopped, "Stopped", nil) + name := a.desc.Spec().Name + to := a.getStopTimeout() + + a.logger.Infof("Stop %v service, with %v timeout", name, to) + start := time.Now() + + // Try to stop the service with timeout + // If timed out and the service is still not stopped the runtime is set to STOPPED state anyways. + // This avoids leaving the runtime indefinitely in the failed state. + // + // The Agent is not managing the Endpoint service state by design. + // The service runtime should send STOPPING state to the Endpoint service only before the Endpoint is expected to be uninstalled. + // So if the Agent never receives the STOPPING check-in from the Endpoint after this, it's ok to set the state + // to STOPPED following with the Endpoint service uninstall. + if err := srvState.Stop(to); err != nil { + // Log the error + a.logger.Errorf("Failed to stop %v service after %v timeout", name, to) } - a.srvState = nil + // Cleanup + a.appLock.Lock() + defer a.appLock.Unlock() + + a.srvState = nil a.cleanUp() a.stopCredsListener() - a.appLock.Unlock() + + // Set the service state to "stopped", otherwise the agent is stuck in the failed stop state until restarted + a.logger.Infof("setting %s service status to Stopped, took: %v", name, time.Since(start)) + a.setState(state.Stopped, "Stopped", nil) } // Shutdown disconnects the service, but doesn't signal it to stop. @@ -327,7 +349,7 @@ func (a *Application) setState(s state.Status, msg string, payload map[string]in } func (a *Application) cleanUp() { - a.monitor.Cleanup(a.desc.Spec(), a.pipelineID) + _ = a.monitor.Cleanup(a.desc.Spec(), a.pipelineID) } func (a *Application) startCredsListener() error { diff --git a/internal/spec/endpoint.yml b/internal/spec/endpoint.yml index 5f452ba1943..e3e8c4fbe3e 100644 --- a/internal/spec/endpoint.yml +++ b/internal/spec/endpoint.yml @@ -2,6 +2,11 @@ name: Endpoint Security cmd: endpoint-security artifact: endpoint-dev service: 6788 +process: + # After discussion with Endpoint team the stop timeout is set to 3m, + # in order to give enough time for the Endpoint to stop gracefully. + # https://github.com/elastic/elastic-agent/issues/1262 + stop_timeout: 3m action_input_types: - endpoint log_paths: