From f5763d0541cf71f98f6b7b053dd59ee39697a361 Mon Sep 17 00:00:00 2001 From: Mritunjay Kumar Sharma Date: Tue, 14 Dec 2021 23:49:50 +0530 Subject: [PATCH] [FIX]: adds case to handle kubeletstats reciever to ignore endpoint (#558) * adds case to handle kubeletstats receiver to ignore endpoint --- pkg/collector/parser/receiver.go | 6 ++++++ pkg/collector/parser/receiver_test.go | 15 +++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/pkg/collector/parser/receiver.go b/pkg/collector/parser/receiver.go index 2fcf0209b5..fb37ae9a56 100644 --- a/pkg/collector/parser/receiver.go +++ b/pkg/collector/parser/receiver.go @@ -100,6 +100,12 @@ func singlePortFromConfigEndpoint(logger logr.Logger, name string, config map[in case name == "tcplog" || name == "udplog": endpoint = getAddressFromConfig(logger, name, listenAddressKey, config) + // ignore kubeletstats receiver as it holds the field key endpoint, and it + // is a scraper, we only expose endpoint through k8s service objects for + // receivers that aren't scrapers. + case name == "kubeletstats": + return nil + default: endpoint = getAddressFromConfig(logger, name, endpointKey, config) } diff --git a/pkg/collector/parser/receiver_test.go b/pkg/collector/parser/receiver_test.go index 10252e801b..b706987ae6 100644 --- a/pkg/collector/parser/receiver_test.go +++ b/pkg/collector/parser/receiver_test.go @@ -98,6 +98,21 @@ func TestReceiverFailsWhenPortIsntString(t *testing.T) { assert.Nil(t, p) } +func TestIgnorekubeletstatsEndpoint(t *testing.T) { + // ignore "kubeletstats" receiver endpoint field, this is special case + // as this receiver gets parsed by generic receiver parser + builder := NewGenericReceiverParser(logger, "kubeletstats", map[interface{}]interface{}{ + "endpoint": "0.0.0.0:9000", + }) + + // test + ports, err := builder.Ports() + + // verify + assert.NoError(t, err) + assert.Len(t, ports, 0) +} + func TestReceiverFallbackWhenNotRegistered(t *testing.T) { // test p := For(logger, "myreceiver", map[interface{}]interface{}{})