diff --git a/go.mod b/go.mod index 27276f482666..fdcba8718dde 100644 --- a/go.mod +++ b/go.mod @@ -419,4 +419,4 @@ replace ( // Exclude this version because the version has an invalid checksum. exclude github.com/docker/distribution v2.8.0+incompatible -replace github.com/elastic/elastic-agent-client/v7 => github.com/AndersonQ/elastic-agent-client/v7 v7.0.0-20240104111824-f7e6d65a8409 +replace github.com/elastic/elastic-agent-client/v7 => github.com/AndersonQ/elastic-agent-client/v7 v7.0.0-20240108094727-ab590759de8d diff --git a/go.sum b/go.sum index 2a3fa3ec75bc..738f10704240 100644 --- a/go.sum +++ b/go.sum @@ -83,8 +83,8 @@ github.com/99designs/go-keychain v0.0.0-20191008050251-8e49817e8af4/go.mod h1:hN github.com/99designs/keyring v1.2.1/go.mod h1:fc+wB5KTk9wQ9sDx0kFXB3A0MaeGHM9AwRStKOQ5vOA= github.com/AdaLogics/go-fuzz-headers v0.0.0-20230811130428-ced1acdcaa24 h1:bvDV9vkmnHYOMsOr4WLk+Vo07yKIzd94sVoIqshQ4bU= github.com/AdaLogics/go-fuzz-headers v0.0.0-20230811130428-ced1acdcaa24/go.mod h1:8o94RPi1/7XTJvwPpRSzSUedZrtlirdB3r9Z20bi2f8= -github.com/AndersonQ/elastic-agent-client/v7 v7.0.0-20240104111824-f7e6d65a8409 h1:4FgbXnXO7OJGxmybbj0CTC5uExSxMMOyLB+xgS5id5g= -github.com/AndersonQ/elastic-agent-client/v7 v7.0.0-20240104111824-f7e6d65a8409/go.mod h1:REUJJek8Tk3ki8yplGiiTgkRGnHu/tyounlajAZNO9A= +github.com/AndersonQ/elastic-agent-client/v7 v7.0.0-20240108094727-ab590759de8d h1:4RpV8WPkT+GUlWAOzUevjL1FwD3d9JaxDoKfDxQ1IBw= +github.com/AndersonQ/elastic-agent-client/v7 v7.0.0-20240108094727-ab590759de8d/go.mod h1:arA5Vauukv2jFKcobkXoC/d28/jFFLnxVW1bQEIHDGA= github.com/Azure/azure-amqp-common-go/v3 v3.2.1 h1:uQyDk81yn5hTP1pW4Za+zHzy97/f4vDz9o1d/exI4j4= github.com/Azure/azure-amqp-common-go/v3 v3.2.1/go.mod h1:O6X1iYHP7s2x7NjUKsXVhkwWrQhxrd+d8/3rRadj4CI= github.com/Azure/azure-event-hubs-go/v3 v3.3.15 h1:2yAik9gS5Qjs4Z6EM1B6d0tfZJ506B/0oA08JlRQxb8= diff --git a/libbeat/beat/info.go b/libbeat/beat/info.go index a59bb8df1eb2..e1068d17ff5e 100644 --- a/libbeat/beat/info.go +++ b/libbeat/beat/info.go @@ -50,9 +50,3 @@ func (i Info) FQDNAwareHostname(useFQDN bool) string { return i.Hostname } - -func (i Info) VersionPackageAware() string { - // anderson TODO implement it! - - return i.Version -} diff --git a/libbeat/cmd/instance/beat.go b/libbeat/cmd/instance/beat.go index efe8bd48f79a..144b0d4d6e93 100644 --- a/libbeat/cmd/instance/beat.go +++ b/libbeat/cmd/instance/beat.go @@ -224,6 +224,8 @@ func Run(settings Settings, bt beat.Creator) error { // NewInitializedBeat creates a new beat where all information and initialization is derived from settings func NewInitializedBeat(settings Settings) (*Beat, error) { + // anderson: could we read os.Stdin here? then we could parse the version + // and propagate it b, err := NewBeat(settings.Name, settings.IndexPrefix, settings.Version, settings.ElasticLicensed) if err != nil { return nil, err @@ -840,6 +842,13 @@ func (b *Beat) configure(settings Settings) error { return err } + // The manager initialisation reads the package version sent by the agent, + // now the manager is initialised, we apply the package version if the agent + // sent it. + if b.Manager.PackageVersion() != "" { + b.Info.Version = b.Manager.PackageVersion() + } + if err := b.Manager.CheckRawConfig(b.RawConfig); err != nil { return err } @@ -1518,13 +1527,13 @@ func (bc *beatConfig) Validate() error { if bc.Pipeline.Queue.IsSet() && outputPC.Queue.IsSet() { return fmt.Errorf("top level queue and output level queue settings defined, only one is allowed") } - //elastic-agent doesn't support disk queue yet + // elastic-agent doesn't support disk queue yet if bc.Management.Enabled() && outputPC.Queue.Config().Enabled() && outputPC.Queue.Name() == diskqueue.QueueType { return fmt.Errorf("disk queue is not supported when management is enabled") } } - //elastic-agent doesn't support disk queue yet + // elastic-agent doesn't support disk queue yet if bc.Management.Enabled() && bc.Pipeline.Queue.Config().Enabled() && bc.Pipeline.Queue.Name() == diskqueue.QueueType { return fmt.Errorf("disk queue is not supported when management is enabled") } diff --git a/libbeat/cmd/root.go b/libbeat/cmd/root.go index be2cb9d441ae..6fd8d4b1da2b 100644 --- a/libbeat/cmd/root.go +++ b/libbeat/cmd/root.go @@ -55,7 +55,7 @@ type BeatsRootCmd struct { KeystoreCmd *cobra.Command } -// GenRootCmdWithSettings returns the root command to use for your beat. It take the +// GenRootCmdWithSettings returns the root command to use for your beat. It takes the // run command, which will be called if no args are given (for backwards compatibility), // and beat settings func GenRootCmdWithSettings(beatCreator beat.Creator, settings instance.Settings) *BeatsRootCmd { diff --git a/libbeat/management/management.go b/libbeat/management/management.go index 88faa48f5408..8704d2be867c 100644 --- a/libbeat/management/management.go +++ b/libbeat/management/management.go @@ -82,9 +82,14 @@ type Manager interface { // // Calls to 'CheckRawConfig()' or 'SetPayload()' will be ignored after calling stop. // - // Note: Stop will not call 'UnregisterAction()' automaticallty. + // Note: Stop will not call 'UnregisterAction()' automatically. Stop() + // PackageVersion returns the version of the agent package that should be + // presented in user visible fields and messages. If it's empty, the beat + // version should be used. + PackageVersion() string + // SetStopCallback accepts a function that need to be called when the manager want to shutdown the // beats. This is needed when you want your beats to be gracefully shutdown remotely by the Elastic Agent // when a policy doesn't need to run this beat. @@ -190,6 +195,7 @@ func (n *fallbackManager) Stop() { // but that does not mean the Beat is being managed externally, // hence it will always return false. func (n *fallbackManager) Enabled() bool { return false } +func (n *fallbackManager) PackageVersion() string { return "" } func (n *fallbackManager) Start() error { return nil } func (n *fallbackManager) CheckRawConfig(cfg *config.C) error { return nil } func (n *fallbackManager) RegisterAction(action client.Action) {} diff --git a/libbeat/publisher/processing/default.go b/libbeat/publisher/processing/default.go index f9ba74cb560a..d0a4103dee9c 100644 --- a/libbeat/publisher/processing/default.go +++ b/libbeat/publisher/processing/default.go @@ -118,7 +118,6 @@ func MakeDefaultSupport( if fleetmode.Enabled() && !beatCfg.HasField("processors") { log.Debugf("In fleet mode with no processors specified, defaulting to global processors") rawProcessors = fleetDefaultProcessors - } else { rawProcessors = cfg.Processors } @@ -161,7 +160,7 @@ var WithHost modifier = builtinModifier(func(info beat.Info) mapstr.M { func WithAgentMeta() modifier { return builtinModifier(func(info beat.Info) mapstr.M { hostname := info.FQDNAwareHostname(features.FQDN()) - // get version + // anderson: get version here or have it on 'info' already metadata := mapstr.M{ "ephemeral_id": info.EphemeralID.String(), diff --git a/libbeat/version/helper.go b/libbeat/version/helper.go index 5ed206d8a6c0..fcaf0a05c843 100644 --- a/libbeat/version/helper.go +++ b/libbeat/version/helper.go @@ -19,9 +19,20 @@ package version import "time" +// packageVersion is the Elastic Agent's package version. When running in managed +// mode the beats should report the Agent's package version instead its own version. +var packageVersion string + // GetDefaultVersion returns the current libbeat version. // This method is in a separate file as the version.go file is auto generated +// TODO(AndersonQ): does it need to be changed? in the agent's code there is still a GetDefaultVersion +// with the same behaviour as this one and it's used in several place. And there +// is another function for the package version. func GetDefaultVersion() string { + if packageVersion != "" { + return packageVersion + } + if qualifier == "" { return defaultBeatVersion } diff --git a/x-pack/libbeat/management/managerV2.go b/x-pack/libbeat/management/managerV2.go index efdede278609..2a362436162d 100644 --- a/x-pack/libbeat/management/managerV2.go +++ b/x-pack/libbeat/management/managerV2.go @@ -246,6 +246,10 @@ func NewV2AgentManagerWithClient(config *Config, registry *reload.Registry, agen // Beats central management interface implementation // ================================ +func (cm *BeatV2Manager) PackageVersion() string { + return cm.client.PackageVersion() +} + // RegisterDiagnosticHook will register a diagnostic callback function when elastic-agent asks for a diagnostics dump func (cm *BeatV2Manager) RegisterDiagnosticHook(name string, description string, filename string, contentType string, hook client.DiagnosticHook) { cm.client.RegisterDiagnosticHook(name, description, filename, contentType, hook)