Skip to content

Commit

Permalink
Allow kubernetes discoverer to use gRPC destinations
Browse files Browse the repository at this point in the history
Summary
I updated the kubnetes discoverer to look for veneur global containers with a grpc port name. This will allow us to specify that we are using gRPC.
Additionally, I removed the http:// prefix in the saved podIp because it hits a "too many colons in address" error with gRPC. This will still work with forwarding with http because in proxy.go, the doPost method will check and append it if its missing.
This PR is related to issue stripe#762 as it removes the http hard coding.

Motivation
In Kubernetes we want to proxy metrics to veneur global with gRPC. This edit in our fork fixed the issues we were hitting.

Test plan
Ran this in our veneur-proxy pods that utilize this Kubernetes discoverer code with gRPC to verify everything works.

Rollout/monitoring/revert plan
This change should be backwards compatible as the doPost function for http communication prepends the necessary prefix. This only affects gRPC destinations used by proxysrv which shouldn't have been available with kubernetes.
  • Loading branch information
andrewhan-square committed Mar 18, 2021
1 parent db69209 commit f016f9f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
* A gRPC server that listens for SSF spans and dogstatsd metrics on grpc_listening_addresses. Thanks [eriwo-stripe](https://github.com/eriwo-stripe) and [shrivu-stripe](https://github.com/shrivu-stripe)!
* The ability to emit metrics from veneur-emit via the gRPC protocol as well as the option to specify a proxy for those metrics. Thanks [eriwo-stripe](https://github.com/eriwo-stripe) and [shrivu-stripe](https://github.com/shrivu-stripe)!
* The "veneur.listen.received_per_protocol_total" metric to be published by global Veneur instances. This is a counter to track the metrics being directly listened for (rather than imported) by protocol. Thanks, [eriwo-stripe](https://github.com/eriwo-stripe)!
* A fix for forwarding metrics with gRPC using the kubernetes discoverer. Thanks, [androohan](https://github.com/androohan)!

# 14.0.0, 2020-01-14

Expand Down
9 changes: 7 additions & 2 deletions kubernetes.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,12 @@ func (kd *KubernetesDiscoverer) GetDestinationsForService(serviceName string) ([
if len(pod.Spec.Containers) > 0 {
for _, container := range pod.Spec.Containers {
for _, port := range container.Ports {
if port.Name == "grpc" {
forwardPort = strconv.Itoa(int(port.ContainerPort))
log.WithField("port", forwardPort).Debug("Found grpc port")
break
}

if port.Name == "http" {
forwardPort = strconv.Itoa(int(port.ContainerPort))
log.WithField("port", forwardPort).Debug("Found http port")
Expand Down Expand Up @@ -83,8 +89,7 @@ func (kd *KubernetesDiscoverer) GetDestinationsForService(serviceName string) ([
continue
}

// prepend with // so that it is a valid URL parseable by url.Parse
podIp := fmt.Sprintf("http://%s:%s", pod.Status.PodIP, forwardPort)
podIp := fmt.Sprintf("%s:%s", pod.Status.PodIP, forwardPort)
ips = append(ips, podIp)
}
return ips, nil
Expand Down

0 comments on commit f016f9f

Please sign in to comment.