Skip to content

Commit 72df5e5

Browse files
authored
Intoduce SkipAddHostName setting. (#10728)
fixes #apm-server/1846
1 parent 1eba952 commit 72df5e5

5 files changed

Lines changed: 63 additions & 4 deletions

File tree

CHANGELOG-developer.next.asciidoc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,4 @@ The list below covers the major changes between 7.0.0-alpha2 and master only.
3434
- Introduce ILM and IndexManagement support to beat.Settings. {pull}10347[10347]
3535
- Generating index pattern on demand instead of shipping them in the packages. {pull}10478[10478]
3636
- Metricset generator generates beta modules by default now. {pull}10657[10657]
37+
- Move host name addition to a processor. {pull}10728[10728]

libbeat/beat/pipeline.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,10 @@ type ClientConfig struct {
8080
// To skip adding that metadata set this to true.
8181
SkipAgentMetadata bool
8282

83+
// By default events are decorated with a host name.
84+
// To skip adding that host.name set this to true.
85+
SkipHostName bool
86+
8387
// ACK handler strategies.
8488
// Note: ack handlers are run in another go-routine owned by the publisher pipeline.
8589
// They should not block for to long, to not block the internal buffers for

libbeat/publisher/pipeline/module.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,6 @@ func Load(
8585
Annotations: Annotations{
8686
Event: config.EventMetadata,
8787
Builtin: common.MapStr{
88-
"host": common.MapStr{
89-
"name": name,
90-
},
9188
"ecs": common.MapStr{
9289
"version": "1.0.0-beta2",
9390
},

libbeat/publisher/pipeline/processor.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,12 +127,17 @@ func newProcessorPipeline(
127127
processors.add(actions.NewAddFields(meta, needsCopy))
128128
}
129129

130-
// setup 7: add agent metadata
130+
// setup 7: add agent metadata and host name
131131
if !config.SkipAgentMetadata {
132132
needsCopy := global.alwaysCopy || global.processors != nil
133133
processors.add(actions.NewAddFields(createAgentFields(info), needsCopy))
134134
}
135135

136+
if !config.SkipHostName {
137+
needsCopy := global.alwaysCopy || global.processors != nil
138+
processors.add(actions.NewAddFields(addHostName(info), needsCopy))
139+
}
140+
136141
// setup 8: pipeline processors list
137142
processors.add(global.processors)
138143

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

291+
func addHostName(info beat.Info) common.MapStr {
292+
return common.MapStr{"host": common.MapStr{"name": info.Name}}
293+
}
294+
286295
func debugPrintProcessor(info beat.Info, monitors Monitors) *processorFn {
287296
// ensure only one go-routine is using the encoder (in case
288297
// beat.Client is shared between multiple go-routines by accident)

libbeat/publisher/pipeline/processor_test.go

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ func TestProcessors(t *testing.T) {
3838
events []common.MapStr
3939
expected []common.MapStr
4040
includeAgentMetadata bool
41+
includeHostName bool
4142
}
4243

4344
tests := []struct {
@@ -148,6 +149,52 @@ func TestProcessors(t *testing.T) {
148149
},
149150
},
150151
},
152+
{
153+
name: "add host name",
154+
global: pipelineProcessors{
155+
fields: common.MapStr{"global": 1, "host": common.MapStr{"name": "host123"}},
156+
},
157+
info: &beat.Info{
158+
Hostname: "test.host.hostname",
159+
Name: "test.host.name",
160+
},
161+
local: []local{
162+
{
163+
config: beat.ClientConfig{},
164+
events: []common.MapStr{{"value": "abc"}},
165+
expected: []common.MapStr{
166+
{
167+
"host": common.MapStr{"name": "test.host.name"},
168+
"value": "abc", "global": 1,
169+
},
170+
},
171+
includeHostName: true,
172+
},
173+
},
174+
},
175+
{
176+
name: "add host name to existing host",
177+
global: pipelineProcessors{
178+
fields: common.MapStr{"global": 1, "host": common.MapStr{"name": "host123"}},
179+
},
180+
info: &beat.Info{
181+
Hostname: "test.host.hostname",
182+
Name: "test.host.name",
183+
},
184+
local: []local{
185+
{
186+
config: beat.ClientConfig{},
187+
events: []common.MapStr{{"value": "abc", "host": common.MapStr{"hostname": "test.other.hostname"}}},
188+
expected: []common.MapStr{
189+
{
190+
"host": common.MapStr{"name": "test.host.name", "hostname": "test.other.hostname"},
191+
"value": "abc", "global": 1,
192+
},
193+
},
194+
includeHostName: true,
195+
},
196+
},
197+
},
151198
{
152199
name: "beat local fields",
153200
local: []local{
@@ -393,6 +440,7 @@ func TestProcessors(t *testing.T) {
393440
}
394441
for i, local := range test.local {
395442
local.config.SkipAgentMetadata = !local.includeAgentMetadata
443+
local.config.SkipHostName = !local.includeHostName
396444
programs[i] = newProcessorPipeline(info, monitors, test.global, local.config)
397445
}
398446

0 commit comments

Comments
 (0)