Skip to content

Commit

Permalink
Skip service port for scraper receivers (#1866)
Browse files Browse the repository at this point in the history
* Skip service port for scraper receivers

* Update list

* Add map for lookups

* Update pkg/collector/parser/receiver.go

* Add CHANGELOG entry

* fix lint
  • Loading branch information
srikanthccv authored Jul 6, 2023
1 parent a133f82 commit 7ccefde
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 6 deletions.
16 changes: 16 additions & 0 deletions .chloggen/service-ports.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
change_type: bug_fix

# The name of the component, or a single word describing the area of concern, (e.g. operator, target allocator, github action)
component: receivers

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: Skip service port for scraper receivers

# One or more tracking issues related to the change
issues: [1866]

# (Optional) One or more lines of additional information to render under the primary note.
# These lines will be padded with 2 spaces and then inserted directly into the document.
# Use pipe (|) for multiline entries.
subtext:
45 changes: 39 additions & 6 deletions pkg/collector/parser/receiver.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,45 @@ func IsRegistered(name string) bool {
var (
endpointKey = "endpoint"
listenAddressKey = "listen_address"
scraperReceivers = map[string]struct{}{
"prometheus": {},
"kubeletstats": {},
"sshcheck": {},
"cloudfoundry": {},
"vcenter": {},
"oracledb": {},
"snmp": {},
"googlecloudpubsub": {},
"chrony": {},
"jmx": {},
"podman_stats": {},
"pulsar": {},
"docker_stats": {},
"aerospike": {},
"zookeeper": {},
"prometheus_simple": {},
"saphana": {},
"riak": {},
"redis": {},
"rabbitmq": {},
"purefb": {},
"postgresql": {},
"nsxt": {},
"nginx": {},
"mysql": {},
"memcached": {},
"httpcheck": {},
"haproxy": {},
"flinkmetrics": {},
"couchdb": {},
}
)

func isScraperReceiver(name string) bool {
_, exists := scraperReceivers[name]
return exists
}

func singlePortFromConfigEndpoint(logger logr.Logger, name string, config map[interface{}]interface{}) *v1.ServicePort {
var endpoint interface{}
switch {
Expand All @@ -101,14 +138,10 @@ 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
// ignore the 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

// ignore prometheus receiver as it has no listening endpoint
case name == "prometheus":
case isScraperReceiver(name):
return nil

default:
Expand Down
11 changes: 11 additions & 0 deletions pkg/collector/parser/receiver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,3 +147,14 @@ func (m *mockParser) Ports() ([]corev1.ServicePort, error) {
func (m *mockParser) ParserName() string {
return "__mock"
}

func TestSkipPortsForScrapers(t *testing.T) {
for receiver := range scraperReceivers {
builder := NewGenericReceiverParser(logger, receiver, map[interface{}]interface{}{
"endpoint": "0.0.0.0:42069",
})
ports, err := builder.Ports()
assert.NoError(t, err)
assert.Len(t, ports, 0)
}
}

0 comments on commit 7ccefde

Please sign in to comment.