Skip to content

Commit

Permalink
[Elastic Agent] Add the ability to run the Fleet Server (#23736)
Browse files Browse the repository at this point in the history
* Add the ability to run the Fleet Server.

* Add test and changelog.

* Fix changelog.
  • Loading branch information
blakerouse authored Feb 1, 2021
1 parent 5cb370e commit d59f780
Show file tree
Hide file tree
Showing 10 changed files with 152 additions and 60 deletions.
48 changes: 48 additions & 0 deletions dev-tools/packaging/packages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,18 @@ shared:
source: '{{.AgentDropPath}}/apm-server-{{ beat_version }}{{if .Snapshot}}-SNAPSHOT{{end}}-{{.GOOS}}-{{.AgentArchName}}.tar.gz.asc'
mode: 0644
skip_on_missing: true
/var/lib/{{.BeatName}}/data/{{.BeatName}}-{{ commit_short }}/downloads/fleet-server-{{ beat_version }}{{if .Snapshot}}-SNAPSHOT{{end}}-{{.GOOS}}-{{.AgentArchName}}.tar.gz:
source: '{{.AgentDropPath}}/fleet-server-{{ beat_version }}{{if .Snapshot}}-SNAPSHOT{{end}}-{{.GOOS}}-{{.AgentArchName}}.tar.gz'
mode: 0644
skip_on_missing: true
/var/lib/{{.BeatName}}/data/{{.BeatName}}-{{ commit_short }}/downloads/fleet-server-{{ beat_version }}{{if .Snapshot}}-SNAPSHOT{{end}}-{{.GOOS}}-{{.AgentArchName}}.tar.gz.sha512:
source: '{{.AgentDropPath}}/fleet-server-{{ beat_version }}{{if .Snapshot}}-SNAPSHOT{{end}}-{{.GOOS}}-{{.AgentArchName}}.tar.gz.sha512'
mode: 0644
skip_on_missing: true
/var/lib/{{.BeatName}}/data/{{.BeatName}}-{{ commit_short }}/downloads/fleet-server-{{ beat_version }}{{if .Snapshot}}-SNAPSHOT{{end}}-{{.GOOS}}-{{.AgentArchName}}.tar.gz.asc:
source: '{{.AgentDropPath}}/fleet-server-{{ beat_version }}{{if .Snapshot}}-SNAPSHOT{{end}}-{{.GOOS}}-{{.AgentArchName}}.tar.gz.asc'
mode: 0644
skip_on_missing: true



Expand Down Expand Up @@ -201,6 +213,18 @@ shared:
source: '{{.AgentDropPath}}/apm-server-{{ beat_version }}{{if .Snapshot}}-SNAPSHOT{{end}}-{{.GOOS}}-{{.AgentArchName}}.tar.gz.asc'
mode: 0644
skip_on_missing: true
/etc/{{.BeatName}}/data/{{.BeatName}}-{{ commit_short }}/downloads/fleet-server-{{ beat_version }}{{if .Snapshot}}-SNAPSHOT{{end}}-{{.GOOS}}-{{.AgentArchName}}.tar.gz:
source: '{{.AgentDropPath}}/fleet-server-{{ beat_version }}{{if .Snapshot}}-SNAPSHOT{{end}}-{{.GOOS}}-{{.AgentArchName}}.tar.gz'
mode: 0644
skip_on_missing: true
/etc/{{.BeatName}}/data/{{.BeatName}}-{{ commit_short }}/downloads/fleet-server-{{ beat_version }}{{if .Snapshot}}-SNAPSHOT{{end}}-{{.GOOS}}-{{.AgentArchName}}.tar.gz.sha512:
source: '{{.AgentDropPath}}/fleet-server-{{ beat_version }}{{if .Snapshot}}-SNAPSHOT{{end}}-{{.GOOS}}-{{.AgentArchName}}.tar.gz.sha512'
mode: 0644
skip_on_missing: true
/etc/{{.BeatName}}/data/{{.BeatName}}-{{ commit_short }}/downloads/fleet-server-{{ beat_version }}{{if .Snapshot}}-SNAPSHOT{{end}}-{{.GOOS}}-{{.AgentArchName}}.tar.gz.asc:
source: '{{.AgentDropPath}}/fleet-server-{{ beat_version }}{{if .Snapshot}}-SNAPSHOT{{end}}-{{.GOOS}}-{{.AgentArchName}}.tar.gz.asc'
mode: 0644
skip_on_missing: true

- &agent_binary_files
'{{.BeatName}}{{.BinaryExt}}':
Expand Down Expand Up @@ -283,6 +307,18 @@ shared:
source: '{{.AgentDropPath}}/apm-server-{{ beat_version }}{{if .Snapshot}}-SNAPSHOT{{end}}-{{.GOOS}}-{{.AgentArchName}}.tar.gz.asc'
mode: 0644
skip_on_missing: true
'data/{{.BeatName}}-{{ commit_short }}/downloads/fleet-server-{{ beat_version }}{{if .Snapshot}}-SNAPSHOT{{end}}-{{.GOOS}}-{{.AgentArchName}}.tar.gz':
source: '{{.AgentDropPath}}/fleet-server-{{ beat_version }}{{if .Snapshot}}-SNAPSHOT{{end}}-{{.GOOS}}-{{.AgentArchName}}.tar.gz'
mode: 0644
skip_on_missing: true
'data/{{.BeatName}}-{{ commit_short }}/downloads/fleet-server-{{ beat_version }}{{if .Snapshot}}-SNAPSHOT{{end}}-{{.GOOS}}-{{.AgentArchName}}.tar.gz.sha512':
source: '{{.AgentDropPath}}/fleet-server-{{ beat_version }}{{if .Snapshot}}-SNAPSHOT{{end}}-{{.GOOS}}-{{.AgentArchName}}.tar.gz.sha512'
mode: 0644
skip_on_missing: true
'data/{{.BeatName}}-{{ commit_short }}/downloads/fleet-server-{{ beat_version }}{{if .Snapshot}}-SNAPSHOT{{end}}-{{.GOOS}}-{{.AgentArchName}}.tar.gz.asc':
source: '{{.AgentDropPath}}/fleet-server-{{ beat_version }}{{if .Snapshot}}-SNAPSHOT{{end}}-{{.GOOS}}-{{.AgentArchName}}.tar.gz.asc'
mode: 0644
skip_on_missing: true


# Binary package spec (zip for windows) for community beats.
Expand Down Expand Up @@ -334,6 +370,18 @@ shared:
source: '{{.AgentDropPath}}/apm-server-{{ beat_version }}{{if .Snapshot}}-SNAPSHOT{{end}}-{{.GOOS}}-{{.AgentArchName}}.zip.asc'
mode: 0644
skip_on_missing: true
'data/{{.BeatName}}-{{ commit_short }}/downloads/fleet-server-{{ beat_version }}{{if .Snapshot}}-SNAPSHOT{{end}}-{{.GOOS}}-{{.AgentArchName}}.zip':
source: '{{.AgentDropPath}}/fleet-server-{{ beat_version }}{{if .Snapshot}}-SNAPSHOT{{end}}-{{.GOOS}}-{{.AgentArchName}}.zip'
mode: 0644
skip_on_missing: true
'data/{{.BeatName}}-{{ commit_short }}/downloads/fleet-server-{{ beat_version }}{{if .Snapshot}}-SNAPSHOT{{end}}-{{.GOOS}}-{{.AgentArchName}}.zip.sha512':
source: '{{.AgentDropPath}}/fleet-server-{{ beat_version }}{{if .Snapshot}}-SNAPSHOT{{end}}-{{.GOOS}}-{{.AgentArchName}}.zip.sha512'
mode: 0644
skip_on_missing: true
'data/{{.BeatName}}-{{ commit_short }}/downloads/fleet-server-{{ beat_version }}{{if .Snapshot}}-SNAPSHOT{{end}}-{{.GOOS}}-{{.AgentArchName}}.zip.asc':
source: '{{.AgentDropPath}}/fleet-server-{{ beat_version }}{{if .Snapshot}}-SNAPSHOT{{end}}-{{.GOOS}}-{{.AgentArchName}}.zip.asc'
mode: 0644
skip_on_missing: true

- &agent_docker_spec
<<: *agent_binary_spec
Expand Down
1 change: 1 addition & 0 deletions x-pack/elastic-agent/CHANGELOG.next.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,4 @@
- Log level reloadable from fleet {pull}22690[22690]
- Push log level downstream {pull}22815[22815]
- Add metrics collection for Agent {pull}22793[22793]
- Add support for Fleet Server {pull}23736[23736]
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,13 @@ func injectFleet(cfg *config.Config, hostInfo types.HostInfo, agentInfo *info.Ag
transpiler.NewKey("id", transpiler.NewStrVal(hostInfo.UniqueID)),
}))

