Skip to content

Commit

Permalink
Add syslog tcplog and udplog receivers (open-telemetry#425)
Browse files Browse the repository at this point in the history
  • Loading branch information
VineethReddy02 authored Sep 13, 2021
1 parent 70f382a commit bebff50
Showing 1 changed file with 38 additions and 5 deletions.
43 changes: 38 additions & 5 deletions pkg/collector/parser/receiver.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,18 +73,42 @@ func IsRegistered(name string) bool {
return ok
}

var (
endpointKey = "endpoint"
listenAddressKey = "listen_address"
)

func singlePortFromConfigEndpoint(logger logr.Logger, name string, config map[interface{}]interface{}) *v1.ServicePort {
endpoint, ok := config["endpoint"]
if !ok {
logger.V(2).Info("receiver doesn't have an endpoint")
return nil
var endpoint interface{}
switch {
// syslog receiver contains the endpoint
// that needs to be exposed one level down inside config
// i.e. either in tcp or udp section with field key
// as `listen_address`
case name == "syslog":
var c map[interface{}]interface{}
if udp, isUDP := config["udp"]; isUDP && udp != nil {
c = udp.(map[interface{}]interface{})
endpoint = getAddressFromConfig(logger, name, listenAddressKey, c)
} else if tcp, isTCP := config["tcp"]; isTCP && tcp != nil {
c = tcp.(map[interface{}]interface{})
endpoint = getAddressFromConfig(logger, name, listenAddressKey, c)
}

// tcplog and udplog receivers hold the endpoint
// value in `listen_address` field
case name == "tcplog" || name == "udplog":
endpoint = getAddressFromConfig(logger, name, listenAddressKey, config)

default:
endpoint = getAddressFromConfig(logger, name, endpointKey, config)
}

switch endpoint := endpoint.(type) {
case string:
port, err := portFromEndpoint(endpoint)
if err != nil {
logger.WithValues("endpoint", endpoint).Info("couldn't parse the endpoint's port")
logger.WithValues(endpointKey, endpoint).Info("couldn't parse the endpoint's port")
return nil
}

Expand All @@ -99,6 +123,15 @@ func singlePortFromConfigEndpoint(logger logr.Logger, name string, config map[in
return nil
}

func getAddressFromConfig(logger logr.Logger, name, key string, config map[interface{}]interface{}) interface{} {
endpoint, ok := config[key]
if !ok {
logger.V(2).Info("%s receiver doesn't have an %s", name, key)
return nil
}
return endpoint
}

func portName(receiverName string, port int32) string {
if len(receiverName) > 63 {
return fmt.Sprintf("port-%d", port)
Expand Down

0 comments on commit bebff50

Please sign in to comment.