Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
AndersonQ committed Jan 8, 2024
1 parent 9dc4a26 commit 8645bc5
Show file tree
Hide file tree
Showing 9 changed files with 38 additions and 15 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
6 changes: 0 additions & 6 deletions libbeat/beat/info.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
13 changes: 11 additions & 2 deletions libbeat/cmd/instance/beat.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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")
}
Expand Down
2 changes: 1 addition & 1 deletion libbeat/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
8 changes: 7 additions & 1 deletion libbeat/management/management.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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) {}
Expand Down
3 changes: 1 addition & 2 deletions libbeat/publisher/processing/default.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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(),
Expand Down
11 changes: 11 additions & 0 deletions libbeat/version/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
4 changes: 4 additions & 0 deletions x-pack/libbeat/management/managerV2.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 8645bc5

Please sign in to comment.