From 3f1e3a5d016487f4cc995b019a846f3f13104f03 Mon Sep 17 00:00:00 2001 From: Michal Pristas Date: Thu, 24 Sep 2020 10:42:04 +0200 Subject: [PATCH 1/4] send snapshot data --- .../pkg/agent/application/info/agent_metadata.go | 10 ++++++++-- x-pack/elastic-agent/pkg/release/version.go | 2 +- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/x-pack/elastic-agent/pkg/agent/application/info/agent_metadata.go b/x-pack/elastic-agent/pkg/agent/application/info/agent_metadata.go index c98f9b8e015..ec17d4e0ccf 100644 --- a/x-pack/elastic-agent/pkg/agent/application/info/agent_metadata.go +++ b/x-pack/elastic-agent/pkg/agent/application/info/agent_metadata.go @@ -33,6 +33,10 @@ 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,omitempty"` + // BuildOriginal is an extended build information for the agent. + BuildOriginal string `json:"build.original"` } // SystemECSMeta is a collection of operating system metadata in ECS compliant object form. @@ -126,8 +130,10 @@ 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(), }, }, Host: &HostECSMeta{ diff --git a/x-pack/elastic-agent/pkg/release/version.go b/x-pack/elastic-agent/pkg/release/version.go index 37579ac86de..0802dce0350 100644 --- a/x-pack/elastic-agent/pkg/release/version.go +++ b/x-pack/elastic-agent/pkg/release/version.go @@ -59,7 +59,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) From 93f569e446ea82b86eb5f656cb63382651c65656 Mon Sep 17 00:00:00 2001 From: Michal Pristas Date: Wed, 30 Sep 2020 16:30:22 +0200 Subject: [PATCH 2/4] upgradable --- .../pkg/agent/application/info/agent_metadata.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/x-pack/elastic-agent/pkg/agent/application/info/agent_metadata.go b/x-pack/elastic-agent/pkg/agent/application/info/agent_metadata.go index ec17d4e0ccf..df926ea5327 100644 --- a/x-pack/elastic-agent/pkg/agent/application/info/agent_metadata.go +++ b/x-pack/elastic-agent/pkg/agent/application/info/agent_metadata.go @@ -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" @@ -37,6 +38,8 @@ type AgentECSMeta struct { Snapshot bool `json:"snapshot,omitempty"` // BuildOriginal is an extended build information for the agent. BuildOriginal string `json:"build.original"` + // Upgradable is a flag specifying if it is possible for agent to be upgraded. + Upgradable bool `json:"upgradable"` } // SystemECSMeta is a collection of operating system metadata in ECS compliant object form. @@ -134,6 +137,9 @@ func (i *AgentInfo) ECSMetadata() (*ECSMeta, error) { Version: release.Version(), Snapshot: release.Snapshot(), BuildOriginal: release.Info().String(), + // only upgradable if running from Agent installer and running under the + // control of the system supervisor (or built specifically with upgrading enabled) + Upgradable: release.Upgradable() || (install.RunningInstalled() && install.RunningUnderSupervisor()), }, }, Host: &HostECSMeta{ From e2ef4fc375a5ece83d5d38f57b2977d7866b5819 Mon Sep 17 00:00:00 2001 From: Michal Pristas Date: Wed, 30 Sep 2020 16:34:37 +0200 Subject: [PATCH 3/4] always report snapshot --- .../elastic-agent/pkg/agent/application/info/agent_metadata.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x-pack/elastic-agent/pkg/agent/application/info/agent_metadata.go b/x-pack/elastic-agent/pkg/agent/application/info/agent_metadata.go index df926ea5327..dbcbcfa5228 100644 --- a/x-pack/elastic-agent/pkg/agent/application/info/agent_metadata.go +++ b/x-pack/elastic-agent/pkg/agent/application/info/agent_metadata.go @@ -35,7 +35,7 @@ type AgentECSMeta struct { // 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,omitempty"` + Snapshot bool `json:"snapshot"` // BuildOriginal is an extended build information for the agent. BuildOriginal string `json:"build.original"` // Upgradable is a flag specifying if it is possible for agent to be upgraded. From 04fd192bfc6f7301a7f9cb1b73de2c62321bc4eb Mon Sep 17 00:00:00 2001 From: Michal Pristas Date: Thu, 1 Oct 2020 08:50:04 +0200 Subject: [PATCH 4/4] grammar check --- .../agent/application/info/agent_metadata.go | 8 ++--- .../pkg/agent/application/upgrade/upgrade.go | 36 +++++++++---------- x-pack/elastic-agent/pkg/release/upgrade.go | 4 +-- 3 files changed, 24 insertions(+), 24 deletions(-) diff --git a/x-pack/elastic-agent/pkg/agent/application/info/agent_metadata.go b/x-pack/elastic-agent/pkg/agent/application/info/agent_metadata.go index dbcbcfa5228..c5712646cfb 100644 --- a/x-pack/elastic-agent/pkg/agent/application/info/agent_metadata.go +++ b/x-pack/elastic-agent/pkg/agent/application/info/agent_metadata.go @@ -38,8 +38,8 @@ type AgentECSMeta struct { Snapshot bool `json:"snapshot"` // BuildOriginal is an extended build information for the agent. BuildOriginal string `json:"build.original"` - // Upgradable is a flag specifying if it is possible for agent to be upgraded. - Upgradable bool `json:"upgradable"` + // 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. @@ -137,9 +137,9 @@ func (i *AgentInfo) ECSMetadata() (*ECSMeta, error) { Version: release.Version(), Snapshot: release.Snapshot(), BuildOriginal: release.Info().String(), - // 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) - Upgradable: release.Upgradable() || (install.RunningInstalled() && install.RunningUnderSupervisor()), + Upgradeable: release.Upgradeable() || (install.RunningInstalled() && install.RunningUnderSupervisor()), }, }, Host: &HostECSMeta{ diff --git a/x-pack/elastic-agent/pkg/agent/application/upgrade/upgrade.go b/x-pack/elastic-agent/pkg/agent/application/upgrade/upgrade.go index 9c2c4f02286..a6a36db8ba3 100644 --- a/x-pack/elastic-agent/pkg/agent/application/upgrade/upgrade.go +++ b/x-pack/elastic-agent/pkg/agent/application/upgrade/upgrade.go @@ -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 { @@ -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") @@ -153,9 +153,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 { diff --git a/x-pack/elastic-agent/pkg/release/upgrade.go b/x-pack/elastic-agent/pkg/release/upgrade.go index ac1e8552dd2..2e63eb47ad5 100644 --- a/x-pack/elastic-agent/pkg/release/upgrade.go +++ b/x-pack/elastic-agent/pkg/release/upgrade.go @@ -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" }