From 606a7d27e9f14d7bf0eec3136de04b850c7db3bd Mon Sep 17 00:00:00 2001 From: Andrea Spacca Date: Wed, 24 Nov 2021 10:15:41 +0100 Subject: [PATCH] override host on statsd metricset (#29103) * override host on statsd metricset * changelog --- CHANGELOG.next.asciidoc | 1 + metricbeat/helper/server/udp/udp.go | 4 ++++ x-pack/metricbeat/module/statsd/server/server.go | 6 ++++++ 3 files changed, 11 insertions(+) diff --git a/CHANGELOG.next.asciidoc b/CHANGELOG.next.asciidoc index 8c10a23c61d..d5d97facca2 100644 --- a/CHANGELOG.next.asciidoc +++ b/CHANGELOG.next.asciidoc @@ -372,6 +372,7 @@ https://github.com/elastic/beats/compare/v7.0.0-alpha2...master[Check the HEAD d - Preliminary AIX support {pull}27954[27954] - Register additional name for `storage` metricset in the azure module. {pull}28447[28447] - Update reference to gosigar pacakge for filesystem windows fix. {pull}28909[28909] +- Override `Host()` on statsd MetricSet {pull}29103[29103] *Packetbeat* diff --git a/metricbeat/helper/server/udp/udp.go b/metricbeat/helper/server/udp/udp.go index e19f8697519..6bec8489b46 100644 --- a/metricbeat/helper/server/udp/udp.go +++ b/metricbeat/helper/server/udp/udp.go @@ -71,6 +71,10 @@ func NewUdpServer(base mb.BaseMetricSet) (server.Server, error) { }, nil } +func (g *UdpServer) GetHost() string { + return g.udpaddr.String() +} + func (g *UdpServer) Start() error { listener, err := net.ListenUDP("udp", g.udpaddr) if err != nil { diff --git a/x-pack/metricbeat/module/statsd/server/server.go b/x-pack/metricbeat/module/statsd/server/server.go index 3e9f35d8436..b9df691b6b8 100644 --- a/x-pack/metricbeat/module/statsd/server/server.go +++ b/x-pack/metricbeat/module/statsd/server/server.go @@ -104,6 +104,12 @@ func New(base mb.BaseMetricSet) (mb.MetricSet, error) { }, nil } +// Host returns the hostname or other module specific value that identifies a +// specific host or service instance from which to collect metrics. +func (b *MetricSet) Host() string { + return b.server.(*udp.UdpServer).GetHost() +} + func buildMappings(config []StatsdMapping) (map[string]StatsdMapping, error) { mappings := make(map[string]StatsdMapping, len(config)) replacer := strings.NewReplacer(".", `\.`, "<", "(?P<", ">", ">[^.]+)")