Skip to content

Commit

Permalink
[Ingest Manager] Send snapshot flag together with metadata (#21285)
Browse files Browse the repository at this point in the history
[Ingest Manager] Send snapshot flag together with metadata (#21285)
  • Loading branch information
michalpristas authored Oct 1, 2020
1 parent 514809a commit 075696e
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 23 deletions.
16 changes: 14 additions & 2 deletions x-pack/elastic-agent/pkg/agent/application/info/agent_metadata.go
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(),
// 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

0 comments on commit 075696e

Please sign in to comment.