Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions agent/kibana/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@ import (

// Config is the configuration for the Kibana client.
type Config struct {
Protocol Protocol `config:"protocol"`
SpaceID string `config:"space.id"`
Username string `config:"username"`
Password string `config:"password"`
Path string `config:"path"`
Host string `config:"host"`
Timeout time.Duration `config:"timeout"`
TLS *tlscommon.Config `config:"ssl"`
Protocol Protocol `config:"protocol" yaml:"protocol"`
SpaceID string `config:"space.id" yaml:"space.id,omitempty"`
Username string `config:"username" yaml:"username,omitempty"`
Password string `config:"password" yaml:"password,omitempty"`
Path string `config:"path" yaml:"path,omitempty"`
Host string `config:"host" yaml:"host,omitempty"`
Timeout time.Duration `config:"timeout" yaml:"timeout,omitempty"`
TLS *tlscommon.Config `config:"ssl" yaml:"ssl,omitempty"`
}

// Protocol define the protocol to use to make the connection. (Either HTTPS or HTTP)
Expand Down
52 changes: 52 additions & 0 deletions x-pack/agent/_meta/agent.fleet.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#================================ General =====================================
# Beats is configured under Fleet, you can define most settings
# from the Kibana UI. You can update this file to configure the settings that
# are not supported by Fleet.
management:
#
mode: "fleet"

# reattach collection path is a way of tracking started processes by agent.
reattach_collection_path: "/home/elastic/reattach"

download:
# operating system [linux, windows, darwin]
operating_system: "linux"
# target architecture [32, 64]
arch: "32"
# source of the artifacts, requires elastic like structure and naming of the binaries
# e.g /windows-x86.zip
sourceURI: "https://artifacts.elastic.co/downloads/beats/"
# path to the directory containing downloaded packages
target_directory: "/home/elastic/downloads"
# timeout for downloading package
timeout: 30s
# file path to a public key used for verifying downloaded artifacts
# if not file is present agent will try to load public key from elastic.co website.
pgpfile: "/home/elastic/elastic.pgp"# install describes the location of installed packages/programs. It is also used
# for reading program specifications.
install_path: "/"

process:
# minimal port number for spawned processes
min_port: 10000
# maximum port number for spawned processes
max_port: 30000
# timeout for creating new processes. when process is not successfully created by this timeout
# start operation is considered a failure
spawn_timeout: 30s

retry:
# enabled determines whether retry is possible. Default is false.
enabled: true
# retries_count specifies number of retries. Default is 3.
# Retry count of 1 means it will be retried one time after one failure.
retries_count: 3
# delay specifies delay in ms between retries. Default is 30s
delay: 30s
# max_delay specifies maximum delay in ms between retries. Default is 300s
max_delay: 5m
# Exponential determines whether delay is treated as exponential.
# With 30s delay and 3 retries: 30, 60, 120s
# Default is false
exponential: false
111 changes: 111 additions & 0 deletions x-pack/agent/dev-tools/cmd/buildfleetcfg/buildfleetcfg.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 11 additions & 1 deletion x-pack/agent/magefile.go
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ func flags() string {

// Update is an alias for executing fields, dashboards, config, includes.
func Update() {
mg.SerialDeps(Config, BuildSpec)
mg.SerialDeps(Config, BuildSpec, BuildFleetCfg)
}

// CrossBuild cross-builds the beat for all target platforms.
Expand Down Expand Up @@ -405,3 +405,13 @@ func UnitTest() {
func IntegTest() {
os.Create(filepath.Join("build", "TEST-go-integration.out"))
}

// BuildFleetCfg embed the default fleet configuration as part of the binary.
func BuildFleetCfg() error {
goF := filepath.Join("dev-tools", "cmd", "buildfleetcfg", "buildfleetcfg.go")
in := filepath.Join("_meta", "agent.fleet.yml")
out := filepath.Join("pkg", "agent", "application", "configuration_embed.go")

fmt.Printf(">> BuildFleetCfg %s to %s\n", in, out)
return RunGo("run", goF, "--in", in, "--out", out)
}
79 changes: 2 additions & 77 deletions x-pack/agent/pkg/agent/application/application.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,6 @@ import (

"github.com/elastic/beats/x-pack/agent/pkg/config"
"github.com/elastic/beats/x-pack/agent/pkg/core/logger"
"github.com/elastic/beats/x-pack/agent/pkg/fleetapi"
reporting "github.com/elastic/beats/x-pack/agent/pkg/reporter"
fleetreporter "github.com/elastic/beats/x-pack/agent/pkg/reporter/fleet"
logreporter "github.com/elastic/beats/x-pack/agent/pkg/reporter/log"
)

// Application is the application interface implemented by the different running mode.
Expand Down Expand Up @@ -53,89 +49,18 @@ func createApplication(
return nil, errors.Wrap(err, "initiating application")
}

client, err := getKibanaClient(log, mgmt)
if err != nil {
return nil, errors.Wrap(err, "initiating application")
}

reporter, err := getReporter(c.Management, log, getAgentID(), client)
if err != nil {
return nil, err
}

router, err := newRouter(log, streamFactory(config, client, reporter))
if err != nil {
return nil, errors.Wrap(err, "initiating application")
}

switch mgmt.Mode {
case localMode:
log.Info("Agent is managed locally")
return newLocal(log, pathConfigFile, c.Management, router)
return newLocal(log, pathConfigFile, c.Management)
case fleetMode:
log.Info("Agent is managed by Fleet")
return newManaged(log, c.Management, router, client)
return newManaged(log, c.Management)
default:
return nil, ErrInvalidMgmtMode
}
}

func getKibanaClient(log *logger.Logger, c *ManagementConfig) (_ sender, err error) {
if c.Mode == localMode {
// fleet not configured client not needed
return nil, nil
}

defer func() {
if err != nil {
err = errors.Wrap(err, "fail to create the API client")
}
}()

if c.Fleet == nil {
return nil, errors.New("fleet mode enabled but management.fleet not specified")
}

kibanaConfig := c.Fleet.Kibana
if kibanaConfig == nil {
return nil, errors.New("fleet mode enabled but management.fleet.kibana not specified")
}

if c.Fleet.AccessAPIKey != "" {
rawConfig, err := config.NewConfigFrom(kibanaConfig)
if err != nil {
return nil, err
}

return fleetapi.NewAuthWithConfig(log, rawConfig, c.Fleet.AccessAPIKey)
}

return fleetapi.NewWithConfig(log, kibanaConfig)
}

func getReporter(cfg *config.Config, log *logger.Logger, id string, client sender) (reporter, error) {
c := defaultManagementConfig()
if err := cfg.Unpack(&c); err != nil {
return nil, err
}

backends := make([]reporting.Backend, 0, 2)
backends = append(backends, logreporter.NewReporter(log, c.Reporting.LogReporting))

if c.Mode == fleetMode && c.Reporting.FleetManagement != nil && c.Reporting.FleetManagement.Enabled {
agentID := getAgentID()

fr, err := fleetreporter.NewReporter(agentID, log, c.Reporting.FleetManagement, client)
if err != nil {
return nil, err
}

backends = append(backends, fr)
}

return reporting.NewReporter(log, id, backends...), nil
}

func getAgentID() string {
// TODO: implement correct way of acquiring agent ID
return "default"
Expand Down
Loading