Skip to content
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

Port "Improve shutdown logs" from 8.5 back to main #1930

Merged
merged 3 commits into from
Dec 12, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions NOTICE.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1273,11 +1273,19 @@ SOFTWARE

--------------------------------------------------------------------------------
Dependency : github.com/elastic/elastic-agent-libs
<<<<<<< HEAD
Version: v0.2.15
Licence type (autodetected): Apache-2.0
--------------------------------------------------------------------------------

Contents of probable licence file $GOMODCACHE/github.com/elastic/[email protected]/LICENSE:
=======
Version: v0.2.14
Licence type (autodetected): Apache-2.0
--------------------------------------------------------------------------------

Contents of probable licence file $GOMODCACHE/github.com/elastic/[email protected]/LICENSE:
>>>>>>> 567f9e2dce (Improve shutdown logs (#1618) (#1627))

Apache License
Version 2.0, January 2004
Expand Down
31 changes: 31 additions & 0 deletions changelog/fragments/1666789812-Improve-shutdown-logs.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Kind can be one of:
# - breaking-change: a change to previously-documented behavior
# - deprecation: functionality that is being removed in a later release
# - bug-fix: fixes a problem in a previous version
# - enhancement: extends functionality but does not break or fix existing behavior
# - feature: new functionality
# - known-issue: problems that we are aware of in a given version
# - security: impacts on the security of a product or a user’s deployment.
# - upgrade: important information for someone upgrading from a prior version
# - other: does not fit into any of the other categories
kind: feature

# Change summary; a 80ish characters long description of the change.
summary: Improve shutdown logs

# Long description; in case the summary is not enough to describe the change
# this field accommodate a description without length limits.
#description:

# Affected component; a word indicating the component this changeset affects.
component: cmd, handler, upgrade

# PR number; optional; the PR number that added the changeset.
# If not present is automatically filled by the tooling finding the PR where this changelog fragment has been added.
# NOTE: the tooling supports backports, so it's able to fill the original PR number instead of the backport PR number.
# Please provide it if you are adding a fragment for a different PR.
pr: 1618

# Issue number; optional; the GitHub issue related to this changeset (either closes or is part of).
# If not present is automatically filled by the tooling with the issue linked to the PR number.
issue: 1358
6 changes: 6 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,15 @@ require (
github.com/dolmen-go/contextio v0.0.0-20200217195037-68fc5150bcd5
github.com/elastic/e2e-testing v1.99.2-0.20220117192005-d3365c99b9c4
github.com/elastic/elastic-agent-autodiscover v0.2.1
<<<<<<< HEAD
github.com/elastic/elastic-agent-client/v7 v7.0.2-0.20221129150247-15881a8e64ef
github.com/elastic/elastic-agent-libs v0.2.15
github.com/elastic/elastic-agent-system-metrics v0.4.4
=======
github.com/elastic/elastic-agent-client/v7 v7.0.0-20210727140539-f0905d9377f6
github.com/elastic/elastic-agent-libs v0.2.14
github.com/elastic/elastic-agent-system-metrics v0.3.0
>>>>>>> 567f9e2dce (Improve shutdown logs (#1618) (#1627))
github.com/elastic/go-licenser v0.4.0
github.com/elastic/go-sysinfo v1.8.1
github.com/elastic/go-ucfg v0.8.6
Expand Down
7 changes: 7 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -387,10 +387,17 @@ github.com/elastic/elastic-agent-autodiscover v0.2.1/go.mod h1:gPnzzfdYNdgznAb+i
github.com/elastic/elastic-agent-client/v7 v7.0.2-0.20221129150247-15881a8e64ef h1:+3AWaimDL826eoU06qOFBtA3xmyuTr9YUMVWvnim4mU=
github.com/elastic/elastic-agent-client/v7 v7.0.2-0.20221129150247-15881a8e64ef/go.mod h1:cHviLpA5fAwMbfBIHBVNl16qp90bO7pKHMAQaG+9raU=
github.com/elastic/elastic-agent-libs v0.2.5/go.mod h1:chO3rtcLyGlKi9S0iGVZhYCzDfdDsAQYBc+ui588AFE=
<<<<<<< HEAD
github.com/elastic/elastic-agent-libs v0.2.15 h1:hdAbrZZ2mCPcQLRCE3E8xw3mHKl8HFMt36w7jan/XGo=
github.com/elastic/elastic-agent-libs v0.2.15/go.mod h1:0J9lzJh+BjttIiVjYDLncKYCEWUUHiiqnuI64y6C6ss=
github.com/elastic/elastic-agent-system-metrics v0.4.4 h1:Br3S+TlBhijrLysOvbHscFhgQ00X/trDT5VEnOau0E0=
github.com/elastic/elastic-agent-system-metrics v0.4.4/go.mod h1:tF/f9Off38nfzTZHIVQ++FkXrDm9keFhFpJ+3pQ00iI=
=======
github.com/elastic/elastic-agent-libs v0.2.14 h1:o1agY/37TKl5kjhv3ur5M9d127wzQPRxwA4Xoh0jUEo=
github.com/elastic/elastic-agent-libs v0.2.14/go.mod h1:0J9lzJh+BjttIiVjYDLncKYCEWUUHiiqnuI64y6C6ss=
github.com/elastic/elastic-agent-system-metrics v0.3.0 h1:W8L0E8lWJmdguH+oIR7OzuFgopvw8ucZAE9w6iqVlpE=
github.com/elastic/elastic-agent-system-metrics v0.3.0/go.mod h1:RIYhJOS7mUeyIthfOSqmmbEILYSzaDWLi5zQ70bQo+o=
>>>>>>> 567f9e2dce (Improve shutdown logs (#1618) (#1627))
github.com/elastic/elastic-package v0.32.1/go.mod h1:l1fEnF52XRBL6a5h6uAemtdViz2bjtjUtgdQcuRhEAY=
github.com/elastic/go-elasticsearch/v7 v7.16.0/go.mod h1:OJ4wdbtDNk5g503kvlHLyErCgQwwzmDtaFC4XyOxXA4=
github.com/elastic/go-elasticsearch/v8 v8.0.0-20210317102009-a9d74cec0186/go.mod h1:xe9a/L2aeOgFKKgrO3ibQTnMdpAeL0GC+5/HpGScSa4=
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,12 @@ func (h *Settings) Handle(ctx context.Context, a fleetapi.Action, acker acker.Ac
h.log.Errorf("failed to commit acker after acknowledging action with id '%s'", action.ActionID)
}

<<<<<<< HEAD:internal/pkg/agent/application/actions/handlers/handler_action_settings.go
h.coord.ReExec(nil)
=======
h.log.Info("SETTINGS action done, triggering agent restart")
h.reexec.ReExec(nil)
>>>>>>> 567f9e2dce (Improve shutdown logs (#1618) (#1627)):internal/pkg/agent/application/pipeline/actions/handlers/handler_action_settings.go
return nil
}

Expand Down
20 changes: 20 additions & 0 deletions internal/pkg/agent/application/upgrade/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,27 @@ func (u *Upgrader) Upgrade(ctx context.Context, version string, sourceURI string
return nil, err
}

<<<<<<< HEAD
cb := shutdownCallback(u.log, paths.Home(), release.Version(), version, release.TrimCommit(newHash))
=======
trimmedNewHash := release.TrimCommit(newHash)
cb := shutdownCallback(u.log, paths.Home(), release.Version(), a.Version(), trimmedNewHash)
if reexecNow {
u.log.Debugw("Removing downloads directory", "file.path", paths.Downloads(), "rexec", reexecNow)
err = os.RemoveAll(paths.Downloads())
if err != nil {
u.log.Errorw("Unable to clean downloads after update", "error.message", err, "downloads.path", paths.Downloads())
}

u.log.Infow("Restarting after upgrade",
"new_version", release.Version(),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is probably reversed, example from a recent 8.5.3 upgrade attempt

"Restarting after upgrade","new_version":"8.5.3","prev_version":"8.6.0",

"prev_version", a.Version(),
"hash", trimmedNewHash,
"home", paths.Home())
u.reexec.ReExec(cb)
return nil, nil
}
>>>>>>> 567f9e2dce (Improve shutdown logs (#1618) (#1627))

// Clean everything from the downloads dir
u.log.Debugw("Removing downloads directory", "file.path", paths.Downloads())
Expand Down
35 changes: 35 additions & 0 deletions internal/pkg/agent/cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,19 @@ func newRunCommandWithArgs(_ []string, streams *cli.IOStreams) *cobra.Command {
Use: "run",
Short: "Start the elastic-agent.",
Run: func(_ *cobra.Command, _ []string) {
<<<<<<< HEAD
if err := run(nil); err != nil && !errors.Is(err, context.Canceled) {
=======
if err := run(nil); err != nil {
logp.NewLogger("cmd_run").
Errorw("run command finished with error",
"error.message", err)
>>>>>>> 567f9e2dce (Improve shutdown logs (#1618) (#1627))
fmt.Fprintf(streams.Err, "Error: %v\n%s\n", err, troubleshootMessage())

// TODO: remove it. os.Exit will be called on main and if it's called
// too early some goroutines with deferred functions related
// to the shutdown process might not run.
os.Exit(1)
}
},
Expand Down Expand Up @@ -205,6 +216,7 @@ LOOP:
for {
select {
case <-stop:
<<<<<<< HEAD
break LOOP
case <-appDone:
logShutdown = false
Expand All @@ -213,13 +225,36 @@ LOOP:
isRex = true
logShutdown = false
break LOOP
=======
logger.Info("service.HandleSignals invoked stop function. Shutting down")
breakout = true
case <-rex.ShutdownChan():
logger.Info("reexec Shutdown channel triggered")
reexecing = true
breakout = true
>>>>>>> 567f9e2dce (Improve shutdown logs (#1618) (#1627))
case sig := <-signals:
logger.Infof("signal %q received", sig)
if sig == syscall.SIGHUP {
<<<<<<< HEAD
rexLogger.Infof("SIGHUP triggered re-exec")
isRex = true
rex.ReExec(nil)
} else {
break LOOP
=======
logger.Infof("signals syscall.SIGHUP received, triggering agent restart")
rex.ReExec(nil)
} else {
breakout = true
}
}
if breakout {
if !reexecing {
logger.Info("Shutting down Elastic Agent and sending last events...")
} else {
logger.Info("Restarting Elastic Agent")
>>>>>>> 567f9e2dce (Improve shutdown logs (#1618) (#1627))
}
}
}
Expand Down