Skip to content

Commit

Permalink
Beat: Allow setting beat name in configuration (#12176) (#12224)
Browse files Browse the repository at this point in the history
Uses the beat name if set in the configuration file. Restores what
used to work on 7.x and perhaps prior to #9149 being introduced.

This undoes an unwanted breaking change that caused beat.name to be
ignored.

Signed-off-by: Marc Lopez Rubio <[email protected]>
Co-authored-by: kruskall <[email protected]>
(cherry picked from commit a56c605)

Co-authored-by: Marc Lopez Rubio <[email protected]>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
  • Loading branch information
mergify[bot] and marclop authored Dec 14, 2023
1 parent 4833061 commit f86688d
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 2 deletions.
1 change: 1 addition & 0 deletions changelogs/8.12.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ https://github.com/elastic/apm-server/compare/8.11\...8.12[View commits]
==== Breaking Changes
- The unsupported apm_data_stream_migration ingest pipeline has been removed {pull}12102[12102].
- "publish_ready" is always false in the "GET /" response until events are received by apm-server {pull}12150[12150]
- Reverts a breaking change that ignored the beat name. This is visible in Stack Monitoring {pull}12176[12176]

[float]
==== Bug fixes
Expand Down
6 changes: 5 additions & 1 deletion internal/beatcmd/beat.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,14 +102,18 @@ func NewBeat(args BeatParams) (*Beat, error) {
return nil, err
}

beatName := cfg.Name
if beatName == "" {
beatName = hostname
}
b := &Beat{
Beat: beat.Beat{
Info: beat.Info{
Beat: "apm-server",
ElasticLicensed: args.ElasticLicensed,
IndexPrefix: "apm-server",
Version: version.Version,
Name: hostname,
Name: beatName,
Hostname: hostname,
StartTime: time.Now(),
EphemeralID: metricreport.EphemeralID(),
Expand Down
4 changes: 3 additions & 1 deletion internal/beatcmd/beat_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ func TestRunMaxProcs(t *testing.T) {

func TestRunnerParams(t *testing.T) {
calls := make(chan RunnerParams, 1)
b := newBeat(t, "output.console.enabled: true", func(args RunnerParams) (Runner, error) {
b := newBeat(t, "output.console.enabled: true\nname: my-custom-name", func(args RunnerParams) (Runner, error) {
calls <- args
return newNopRunner(args), nil
})
Expand All @@ -86,6 +86,7 @@ func TestRunnerParams(t *testing.T) {
assert.Equal(t, "apm-server", args.Info.Beat)
assert.Equal(t, version.Version, args.Info.Version)
assert.True(t, args.Info.ElasticLicensed)
assert.Equal(t, "my-custom-name", b.Beat.Info.Name)
assert.NotZero(t, args.Info.ID)
assert.NotZero(t, args.Info.EphemeralID)
assert.NotZero(t, args.Info.FirstStart)
Expand All @@ -100,6 +101,7 @@ func TestRunnerParams(t *testing.T) {
err := args.Config.Unpack(&m)
require.NoError(t, err)
assert.Equal(t, map[string]interface{}{
"name": "my-custom-name",
"output": map[string]interface{}{
"console": map[string]interface{}{
"enabled": true,
Expand Down
4 changes: 4 additions & 0 deletions internal/beatcmd/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ type Config struct {
// APMServer holds apm-server.* configuration.
APMServer *config.C `config:"apm-server"`

// Allow overwriting beat.Info.Name. This is mainly for stack monitoring
// and reporting purposes.
Name string `config:"name"`

MaxProcs int `config:"max_procs"`
GCPercent int `config:"gc_percent"`

Expand Down

0 comments on commit f86688d

Please sign in to comment.