fleet := transpiler.NewDict([]transpiler.Node{agent, token, kbn, host})
nodes := []transpiler.Node{agent, token, kbn, host}
server, ok := transpiler.Lookup(ast, "fleet.server")
if ok {
nodes = append(nodes, server)
}
fleet := transpiler.NewDict(nodes)

err = transpiler.Insert(rootAst, fleet, "fleet")
if err != nil {
return err
Expand Down
4 changes: 2 additions & 2 deletions x-pack/elastic-agent/pkg/agent/program/program_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -384,8 +384,8 @@ func TestConfiguration(t *testing.T) {
err bool
}{
"single_config": {
programs: []string{"filebeat", "heartbeat", "metricbeat", "endpoint", "packetbeat"},
expected: 5,
programs: []string{"filebeat", "fleet-server", "heartbeat", "metricbeat", "endpoint", "packetbeat"},
expected: 6,
},
// "audit_config": {
// programs: []string{"auditbeat"},
Expand Down
3 changes: 2 additions & 1 deletion x-pack/elastic-agent/pkg/agent/program/supported.go

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

Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
fleet:
agent:
id: fleet-agent-id

output:
elasticsearch:
hosts: [ 127.0.0.1:9200, 127.0.0.1:9300 ]
username: fleet
password: fleetpassword

inputs:
- id: fleet-server-id
type: fleet-server
11 changes: 11 additions & 0 deletions x-pack/elastic-agent/pkg/agent/program/testdata/single_config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ fleet:
protocol: https
host: localhost:5601
timeout: 30s
server:
output:
elasticsearch:
hosts: [ 127.0.0.1:9200, 127.0.0.1:9300 ]
username: fleet
password: fleetpassword

outputs:
default:
Expand All @@ -25,6 +31,11 @@ outputs:
ca_sha256: "7lHLiyp4J8m9kw38SJ7SURJP4bXRZv/BNxyyXkCcE/M="

inputs:
- id: fleet-server-id
type: fleet-server
use_output: default
data_stream:
type: default
- type: docker/metrics
use_output: default
streams:
Expand Down
61 changes: 5 additions & 56 deletions x-pack/elastic-agent/pkg/core/app/descriptor.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
package app

import (
"path"
"path/filepath"
"strings"

Expand All @@ -29,7 +28,7 @@ func NewDescriptor(spec program.Spec, version string, config *artifact.Config, t
spec: spec,
directory: dir,
executionCtx: NewExecutionContext(spec.ServicePort, spec.Cmd, version, tags),
process: specification(dir, spec.Cmd),
process: specification(dir, spec),
}
}

Expand Down Expand Up @@ -78,23 +77,12 @@ func (p *Descriptor) Directory() string {
return p.directory
}

func defaultSpec(dir string, binaryName string) ProcessSpec {
if !isKnownBeat(binaryName) {
return ProcessSpec{
BinaryPath: path.Join(dir, binaryName),
}
}

func specification(dir string, spec program.Spec) ProcessSpec {
return ProcessSpec{
BinaryPath: path.Join(dir, binaryName),
Args: []string{},
BinaryPath: filepath.Join(dir, spec.Cmd),
Args: spec.Args,
Configuration: nil,
}

}

func specification(directory, binaryName string) ProcessSpec {
defaultSpec := defaultSpec(directory, binaryName)
return populateSpec(directory, binaryName, defaultSpec)
}

func directory(spec program.Spec, version string, config *artifact.Config) string {
Expand All @@ -114,42 +102,3 @@ func directory(spec program.Spec, version string, config *artifact.Config) strin

return strings.TrimSuffix(path, suffix)
}

func isKnownBeat(name string) bool {
switch name {
case "filebeat":
fallthrough
case "metricbeat":
return true
}

return false
}

func populateSpec(dir, binaryName string, spec ProcessSpec) ProcessSpec {
var programSpec program.Spec
var found bool
binaryName = strings.ToLower(binaryName)
for _, prog := range program.Supported {
if binaryName != strings.ToLower(prog.Name) {
continue
}
found = true
programSpec = prog
break
}

if !found {
return spec
}

if programSpec.Cmd != "" {
spec.BinaryPath = filepath.Join(dir, programSpec.Cmd)
}

if len(programSpec.Args) > 0 {
spec.Args = programSpec.Args
}

return spec
}
2 changes: 2 additions & 0 deletions x-pack/elastic-agent/spec/endpoint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ rules:
key: access_api_key
- remove_key:
key: kibana
- remove_key:
key: server

- filter:
selectors:
Expand Down
61 changes: 61 additions & 0 deletions x-pack/elastic-agent/spec/fleet-server.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
name: Fleet Server
cmd: fleet-server
args: ["--agent-mode"]
artifact: fleet-server
rules:
- fix_stream: {}

- filter_values:
selector: inputs
key: type
values:
- fleet-server

- filter_values:
selector: inputs
key: enabled
values:
- true

- remove_key:
key: output

- select_into:
selectors: [ fleet.server.output.elasticsearch ]
path: output

- map:
path: fleet
rules:
- remove_key:
key: enabled
- remove_key:
key: access_api_key
- remove_key:
key: kibana
- remove_key:
key: reporting
- remove_key:
key: server

- map:
path: inputs
rules:
- remove_key:
key: use_output
- remove_key:
key: data_stream
- remove_key:
key: data_stream.namespace
- remove_key:
key: data_stream.dataset
- remove_key:
key: streams

- filter:
selectors:
- fleet
- inputs
- output

when: length(${fleet}) > 0 and length(${inputs}) > 0 and hasKey(${output}, 'elasticsearch')

0 comments on commit d59f780

Please sign in to comment.