Skip to content

Commit

Permalink
Add heartbeat support for V2 (#33157)
Browse files Browse the repository at this point in the history
* add v2 config

* fix name

* fix doc
  • Loading branch information
fearful-symmetry authored Oct 11, 2022
1 parent 6eecb84 commit 8dc24d6
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions x-pack/heartbeat/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,39 @@
package cmd

import (
"fmt"

heartbeatCmd "github.com/elastic/beats/v7/heartbeat/cmd"
"github.com/elastic/beats/v7/libbeat/cmd"
"github.com/elastic/beats/v7/libbeat/common/reload"
"github.com/elastic/elastic-agent-client/v7/pkg/client"
"github.com/elastic/elastic-agent-client/v7/pkg/proto"

_ "github.com/elastic/beats/v7/x-pack/libbeat/include"
"github.com/elastic/beats/v7/x-pack/libbeat/management"
)

// RootCmd to handle beats cli
var RootCmd *cmd.BeatsRootCmd

// heartbeatCfg is a callback registered via SetTransform that returns a Elastic Agent client.Unit
// configuration generated from a raw Elastic Agent config
func heartbeatCfg(rawIn *proto.UnitExpectedConfig, agentInfo *client.AgentInfo) ([]*reload.ConfigWithMeta, error) {
//grab and properly format the input streams
inputStreams, err := management.CreateInputsFromStreams(rawIn, "metrics", agentInfo)
if err != nil {
return nil, fmt.Errorf("error generating new stream config: %w", err)
}

configList, err := management.CreateReloadConfigFromInputs(inputStreams)
if err != nil {
return nil, fmt.Errorf("error creating reloader config: %w", err)
}
return configList, nil
}

func init() {
management.ConfigTransform.SetTransform(heartbeatCfg)
settings := heartbeatCmd.HeartbeatSettings()
settings.ElasticLicensed = true
RootCmd = heartbeatCmd.Initialize(settings)
Expand Down

0 comments on commit 8dc24d6

Please sign in to comment.