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

[Ingest Manager] Send snapshot flag together with metadata #21285

Merged
merged 7 commits into from
Oct 1, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"runtime"
"strings"

"github.com/elastic/beats/v7/x-pack/elastic-agent/pkg/agent/install"
"github.com/elastic/beats/v7/x-pack/elastic-agent/pkg/release"
"github.com/elastic/go-sysinfo"
"github.com/elastic/go-sysinfo/types"
Expand All @@ -33,6 +34,12 @@ type AgentECSMeta struct {
ID string `json:"id"`
// Version specifies current version of an agent.
Version string `json:"version"`
// Snapshot is a flag specifying that the agent used is a snapshot build.
Snapshot bool `json:"snapshot"`
// BuildOriginal is an extended build information for the agent.
BuildOriginal string `json:"build.original"`
// Upgradeable is a flag specifying if it is possible for agent to be upgraded.
Upgradeable bool `json:"upgradeable"`
}

// SystemECSMeta is a collection of operating system metadata in ECS compliant object form.
Expand Down Expand Up @@ -126,8 +133,13 @@ func (i *AgentInfo) ECSMetadata() (*ECSMeta, error) {
return &ECSMeta{
Elastic: &ElasticECSMeta{
Agent: &AgentECSMeta{
ID: i.agentID,
Version: release.Version(),
ID: i.agentID,
Version: release.Version(),
Snapshot: release.Snapshot(),
BuildOriginal: release.Info().String(),
Copy link
Contributor

Choose a reason for hiding this comment

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

This is probably a great place to put if the agent is also upgradable.

Should we add Upgradable: false for now, then replace it with the correct check once #21206 lands.

// only upgradeable if running from Agent installer and running under the
// control of the system supervisor (or built specifically with upgrading enabled)
Upgradeable: release.Upgradeable() || (install.RunningInstalled() && install.RunningUnderSupervisor()),
},
},
Host: &HostECSMeta{
Expand Down
36 changes: 18 additions & 18 deletions x-pack/elastic-agent/pkg/agent/application/upgrade/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@ const (

// Upgrader performs an upgrade
type Upgrader struct {
settings *artifact.Config
log *logger.Logger
closers []context.CancelFunc
reexec reexecManager
acker acker
upgradable bool
settings *artifact.Config
log *logger.Logger
closers []context.CancelFunc
reexec reexecManager
acker acker
upgradeable bool
}

type reexecManager interface {
Expand All @@ -53,23 +53,23 @@ type acker interface {
// NewUpgrader creates an upgrader which is capable of performing upgrade operation
func NewUpgrader(settings *artifact.Config, log *logger.Logger, closers []context.CancelFunc, reexec reexecManager, a acker) *Upgrader {
return &Upgrader{
settings: settings,
log: log,
closers: closers,
reexec: reexec,
acker: a,
upgradable: getUpgradable(),
settings: settings,
log: log,
closers: closers,
reexec: reexec,
acker: a,
upgradeable: getUpgradable(),
}
}

// Upgradable returns true if the Elastic Agent can be upgraded.
func (u *Upgrader) Upgradable() bool {
return u.upgradable
// Upgradeable returns true if the Elastic Agent can be upgraded.
func (u *Upgrader) Upgradeable() bool {
return u.upgradeable
}

// Upgrade upgrades running agent
func (u *Upgrader) Upgrade(ctx context.Context, a *fleetapi.ActionUpgrade) error {
if !u.upgradable {
if !u.upgradeable {
return fmt.Errorf(
"cannot be upgraded; must be installed with install sub-command and " +
"running under control of the systems supervisor")
Expand Down Expand Up @@ -164,9 +164,9 @@ func rollbackInstall(hash string) {
}

func getUpgradable() bool {
// only upgradable if running from Agent installer and running under the
// only upgradeable if running from Agent installer and running under the
// control of the system supervisor (or built specifically with upgrading enabled)
return release.Upgradable() || (install.RunningInstalled() && install.RunningUnderSupervisor())
return release.Upgradeable() || (install.RunningInstalled() && install.RunningUnderSupervisor())
}

func copyActionStore(newHash string) error {
Expand Down
4 changes: 2 additions & 2 deletions x-pack/elastic-agent/pkg/release/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

package release

// Upgradable return true when release is built specifically for upgrading.
func Upgradable() bool {
// Upgradeable return true when release is built specifically for upgrading.
func Upgradeable() bool {
return allowUpgrade == "true"
}
2 changes: 1 addition & 1 deletion x-pack/elastic-agent/pkg/release/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func Info() VersionInfo {
}

// String returns the string format for the version information.
func (v *VersionInfo) String() string {
func (v VersionInfo) String() string {
var sb strings.Builder

sb.WriteString(v.Version)
Expand Down