From 6b9a6137fc32b9a2245d4713b0ca4ef4f63d6413 Mon Sep 17 00:00:00 2001 From: Marc Lopez Rubio Date: Thu, 7 Dec 2023 20:36:19 +0800 Subject: [PATCH] Beat: Allow setting beat name in configuration (#12176) 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 Co-authored-by: kruskall <99559985+kruskall@users.noreply.github.com> (cherry picked from commit a56c6054df6743aeb49b136c98564322eeee70ca) # Conflicts: # changelogs/head.asciidoc --- changelogs/head.asciidoc | 28 ++++++++++++++++++++++++++++ internal/beatcmd/beat.go | 6 +++++- internal/beatcmd/beat_test.go | 4 +++- internal/beatcmd/config.go | 4 ++++ 4 files changed, 40 insertions(+), 2 deletions(-) create mode 100644 changelogs/head.asciidoc diff --git a/changelogs/head.asciidoc b/changelogs/head.asciidoc new file mode 100644 index 00000000000..37ff7d0ef18 --- /dev/null +++ b/changelogs/head.asciidoc @@ -0,0 +1,28 @@ +[[release-notes-head]] +== APM version HEAD + +https://github.com/elastic/apm-server/compare/8.11\...main[View commits] + +[float] +==== 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 +- Switch built-in ILM rollover policies from max_size to max_primary_shard_size {pull}11729[11729]. + +[float] +==== Deprecations + +[float] +==== Intake API Changes + +[float] +==== Added +- Update container base image to Ubuntu 22.04 {pull}11778[11778] +- Add support for returning partial success response in OTLP input {pull}11883[11883] +- Setting event timestamp from OTel observed timestamp when needed {pull}11935[11935] +- Field mappings have been added for various formerly unindexed fields {pull}12102[12102] +- We now assert that index templates are installed by attempting to create data streams {pull}12150[12150] diff --git a/internal/beatcmd/beat.go b/internal/beatcmd/beat.go index 2ce87c017ec..ce9fd5e7b6e 100644 --- a/internal/beatcmd/beat.go +++ b/internal/beatcmd/beat.go @@ -102,6 +102,10 @@ func NewBeat(args BeatParams) (*Beat, error) { return nil, err } + beatName := cfg.Name + if beatName == "" { + beatName = hostname + } b := &Beat{ Beat: beat.Beat{ Info: beat.Info{ @@ -109,7 +113,7 @@ func NewBeat(args BeatParams) (*Beat, error) { ElasticLicensed: args.ElasticLicensed, IndexPrefix: "apm-server", Version: version.Version, - Name: hostname, + Name: beatName, Hostname: hostname, StartTime: time.Now(), EphemeralID: metricreport.EphemeralID(), diff --git a/internal/beatcmd/beat_test.go b/internal/beatcmd/beat_test.go index e676b645464..9285a018ae5 100644 --- a/internal/beatcmd/beat_test.go +++ b/internal/beatcmd/beat_test.go @@ -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 }) @@ -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) @@ -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, diff --git a/internal/beatcmd/config.go b/internal/beatcmd/config.go index 48f76db5f9d..8b84263e6ca 100644 --- a/internal/beatcmd/config.go +++ b/internal/beatcmd/config.go @@ -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"`