Skip to content

Commit

Permalink
Intoduce SkipAddHostName setting. (elastic#10728)
Browse files Browse the repository at this point in the history
fixes #apm-server/1846
  • Loading branch information
simitt authored Feb 15, 2019
1 parent 1eba952 commit 72df5e5
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG-developer.next.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,4 @@ The list below covers the major changes between 7.0.0-alpha2 and master only.
- Introduce ILM and IndexManagement support to beat.Settings. {pull}10347[10347]
- Generating index pattern on demand instead of shipping them in the packages. {pull}10478[10478]
- Metricset generator generates beta modules by default now. {pull}10657[10657]
- Move host name addition to a processor. {pull}10728[10728]
4 changes: 4 additions & 0 deletions libbeat/beat/pipeline.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,10 @@ type ClientConfig struct {
// To skip adding that metadata set this to true.
SkipAgentMetadata bool

// By default events are decorated with a host name.
// To skip adding that host.name set this to true.
SkipHostName bool

// ACK handler strategies.
// Note: ack handlers are run in another go-routine owned by the publisher pipeline.
// They should not block for to long, to not block the internal buffers for
Expand Down
3 changes: 0 additions & 3 deletions libbeat/publisher/pipeline/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,6 @@ func Load(
Annotations: Annotations{
Event: config.EventMetadata,
Builtin: common.MapStr{
"host": common.MapStr{
"name": name,
},
"ecs": common.MapStr{
"version": "1.0.0-beta2",
},
Expand Down
11 changes: 10 additions & 1 deletion libbeat/publisher/pipeline/processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,12 +127,17 @@ func newProcessorPipeline(
processors.add(actions.NewAddFields(meta, needsCopy))
}

// setup 7: add agent metadata
// setup 7: add agent metadata and host name
if !config.SkipAgentMetadata {
needsCopy := global.alwaysCopy || global.processors != nil
processors.add(actions.NewAddFields(createAgentFields(info), needsCopy))
}

if !config.SkipHostName {
needsCopy := global.alwaysCopy || global.processors != nil
processors.add(actions.NewAddFields(addHostName(info), needsCopy))
}

// setup 8: pipeline processors list
processors.add(global.processors)

Expand Down Expand Up @@ -283,6 +288,10 @@ func createAgentFields(info beat.Info) common.MapStr {
return common.MapStr{"agent": metadata}
}

func addHostName(info beat.Info) common.MapStr {
return common.MapStr{"host": common.MapStr{"name": info.Name}}
}

func debugPrintProcessor(info beat.Info, monitors Monitors) *processorFn {
// ensure only one go-routine is using the encoder (in case
// beat.Client is shared between multiple go-routines by accident)
Expand Down
48 changes: 48 additions & 0 deletions libbeat/publisher/pipeline/processor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ func TestProcessors(t *testing.T) {
events []common.MapStr
expected []common.MapStr
includeAgentMetadata bool
includeHostName bool
}

tests := []struct {
Expand Down Expand Up @@ -148,6 +149,52 @@ func TestProcessors(t *testing.T) {
},
},
},
{
name: "add host name",
global: pipelineProcessors{
fields: common.MapStr{"global": 1, "host": common.MapStr{"name": "host123"}},
},
info: &beat.Info{
Hostname: "test.host.hostname",
Name: "test.host.name",
},
local: []local{
{
config: beat.ClientConfig{},
events: []common.MapStr{{"value": "abc"}},
expected: []common.MapStr{
{
"host": common.MapStr{"name": "test.host.name"},
"value": "abc", "global": 1,
},
},
includeHostName: true,
},
},
},
{
name: "add host name to existing host",
global: pipelineProcessors{
fields: common.MapStr{"global": 1, "host": common.MapStr{"name": "host123"}},
},
info: &beat.Info{
Hostname: "test.host.hostname",
Name: "test.host.name",
},
local: []local{
{
config: beat.ClientConfig{},
events: []common.MapStr{{"value": "abc", "host": common.MapStr{"hostname": "test.other.hostname"}}},
expected: []common.MapStr{
{
"host": common.MapStr{"name": "test.host.name", "hostname": "test.other.hostname"},
"value": "abc", "global": 1,
},
},
includeHostName: true,
},
},
},
{
name: "beat local fields",
local: []local{
Expand Down Expand Up @@ -393,6 +440,7 @@ func TestProcessors(t *testing.T) {
}
for i, local := range test.local {
local.config.SkipAgentMetadata = !local.includeAgentMetadata
local.config.SkipHostName = !local.includeHostName
programs[i] = newProcessorPipeline(info, monitors, test.global, local.config)
}

Expand Down

0 comments on commit 72df5e5

Please sign in to comment.